@adaas/are-html 0.0.21 → 0.0.23
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/.conf/tsconfig.base.json +1 -0
- package/.conf/tsconfig.browser.json +1 -0
- package/.conf/tsconfig.node.json +1 -0
- package/dist/browser/index.d.mts +214 -3
- package/dist/browser/index.mjs +787 -201
- 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 +55 -2
- package/dist/node/directives/AreDirectiveFor.directive.d.ts +55 -2
- package/dist/node/directives/AreDirectiveFor.directive.js +141 -12
- package/dist/node/directives/AreDirectiveFor.directive.js.map +1 -1
- package/dist/node/directives/AreDirectiveFor.directive.mjs +141 -12
- package/dist/node/directives/AreDirectiveFor.directive.mjs.map +1 -1
- package/dist/node/directives/AreDirectiveIf.directive.d.mts +1 -1
- package/dist/node/directives/AreDirectiveIf.directive.d.ts +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 +1 -1
- package/dist/node/engine/AreHTML.compiler.d.ts +1 -1
- package/dist/node/engine/AreHTML.compiler.js +4 -0
- package/dist/node/engine/AreHTML.compiler.js.map +1 -1
- package/dist/node/engine/AreHTML.compiler.mjs +4 -0
- 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 +2 -2
- package/dist/node/engine/AreHTML.lifecycle.d.ts +2 -2
- package/dist/node/engine/AreHTML.lifecycle.js +32 -4
- package/dist/node/engine/AreHTML.lifecycle.js.map +1 -1
- package/dist/node/engine/AreHTML.lifecycle.mjs +32 -4
- 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/helpers/AreScheduler.helper.d.mts +39 -0
- package/dist/node/helpers/AreScheduler.helper.d.ts +39 -0
- package/dist/node/helpers/AreScheduler.helper.js +40 -0
- package/dist/node/helpers/AreScheduler.helper.js.map +1 -0
- package/dist/node/helpers/AreScheduler.helper.mjs +40 -0
- package/dist/node/helpers/AreScheduler.helper.mjs.map +1 -0
- 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 +1 -1
- package/dist/node/lib/AreRoot/AreRoot.component.js.map +1 -1
- package/dist/node/lib/AreRoot/AreRoot.component.mjs +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/{mq19zxz4-mnlgmd.js → mqiw5sqa-ypckmj.js} +2275 -1323
- package/examples/dashboard/src/concept.ts +3 -2
- package/examples/for-perf/concept.ts +45 -0
- package/examples/for-perf/containers/UI.container.ts +161 -0
- package/examples/for-perf/dist/index.html +270 -0
- package/examples/for-perf/dist/mqj1mpf2-z4aokv.js +15664 -0
- package/examples/for-perf/dist/mqj1mpff-4fr7mw.js +15664 -0
- package/examples/for-perf/public/index.html +270 -0
- package/examples/for-perf/src/components/PerfApp.component.ts +37 -0
- package/examples/for-perf/src/components/PerfControls.component.ts +34 -0
- package/examples/for-perf/src/components/PerfGrid.component.ts +225 -0
- package/examples/for-perf/src/components/PerfHeader.component.ts +34 -0
- package/examples/for-perf/src/components/PerfStats.component.ts +43 -0
- package/examples/for-perf/src/concept.ts +94 -0
- package/examples/jumpstart/dist/index.html +1 -1
- package/examples/jumpstart/dist/{mq7hqrxy-4kus50.js → mq7mgf58-vbf07e.js} +269 -91
- package/examples/signal-routing/dist/index.html +1 -1
- package/examples/signal-routing/dist/{mq7k53th-qiwy4x.js → mqiwo23h-bhcolu.js} +2090 -1430
- package/jest.config.ts +1 -0
- package/package.json +10 -9
- package/src/directives/AreDirectiveFor.directive.ts +233 -19
- package/src/engine/AreHTML.compiler.ts +13 -0
- 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 +91 -7
- package/src/engine/AreHTML.tokenizer.ts +30 -1
- package/src/helpers/AreScheduler.helper.ts +61 -0
- 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 +4 -1
- package/tests/StaticIsland.test.ts +115 -0
- package/tsconfig.json +1 -0
|
@@ -115,7 +115,171 @@ function toDOMString(value) {
|
|
|
115
115
|
return "";
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
+
const STANDARD_HTML_TAGS = /* @__PURE__ */ new Set([
|
|
119
|
+
// root / sections
|
|
120
|
+
"html",
|
|
121
|
+
"body",
|
|
122
|
+
"header",
|
|
123
|
+
"footer",
|
|
124
|
+
"main",
|
|
125
|
+
"nav",
|
|
126
|
+
"section",
|
|
127
|
+
"article",
|
|
128
|
+
"aside",
|
|
129
|
+
"address",
|
|
130
|
+
"hgroup",
|
|
131
|
+
// headings
|
|
132
|
+
"h1",
|
|
133
|
+
"h2",
|
|
134
|
+
"h3",
|
|
135
|
+
"h4",
|
|
136
|
+
"h5",
|
|
137
|
+
"h6",
|
|
138
|
+
// grouping
|
|
139
|
+
"div",
|
|
140
|
+
"p",
|
|
141
|
+
"span",
|
|
142
|
+
"pre",
|
|
143
|
+
"blockquote",
|
|
144
|
+
"figure",
|
|
145
|
+
"figcaption",
|
|
146
|
+
"hr",
|
|
147
|
+
"br",
|
|
148
|
+
"wbr",
|
|
149
|
+
// lists
|
|
150
|
+
"ul",
|
|
151
|
+
"ol",
|
|
152
|
+
"li",
|
|
153
|
+
"dl",
|
|
154
|
+
"dt",
|
|
155
|
+
"dd",
|
|
156
|
+
"menu",
|
|
157
|
+
// text-level / phrasing
|
|
158
|
+
"a",
|
|
159
|
+
"b",
|
|
160
|
+
"i",
|
|
161
|
+
"u",
|
|
162
|
+
"s",
|
|
163
|
+
"em",
|
|
164
|
+
"strong",
|
|
165
|
+
"small",
|
|
166
|
+
"mark",
|
|
167
|
+
"abbr",
|
|
168
|
+
"cite",
|
|
169
|
+
"q",
|
|
170
|
+
"code",
|
|
171
|
+
"kbd",
|
|
172
|
+
"samp",
|
|
173
|
+
"var",
|
|
174
|
+
"sub",
|
|
175
|
+
"sup",
|
|
176
|
+
"time",
|
|
177
|
+
"data",
|
|
178
|
+
"dfn",
|
|
179
|
+
"bdi",
|
|
180
|
+
"bdo",
|
|
181
|
+
"ruby",
|
|
182
|
+
"rt",
|
|
183
|
+
"rp",
|
|
184
|
+
"del",
|
|
185
|
+
"ins",
|
|
186
|
+
// media / embedded (no special namespace handling needed)
|
|
187
|
+
"img",
|
|
188
|
+
"picture",
|
|
189
|
+
"source",
|
|
190
|
+
"figure",
|
|
191
|
+
"audio",
|
|
192
|
+
"video",
|
|
193
|
+
"track",
|
|
194
|
+
// tables
|
|
195
|
+
"table",
|
|
196
|
+
"caption",
|
|
197
|
+
"colgroup",
|
|
198
|
+
"col",
|
|
199
|
+
"thead",
|
|
200
|
+
"tbody",
|
|
201
|
+
"tfoot",
|
|
202
|
+
"tr",
|
|
203
|
+
"th",
|
|
204
|
+
"td",
|
|
205
|
+
// forms (display only — these still render fine from innerHTML)
|
|
206
|
+
"label",
|
|
207
|
+
"fieldset",
|
|
208
|
+
"legend",
|
|
209
|
+
"datalist",
|
|
210
|
+
"option",
|
|
211
|
+
"optgroup",
|
|
212
|
+
"output",
|
|
213
|
+
"progress",
|
|
214
|
+
"meter",
|
|
215
|
+
// interactive
|
|
216
|
+
"details",
|
|
217
|
+
"summary",
|
|
218
|
+
"dialog"
|
|
219
|
+
]);
|
|
220
|
+
function isStaticMarkup(inner) {
|
|
221
|
+
if (!inner) return false;
|
|
222
|
+
if (inner.indexOf("{{") !== -1) return false;
|
|
223
|
+
const n = inner.length;
|
|
224
|
+
let i = 0;
|
|
225
|
+
while (i < n) {
|
|
226
|
+
const lt = inner.indexOf("<", i);
|
|
227
|
+
if (lt === -1) break;
|
|
228
|
+
if (inner.startsWith("<!--", lt)) {
|
|
229
|
+
const end = inner.indexOf("-->", lt + 4);
|
|
230
|
+
if (end === -1) return false;
|
|
231
|
+
i = end + 3;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (inner[lt + 1] === "/" || inner[lt + 1] === "!" || inner[lt + 1] === "?") {
|
|
235
|
+
const gt = inner.indexOf(">", lt);
|
|
236
|
+
if (gt === -1) return false;
|
|
237
|
+
i = gt + 1;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const nameMatch = /^<([a-zA-Z][a-zA-Z0-9-]*)/.exec(inner.slice(lt));
|
|
241
|
+
if (!nameMatch) {
|
|
242
|
+
i = lt + 1;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const tag = nameMatch[1].toLowerCase();
|
|
246
|
+
if (tag.indexOf("-") !== -1 || !STANDARD_HTML_TAGS.has(tag)) return false;
|
|
247
|
+
let j = lt + nameMatch[0].length;
|
|
248
|
+
let inSingle = false;
|
|
249
|
+
let inDouble = false;
|
|
250
|
+
let atNameBoundary = true;
|
|
251
|
+
let tagEnd = -1;
|
|
252
|
+
while (j < n) {
|
|
253
|
+
const ch = inner[j];
|
|
254
|
+
if (inDouble) {
|
|
255
|
+
if (ch === '"') inDouble = false;
|
|
256
|
+
} else if (inSingle) {
|
|
257
|
+
if (ch === "'") inSingle = false;
|
|
258
|
+
} else if (ch === '"') {
|
|
259
|
+
inDouble = true;
|
|
260
|
+
atNameBoundary = false;
|
|
261
|
+
} else if (ch === "'") {
|
|
262
|
+
inSingle = true;
|
|
263
|
+
atNameBoundary = false;
|
|
264
|
+
} else if (ch === ">") {
|
|
265
|
+
tagEnd = j;
|
|
266
|
+
break;
|
|
267
|
+
} else if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "/") {
|
|
268
|
+
atNameBoundary = true;
|
|
269
|
+
} else {
|
|
270
|
+
if (atNameBoundary && (ch === "$" || ch === ":" || ch === "@")) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
atNameBoundary = false;
|
|
274
|
+
}
|
|
275
|
+
j++;
|
|
276
|
+
}
|
|
277
|
+
if (tagEnd === -1) return false;
|
|
278
|
+
i = tagEnd + 1;
|
|
279
|
+
}
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
118
282
|
|
|
119
|
-
export { BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, SVG_ATTRIBUTE_NS, SVG_NAMESPACE, VOID_ELEMENTS, isBooleanAttribute, isIDLFormProperty, isVoidElement, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
|
|
283
|
+
export { BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, STANDARD_HTML_TAGS, SVG_ATTRIBUTE_NS, SVG_NAMESPACE, VOID_ELEMENTS, isBooleanAttribute, isIDLFormProperty, isStaticMarkup, isVoidElement, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
|
|
120
284
|
//# sourceMappingURL=AreHTML.constants.mjs.map
|
|
121
285
|
//# sourceMappingURL=AreHTML.constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/engine/AreHTML.constants.ts"],"names":[],"mappings":";;AAKO,MAAM,aAAA,GAAgB;AAMtB,MAAM,gBAAA,GAA2C;AAAA,EACpD,KAAA,EAAO,8BAAA;AAAA,EACP,GAAA,EAAK,sCAAA;AAAA,EACL,KAAA,EAAO;AACX;AAaO,MAAM,aAAA,uBAAoB,GAAA,CAAY;AAAA,EACzC,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,IAAA;AAAA,EAAM,KAAA;AAAA,EAAO,OAAA;AAAA,EAAS,IAAA;AAAA,EAAM,KAAA;AAAA,EAAO,OAAA;AAAA,EACnD,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,OAAA;AAAA,EAAS,QAAA;AAAA,EAAU,OAAA;AAAA,EAAS;AAChD,CAAC;AAEM,SAAS,cAAc,OAAA,EAA0B;AACpD,EAAA,OAAO,aAAA,CAAc,GAAA,CAAI,OAAA,CAAQ,WAAA,EAAa,CAAA;AAClD;AASO,MAAM,kBAAA,uBAAyB,GAAA,CAAY;AAAA,EAC9C,iBAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,gBAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,E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SAAS,eAAe,GAAA,EAA8B;AACzD,EAAA,MAAM,CAAC,KAAA,EAAO,GAAG,SAAS,CAAA,GAAI,GAAA,CAAI,MAAM,GAAG,CAAA;AAC3C,EAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,IAAI,GAAA,CAAI,SAAS,CAAA,EAAE;AAClD;AAKO,MAAM,4CAA4B,IAAI,GAAA,CAAI,CAAC,SAAA,EAAW,MAAA,EAAQ,SAAS,CAAC;AAMxE,SAAS,YAAY,KAAA,EAAoB;AAC5C,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,EAAW,OAAO,EAAA;AAClD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,KAAA;AACtC,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,OAAO,UAAU,SAAA,EAAW,OAAO,OAAO,KAAK,CAAA;AAChF,EAAA,IAAI;AACA,IAAA,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,EAAA;AAAA,EACX;AACJ","file":"AreHTML.constants.mjs","sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// ── SVG ──────────────────────────────────────────────────────────────────────\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** XML namespace URI for SVG elements. */\nexport const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\n/**\n * Maps namespace prefixes used in SVG/XML attributes to their canonical URIs.\n * Used by the interpreter when calling setAttributeNS / removeAttributeNS.\n */\nexport const SVG_ATTRIBUTE_NS: Record<string, string> = {\n xlink: 'http://www.w3.org/1999/xlink',\n xml: 'http://www.w3.org/XML/1998/namespace',\n xmlns: 'http://www.w3.org/2000/xmlns/',\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ── HTML void elements ────────────────────────────────────────────────────────\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Void HTML elements that cannot have children and must not have a closing tag.\n * Per the HTML5 spec these are treated as self-closing even when written as\n * `<input>` (without the trailing slash `/>`).\n *\n * Reference: https://html.spec.whatwg.org/multipage/syntax.html#void-elements\n */\nexport const VOID_ELEMENTS = new Set<string>([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\nexport function isVoidElement(tagName: string): boolean {\n return VOID_ELEMENTS.has(tagName.toLowerCase());\n}\n\n/**\n * Boolean HTML attributes whose presence (regardless of value) implies \"true\",\n * and whose absence implies \"false\". Setting these via `setAttribute(name, value)`\n * always renders the attribute, which is wrong for reactive bindings.\n *\n * Reference: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n */\nexport const BOOLEAN_ATTRIBUTES = new Set<string>([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n]);\n\nexport function isBooleanAttribute(name: string): boolean {\n return BOOLEAN_ATTRIBUTES.has(name.toLowerCase());\n}\n\n/**\n * Form-control IDL properties that must be set as a JS property\n * (not just an attribute) so live user input is reflected.\n *\n * `<input value=\"foo\">` only sets the *default* value;\n * `input.value = \"foo\"` updates the live state.\n */\nexport const IDL_FORM_PROPERTIES: Record<string, Set<string>> = {\n INPUT: new Set(['value', 'checked', 'indeterminate']),\n TEXTAREA: new Set(['value']),\n SELECT: new Set(['value']),\n OPTION: new Set(['selected']),\n};\n\nexport function isIDLFormProperty(tagName: string, attrName: string): boolean {\n const set = IDL_FORM_PROPERTIES[tagName.toUpperCase()];\n return !!set && set.has(attrName);\n}\n\n/**\n * Normalize a `:class` binding value into a single space-separated string.\n * Supports the common shapes:\n * - string → \"a b\"\n * - array<string | object | falsy> → [\"a\", { b: true, c: cond }, null]\n * - object<string, boolean> → { a: true, b: false }\n */\nexport function normalizeClassValue(value: any): string {\n if (value === null || value === undefined || value === false) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n\n if (Array.isArray(value)) {\n return value.map(normalizeClassValue).filter(Boolean).join(' ');\n }\n if (typeof value === 'object') {\n const parts: string[] = [];\n for (const key of Object.keys(value)) {\n if (value[key]) parts.push(key);\n }\n return parts.join(' ');\n }\n return '';\n}\n\n/**\n * Normalize a `:style` binding value into an inline-style string.\n * Supports:\n * - string → \"color: red; font-size: 12px\"\n * - object<string, string|number> → { color: 'red', fontSize: '12px' }\n * - array<string | object> → ['color: red', { fontSize: '12px' }]\n */\nexport function normalizeStyleValue(value: any): string {\n if (value === null || value === undefined || value === false) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n\n if (Array.isArray(value)) {\n return value.map(normalizeStyleValue).filter(Boolean).join('; ');\n }\n if (typeof value === 'object') {\n const parts: string[] = [];\n for (const key of Object.keys(value)) {\n const v = value[key];\n if (v === null || v === undefined || v === false) continue;\n const kebab = key.replace(/[A-Z]/g, m => '-' + m.toLowerCase());\n parts.push(`${kebab}: ${v}`);\n }\n return parts.join('; ');\n }\n return '';\n}\n\n/**\n * Parse a DOM event name with modifiers, e.g. \"click.stop.prevent\" or \"keydown.enter\".\n * Returns the bare event name plus the modifier set.\n */\nexport interface ParsedEventName {\n event: string;\n modifiers: Set<string>;\n}\n\nexport function parseEventName(raw: string): ParsedEventName {\n const [event, ...modifiers] = raw.split('.');\n return { event, modifiers: new Set(modifiers) };\n}\n\n/**\n * Known event-listener modifiers that map directly to addEventListener options.\n */\nexport const LISTENER_OPTION_MODIFIERS = new Set(['capture', 'once', 'passive']);\n\n/**\n * Coerce a value into a string for DOM consumption.\n * Avoids \"undefined\"/\"null\"/\"[object Object]\" leaks into the DOM.\n */\nexport function toDOMString(value: any): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return '';\n }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/engine/AreHTML.constants.ts"],"names":[],"mappings":";;AAKO,MAAM,aAAA,GAAgB;AAMtB,MAAM,gBAAA,GAA2C;AAAA,EACpD,KAAA,EAAO,8BAAA;AAAA,EACP,GAAA,EAAK,sCAAA;AAAA,EACL,KAAA,EAAO;AACX;AAaO,MAAM,aAAA,uBAAoB,GAAA,CAAY;AAAA,EACzC,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,IAAA;AAAA,EAAM,KAAA;AAAA,EAAO,OAAA;AAAA,EAAS,IAAA;AAAA,EAAM,KAAA;AAAA,EAAO,OAAA;AAAA,EACnD,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,OAAA;AAAA,EAAS,QAAA;AAAA,EAAU,OAAA;AAAA,EAAS;AAChD,CAAC;AAEM,SAAS,cAAc,OAAA,EAA0B;AACpD,EAAA,OAAO,aAAA,CAAc,GAAA,CAAI,OAAA,CAAQ,WAAA,EAAa,CAAA;AAClD;AASO,MAAM,kBAAA,uBAAyB,GAAA,CAAY;AAAA,EAC9C,iBAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,gBAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA;AACJ,CAAC;AAEM,SAAS,mBAAmB,IAAA,EAAuB;AACtD,EAAA,OAAO,kB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A;AAAA,MACrB;AACA,MAAA,CAAA,EAAA;AAAA,IACJ;AAEA,IAAA,IAAI,MAAA,KAAW,IAAI,OAAO,KAAA;AAC1B,IAAA,CAAA,GAAI,MAAA,GAAS,CAAA;AAAA,EACjB;AAEA,EAAA,OAAO,IAAA;AACX","file":"AreHTML.constants.mjs","sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// ── SVG ──────────────────────────────────────────────────────────────────────\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** XML namespace URI for SVG elements. */\nexport const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\n/**\n * Maps namespace prefixes used in SVG/XML attributes to their canonical URIs.\n * Used by the interpreter when calling setAttributeNS / removeAttributeNS.\n */\nexport const SVG_ATTRIBUTE_NS: Record<string, string> = {\n xlink: 'http://www.w3.org/1999/xlink',\n xml: 'http://www.w3.org/XML/1998/namespace',\n xmlns: 'http://www.w3.org/2000/xmlns/',\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ── HTML void elements ────────────────────────────────────────────────────────\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Void HTML elements that cannot have children and must not have a closing tag.\n * Per the HTML5 spec these are treated as self-closing even when written as\n * `<input>` (without the trailing slash `/>`).\n *\n * Reference: https://html.spec.whatwg.org/multipage/syntax.html#void-elements\n */\nexport const VOID_ELEMENTS = new Set<string>([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr',\n]);\n\nexport function isVoidElement(tagName: string): boolean {\n return VOID_ELEMENTS.has(tagName.toLowerCase());\n}\n\n/**\n * Boolean HTML attributes whose presence (regardless of value) implies \"true\",\n * and whose absence implies \"false\". Setting these via `setAttribute(name, value)`\n * always renders the attribute, which is wrong for reactive bindings.\n *\n * Reference: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n */\nexport const BOOLEAN_ATTRIBUTES = new Set<string>([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n]);\n\nexport function isBooleanAttribute(name: string): boolean {\n return BOOLEAN_ATTRIBUTES.has(name.toLowerCase());\n}\n\n/**\n * Form-control IDL properties that must be set as a JS property\n * (not just an attribute) so live user input is reflected.\n *\n * `<input value=\"foo\">` only sets the *default* value;\n * `input.value = \"foo\"` updates the live state.\n */\nexport const IDL_FORM_PROPERTIES: Record<string, Set<string>> = {\n INPUT: new Set(['value', 'checked', 'indeterminate']),\n TEXTAREA: new Set(['value']),\n SELECT: new Set(['value']),\n OPTION: new Set(['selected']),\n};\n\nexport function isIDLFormProperty(tagName: string, attrName: string): boolean {\n const set = IDL_FORM_PROPERTIES[tagName.toUpperCase()];\n return !!set && set.has(attrName);\n}\n\n/**\n * Normalize a `:class` binding value into a single space-separated string.\n * Supports the common shapes:\n * - string → \"a b\"\n * - array<string | object | falsy> → [\"a\", { b: true, c: cond }, null]\n * - object<string, boolean> → { a: true, b: false }\n */\nexport function normalizeClassValue(value: any): string {\n if (value === null || value === undefined || value === false) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n\n if (Array.isArray(value)) {\n return value.map(normalizeClassValue).filter(Boolean).join(' ');\n }\n if (typeof value === 'object') {\n const parts: string[] = [];\n for (const key of Object.keys(value)) {\n if (value[key]) parts.push(key);\n }\n return parts.join(' ');\n }\n return '';\n}\n\n/**\n * Normalize a `:style` binding value into an inline-style string.\n * Supports:\n * - string → \"color: red; font-size: 12px\"\n * - object<string, string|number> → { color: 'red', fontSize: '12px' }\n * - array<string | object> → ['color: red', { fontSize: '12px' }]\n */\nexport function normalizeStyleValue(value: any): string {\n if (value === null || value === undefined || value === false) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n\n if (Array.isArray(value)) {\n return value.map(normalizeStyleValue).filter(Boolean).join('; ');\n }\n if (typeof value === 'object') {\n const parts: string[] = [];\n for (const key of Object.keys(value)) {\n const v = value[key];\n if (v === null || v === undefined || v === false) continue;\n const kebab = key.replace(/[A-Z]/g, m => '-' + m.toLowerCase());\n parts.push(`${kebab}: ${v}`);\n }\n return parts.join('; ');\n }\n return '';\n}\n\n/**\n * Parse a DOM event name with modifiers, e.g. \"click.stop.prevent\" or \"keydown.enter\".\n * Returns the bare event name plus the modifier set.\n */\nexport interface ParsedEventName {\n event: string;\n modifiers: Set<string>;\n}\n\nexport function parseEventName(raw: string): ParsedEventName {\n const [event, ...modifiers] = raw.split('.');\n return { event, modifiers: new Set(modifiers) };\n}\n\n/**\n * Known event-listener modifiers that map directly to addEventListener options.\n */\nexport const LISTENER_OPTION_MODIFIERS = new Set(['capture', 'once', 'passive']);\n\n/**\n * Coerce a value into a string for DOM consumption.\n * Avoids \"undefined\"/\"null\"/\"[object Object]\" leaks into the DOM.\n */\nexport function toDOMString(value: any): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return '';\n }\n}\n\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ── Static-island detection ──────────────────────────────────────────────────\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Standard HTML element names that are safe to materialise wholesale via\n * `innerHTML` / a cached `<template>` clone.\n *\n * The set is intentionally an allow-list of plain HTML flow/phrasing/table/list\n * /form-display tags. Anything NOT in this set — custom elements, registered\n * ARE components (resolved by PascalCase tag), and SVG/MathML elements — is\n * excluded so those subtrees keep flowing through the normal per-node pipeline\n * (SVG needs createElementNS; components need their own lifecycle).\n */\nexport const STANDARD_HTML_TAGS = new Set<string>([\n // root / sections\n 'html', 'body', 'header', 'footer', 'main', 'nav', 'section', 'article',\n 'aside', 'address', 'hgroup',\n // headings\n 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',\n // grouping\n 'div', 'p', 'span', 'pre', 'blockquote', 'figure', 'figcaption',\n 'hr', 'br', 'wbr',\n // lists\n 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'menu',\n // text-level / phrasing\n 'a', 'b', 'i', 'u', 's', 'em', 'strong', 'small', 'mark', 'abbr', 'cite',\n 'q', 'code', 'kbd', 'samp', 'var', 'sub', 'sup', 'time', 'data', 'dfn',\n 'bdi', 'bdo', 'ruby', 'rt', 'rp', 'del', 'ins',\n // media / embedded (no special namespace handling needed)\n 'img', 'picture', 'source', 'figure', 'audio', 'video', 'track',\n // tables\n 'table', 'caption', 'colgroup', 'col', 'thead', 'tbody', 'tfoot',\n 'tr', 'th', 'td',\n // forms (display only — these still render fine from innerHTML)\n 'label', 'fieldset', 'legend', 'datalist', 'option', 'optgroup', 'output',\n 'progress', 'meter',\n // interactive\n 'details', 'summary', 'dialog',\n]);\n\n/**\n * Detects whether an inner-markup string is a fully *static island* — i.e. it\n * contains no ARE-reactive constructs and therefore can be rendered in one shot\n * (browser-parsed `innerHTML` / cached `<template>` clone) instead of being\n * exploded into one AreNode per element/text/interpolation.\n *\n * A subtree is static iff it contains:\n * 1. no `{{ }}` interpolations, and\n * 2. no dynamic attributes (`$`-directive / `:`-binding / `@`-event), and\n * 3. only standard HTML tags (no custom elements, ARE components or SVG).\n *\n * The scanner is quote-aware so a `:` / `@` / `$` inside an attribute *value*\n * (e.g. `href=\"http://…\"`, `style=\"color:red\"`) is never mistaken for a\n * dynamic-attribute prefix. The detector is deliberately conservative: any\n * ambiguity resolves to `false` (skip the optimisation, keep the safe path).\n *\n * NOTE: pure-text content (no tags at all) is also considered static — this is\n * what lets ` `, `&`, ` ` and friends decode correctly, since the\n * browser HTML parser handles entities that hand-built text nodes do not.\n */\nexport function isStaticMarkup(inner: string): boolean {\n if (!inner) return false;\n // 1. interpolations make the subtree dynamic\n if (inner.indexOf('{{') !== -1) return false;\n\n const n = inner.length;\n let i = 0;\n\n while (i < n) {\n const lt = inner.indexOf('<', i);\n if (lt === -1) break; // remaining content is plain text — safe\n\n // HTML comment — inert, skip over it\n if (inner.startsWith('<!--', lt)) {\n const end = inner.indexOf('-->', lt + 4);\n if (end === -1) return false; // malformed\n i = end + 3;\n continue;\n }\n\n // closing tag, doctype or processing instruction — skip to its '>'\n if (inner[lt + 1] === '/' || inner[lt + 1] === '!' || inner[lt + 1] === '?') {\n const gt = inner.indexOf('>', lt);\n if (gt === -1) return false;\n i = gt + 1;\n continue;\n }\n\n // opening tag — extract the tag name\n const nameMatch = /^<([a-zA-Z][a-zA-Z0-9-]*)/.exec(inner.slice(lt));\n if (!nameMatch) { i = lt + 1; continue; }\n\n const tag = nameMatch[1].toLowerCase();\n // custom element / ARE component / non-standard (incl. SVG) → not static\n if (tag.indexOf('-') !== -1 || !STANDARD_HTML_TAGS.has(tag)) return false;\n\n // walk the opening tag (quote-aware) to find its closing '>' and inspect\n // attribute-name boundaries for dynamic prefixes\n let j = lt + nameMatch[0].length;\n let inSingle = false;\n let inDouble = false;\n let atNameBoundary = true; // true right after whitespace / '/' inside a tag\n let tagEnd = -1;\n\n while (j < n) {\n const ch = inner[j];\n\n if (inDouble) {\n if (ch === '\"') inDouble = false;\n } else if (inSingle) {\n if (ch === \"'\") inSingle = false;\n } else if (ch === '\"') {\n inDouble = true;\n atNameBoundary = false;\n } else if (ch === \"'\") {\n inSingle = true;\n atNameBoundary = false;\n } else if (ch === '>') {\n tagEnd = j;\n break;\n } else if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r' || ch === '/') {\n atNameBoundary = true;\n } else {\n // a dynamic-attribute prefix only counts when it STARTS an\n // attribute name (i.e. sits at a name boundary, outside quotes)\n if (atNameBoundary && (ch === '$' || ch === ':' || ch === '@')) {\n return false;\n }\n atNameBoundary = false;\n }\n j++;\n }\n\n if (tagEnd === -1) return false; // unterminated tag — bail to safe path\n i = tagEnd + 1;\n }\n\n return true;\n}\n\n\n"]}
|
|
@@ -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
|
*
|
|
@@ -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,IAA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;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;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,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AAQ,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;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"]}
|