Files
LuaScript/src/main/java/org/openautonomousconnection/luascript/hosts/DomHost.java

150 lines
3.6 KiB
Java
Raw Normal View History

2026-01-16 21:47:04 +01:00
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
2026-01-16 21:53:46 +01:00
* @param text text
2026-01-16 21:47:04 +01:00
*/
void setTextContent(String elementId, String text);
/**
* Gets a single attribute or null if missing.
*
* @param elementId element id
2026-01-16 21:53:46 +01:00
* @param name attribute name
2026-01-16 21:47:04 +01:00
* @return value or null
*/
String getAttribute(String elementId, String name);
/**
* Sets an attribute (creates it if missing).
*
* @param elementId element id
2026-01-16 21:53:46 +01:00
* @param name attribute name
* @param value attribute value
2026-01-16 21:47:04 +01:00
*/
void setAttribute(String elementId, String name, String value);
/**
* Removes an attribute.
*
* @param elementId element id
2026-01-16 21:53:46 +01:00
* @param name attribute name
2026-01-16 21:47:04 +01:00
*/
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.
*
2026-01-16 21:53:46 +01:00
* @param tagName tag name
2026-01-16 21:47:04 +01:00
* @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
2026-01-16 21:53:46 +01:00
* @param childId child id
2026-01-16 21:47:04 +01:00
*/
void appendChild(String parentId, String childId);
/**
* Inserts child before an existing direct child.
*
2026-01-16 21:53:46 +01:00
* @param parentId parent id
* @param childId child id
2026-01-16 21:47:04 +01:00
* @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);
}