@adaas/are-html 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.mts +194 -10
- package/dist/browser/index.mjs +696 -245
- package/dist/browser/index.mjs.map +1 -1
- package/dist/node/{AreBinding.attribute-doUvtOjc.d.mts → AreBinding.attribute-BWzEIw6H.d.mts} +45 -0
- package/dist/node/{AreBinding.attribute-Bm5LlOyE.d.ts → AreBinding.attribute-GpT-5Qmf.d.ts} +45 -0
- package/dist/node/attributes/AreBinding.attribute.d.mts +1 -1
- package/dist/node/attributes/AreBinding.attribute.d.ts +1 -1
- package/dist/node/attributes/AreDirective.attribute.d.mts +1 -1
- package/dist/node/attributes/AreDirective.attribute.d.ts +1 -1
- package/dist/node/attributes/AreEvent.attribute.d.mts +1 -1
- package/dist/node/attributes/AreEvent.attribute.d.ts +1 -1
- package/dist/node/attributes/AreStatic.attribute.d.mts +1 -1
- package/dist/node/attributes/AreStatic.attribute.d.ts +1 -1
- package/dist/node/directives/AreDirectiveFor.directive.d.mts +18 -1
- package/dist/node/directives/AreDirectiveFor.directive.d.ts +18 -1
- package/dist/node/directives/AreDirectiveFor.directive.js +57 -9
- package/dist/node/directives/AreDirectiveFor.directive.js.map +1 -1
- package/dist/node/directives/AreDirectiveFor.directive.mjs +57 -9
- package/dist/node/directives/AreDirectiveFor.directive.mjs.map +1 -1
- package/dist/node/directives/AreDirectiveIf.directive.d.mts +18 -2
- package/dist/node/directives/AreDirectiveIf.directive.d.ts +18 -2
- package/dist/node/directives/AreDirectiveIf.directive.js +29 -6
- package/dist/node/directives/AreDirectiveIf.directive.js.map +1 -1
- package/dist/node/directives/AreDirectiveIf.directive.mjs +29 -6
- package/dist/node/directives/AreDirectiveIf.directive.mjs.map +1 -1
- package/dist/node/directives/AreDirectiveShow.directive.d.mts +1 -1
- package/dist/node/directives/AreDirectiveShow.directive.d.ts +1 -1
- package/dist/node/engine/AreHTML.compiler.d.mts +4 -2
- package/dist/node/engine/AreHTML.compiler.d.ts +4 -2
- package/dist/node/engine/AreHTML.compiler.js +11 -4
- package/dist/node/engine/AreHTML.compiler.js.map +1 -1
- package/dist/node/engine/AreHTML.compiler.mjs +11 -4
- package/dist/node/engine/AreHTML.compiler.mjs.map +1 -1
- package/dist/node/engine/AreHTML.constants.d.mts +33 -1
- package/dist/node/engine/AreHTML.constants.d.ts +33 -1
- package/dist/node/engine/AreHTML.constants.js +166 -0
- package/dist/node/engine/AreHTML.constants.js.map +1 -1
- package/dist/node/engine/AreHTML.constants.mjs +165 -1
- package/dist/node/engine/AreHTML.constants.mjs.map +1 -1
- package/dist/node/engine/AreHTML.context.d.mts +66 -0
- package/dist/node/engine/AreHTML.context.d.ts +66 -0
- package/dist/node/engine/AreHTML.context.js +98 -0
- package/dist/node/engine/AreHTML.context.js.map +1 -1
- package/dist/node/engine/AreHTML.context.mjs +98 -0
- package/dist/node/engine/AreHTML.context.mjs.map +1 -1
- package/dist/node/engine/AreHTML.interpreter.d.mts +3 -0
- package/dist/node/engine/AreHTML.interpreter.d.ts +3 -0
- package/dist/node/engine/AreHTML.interpreter.js +66 -10
- package/dist/node/engine/AreHTML.interpreter.js.map +1 -1
- package/dist/node/engine/AreHTML.interpreter.mjs +66 -10
- package/dist/node/engine/AreHTML.interpreter.mjs.map +1 -1
- package/dist/node/engine/AreHTML.lifecycle.d.mts +1 -8
- package/dist/node/engine/AreHTML.lifecycle.d.ts +1 -8
- package/dist/node/engine/AreHTML.lifecycle.js +29 -44
- package/dist/node/engine/AreHTML.lifecycle.js.map +1 -1
- package/dist/node/engine/AreHTML.lifecycle.mjs +29 -44
- package/dist/node/engine/AreHTML.lifecycle.mjs.map +1 -1
- package/dist/node/engine/AreHTML.tokenizer.d.mts +1 -1
- package/dist/node/engine/AreHTML.tokenizer.d.ts +1 -1
- package/dist/node/engine/AreHTML.tokenizer.js +7 -1
- package/dist/node/engine/AreHTML.tokenizer.js.map +1 -1
- package/dist/node/engine/AreHTML.tokenizer.mjs +7 -1
- package/dist/node/engine/AreHTML.tokenizer.mjs.map +1 -1
- package/dist/node/engine/AreHTML.transformer.d.mts +1 -1
- package/dist/node/engine/AreHTML.transformer.d.ts +1 -1
- package/dist/node/index.d.mts +4 -3
- package/dist/node/index.d.ts +4 -3
- package/dist/node/index.js +7 -0
- package/dist/node/index.mjs +1 -0
- package/dist/node/instructions/AddStaticHTML.instruction.d.mts +8 -0
- package/dist/node/instructions/AddStaticHTML.instruction.d.ts +8 -0
- package/dist/node/instructions/AddStaticHTML.instruction.js +31 -0
- package/dist/node/instructions/AddStaticHTML.instruction.js.map +1 -0
- package/dist/node/instructions/AddStaticHTML.instruction.mjs +24 -0
- package/dist/node/instructions/AddStaticHTML.instruction.mjs.map +1 -0
- package/dist/node/instructions/AreHTML.instructions.constants.d.mts +1 -0
- package/dist/node/instructions/AreHTML.instructions.constants.d.ts +1 -0
- package/dist/node/instructions/AreHTML.instructions.constants.js +1 -0
- package/dist/node/instructions/AreHTML.instructions.constants.js.map +1 -1
- package/dist/node/instructions/AreHTML.instructions.constants.mjs +1 -0
- package/dist/node/instructions/AreHTML.instructions.constants.mjs.map +1 -1
- package/dist/node/instructions/AreHTML.instructions.types.d.mts +9 -1
- package/dist/node/instructions/AreHTML.instructions.types.d.ts +9 -1
- package/dist/node/lib/AreDirective/AreDirective.component.d.mts +1 -1
- package/dist/node/lib/AreDirective/AreDirective.component.d.ts +1 -1
- package/dist/node/lib/AreDirective/AreDirective.types.d.mts +1 -1
- package/dist/node/lib/AreDirective/AreDirective.types.d.ts +1 -1
- package/dist/node/lib/AreHTML/AreHTML.tokenizer.d.mts +1 -1
- package/dist/node/lib/AreHTML/AreHTML.tokenizer.d.ts +1 -1
- package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.d.mts +1 -1
- package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.d.ts +1 -1
- package/dist/node/lib/AreHTMLNode/AreHTMLNode.d.mts +1 -1
- package/dist/node/lib/AreHTMLNode/AreHTMLNode.d.ts +1 -1
- package/dist/node/lib/AreHTMLNode/AreHTMLNode.js +51 -0
- package/dist/node/lib/AreHTMLNode/AreHTMLNode.js.map +1 -1
- package/dist/node/lib/AreHTMLNode/AreHTMLNode.mjs +51 -0
- package/dist/node/lib/AreHTMLNode/AreHTMLNode.mjs.map +1 -1
- package/dist/node/lib/AreRoot/AreRoot.component.js.map +1 -1
- package/dist/node/lib/AreRoot/AreRoot.component.mjs.map +1 -1
- package/dist/node/nodes/AreComment.d.mts +1 -1
- package/dist/node/nodes/AreComment.d.ts +1 -1
- package/dist/node/nodes/AreComponent.d.mts +1 -1
- package/dist/node/nodes/AreComponent.d.ts +1 -1
- package/dist/node/nodes/AreInterpolation.d.mts +1 -1
- package/dist/node/nodes/AreInterpolation.d.ts +1 -1
- package/dist/node/nodes/AreRoot.d.mts +1 -1
- package/dist/node/nodes/AreRoot.d.ts +1 -1
- package/dist/node/nodes/AreText.d.mts +1 -1
- package/dist/node/nodes/AreText.d.ts +1 -1
- package/examples/dashboard/concept.ts +1 -1
- package/examples/dashboard/dist/index.html +1 -1
- package/examples/dashboard/dist/{mqh9ryml-xat335.js → mqiw5sqa-ypckmj.js} +403 -57
- package/examples/for-perf/dist/index.html +1 -1
- package/examples/for-perf/dist/{mqh9ryfo-6a8d0o.js → mqp8i2py-vltsx0.js} +3030 -2474
- package/examples/lazy-loading/README.md +76 -0
- package/examples/lazy-loading/concept.ts +55 -0
- package/examples/lazy-loading/containers/UI.container.ts +215 -0
- package/examples/lazy-loading/dist/app.js +3803 -0
- package/examples/{for-perf/dist/mqh9ryfq-4pf5cv.js → lazy-loading/dist/chunks/chunk-6K72IBO4.js} +2708 -5476
- package/examples/lazy-loading/dist/index.html +36 -0
- package/examples/lazy-loading/dist/lazy/about-page.js +59 -0
- package/examples/lazy-loading/dist/lazy/reports-page.js +65 -0
- package/examples/lazy-loading/dist/lazy/settings-page.js +54 -0
- package/examples/lazy-loading/public/index.html +36 -0
- package/examples/lazy-loading/src/components/AppShell.component.ts +44 -0
- package/examples/lazy-loading/src/components/HomePage.component.ts +59 -0
- package/examples/lazy-loading/src/components/LazyOutlet.component.ts +108 -0
- package/examples/lazy-loading/src/components/NavBar.component.ts +98 -0
- package/examples/lazy-loading/src/concept.ts +116 -0
- package/examples/lazy-loading/src/lazy/AboutPage.component.ts +54 -0
- package/examples/lazy-loading/src/lazy/ReportsPage.component.ts +56 -0
- package/examples/lazy-loading/src/lazy/SettingsPage.component.ts +45 -0
- package/examples/lazy-loading/src/runtime/ComponentManifest.fragment.ts +61 -0
- package/examples/lazy-loading/src/runtime/LazyComponentResolver.fragment.ts +77 -0
- package/examples/os-desktop/README.md +91 -0
- package/examples/os-desktop/concept.ts +54 -0
- package/examples/os-desktop/containers/OS.container.ts +198 -0
- package/examples/os-desktop/containers/apps/AppBackend.ts +29 -0
- package/examples/os-desktop/containers/apps/GanttApp.backend.ts +56 -0
- package/examples/os-desktop/containers/apps/MarketingApp.backend.ts +68 -0
- package/examples/os-desktop/dist/app.js +4410 -0
- package/examples/os-desktop/dist/apps/gantt/app.js +271 -0
- package/examples/os-desktop/dist/apps/marketing/app.js +346 -0
- package/examples/{for-perf/dist/mqh9ryde-m243t8.js → os-desktop/dist/chunks/chunk-6K72IBO4.js} +2708 -5476
- package/examples/os-desktop/dist/chunks/chunk-EIIGUL6N.js +30 -0
- package/examples/os-desktop/dist/chunks/chunk-WOH7L5UR.js +30 -0
- package/examples/os-desktop/dist/index.html +33 -0
- package/examples/os-desktop/public/index.html +33 -0
- package/examples/os-desktop/src/apps/gantt/GanttApp.component.ts +41 -0
- package/examples/os-desktop/src/apps/gantt/GanttChart.component.ts +126 -0
- package/examples/os-desktop/src/apps/gantt/GanttStore.ts +47 -0
- package/examples/os-desktop/src/apps/gantt/GanttToolbar.component.ts +73 -0
- package/examples/os-desktop/src/apps/gantt/index.ts +13 -0
- package/examples/os-desktop/src/apps/marketing/MarketingApp.component.ts +53 -0
- package/examples/os-desktop/src/apps/marketing/MarketingStore.ts +34 -0
- package/examples/os-desktop/src/apps/marketing/PostEditor.component.ts +153 -0
- package/examples/os-desktop/src/apps/marketing/PostPreview.component.ts +110 -0
- package/examples/os-desktop/src/apps/marketing/index.ts +16 -0
- package/examples/os-desktop/src/concept.ts +126 -0
- package/examples/os-desktop/src/os/AppStage.component.ts +112 -0
- package/examples/os-desktop/src/os/AppWindow.component.ts +102 -0
- package/examples/os-desktop/src/os/Desktop.component.ts +106 -0
- package/examples/os-desktop/src/os/Dock.component.ts +174 -0
- package/examples/os-desktop/src/os/Hud.component.ts +83 -0
- package/examples/os-desktop/src/os/Launchpad.component.ts +191 -0
- package/examples/os-desktop/src/os/MenuBar.component.ts +156 -0
- package/examples/os-desktop/src/runtime/AppComponentResolver.fragment.ts +121 -0
- package/examples/os-desktop/src/runtime/AppRegistry.fragment.ts +104 -0
- package/examples/os-desktop/src/signals/MouseState.signal.ts +34 -0
- package/examples/os-desktop/src/signals/OSRoute.signal.ts +37 -0
- package/examples/os-desktop/src/signals/SelectionState.signal.ts +34 -0
- package/examples/signal-routing/dist/index.html +1 -1
- package/examples/signal-routing/dist/{mqh9ryc9-dkcbkx.js → mqp8hgce-4d6rh0.js} +3196 -2640
- package/package.json +13 -9
- package/src/directives/AreDirectiveFor.directive.ts +99 -16
- package/src/directives/AreDirectiveIf.directive.ts +33 -4
- package/src/engine/AreHTML.compiler.ts +25 -2
- package/src/engine/AreHTML.constants.ts +142 -0
- package/src/engine/AreHTML.context.ts +112 -0
- package/src/engine/AreHTML.interpreter.ts +114 -13
- package/src/engine/AreHTML.lifecycle.ts +81 -74
- package/src/engine/AreHTML.tokenizer.ts +30 -1
- package/src/index.ts +1 -0
- package/src/instructions/AddStaticHTML.instruction.ts +23 -0
- package/src/instructions/AreHTML.instructions.constants.ts +1 -0
- package/src/instructions/AreHTML.instructions.types.ts +9 -0
- package/src/lib/AreHTMLNode/AreHTMLNode.ts +74 -0
- package/src/lib/AreRoot/AreRoot.component.ts +3 -3
- package/tests/PropPropagation.test.ts +181 -0
- package/tests/StaticIsland.test.ts +115 -0
- package/tests/jest.setup.ts +11 -0
|
@@ -44,8 +44,74 @@ declare class AreHTMLEngineContext extends AreContext {
|
|
|
44
44
|
* The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.
|
|
45
45
|
*/
|
|
46
46
|
protected _container: Document;
|
|
47
|
+
/**
|
|
48
|
+
* Parsed-fragment cache for static islands (see AddStaticHTMLInstruction).
|
|
49
|
+
*
|
|
50
|
+
* Keyed by `hostTag\u0000markup`, each entry holds a `DocumentFragment` whose
|
|
51
|
+
* children were parsed by the browser exactly once — in the *correct element
|
|
52
|
+
* context* (the host tag), so table fragments (`<tr>`, `<td>`, …) and other
|
|
53
|
+
* context-sensitive content parse correctly. Repeated static islands with
|
|
54
|
+
* identical markup (e.g. list rows, reused components) clone the pre-parsed
|
|
55
|
+
* fragment instead of re-parsing the HTML string on every mount — turning an
|
|
56
|
+
* O(parse) operation into an O(clone) one.
|
|
57
|
+
*/
|
|
58
|
+
protected _staticFragmentCache: Map<string, DocumentFragment>;
|
|
59
|
+
/**
|
|
60
|
+
* Live-DOM attachments deferred while a mount pass is batching.
|
|
61
|
+
*
|
|
62
|
+
* A freshly-mounted subtree is built inside a *detached* root element, so
|
|
63
|
+
* every descendant `appendChild`/`insertBefore` happens off-document and
|
|
64
|
+
* triggers zero layout/paint invalidation. The single mutation that actually
|
|
65
|
+
* connects the built subtree to the live document is deferred and collected
|
|
66
|
+
* here, then flushed once when the batch closes — collapsing O(nodes) reflows
|
|
67
|
+
* into O(1) per mount root.
|
|
68
|
+
*/
|
|
69
|
+
protected _pendingAttachments: Array<() => void>;
|
|
70
|
+
/**
|
|
71
|
+
* Depth of the currently open batching scopes. Re-entrant so that nested
|
|
72
|
+
* `beginBatch`/`endBatch` pairs flush exactly once, when the outermost scope
|
|
73
|
+
* closes.
|
|
74
|
+
*/
|
|
75
|
+
protected _batchDepth: number;
|
|
47
76
|
constructor(props: Partial<AreHTMLContextConstructor>);
|
|
48
77
|
get container(): Document;
|
|
78
|
+
/**
|
|
79
|
+
* `true` while a synchronous mount pass is batching live-DOM attachments.
|
|
80
|
+
* Interpreter handlers consult this to decide whether to attach an element
|
|
81
|
+
* immediately or hand the attachment to {@link deferAttach}.
|
|
82
|
+
*/
|
|
83
|
+
get isBatching(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Opens a batching scope. Re-entrant: only the outermost matching
|
|
86
|
+
* {@link endBatch} flushes the deferred attachments, so a single mount pass
|
|
87
|
+
* connects its built subtree to the live DOM exactly once.
|
|
88
|
+
*/
|
|
89
|
+
beginBatch(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Registers a live-DOM attachment to run when the current batch flushes. If
|
|
92
|
+
* no batch is active the attachment runs immediately, preserving the original
|
|
93
|
+
* synchronous behaviour for updates that mount outside a batch.
|
|
94
|
+
*
|
|
95
|
+
* @param attach the DOM mutation that connects a built subtree to the document
|
|
96
|
+
*/
|
|
97
|
+
deferAttach(attach: () => void): void;
|
|
98
|
+
/**
|
|
99
|
+
* Closes a batching scope. When the outermost scope closes, every deferred
|
|
100
|
+
* attachment runs in registration (document) order, connecting the built
|
|
101
|
+
* subtrees to the live DOM in a single pass.
|
|
102
|
+
*/
|
|
103
|
+
endBatch(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Returns a `DocumentFragment` containing the parsed form of `html`, parsed
|
|
106
|
+
* once in the context of `hostTag` (so context-sensitive content such as
|
|
107
|
+
* table rows/cells parses correctly) and cached thereafter. Callers should
|
|
108
|
+
* `cloneNode(true)` the returned fragment rather than mutating it, so the
|
|
109
|
+
* cache stays reusable.
|
|
110
|
+
*
|
|
111
|
+
* @param hostTag the tag name of the element the markup will be injected into
|
|
112
|
+
* @param html verbatim static-island inner markup
|
|
113
|
+
*/
|
|
114
|
+
getStaticFragment(hostTag: string, html: string): DocumentFragment;
|
|
49
115
|
/**
|
|
50
116
|
* Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.
|
|
51
117
|
*
|
|
@@ -52,11 +52,109 @@ exports.AreHTMLEngineContext = class AreHTMLEngineContext extends are.AreContext
|
|
|
52
52
|
*/
|
|
53
53
|
elementListeners: /* @__PURE__ */ new WeakMap()
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Parsed-fragment cache for static islands (see AddStaticHTMLInstruction).
|
|
57
|
+
*
|
|
58
|
+
* Keyed by `hostTag\u0000markup`, each entry holds a `DocumentFragment` whose
|
|
59
|
+
* children were parsed by the browser exactly once — in the *correct element
|
|
60
|
+
* context* (the host tag), so table fragments (`<tr>`, `<td>`, …) and other
|
|
61
|
+
* context-sensitive content parse correctly. Repeated static islands with
|
|
62
|
+
* identical markup (e.g. list rows, reused components) clone the pre-parsed
|
|
63
|
+
* fragment instead of re-parsing the HTML string on every mount — turning an
|
|
64
|
+
* O(parse) operation into an O(clone) one.
|
|
65
|
+
*/
|
|
66
|
+
this._staticFragmentCache = /* @__PURE__ */ new Map();
|
|
67
|
+
/**
|
|
68
|
+
* Live-DOM attachments deferred while a mount pass is batching.
|
|
69
|
+
*
|
|
70
|
+
* A freshly-mounted subtree is built inside a *detached* root element, so
|
|
71
|
+
* every descendant `appendChild`/`insertBefore` happens off-document and
|
|
72
|
+
* triggers zero layout/paint invalidation. The single mutation that actually
|
|
73
|
+
* connects the built subtree to the live document is deferred and collected
|
|
74
|
+
* here, then flushed once when the batch closes — collapsing O(nodes) reflows
|
|
75
|
+
* into O(1) per mount root.
|
|
76
|
+
*/
|
|
77
|
+
this._pendingAttachments = [];
|
|
78
|
+
/**
|
|
79
|
+
* Depth of the currently open batching scopes. Re-entrant so that nested
|
|
80
|
+
* `beginBatch`/`endBatch` pairs flush exactly once, when the outermost scope
|
|
81
|
+
* closes.
|
|
82
|
+
*/
|
|
83
|
+
this._batchDepth = 0;
|
|
55
84
|
this._container = props.container;
|
|
56
85
|
}
|
|
57
86
|
get container() {
|
|
58
87
|
return this._container;
|
|
59
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* `true` while a synchronous mount pass is batching live-DOM attachments.
|
|
91
|
+
* Interpreter handlers consult this to decide whether to attach an element
|
|
92
|
+
* immediately or hand the attachment to {@link deferAttach}.
|
|
93
|
+
*/
|
|
94
|
+
get isBatching() {
|
|
95
|
+
return this._batchDepth > 0;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Opens a batching scope. Re-entrant: only the outermost matching
|
|
99
|
+
* {@link endBatch} flushes the deferred attachments, so a single mount pass
|
|
100
|
+
* connects its built subtree to the live DOM exactly once.
|
|
101
|
+
*/
|
|
102
|
+
beginBatch() {
|
|
103
|
+
this._batchDepth++;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Registers a live-DOM attachment to run when the current batch flushes. If
|
|
107
|
+
* no batch is active the attachment runs immediately, preserving the original
|
|
108
|
+
* synchronous behaviour for updates that mount outside a batch.
|
|
109
|
+
*
|
|
110
|
+
* @param attach the DOM mutation that connects a built subtree to the document
|
|
111
|
+
*/
|
|
112
|
+
deferAttach(attach) {
|
|
113
|
+
if (this._batchDepth > 0) {
|
|
114
|
+
this._pendingAttachments.push(attach);
|
|
115
|
+
} else {
|
|
116
|
+
attach();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Closes a batching scope. When the outermost scope closes, every deferred
|
|
121
|
+
* attachment runs in registration (document) order, connecting the built
|
|
122
|
+
* subtrees to the live DOM in a single pass.
|
|
123
|
+
*/
|
|
124
|
+
endBatch() {
|
|
125
|
+
if (this._batchDepth === 0) return;
|
|
126
|
+
this._batchDepth--;
|
|
127
|
+
if (this._batchDepth > 0) return;
|
|
128
|
+
const pending = this._pendingAttachments;
|
|
129
|
+
this._pendingAttachments = [];
|
|
130
|
+
for (let i = 0; i < pending.length; i++) {
|
|
131
|
+
pending[i]();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns a `DocumentFragment` containing the parsed form of `html`, parsed
|
|
136
|
+
* once in the context of `hostTag` (so context-sensitive content such as
|
|
137
|
+
* table rows/cells parses correctly) and cached thereafter. Callers should
|
|
138
|
+
* `cloneNode(true)` the returned fragment rather than mutating it, so the
|
|
139
|
+
* cache stays reusable.
|
|
140
|
+
*
|
|
141
|
+
* @param hostTag the tag name of the element the markup will be injected into
|
|
142
|
+
* @param html verbatim static-island inner markup
|
|
143
|
+
*/
|
|
144
|
+
getStaticFragment(hostTag, html) {
|
|
145
|
+
const key = `${hostTag}\0${html}`;
|
|
146
|
+
let fragment = this._staticFragmentCache.get(key);
|
|
147
|
+
if (!fragment) {
|
|
148
|
+
const container = this._container.createElement(hostTag);
|
|
149
|
+
container.innerHTML = html;
|
|
150
|
+
fragment = this._container.createDocumentFragment();
|
|
151
|
+
while (container.firstChild) {
|
|
152
|
+
fragment.appendChild(container.firstChild);
|
|
153
|
+
}
|
|
154
|
+
this._staticFragmentCache.set(key, fragment);
|
|
155
|
+
}
|
|
156
|
+
return fragment;
|
|
157
|
+
}
|
|
60
158
|
getNodeElement(node) {
|
|
61
159
|
if (typeof node === "string") {
|
|
62
160
|
return this.index.nodeToHostElements.get(node);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":["AreHTMLEngineContext","AreContext","AreDeclaration","A_Frame"],"mappings":";;;;;;;;;;;;;AASaA,4BAAA,GAAN,mCAAmCC,cAAA,CAAW;AAAA,EAgDjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE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KAAS,CAAA,EAAG,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,MAChD;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,IAC5B;AAAA,EACJ;AACJ;AAzNaF,4BAAA,GAAN,eAAA,CAAA;AAAA,EAJNG,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYH,4BAAA,CAAA","file":"AreHTML.context.js","sourcesContent":["import { AreContext, AreDeclaration, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives.'\n})\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n // Only update the host-element pointer for declaration instructions.\n // Mutations (attributes, styles, event listeners, …) produce auxiliary DOM\n // that must never overwrite the owning node's primary element in the index.\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n const byEvent = this.index.elementListeners.get(element)!;\n if (!byEvent.has(eventName)) {\n byEvent.set(eventName, new Set());\n }\n byEvent.get(eventName)!.add(listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n const set = this.index.elementListeners.get(element)?.get(eventName);\n if (!set || set.size === 0) return undefined;\n // Return the first listener for backwards compatibility.\n return set.values().next().value;\n }\n\n /**\n * Returns all listeners registered for a given element + event name.\n */\n getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void {\n const byEvent = this.index.elementListeners.get(element);\n if (!byEvent) return;\n if (listener) {\n const set = byEvent.get(eventName);\n if (set) {\n set.delete(listener);\n if (set.size === 0) byEvent.delete(eventName);\n }\n } else {\n byEvent.delete(eventName);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":["AreHTMLEngineContext","AreContext","AreDeclaration","A_Frame"],"mappings":";;;;;;;;;;;;;AASaA,4BAAA,GAAN,mCAAmCC,cAAA,CAAW;AAAA,EAgFjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE,CAAA;AAtE/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAU,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMd,kBAAA,sBAAwB,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM1C,eAAA,sBAAqB,GAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5C,oBAAA,sBAA0B,OAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMhD,oBAAA,sBAA0B,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA,MAI5C,gBAAA,sBAAsB,OAAA;AAAoE,KAC9F;AAkBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAU,oBAAA,uBAA2B,GAAA,EAA8B;AAYnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AI,OAAO,QAAQ,CAAA;AACnB,QAAA,IAAI,GAAA,CAAI,IAAA,KAAS,CAAA,EAAG,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,MAChD;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,IAC5B;AAAA,EACJ;AACJ;AAzUaF,4BAAA,GAAN,eAAA,CAAA;AAAA,EAJNG,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYH,4BAAA,CAAA","file":"AreHTML.context.js","sourcesContent":["import { AreContext, AreDeclaration, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives.'\n})\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n /**\n * Parsed-fragment cache for static islands (see AddStaticHTMLInstruction).\n *\n * Keyed by `hostTag\\u0000markup`, each entry holds a `DocumentFragment` whose\n * children were parsed by the browser exactly once — in the *correct element\n * context* (the host tag), so table fragments (`<tr>`, `<td>`, …) and other\n * context-sensitive content parse correctly. Repeated static islands with\n * identical markup (e.g. list rows, reused components) clone the pre-parsed\n * fragment instead of re-parsing the HTML string on every mount — turning an\n * O(parse) operation into an O(clone) one.\n */\n protected _staticFragmentCache = new Map<string, DocumentFragment>();\n\n /**\n * Live-DOM attachments deferred while a mount pass is batching.\n *\n * A freshly-mounted subtree is built inside a *detached* root element, so\n * every descendant `appendChild`/`insertBefore` happens off-document and\n * triggers zero layout/paint invalidation. The single mutation that actually\n * connects the built subtree to the live document is deferred and collected\n * here, then flushed once when the batch closes — collapsing O(nodes) reflows\n * into O(1) per mount root.\n */\n protected _pendingAttachments: Array<() => void> = [];\n\n /**\n * Depth of the currently open batching scopes. Re-entrant so that nested\n * `beginBatch`/`endBatch` pairs flush exactly once, when the outermost scope\n * closes.\n */\n protected _batchDepth = 0;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n /**\n * `true` while a synchronous mount pass is batching live-DOM attachments.\n * Interpreter handlers consult this to decide whether to attach an element\n * immediately or hand the attachment to {@link deferAttach}.\n */\n get isBatching(): boolean {\n return this._batchDepth > 0;\n }\n\n /**\n * Opens a batching scope. Re-entrant: only the outermost matching\n * {@link endBatch} flushes the deferred attachments, so a single mount pass\n * connects its built subtree to the live DOM exactly once.\n */\n beginBatch(): void {\n this._batchDepth++;\n }\n\n /**\n * Registers a live-DOM attachment to run when the current batch flushes. If\n * no batch is active the attachment runs immediately, preserving the original\n * synchronous behaviour for updates that mount outside a batch.\n *\n * @param attach the DOM mutation that connects a built subtree to the document\n */\n deferAttach(attach: () => void): void {\n if (this._batchDepth > 0) {\n this._pendingAttachments.push(attach);\n } else {\n attach();\n }\n }\n\n /**\n * Closes a batching scope. When the outermost scope closes, every deferred\n * attachment runs in registration (document) order, connecting the built\n * subtrees to the live DOM in a single pass.\n */\n endBatch(): void {\n if (this._batchDepth === 0) return;\n this._batchDepth--;\n if (this._batchDepth > 0) return;\n\n const pending = this._pendingAttachments;\n this._pendingAttachments = [];\n for (let i = 0; i < pending.length; i++) {\n pending[i]();\n }\n }\n\n /**\n * Returns a `DocumentFragment` containing the parsed form of `html`, parsed\n * once in the context of `hostTag` (so context-sensitive content such as\n * table rows/cells parses correctly) and cached thereafter. Callers should\n * `cloneNode(true)` the returned fragment rather than mutating it, so the\n * cache stays reusable.\n *\n * @param hostTag the tag name of the element the markup will be injected into\n * @param html verbatim static-island inner markup\n */\n getStaticFragment(hostTag: string, html: string): DocumentFragment {\n const key = `${hostTag}\\u0000${html}`;\n let fragment = this._staticFragmentCache.get(key);\n if (!fragment) {\n // Parse in the correct element context: the fragment-parsing\n // algorithm uses the container element's tag to choose the right\n // insertion mode (e.g. `<tbody>` legitimately allows `<tr>`).\n const container = this._container.createElement(hostTag);\n container.innerHTML = html;\n\n fragment = this._container.createDocumentFragment();\n while (container.firstChild) {\n fragment.appendChild(container.firstChild);\n }\n\n this._staticFragmentCache.set(key, fragment);\n }\n return fragment;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n // Only update the host-element pointer for declaration instructions.\n // Mutations (attributes, styles, event listeners, …) produce auxiliary DOM\n // that must never overwrite the owning node's primary element in the index.\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n const byEvent = this.index.elementListeners.get(element)!;\n if (!byEvent.has(eventName)) {\n byEvent.set(eventName, new Set());\n }\n byEvent.get(eventName)!.add(listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n const set = this.index.elementListeners.get(element)?.get(eventName);\n if (!set || set.size === 0) return undefined;\n // Return the first listener for backwards compatibility.\n return set.values().next().value;\n }\n\n /**\n * Returns all listeners registered for a given element + event name.\n */\n getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void {\n const byEvent = this.index.elementListeners.get(element);\n if (!byEvent) return;\n if (listener) {\n const set = byEvent.get(eventName);\n if (set) {\n set.delete(listener);\n if (set.size === 0) byEvent.delete(eventName);\n }\n } else {\n byEvent.delete(eventName);\n }\n }\n}\n"]}
|
|
@@ -43,11 +43,109 @@ let AreHTMLEngineContext = class extends AreContext {
|
|
|
43
43
|
*/
|
|
44
44
|
elementListeners: /* @__PURE__ */ new WeakMap()
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Parsed-fragment cache for static islands (see AddStaticHTMLInstruction).
|
|
48
|
+
*
|
|
49
|
+
* Keyed by `hostTag\u0000markup`, each entry holds a `DocumentFragment` whose
|
|
50
|
+
* children were parsed by the browser exactly once — in the *correct element
|
|
51
|
+
* context* (the host tag), so table fragments (`<tr>`, `<td>`, …) and other
|
|
52
|
+
* context-sensitive content parse correctly. Repeated static islands with
|
|
53
|
+
* identical markup (e.g. list rows, reused components) clone the pre-parsed
|
|
54
|
+
* fragment instead of re-parsing the HTML string on every mount — turning an
|
|
55
|
+
* O(parse) operation into an O(clone) one.
|
|
56
|
+
*/
|
|
57
|
+
this._staticFragmentCache = /* @__PURE__ */ new Map();
|
|
58
|
+
/**
|
|
59
|
+
* Live-DOM attachments deferred while a mount pass is batching.
|
|
60
|
+
*
|
|
61
|
+
* A freshly-mounted subtree is built inside a *detached* root element, so
|
|
62
|
+
* every descendant `appendChild`/`insertBefore` happens off-document and
|
|
63
|
+
* triggers zero layout/paint invalidation. The single mutation that actually
|
|
64
|
+
* connects the built subtree to the live document is deferred and collected
|
|
65
|
+
* here, then flushed once when the batch closes — collapsing O(nodes) reflows
|
|
66
|
+
* into O(1) per mount root.
|
|
67
|
+
*/
|
|
68
|
+
this._pendingAttachments = [];
|
|
69
|
+
/**
|
|
70
|
+
* Depth of the currently open batching scopes. Re-entrant so that nested
|
|
71
|
+
* `beginBatch`/`endBatch` pairs flush exactly once, when the outermost scope
|
|
72
|
+
* closes.
|
|
73
|
+
*/
|
|
74
|
+
this._batchDepth = 0;
|
|
46
75
|
this._container = props.container;
|
|
47
76
|
}
|
|
48
77
|
get container() {
|
|
49
78
|
return this._container;
|
|
50
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* `true` while a synchronous mount pass is batching live-DOM attachments.
|
|
82
|
+
* Interpreter handlers consult this to decide whether to attach an element
|
|
83
|
+
* immediately or hand the attachment to {@link deferAttach}.
|
|
84
|
+
*/
|
|
85
|
+
get isBatching() {
|
|
86
|
+
return this._batchDepth > 0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Opens a batching scope. Re-entrant: only the outermost matching
|
|
90
|
+
* {@link endBatch} flushes the deferred attachments, so a single mount pass
|
|
91
|
+
* connects its built subtree to the live DOM exactly once.
|
|
92
|
+
*/
|
|
93
|
+
beginBatch() {
|
|
94
|
+
this._batchDepth++;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Registers a live-DOM attachment to run when the current batch flushes. If
|
|
98
|
+
* no batch is active the attachment runs immediately, preserving the original
|
|
99
|
+
* synchronous behaviour for updates that mount outside a batch.
|
|
100
|
+
*
|
|
101
|
+
* @param attach the DOM mutation that connects a built subtree to the document
|
|
102
|
+
*/
|
|
103
|
+
deferAttach(attach) {
|
|
104
|
+
if (this._batchDepth > 0) {
|
|
105
|
+
this._pendingAttachments.push(attach);
|
|
106
|
+
} else {
|
|
107
|
+
attach();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Closes a batching scope. When the outermost scope closes, every deferred
|
|
112
|
+
* attachment runs in registration (document) order, connecting the built
|
|
113
|
+
* subtrees to the live DOM in a single pass.
|
|
114
|
+
*/
|
|
115
|
+
endBatch() {
|
|
116
|
+
if (this._batchDepth === 0) return;
|
|
117
|
+
this._batchDepth--;
|
|
118
|
+
if (this._batchDepth > 0) return;
|
|
119
|
+
const pending = this._pendingAttachments;
|
|
120
|
+
this._pendingAttachments = [];
|
|
121
|
+
for (let i = 0; i < pending.length; i++) {
|
|
122
|
+
pending[i]();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns a `DocumentFragment` containing the parsed form of `html`, parsed
|
|
127
|
+
* once in the context of `hostTag` (so context-sensitive content such as
|
|
128
|
+
* table rows/cells parses correctly) and cached thereafter. Callers should
|
|
129
|
+
* `cloneNode(true)` the returned fragment rather than mutating it, so the
|
|
130
|
+
* cache stays reusable.
|
|
131
|
+
*
|
|
132
|
+
* @param hostTag the tag name of the element the markup will be injected into
|
|
133
|
+
* @param html verbatim static-island inner markup
|
|
134
|
+
*/
|
|
135
|
+
getStaticFragment(hostTag, html) {
|
|
136
|
+
const key = `${hostTag}\0${html}`;
|
|
137
|
+
let fragment = this._staticFragmentCache.get(key);
|
|
138
|
+
if (!fragment) {
|
|
139
|
+
const container = this._container.createElement(hostTag);
|
|
140
|
+
container.innerHTML = html;
|
|
141
|
+
fragment = this._container.createDocumentFragment();
|
|
142
|
+
while (container.firstChild) {
|
|
143
|
+
fragment.appendChild(container.firstChild);
|
|
144
|
+
}
|
|
145
|
+
this._staticFragmentCache.set(key, fragment);
|
|
146
|
+
}
|
|
147
|
+
return fragment;
|
|
148
|
+
}
|
|
51
149
|
getNodeElement(node) {
|
|
52
150
|
if (typeof node === "string") {
|
|
53
151
|
return this.index.nodeToHostElements.get(node);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":[],"mappings":";;;;AASO,IAAM,oBAAA,GAAN,cAAmC,UAAA,CAAW;AAAA,EAgDjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE,CAAA;AAtC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAU,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMd,kBAAA,sBAAwB,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM1C,eAAA,sBAAqB,GAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5C,oBAAA,sBAA0B,OAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMhD,oBAAA,sBAA0B,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA,MAI5C,gBAAA,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A,CAAiB,IAAI,OAAO,CAAA,EAAG,IAAI,SAAS,CAAA;AACnE,IAAA,IAAI,CAAC,GAAA,IAAO,GAAA,CAAI,IAAA,KAAS,GAAG,OAAO,MAAA;AAEnC,IAAA,OAAO,GAAA,CAAI,MAAA,EAAO,CAAE,IAAA,EAAK,CAAE,KAAA;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,YAAA,CAAa,SAAe,SAAA,EAAwE;AAChG,IAAA,OAAO,KAAK,KAAA,CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA,EAAG,IAAI,SAAS,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAA,CAAe,OAAA,EAAe,SAAA,EAAmB,QAAA,EAAqD;AAClG,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA;AACvD,IAAA,IAAI,CAAC,OAAA,EAAS;AACd,IAAA,IAAI,QAAA,EAAU;AACV,MAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA;AACjC,MAAA,IAAI,GAAA,EAAK;AACL,QAAA,GAAA,CAAI,OAAO,QAAQ,CAAA;AACnB,QAAA,IAAI,GAAA,CAAI,IAAA,KAAS,CAAA,EAAG,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,MAChD;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,IAC5B;AAAA,EACJ;AACJ;AAzNa,oBAAA,GAAN,eAAA,CAAA;AAAA,EAJN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACY,oBAAA,CAAA","file":"AreHTML.context.mjs","sourcesContent":["import { AreContext, AreDeclaration, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives.'\n})\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n // Only update the host-element pointer for declaration instructions.\n // Mutations (attributes, styles, event listeners, …) produce auxiliary DOM\n // that must never overwrite the owning node's primary element in the index.\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n const byEvent = this.index.elementListeners.get(element)!;\n if (!byEvent.has(eventName)) {\n byEvent.set(eventName, new Set());\n }\n byEvent.get(eventName)!.add(listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n const set = this.index.elementListeners.get(element)?.get(eventName);\n if (!set || set.size === 0) return undefined;\n // Return the first listener for backwards compatibility.\n return set.values().next().value;\n }\n\n /**\n * Returns all listeners registered for a given element + event name.\n */\n getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void {\n const byEvent = this.index.elementListeners.get(element);\n if (!byEvent) return;\n if (listener) {\n const set = byEvent.get(eventName);\n if (set) {\n set.delete(listener);\n if (set.size === 0) byEvent.delete(eventName);\n }\n } else {\n byEvent.delete(eventName);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":[],"mappings":";;;;AASO,IAAM,oBAAA,GAAN,c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M,gBAAA,CAAiB,IAAI,OAAO,CAAA,EAAG,IAAI,SAAS,CAAA;AACnE,IAAA,IAAI,CAAC,GAAA,IAAO,GAAA,CAAI,IAAA,KAAS,GAAG,OAAO,MAAA;AAEnC,IAAA,OAAO,GAAA,CAAI,MAAA,EAAO,CAAE,IAAA,EAAK,CAAE,KAAA;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,YAAA,CAAa,SAAe,SAAA,EAAwE;AAChG,IAAA,OAAO,KAAK,KAAA,CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA,EAAG,IAAI,SAAS,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAA,CAAe,OAAA,EAAe,SAAA,EAAmB,QAAA,EAAqD;AAClG,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA;AACvD,IAAA,IAAI,CAAC,OAAA,EAAS;AACd,IAAA,IAAI,QAAA,EAAU;AACV,MAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA;AACjC,MAAA,IAAI,GAAA,EAAK;AACL,QAAA,GAAA,CAAI,OAAO,QAAQ,CAAA;AACnB,QAAA,IAAI,GAAA,CAAI,IAAA,KAAS,CAAA,EAAG,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,MAChD;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,IAC5B;AAAA,EACJ;AACJ;AAzUa,oBAAA,GAAN,eAAA,CAAA;AAAA,EAJN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACY,oBAAA,CAAA","file":"AreHTML.context.mjs","sourcesContent":["import { AreContext, AreDeclaration, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives.'\n})\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n /**\n * Parsed-fragment cache for static islands (see AddStaticHTMLInstruction).\n *\n * Keyed by `hostTag\\u0000markup`, each entry holds a `DocumentFragment` whose\n * children were parsed by the browser exactly once — in the *correct element\n * context* (the host tag), so table fragments (`<tr>`, `<td>`, …) and other\n * context-sensitive content parse correctly. Repeated static islands with\n * identical markup (e.g. list rows, reused components) clone the pre-parsed\n * fragment instead of re-parsing the HTML string on every mount — turning an\n * O(parse) operation into an O(clone) one.\n */\n protected _staticFragmentCache = new Map<string, DocumentFragment>();\n\n /**\n * Live-DOM attachments deferred while a mount pass is batching.\n *\n * A freshly-mounted subtree is built inside a *detached* root element, so\n * every descendant `appendChild`/`insertBefore` happens off-document and\n * triggers zero layout/paint invalidation. The single mutation that actually\n * connects the built subtree to the live document is deferred and collected\n * here, then flushed once when the batch closes — collapsing O(nodes) reflows\n * into O(1) per mount root.\n */\n protected _pendingAttachments: Array<() => void> = [];\n\n /**\n * Depth of the currently open batching scopes. Re-entrant so that nested\n * `beginBatch`/`endBatch` pairs flush exactly once, when the outermost scope\n * closes.\n */\n protected _batchDepth = 0;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n /**\n * `true` while a synchronous mount pass is batching live-DOM attachments.\n * Interpreter handlers consult this to decide whether to attach an element\n * immediately or hand the attachment to {@link deferAttach}.\n */\n get isBatching(): boolean {\n return this._batchDepth > 0;\n }\n\n /**\n * Opens a batching scope. Re-entrant: only the outermost matching\n * {@link endBatch} flushes the deferred attachments, so a single mount pass\n * connects its built subtree to the live DOM exactly once.\n */\n beginBatch(): void {\n this._batchDepth++;\n }\n\n /**\n * Registers a live-DOM attachment to run when the current batch flushes. If\n * no batch is active the attachment runs immediately, preserving the original\n * synchronous behaviour for updates that mount outside a batch.\n *\n * @param attach the DOM mutation that connects a built subtree to the document\n */\n deferAttach(attach: () => void): void {\n if (this._batchDepth > 0) {\n this._pendingAttachments.push(attach);\n } else {\n attach();\n }\n }\n\n /**\n * Closes a batching scope. When the outermost scope closes, every deferred\n * attachment runs in registration (document) order, connecting the built\n * subtrees to the live DOM in a single pass.\n */\n endBatch(): void {\n if (this._batchDepth === 0) return;\n this._batchDepth--;\n if (this._batchDepth > 0) return;\n\n const pending = this._pendingAttachments;\n this._pendingAttachments = [];\n for (let i = 0; i < pending.length; i++) {\n pending[i]();\n }\n }\n\n /**\n * Returns a `DocumentFragment` containing the parsed form of `html`, parsed\n * once in the context of `hostTag` (so context-sensitive content such as\n * table rows/cells parses correctly) and cached thereafter. Callers should\n * `cloneNode(true)` the returned fragment rather than mutating it, so the\n * cache stays reusable.\n *\n * @param hostTag the tag name of the element the markup will be injected into\n * @param html verbatim static-island inner markup\n */\n getStaticFragment(hostTag: string, html: string): DocumentFragment {\n const key = `${hostTag}\\u0000${html}`;\n let fragment = this._staticFragmentCache.get(key);\n if (!fragment) {\n // Parse in the correct element context: the fragment-parsing\n // algorithm uses the container element's tag to choose the right\n // insertion mode (e.g. `<tbody>` legitimately allows `<tr>`).\n const container = this._container.createElement(hostTag);\n container.innerHTML = html;\n\n fragment = this._container.createDocumentFragment();\n while (container.firstChild) {\n fragment.appendChild(container.firstChild);\n }\n\n this._staticFragmentCache.set(key, fragment);\n }\n return fragment;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n // Only update the host-element pointer for declaration instructions.\n // Mutations (attributes, styles, event listeners, …) produce auxiliary DOM\n // that must never overwrite the owning node's primary element in the index.\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node && instruction instanceof AreDeclaration) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n const byEvent = this.index.elementListeners.get(element)!;\n if (!byEvent.has(eventName)) {\n byEvent.set(eventName, new Set());\n }\n byEvent.get(eventName)!.add(listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n const set = this.index.elementListeners.get(element)?.get(eventName);\n if (!set || set.size === 0) return undefined;\n // Return the first listener for backwards compatibility.\n return set.values().next().value;\n }\n\n /**\n * Returns all listeners registered for a given element + event name.\n */\n getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void {\n const byEvent = this.index.elementListeners.get(element);\n if (!byEvent) return;\n if (listener) {\n const set = byEvent.get(eventName);\n if (set) {\n set.delete(listener);\n if (set.size === 0) byEvent.delete(eventName);\n }\n } else {\n byEvent.delete(eventName);\n }\n }\n}\n"]}
|
|
@@ -6,6 +6,7 @@ import { AddElementInstruction } from '../instructions/AddElement.instruction.mj
|
|
|
6
6
|
import { AddListenerInstruction } from '../instructions/AddListener.instruction.mjs';
|
|
7
7
|
import { AddTextInstruction } from '../instructions/AddText.instruction.mjs';
|
|
8
8
|
import { AddStyleInstruction } from '../instructions/AddStyle.instruction.mjs';
|
|
9
|
+
import { AddStaticHTMLInstruction } from '../instructions/AddStaticHTML.instruction.mjs';
|
|
9
10
|
import { HideElementInstruction } from '../instructions/HideElement.instruction.mjs';
|
|
10
11
|
import { AreDirectiveContext } from '../lib/AreDirective/AreDirective.context.mjs';
|
|
11
12
|
import { AreHTMLEngineContext } from './AreHTML.context.mjs';
|
|
@@ -25,6 +26,8 @@ declare class AreHTMLInterpreter extends AreInterpreter {
|
|
|
25
26
|
removeEventListener(mutation: AddListenerInstruction, context: AreHTMLEngineContext): void;
|
|
26
27
|
addText(declaration: AddTextInstruction, context: AreHTMLEngineContext, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, logger?: A_Logger): void;
|
|
27
28
|
removeText(declaration: AddTextInstruction, context: AreHTMLEngineContext): void;
|
|
29
|
+
addStaticHTML(mutation: AddStaticHTMLInstruction, context: AreHTMLEngineContext, logger?: A_Logger): void;
|
|
30
|
+
removeStaticHTML(mutation: AddStaticHTMLInstruction, context: AreHTMLEngineContext): void;
|
|
28
31
|
addComment(declaration: AddCommentInstruction, context: AreHTMLEngineContext, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, logger?: A_Logger): void;
|
|
29
32
|
removeComment(declaration: AddCommentInstruction, context: AreHTMLEngineContext): void;
|
|
30
33
|
addStyle(mutation: AddStyleInstruction, context: AreHTMLEngineContext, logger?: A_Logger): void;
|
|
@@ -6,6 +6,7 @@ import { AddElementInstruction } from '../instructions/AddElement.instruction.js
|
|
|
6
6
|
import { AddListenerInstruction } from '../instructions/AddListener.instruction.js';
|
|
7
7
|
import { AddTextInstruction } from '../instructions/AddText.instruction.js';
|
|
8
8
|
import { AddStyleInstruction } from '../instructions/AddStyle.instruction.js';
|
|
9
|
+
import { AddStaticHTMLInstruction } from '../instructions/AddStaticHTML.instruction.js';
|
|
9
10
|
import { HideElementInstruction } from '../instructions/HideElement.instruction.js';
|
|
10
11
|
import { AreDirectiveContext } from '../lib/AreDirective/AreDirective.context.js';
|
|
11
12
|
import { AreHTMLEngineContext } from './AreHTML.context.js';
|
|
@@ -25,6 +26,8 @@ declare class AreHTMLInterpreter extends AreInterpreter {
|
|
|
25
26
|
removeEventListener(mutation: AddListenerInstruction, context: AreHTMLEngineContext): void;
|
|
26
27
|
addText(declaration: AddTextInstruction, context: AreHTMLEngineContext, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, logger?: A_Logger): void;
|
|
27
28
|
removeText(declaration: AddTextInstruction, context: AreHTMLEngineContext): void;
|
|
29
|
+
addStaticHTML(mutation: AddStaticHTMLInstruction, context: AreHTMLEngineContext, logger?: A_Logger): void;
|
|
30
|
+
removeStaticHTML(mutation: AddStaticHTMLInstruction, context: AreHTMLEngineContext): void;
|
|
28
31
|
addComment(declaration: AddCommentInstruction, context: AreHTMLEngineContext, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, logger?: A_Logger): void;
|
|
29
32
|
removeComment(declaration: AddCommentInstruction, context: AreHTMLEngineContext): void;
|
|
30
33
|
addStyle(mutation: AddStyleInstruction, context: AreHTMLEngineContext, logger?: A_Logger): void;
|