first commit

This commit is contained in:
Finn
2026-01-16 21:47:04 +01:00
commit 02d39e2303
40 changed files with 2658 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package org.openautonomousconnection.luascript.hosts;
/**
* Host capability for console logging.
*/
public interface ConsoleHost {
/** @param message message */
void info(String message);
/** @param message message */
void log(String message);
/** @param message message */
void warn(String message);
/** @param message message */
void error(String message);
/** @param message message */
void exception(String message);
}

View File

@@ -0,0 +1,150 @@
package org.openautonomousconnection.luascript.hosts;
import java.util.List;
import java.util.Map;
/**
* Host capability that exposes a DOM-like API.
*
* <p>Element identity is the (stable) element id.</p>
*/
public interface DomHost {
/**
* Returns all element ids known to the renderer (must be stable).
*
* @return list of element ids
*/
List<String> getAllElementIds();
/**
* Returns all attributes for the given element id.
*
* @param elementId element id
* @return attributes map (attributeName -> attributeValue)
*/
Map<String, String> getAttributes(String elementId);
/**
* Returns the tag name of the element (lowercase recommended), e.g. "script", "button".
*
* @param elementId element id
* @return tag name
*/
String getTagName(String elementId);
/**
* Returns the text content of an element (used for inline <script>...).
*
* @param elementId element id
* @return text content (never null)
*/
String getTextContent(String elementId);
/**
* Sets the text content of an element.
*
* @param elementId element id
* @param text text
*/
void setTextContent(String elementId, String text);
/**
* Gets a single attribute or null if missing.
*
* @param elementId element id
* @param name attribute name
* @return value or null
*/
String getAttribute(String elementId, String name);
/**
* Sets an attribute (creates it if missing).
*
* @param elementId element id
* @param name attribute name
* @param value attribute value
*/
void setAttribute(String elementId, String name, String value);
/**
* Removes an attribute.
*
* @param elementId element id
* @param name attribute name
*/
void removeAttribute(String elementId, String name);
/**
* Returns parent id or null.
*
* @param elementId element id
* @return parent id or null
*/
String getParentId(String elementId);
/**
* Returns direct children ids.
*
* @param elementId element id
* @return children ids
*/
List<String> getChildrenIds(String elementId);
/**
* Creates a new element (detached) and returns its id.
*
* @param tagName tag name
* @param requestedId optional requested id, may be null/blank for auto id
* @return created element id
*/
String createElement(String tagName, String requestedId);
/**
* Removes an element from the DOM.
*
* @param elementId element id
*/
void removeElement(String elementId);
/**
* Moves/appends child under parent.
*
* @param parentId parent id
* @param childId child id
*/
void appendChild(String parentId, String childId);
/**
* Inserts child before an existing direct child.
*
* @param parentId parent id
* @param childId child id
* @param beforeChildId existing child id
*/
void insertBefore(String parentId, String childId, String beforeChildId);
/**
* Checks if an element id exists.
*
* @param id element id
* @return true if exists
*/
boolean exists(String id);
/**
* Returns element ids by tag.
*
* @param tagName tag
* @return ids
*/
List<String> queryByTag(String tagName);
/**
* Returns element ids by class.
*
* @param className class
* @return ids
*/
List<String> queryByClass(String className);
}

View File

@@ -0,0 +1,37 @@
package org.openautonomousconnection.luascript.hosts;
/**
* Event subscription abstraction (implemented by the client UI layer).
*/
public interface EventHost {
/**
* Subscribes to an element event.
*
* @param elementId element id
* @param eventName event name (e.g. click)
*/
void addListener(String elementId, String eventName);
/**
* Unsubscribes from an element event.
*
* @param elementId element id
* @param eventName event name
*/
void removeListener(String elementId, String eventName);
/**
* Subscribes to a global event (app/window scope).
*
* @param eventName event name
*/
void addGlobalListener(String eventName);
/**
* Unsubscribes from a global event.
*
* @param eventName event name
*/
void removeGlobalListener(String eventName);
}

