Finished
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package org.openautonomousconnection.luascript.fx;
|
||||
|
||||
import javafx.scene.web.WebEngine;
|
||||
import org.openautonomousconnection.luascript.fx.FxThreadBridge;
|
||||
import org.openautonomousconnection.luascript.hosts.DomHost;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
@@ -30,6 +29,54 @@ public final class FxDomHost implements DomHost {
|
||||
this.engine = Objects.requireNonNull(engine, "engine");
|
||||
}
|
||||
|
||||
private static boolean hasUsableId(Element el) {
|
||||
String id = el.getAttribute("id");
|
||||
return id != null && !id.isBlank();
|
||||
}
|
||||
|
||||
private static Element ensureStagingContainer(Document doc) {
|
||||
Element body = (Element) doc.getElementsByTagName("body").item(0);
|
||||
if (body == null) throw new IllegalStateException("No <body> element available");
|
||||
|
||||
Element staging = doc.getElementById("__oac_staging");
|
||||
if (staging != null) return staging;
|
||||
|
||||
staging = doc.createElement("div");
|
||||
staging.setAttribute("id", "__oac_staging");
|
||||
staging.setAttribute("style", "display:none !important;");
|
||||
body.appendChild(staging);
|
||||
return staging;
|
||||
}
|
||||
|
||||
private static boolean hasClassToken(String classAttr, String cls) {
|
||||
String[] parts = classAttr.trim().split("\\s+");
|
||||
for (String p : parts) {
|
||||
if (p.equals(cls)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String normalizeTag(String tagName) {
|
||||
if (tagName == null) throw new IllegalArgumentException("tagName is null");
|
||||
String t = tagName.trim().toLowerCase(Locale.ROOT);
|
||||
if (t.isEmpty()) throw new IllegalArgumentException("tagName is empty");
|
||||
return t;
|
||||
}
|
||||
|
||||
private static String normalizeAttr(String name) {
|
||||
if (name == null) throw new IllegalArgumentException("attribute name is null");
|
||||
String n = name.trim();
|
||||
if (n.isEmpty()) throw new IllegalArgumentException("attribute name is empty");
|
||||
return n;
|
||||
}
|
||||
|
||||
private static String normalizeCssIdent(String s) {
|
||||
if (s == null) throw new IllegalArgumentException("identifier is null");
|
||||
String v = s.trim();
|
||||
if (v.isEmpty()) throw new IllegalArgumentException("identifier is empty");
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures every element has a stable id.
|
||||
*/
|
||||
@@ -292,11 +339,6 @@ public final class FxDomHost implements DomHost {
|
||||
return el;
|
||||
}
|
||||
|
||||
private static boolean hasUsableId(Element el) {
|
||||
String id = el.getAttribute("id");
|
||||
return id != null && !id.isBlank();
|
||||
}
|
||||
|
||||
private String generateUniqueId(Document doc) {
|
||||
while (true) {
|
||||
String id = "__auto_" + autoIdSeq.getAndIncrement();
|
||||
@@ -304,49 +346,6 @@ public final class FxDomHost implements DomHost {
|
||||
}
|
||||
}
|
||||
|
||||
private static Element ensureStagingContainer(Document doc) {
|
||||
Element body = (Element) doc.getElementsByTagName("body").item(0);
|
||||
if (body == null) throw new IllegalStateException("No <body> element available");
|
||||
|
||||
Element staging = doc.getElementById("__oac_staging");
|
||||
if (staging != null) return staging;
|
||||
|
||||
staging = doc.createElement("div");
|
||||
staging.setAttribute("id", "__oac_staging");
|
||||
staging.setAttribute("style", "display:none !important;");
|
||||
body.appendChild(staging);
|
||||
return staging;
|
||||
}
|
||||
|
||||
private static boolean hasClassToken(String classAttr, String cls) {
|
||||
String[] parts = classAttr.trim().split("\\s+");
|
||||
for (String p : parts) {
|
||||
if (p.equals(cls)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String normalizeTag(String tagName) {
|
||||
if (tagName == null) throw new IllegalArgumentException("tagName is null");
|
||||
String t = tagName.trim().toLowerCase(Locale.ROOT);
|
||||
if (t.isEmpty()) throw new IllegalArgumentException("tagName is empty");
|
||||
return t;
|
||||
}
|
||||
|
||||
private static String normalizeAttr(String name) {
|
||||
if (name == null) throw new IllegalArgumentException("attribute name is null");
|
||||
String n = name.trim();
|
||||
if (n.isEmpty()) throw new IllegalArgumentException("attribute name is empty");
|
||||
return n;
|
||||
}
|
||||
|
||||
private static String normalizeCssIdent(String s) {
|
||||
if (s == null) throw new IllegalArgumentException("identifier is null");
|
||||
String v = s.trim();
|
||||
if (v.isEmpty()) throw new IllegalArgumentException("identifier is empty");
|
||||
return v;
|
||||
}
|
||||
|
||||
private String normalizeOrGenerateId(String requestedId, Document doc) {
|
||||
if (requestedId != null) {
|
||||
String id = requestedId.trim();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.openautonomousconnection.luascript.fx;
|
||||
|
||||
import org.openautonomousconnection.luascript.fx.FxDomHost;
|
||||
import org.openautonomousconnection.luascript.events.UiEventRegistry;
|
||||
import org.openautonomousconnection.luascript.fx.FxThreadBridge;
|
||||
import org.openautonomousconnection.luascript.hosts.EventHost;
|
||||
import org.openautonomousconnection.luascript.runtime.LuaEventRouter;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.openautonomousconnection.luascript.fx;
|
||||
|
||||
import javafx.scene.web.WebEngine;
|
||||
import org.openautonomousconnection.luascript.fx.FxDomHost;
|
||||
import org.openautonomousconnection.luascript.fx.FxThreadBridge;
|
||||
import org.openautonomousconnection.luascript.hosts.UiHost;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
@@ -30,6 +28,36 @@ public final class FxUiHost implements UiHost {
|
||||
this.dom = Objects.requireNonNull(dom, "dom");
|
||||
}
|
||||
|
||||
private static boolean hasClassToken(String classAttr, String cls) {
|
||||
String[] parts = classAttr.trim().split("\\s+");
|
||||
for (String p : parts) {
|
||||
if (p.equals(cls)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String removeCssProp(String style, String propLower) {
|
||||
if (style == null || style.isBlank()) return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String part : style.split(";")) {
|
||||
String p = part.trim();
|
||||
if (p.isEmpty()) continue;
|
||||
int idx = p.indexOf(':');
|
||||
if (idx <= 0) continue;
|
||||
|
||||
String k = p.substring(0, idx).trim().toLowerCase();
|
||||
if (k.equals(propLower)) continue;
|
||||
|
||||
if (!sb.isEmpty()) sb.append(';');
|
||||
sb.append(p);
|
||||
}
|
||||
|
||||
String out = sb.toString().trim();
|
||||
if (!out.isEmpty() && !out.endsWith(";")) out += ";";
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alert(String message) {
|
||||
// No JS: use simple JavaFX dialog-less fallback (log-style). You can replace with real Dialogs later.
|
||||
@@ -260,34 +288,4 @@ public final class FxUiHost implements UiHost {
|
||||
public long nowMillis() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private static boolean hasClassToken(String classAttr, String cls) {
|
||||
String[] parts = classAttr.trim().split("\\s+");
|
||||
for (String p : parts) {
|
||||
if (p.equals(cls)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String removeCssProp(String style, String propLower) {
|
||||
if (style == null || style.isBlank()) return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String part : style.split(";")) {
|
||||
String p = part.trim();
|
||||
if (p.isEmpty()) continue;
|
||||
int idx = p.indexOf(':');
|
||||
if (idx <= 0) continue;
|
||||
|
||||
String k = p.substring(0, idx).trim().toLowerCase();
|
||||
if (k.equals(propLower)) continue;
|
||||
|
||||
if (!sb.isEmpty()) sb.append(';');
|
||||
sb.append(p);
|
||||
}
|
||||
|
||||
String out = sb.toString().trim();
|
||||
if (!out.isEmpty() && !out.endsWith(";")) out += ";";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.openautonomousconnection.luascript.fx;
|
||||
|
||||
import javafx.scene.web.WebEngine;
|
||||
import org.openautonomousconnection.luascript.fx.FxThreadBridge;
|
||||
import org.openautonomousconnection.luascript.hosts.ResourceHost;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
||||
Reference in New Issue
Block a user