-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom.as
More file actions
38 lines (34 loc) · 1.19 KB
/
Copy pathdom.as
File metadata and controls
38 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* AffineScript High-Assurance DOM Connector
* (c) 2026 hyperpolymath
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
extern type Element;
extern type Text;
extern type Event;
extern fn querySelector(selector: String) -> Option[Element];
extern fn createElement(tag: String) -> Element;
extern fn createTextNode(text: String) -> Text;
extern fn appendChild(parent: Element, child: Element) -> Void;
extern fn appendText(parent: Element, child: Text) -> Void;
extern fn setAttribute(el: Element, name: String, value: String) -> Void;
extern fn addEventListener(el: Element, event: String, callback: fn(Event) -> Void) -> Void;
// Safe mounter
pub fn mount(selector: String, root_element: Element) -> Result[Void, String] {
match querySelector(selector) {
Some(parent) -> {
appendChild(parent, root_element);
Ok(())
}
None -> Err("Target selector not found: " + selector)
}
}
// Fluent API for creating elements
pub fn h(tag: String, attrs: { id: String }, children: List[Element]) -> Element {
let el = createElement(tag);
if attrs.id != "" {
setAttribute(el, "id", attrs.id);
}
// TODO: Iterate children and append
el
}