View File

@@ -0,0 +1,121 @@
package org.openautonomousconnection.luascript.hosts;
import java.util.Objects;
import java.util.Optional;
/**
* Service container holding optional host capabilities.
*
* <p>This avoids one huge "bridge" interface.</p>
*/
public final class HostServices {
private final ConsoleHost console;
private final DomHost dom;
private final EventHost events;
private final ResourceHost resources;
private final UiHost ui;
private HostServices(Builder b) {
this.console = b.console;
this.ui = b.ui;
this.dom = b.dom;
this.events = b.events;
this.resources = b.resources;
}
/**
* @return optional DomHost capability
*/
public Optional<DomHost> dom() {
return Optional.ofNullable(dom);
}
/**
* @return optional EventHost capability
*/
public Optional<EventHost> events() {
return Optional.ofNullable(events);
}
/**
* @return optional ResourceHost capability
*/
public Optional<ResourceHost> resources() {
return Optional.ofNullable(resources);
}
/** @return optional console host */
public Optional<ConsoleHost> console() {
return Optional.ofNullable(console);
}
/** @return optional ui host */
public Optional<UiHost> ui() {
return Optional.ofNullable(ui);
}
/** @return builder */
public static Builder builder() {
return new Builder();
}
/**
* Builder for HostServices.
*/
public static final class Builder {
private ConsoleHost console;
private DomHost dom;
private EventHost events;
private ResourceHost resources;
private UiHost ui;
public Builder console(ConsoleHost console) {
this.console = Objects.requireNonNull(console, "console");
return this;
}
public Builder ui(UiHost ui) {
this.ui = Objects.requireNonNull(ui, "ui");
return this;
}
/**
* Provides dom capability.
*
* @param dom dom host
* @return this
*/
public Builder dom(DomHost dom) {
this.dom = Objects.requireNonNull(dom, "dom");
return this;
}
/**
* Provides event subscription capability.
*
* @param events event host
* @return this
*/
public Builder events(EventHost events) {
this.events = Objects.requireNonNull(events, "events");
return this;
}
/**
* Provides resource loading capability.
*
* @param resources resource host
* @return this
*/
public Builder resources(ResourceHost resources) {
this.resources = Objects.requireNonNull(resources, "resources");
return this;
}
public HostServices build() {
return new HostServices(this);
}
}
}

View File

@@ -0,0 +1,16 @@
package org.openautonomousconnection.luascript.hosts;
/**
* Resource loading abstraction for LuaScript (e.g. script src).
*/
public interface ResourceHost {
/**
* Reads text from a script source (file/url/virtual path).
*
* @param src source identifier
* @return text content
* @throws Exception on load failures
*/
String readText(String src) throws Exception;
}

View File

@@ -0,0 +1,59 @@
package org.openautonomousconnection.luascript.hosts;
/**
* Host capability for UI operations.
*/
public interface UiHost {
void alert(String message);
boolean confirm(String message);
String prompt(String message, String defaultValue);
void setText(String elementId, String text);
String getText(String elementId);
void setHtml(String elementId, String html);
String getHtml(String elementId);
void setValue(String elementId, String value);
String getValue(String elementId);
void setEnabled(String elementId, boolean enabled);
void setVisible(String elementId, boolean visible);
void addClass(String elementId, String className);
void removeClass(String elementId, String className);
boolean toggleClass(String elementId, String className);
boolean hasClass(String elementId, String className);
void setStyle(String elementId, String property, String value);
String getStyle(String elementId, String property);
void setAttribute(String elementId, String name, String value);
String getAttribute(String elementId, String name);
void removeAttribute(String elementId, String name);
void focus(String elementId);
void blur(String elementId);
void scrollIntoView(String elementId);
int viewportWidth();
int viewportHeight();
long nowMillis();
}