@verajs/renderer 0.3.0 → 0.3.1
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/README.md +52 -6
- package/dist/development/vera-renderer-elements.js.map +1 -1
- package/dist/development/vera-renderer-hydrate-slots.js +1 -1
- package/dist/development/vera-renderer-hydrate-slots.js.map +1 -1
- package/dist/development/vera-renderer-hydration.d.ts.map +1 -1
- package/dist/development/vera-renderer-hydration.js +42 -4
- package/dist/development/vera-renderer-hydration.js.map +1 -1
- package/dist/development/vera-renderer-portal.js +1 -1
- package/dist/development/vera-renderer-portal.js.map +1 -1
- package/dist/development/vera-renderer-profiler.d.ts.map +1 -1
- package/dist/development/vera-renderer-profiler.js +304 -97
- package/dist/development/vera-renderer-profiler.js.map +1 -1
- package/dist/development/vera-renderer-slots.js +1 -1
- package/dist/development/vera-renderer-slots.js.map +1 -1
- package/dist/development/vera-renderer-spread.js.map +1 -1
- package/dist/development/vera-renderer-tag.js.map +1 -1
- package/dist/development/vera-renderer.d.ts.map +1 -1
- package/dist/development/vera-renderer.js +304 -97
- package/dist/development/vera-renderer.js.map +1 -1
- package/dist/vera-renderer-elements.min.js.map +1 -1
- package/dist/vera-renderer-hydrate-slots.min.js +1 -1
- package/dist/vera-renderer-hydrate-slots.min.js.map +1 -1
- package/dist/vera-renderer-hydration.min.js +1 -1
- package/dist/vera-renderer-hydration.min.js.map +1 -1
- package/dist/vera-renderer-portal.min.js +1 -1
- package/dist/vera-renderer-portal.min.js.map +1 -1
- package/dist/vera-renderer-slots.min.js +1 -1
- package/dist/vera-renderer-slots.min.js.map +1 -1
- package/dist/vera-renderer-spread.min.js.map +1 -1
- package/dist/vera-renderer-tag.min.js.map +1 -1
- package/dist/vera-renderer.min.js +1 -1
- package/dist/vera-renderer.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -119,6 +119,20 @@ const warnOnce = /* @__PURE__ */ sayOnce('warn');
|
|
|
119
119
|
* core's `html`/`svg`/`mathml` and the renderer's `tag` — a tagged template called as a function. The FACT is shared;
|
|
120
120
|
* the EXAMPLE is each emitter's: `html` writes markup, `tag` an element name — so the emitter passes it.
|
|
121
121
|
*/
|
|
122
|
+
/**
|
|
123
|
+
* A template in a text-only element (`<style>`, a JSON data block, `<title>`, `<textarea>`): its content is text. Lite
|
|
124
|
+
* refuses it, and so does the renderer in a style or JSON block (the server: `ssr-template-in-text`); in a `<title>` or
|
|
125
|
+
* `<textarea>` the renderer places it, as it always has, and says so in development only. A list there is joined.
|
|
126
|
+
*/
|
|
127
|
+
const templateInText = () => [
|
|
128
|
+
'a template inside a text-only element (`<style>`, a JSON `<script>`, `<title>`, `<textarea>`, or never-shown content: `<noscript>`, `<iframe>`) is never shown as markup — its content is text.',
|
|
129
|
+
'Render a string there; a list of strings is joined.',
|
|
130
|
+
];
|
|
131
|
+
/** A template that ends inside a tag: the renderer refuses it in development, the lite tier in every build. */
|
|
132
|
+
const unfinishedTag = () => [
|
|
133
|
+
'a template cannot end inside a tag — the parser drops an unfinished tag.',
|
|
134
|
+
'Close the tag inside the template.',
|
|
135
|
+
];
|
|
122
136
|
/** core's props adoption on an `init()` element, and the renderer's on any other element. */
|
|
123
137
|
const getterOnlyProp = (key) => [
|
|
124
138
|
`received a bound property \`.${key}\` (or \`!${key}\`), but its class declares \`${key}\` as a getter with no setter — the value cannot be delivered and the binding is ignored.`,
|
|
@@ -172,6 +186,11 @@ const nameExpression = (written, given) => [
|
|
|
172
186
|
`an attribute name cannot be an expression — \`${written}\` is read by the parser before any value exists.`,
|
|
173
187
|
`A name known only at runtime is a spread: \`\${spread({ [\`${written}\`]: ${given} })}\` (from @verajs/renderer/spread).`,
|
|
174
188
|
];
|
|
189
|
+
/** The renderer and lite (`namespaces.ts`): an element placed where its namespace does not render. `advice` is built there. */
|
|
190
|
+
const wrongNamespace = (tag, built, host, advice) => [
|
|
191
|
+
`<${tag}> was built as ${built} and placed inside <${host}>, where it will not render.`,
|
|
192
|
+
advice,
|
|
193
|
+
];
|
|
175
194
|
/** The renderer (and, ruled 2026-10-09, @verajs/ssr): data shaped like a template, not made by `html`. */
|
|
176
195
|
const forgedTemplate = () => [
|
|
177
196
|
'is shaped like a template but was not made by html`` — rendered as text.',
|
|
@@ -344,6 +363,46 @@ const SCRIPT_URL_ITEM = /(?:^|;)[\u0000- ]*j[\t\n\r]*a[\t\n\r]*v[\t\n\r]*a[\t\n\
|
|
|
344
363
|
* keeps a twin, held to this one by `tests/inline-handlers.test.mjs`.
|
|
345
364
|
*/
|
|
346
365
|
const INLINE_HANDLER = /^on./i;
|
|
366
|
+
/**
|
|
367
|
+
* **A `<script>` that is a JSON data block, by its `type`** (Brian, 2026-11-17): the only script a value may enter (state
|
|
368
|
+
* handoff, JSON-LD); every other script hole is refused (`script-hole`), since a value there is code — run on a page the
|
|
369
|
+
* server rendered. "The type ends in `json`" never names a script that runs — measured on Chromium, Firefox and WebKit,
|
|
370
|
+
* parameters included (`text/javascript; x=json` is inert), as the spec reads a type (a JavaScript MIME essence match on
|
|
371
|
+
* the whole string); `type=""` and a `language` attribute alone do run, and end in no `json`.
|
|
372
|
+
*/
|
|
373
|
+
const JSON_BLOCK = /json\s*$/i;
|
|
374
|
+
/**
|
|
375
|
+
* Whether a script START TAG, as written, opens a JSON data block: its attributes read IN ORDER (so a `type=` inside
|
|
376
|
+
* another attribute's quoted value is never taken for the type), the first `type` as the parser keeps it, and that value
|
|
377
|
+
* holding no `&` (a character reference is refused rather than decoded — a decoder slightly off would make the server
|
|
378
|
+
* and the client disagree) and ending in `json` (`JSON_BLOCK`). Every side applies it to the start tag that OPENED the
|
|
379
|
+
* script a hole sits in — recorded where the scanner enters raw text, never found by searching back (a `<script…>`
|
|
380
|
+
* inside a script's own text is no start tag). `@verajs/ssr` holds a twin, held equal by a test.
|
|
381
|
+
*/
|
|
382
|
+
const dataBlock = (openTag) => {
|
|
383
|
+
for (const [, name, double, single, bare] of openTag.slice(7).matchAll(/[\s/]*([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]*)))?/g))
|
|
384
|
+
if (name.toLowerCase() === 'type') {
|
|
385
|
+
const type = double ?? single ?? bare ?? '';
|
|
386
|
+
return !type.includes('&') && JSON_BLOCK.test(type);
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* **A raw-text element's composed text, unable to end its element** — the rule every side writes, byte for byte (the
|
|
392
|
+
* server's `styleHole` and JSON rule, the renderer, hydration's comparison, lite, static): in a style each `</style`
|
|
393
|
+
* (any case) as `<\/style` (the same CSS), in a JSON data block every `<` as `\u003c` (the same JSON). A style's or a
|
|
394
|
+
* JSON block's text is serialized VERBATIM (BROWSER-LEDGER), so written as composed, a value became markup once the page
|
|
395
|
+
* was saved from the DOM and parsed again. Applied to the COMPOSED text: a closer can form across a hole. Idempotent —
|
|
396
|
+
* neither form leaves what it replaces.
|
|
397
|
+
*/
|
|
398
|
+
const closedRawText = (text, json) => json ? text.replace(/</g, '\\u003c') : text.replace(/<\/(style)/gi, '<\\/$1');
|
|
399
|
+
/**
|
|
400
|
+
* **A value as inert text in ANY position** — every ASCII non-word character as a character reference (`<` `<`,
|
|
401
|
+
* a space ` `, `=` `=`), everything else as it is: the encoding `@verajs/static` writes every value with, and the
|
|
402
|
+
* renderer writes a never-shown element's values with. Read as raw text it holds no `<`; read as markup it decodes to
|
|
403
|
+
* the same characters and cannot end a tag, a quoted or unquoted attribute value, or the element.
|
|
404
|
+
*/
|
|
405
|
+
const encodeText = (text) => text.replace(/[^\w\u0080-\uffff]/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
347
406
|
/**
|
|
348
407
|
* **The properties that replace an element's whole content** — a binding to one owns the element's children, so it
|
|
349
408
|
* cannot share the element with content of its own (markup, or a child binding the write would strand: a later commit
|
|
@@ -384,6 +443,85 @@ const tagHole = (side) => {
|
|
|
384
443
|
throw new Error(misuse(side, 'tag-hole', true && tagHole$1()));
|
|
385
444
|
};
|
|
386
445
|
|
|
446
|
+
/**
|
|
447
|
+
* **Content in the wrong namespace does not render — DEVELOPMENT ONLY, said by two renderers** (2026-11-18):
|
|
448
|
+
* `` html`<path/>` `` handed into an `<svg>` builds an HTML `<path>`, which draws nothing and says nothing.
|
|
449
|
+
* `@verajs/renderer` and `@verajs/lite` both say it, so the decision and its words live here, once (the shared-emitter
|
|
450
|
+
* rule, `diagnostics.ts`); each renderer passes its own area and the one sentence that differs between them (`retag`:
|
|
451
|
+
* how else a template could get the right namespace). Every call site is behind `true `, so production drops it whole.
|
|
452
|
+
*
|
|
453
|
+
* The host is read from where the content LANDS, and a mismatch is named once per host and content (a toggled subtree
|
|
454
|
+
* would otherwise warn every frame). Silent where HTML is correct — integration points (`<foreignObject>`, `<desc>`,
|
|
455
|
+
* `<title>`, MathML's token elements, an HTML-encoded `<annotation-xml>`) and `<style>`/`<script>`, which never draw.
|
|
456
|
+
*/
|
|
457
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
458
|
+
const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';
|
|
459
|
+
/** The name of a foreign host where HTML does not render, or `null` (not SVG/MathML, or an integration point). */
|
|
460
|
+
const foreignHost = (parent) => {
|
|
461
|
+
const element = parent;
|
|
462
|
+
const namespace = element.namespaceURI;
|
|
463
|
+
const svg = namespace === SVG_NS;
|
|
464
|
+
if (!svg && namespace !== MATHML_NS)
|
|
465
|
+
return null;
|
|
466
|
+
const name = element.localName;
|
|
467
|
+
if (svg)
|
|
468
|
+
return name === 'foreignObject' || name === 'desc' || name === 'title' ? null : name;
|
|
469
|
+
if (name === 'mi' || name === 'mo' || name === 'mn' || name === 'ms' || name === 'mtext')
|
|
470
|
+
return null;
|
|
471
|
+
if (name === 'annotation-xml') {
|
|
472
|
+
/** The ATTRIBUTE — what the parser reads; `image/svg+xml` is MathML's own spelling for an SVG annotation. */
|
|
473
|
+
const encoding = element.getAttribute('encoding')?.toLowerCase();
|
|
474
|
+
return encoding === 'text/html' || encoding === 'application/xhtml+xml' || encoding === 'image/svg+xml' ? null : name;
|
|
475
|
+
}
|
|
476
|
+
return name;
|
|
477
|
+
};
|
|
478
|
+
/** The nodes an insert is about to place — a fragment empties as it is inserted, so they are read first. */
|
|
479
|
+
const landing = (node) => (node.nodeType === 11 ? [...node.childNodes] : [node]);
|
|
480
|
+
/**
|
|
481
|
+
* **Development: each element of `nodes`, placed in `parent`, that will not render there, named once.** `area` is the
|
|
482
|
+
* emitter's label; `retag` is its sentence on another way to the right namespace, read only for HTML content, between
|
|
483
|
+
* "needs the svg`…` or mathml`…` tag at the call site" and the advice for content that is genuinely HTML.
|
|
484
|
+
*/
|
|
485
|
+
const checkForeign = (area, parent, nodes, retag) => {
|
|
486
|
+
const host = foreignHost(parent);
|
|
487
|
+
if (host === null)
|
|
488
|
+
return;
|
|
489
|
+
const hostNamespace = parent.namespaceURI;
|
|
490
|
+
for (const node of nodes) {
|
|
491
|
+
if (node.nodeType !== 1)
|
|
492
|
+
continue;
|
|
493
|
+
const element = node;
|
|
494
|
+
if (element.namespaceURI === hostNamespace)
|
|
495
|
+
continue;
|
|
496
|
+
const tag = element.localName;
|
|
497
|
+
if (tag === 'style' || tag === 'script')
|
|
498
|
+
continue;
|
|
499
|
+
/** The parser itself opens SVG content for an `<svg>` inside `<annotation-xml>`, whatever the encoding. */
|
|
500
|
+
if (host === 'annotation-xml' && tag === 'svg' && element.namespaceURI === SVG_NS)
|
|
501
|
+
continue;
|
|
502
|
+
const built = element.namespaceURI === MATHML_NS ? 'MathML' : element.namespaceURI === SVG_NS ? 'SVG' : 'HTML';
|
|
503
|
+
/** The island and its placement are chosen by the HOST's namespace; the encoding follows the CONTENT. */
|
|
504
|
+
const island = hostNamespace === MATHML_NS
|
|
505
|
+
? `<mtext>, or <annotation-xml encoding="${built === 'SVG' ? 'image/svg+xml' : 'text/html'}">, ` +
|
|
506
|
+
'inside a MathML container such as <mrow> or <math> rather than inside a token element'
|
|
507
|
+
: 'a <foreignObject>, which has to sit in an element whose content model accepts one — a container such as ' +
|
|
508
|
+
'<g> or <svg>, not a text, clipping, gradient or filter element';
|
|
509
|
+
/** Keyed by host namespace AND content namespace: `<a>` is a real element in all three. */
|
|
510
|
+
const seen = `${hostNamespace}${host}>${element.namespaceURI}${tag}`;
|
|
511
|
+
/** `hasWarned` first: the advice below is built only for a case not yet said. */
|
|
512
|
+
if (hasWarned('wrong-namespace', seen))
|
|
513
|
+
continue;
|
|
514
|
+
const advice = built === 'HTML'
|
|
515
|
+
? `If it is meant to be an SVG or MathML element, the template holding it needs the svg\`…\` or mathml\`…\` tag ` +
|
|
516
|
+
`at the call site${retag}. If it is ` +
|
|
517
|
+
`genuinely HTML (a <div>, a custom element), it belongs in ${island}: tagging it will not help, and a custom ` +
|
|
518
|
+
`element only upgrades in the HTML namespace.`
|
|
519
|
+
: `The template's tag is already right — these two namespaces cannot nest directly. Put the ` +
|
|
520
|
+
`${built === 'SVG' ? '<svg>' : '<math>'} root inside ${island}.`;
|
|
521
|
+
warnOnce(area, `<${tag}>`, 'wrong-namespace', true && (() => wrongNamespace(tag, built, host, advice)), seen);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
387
525
|
/**
|
|
388
526
|
* **Reports an error nothing else handled, the way the platform reports one.** `reportError` fires
|
|
389
527
|
* the window's `error` event — what `window.onerror`, error trackers and test runners listen for —
|
|
@@ -642,13 +780,9 @@ const PROSE = {
|
|
|
642
780
|
`a binding inside <${tag}> in SVG or MathML cannot sit beside an element there — the renderer reads <${tag}> as text and rebuilds it around its bindings, which destroys the elements in it.`,
|
|
643
781
|
`Bind text directly in the <${tag}> (no elements), or move the element out of it.`,
|
|
644
782
|
],
|
|
645
|
-
'
|
|
646
|
-
|
|
647
|
-
'
|
|
648
|
-
],
|
|
649
|
-
'unfinished-tag': () => [
|
|
650
|
-
'a template cannot end inside a tag — the parser drops an unfinished tag.',
|
|
651
|
-
'Close the tag inside the template.',
|
|
783
|
+
'script-hole': () => [
|
|
784
|
+
'a value in a <script> is code — on a page the server rendered it runs — so a script hole is refused, except in a JSON data block (its type ends in `json`, with no character reference).',
|
|
785
|
+
'Give the script a JSON type (`type="application/json"` or `application/ld+json`) for state or JSON-LD, or pass the value another way.',
|
|
652
786
|
],
|
|
653
787
|
'inert-binding': (position) => [
|
|
654
788
|
`the value at position ${position} sits inside a nested <template>'s content — inert markup that is never rendered — so it is ignored (and the server ignores it too).`,
|
|
@@ -662,10 +796,6 @@ const PROSE = {
|
|
|
662
796
|
'a binding sits directly inside <table>, where the HTML parser inserts a <tbody> that a client render does not. The same template then renders as `table > tr` and parses as `table > tbody > tr`, so `table > tr` selectors match on only one path and hydration rebuilds this container instead of adopting it.',
|
|
663
797
|
'Write the section explicitly — `<table><tbody>${rows}</tbody></table>` — and every path agrees.',
|
|
664
798
|
],
|
|
665
|
-
'wrong-namespace': (tag, built, host, advice) => [
|
|
666
|
-
`<${tag}> was built as ${built} and placed inside <${host}>, where it will not render.`,
|
|
667
|
-
advice,
|
|
668
|
-
],
|
|
669
799
|
/* ── values (said as they happen) ── */
|
|
670
800
|
'boolean-child': (value) => [
|
|
671
801
|
`a child position was given \`${value}\`, which renders as the word "${value}" — the usual cause is \`\${cond && …}\` with a false \`cond\`.`,
|
|
@@ -724,6 +854,22 @@ const LIVE_CUSTOM = 12;
|
|
|
724
854
|
const REFUSED = 13;
|
|
725
855
|
/** A `<select>`'s `selectedIndex` — the rare spelling of its selection, queued as `SELECT` is (see `flush`). */
|
|
726
856
|
const SELECT_INDEX = 14;
|
|
857
|
+
/**
|
|
858
|
+
* **An HTML `<style>`'s or JSON data block's whole text** — ONE binding (the element's first value; the others are
|
|
859
|
+
* consumed, as a multi-part attribute's are) composes the statics and values and writes the element's text when it
|
|
860
|
+
* changed. Its text is serialized VERBATIM (BROWSER-LEDGER), so it is written unable to end its element, as the server
|
|
861
|
+
* writes it: in a style each `</style` as `<\/style`, in a JSON block every `<` as `\u003c` — on the COMPOSED text, since
|
|
862
|
+
* a closer can form across a hole. Committed in `commit`'s cold branch: the hot text line is untouched.
|
|
863
|
+
*/
|
|
864
|
+
const RAW_STYLE = 15;
|
|
865
|
+
const RAW_JSON = 16;
|
|
866
|
+
/**
|
|
867
|
+
* **An element whose content is never shown** (`<iframe>`, `<noscript>`, `<xmp>`, `<noembed>`, `<noframes>`,
|
|
868
|
+
* `<plaintext>`): its statics and its values composed as text, each VALUE fully encoded (every ASCII non-word character
|
|
869
|
+
* as a character reference), so a page saved from the DOM and parsed again — with scripting on (raw text) or off
|
|
870
|
+
* (markup) — holds no value that can end the element or add an attribute.
|
|
871
|
+
*/
|
|
872
|
+
const RAW_ENCODED = 17;
|
|
727
873
|
/** A child part's mode: what its range currently holds. */
|
|
728
874
|
const EMPTY = 0;
|
|
729
875
|
const TEXT = 1;
|
|
@@ -742,7 +888,7 @@ const NODE = 4;
|
|
|
742
888
|
* capture (`_$capture$`), both read by hydration. One number for both: the three ship in one package, and a change to
|
|
743
889
|
* either seam bumps it. A hydration that meets another number declines (the page renders fresh) and says so.
|
|
744
890
|
*/
|
|
745
|
-
const PROTOCOL =
|
|
891
|
+
const PROTOCOL = 2;
|
|
746
892
|
|
|
747
893
|
/**
|
|
748
894
|
* @verajs/renderer — a template-identity renderer.
|
|
@@ -819,7 +965,12 @@ const SINGLE_QUOTE_END = /'/g;
|
|
|
819
965
|
* writes a text marker and construction turns it into an anchor. `noscript` because Firefox parses it
|
|
820
966
|
* as raw text in a template while Chromium and WebKit do not — listed, it is right in both.
|
|
821
967
|
*/
|
|
822
|
-
const RAW_TEXT_TAGS = /^(?:script|style|textarea|title|iframe|noscript)$/i;
|
|
968
|
+
const RAW_TEXT_TAGS = /^(?:script|style|textarea|title|iframe|noscript|xmp|noembed|noframes|plaintext)$/i;
|
|
969
|
+
/**
|
|
970
|
+
* The HTML elements whose content is never shown — their holes render as encoded text (`RAW_ENCODED`). `tagName` is
|
|
971
|
+
* upper case exactly for an HTML element. (`xmp` shows its text, as text: encoded, a value reads the same.)
|
|
972
|
+
*/
|
|
973
|
+
const NEVER_SHOWN = /^(?:IFRAME|NOSCRIPT|XMP|NOEMBED|NOFRAMES|PLAINTEXT)$/;
|
|
823
974
|
/**
|
|
824
975
|
* The 14 void elements — a start tag with no content and no end tag. Read only by the development tag-shape pass
|
|
825
976
|
* (`<div />` is an open tag; `</br>` is another `<br>`), so production drops it. A regex rather than shared-utils'
|
|
@@ -842,8 +993,6 @@ const UPGRADED = {};
|
|
|
842
993
|
* the SCAN, so development and production parsed one template differently.
|
|
843
994
|
*/
|
|
844
995
|
const SHAPE = /<!--(?:-?>|[\s\S]*?(?:--!?>|$))|<(\/?)([a-zA-Z][^\s/>]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g;
|
|
845
|
-
/** The obsolete elements a parser reads as text whole, which the scanner does not list (production pays nothing for them). */
|
|
846
|
-
const OBSOLETE_RAW = /^(?:xmp|noembed|noframes|plaintext)$/i;
|
|
847
996
|
const tagShape = (strings, type) => {
|
|
848
997
|
const markup = strings.join('');
|
|
849
998
|
/** Where each binding sits in `markup`, so a refusal can ask whether one falls inside an element's content. */
|
|
@@ -868,19 +1017,16 @@ const tagShape = (strings, type) => {
|
|
|
868
1017
|
foreign++;
|
|
869
1018
|
continue;
|
|
870
1019
|
}
|
|
871
|
-
if (!closing &&
|
|
1020
|
+
if (!closing && RAW_TEXT_TAGS.test(tag)) {
|
|
872
1021
|
const end = markup.toLowerCase().indexOf(`</${tag}`, SHAPE.lastIndex);
|
|
873
1022
|
const stop = end === -1 ? markup.length : end;
|
|
874
1023
|
/**
|
|
875
|
-
*
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
* elements are text to the parser whole, which the scanner does not know, so a binding there never renders.
|
|
1024
|
+
* A shape that silently loses a binding, refused: inside `<svg>`/`<math>` a `<title>` or `<style>` is a foreign
|
|
1025
|
+
* element whose content the browser reads as MARKUP, while the renderer reads it as raw text and rebuilds that
|
|
1026
|
+
* text around its bindings — destroying any element inside it.
|
|
879
1027
|
*/
|
|
880
1028
|
if (foreign > 0 && RAW_TEXT_TAGS.test(tag) && bound(SHAPE.lastIndex, stop) && /<[a-zA-Z]/.test(markup.slice(SHAPE.lastIndex, stop)))
|
|
881
1029
|
throw new Error(misuse('renderer', 'foreign-raw-text', true && PROSE['foreign-raw-text'](tag)));
|
|
882
|
-
if (foreign === 0 && OBSOLETE_RAW.test(tag) && bound(SHAPE.lastIndex, stop))
|
|
883
|
-
throw new Error(misuse('renderer', 'obsolete-raw-text', true && PROSE['obsolete-raw-text'](tag)));
|
|
884
1030
|
SHAPE.lastIndex = stop;
|
|
885
1031
|
}
|
|
886
1032
|
if (foreign > 0)
|
|
@@ -975,6 +1121,14 @@ class Template {
|
|
|
975
1121
|
let markup = '';
|
|
976
1122
|
let regex = TEXT_END;
|
|
977
1123
|
let rawEnd;
|
|
1124
|
+
/**
|
|
1125
|
+
* Where the start tag of the raw-text element being opened begins (its string, its offset), its name, and, once its
|
|
1126
|
+
* `>` enters raw text, that start tag as written — in every build, since a script hole is refused in every build (`MARKER` where a hole sat in it) — the tag that OPENED
|
|
1127
|
+
* the raw text a hole sits in, never one found by searching back (a `<script…>` inside a script's text is no tag).
|
|
1128
|
+
*/
|
|
1129
|
+
let rawOpen;
|
|
1130
|
+
let rawName = '';
|
|
1131
|
+
let rawTag = '';
|
|
978
1132
|
/** The previous binding opened an UNQUOTED value, so a string that matches nothing continues it (`a=${x}${y}`). */
|
|
979
1133
|
let open = false;
|
|
980
1134
|
/** Development also scans the LAST static, so a template that ends inside a tag is refused (below); production does not. */
|
|
@@ -999,8 +1153,18 @@ class Template {
|
|
|
999
1153
|
else if (match[1] !== undefined)
|
|
1000
1154
|
regex = COMMENT2_END;
|
|
1001
1155
|
else {
|
|
1002
|
-
if (match[2] !== undefined && RAW_TEXT_TAGS.test(match[2]))
|
|
1003
|
-
|
|
1156
|
+
if (match[2] !== undefined && RAW_TEXT_TAGS.test(match[2])) {
|
|
1157
|
+
/**
|
|
1158
|
+
* The end tag needs the tokenizer's boundary after its name (whitespace, `/`, `>`): `</stylex>` ends
|
|
1159
|
+
* nothing. Or the string's end: `</style${x}` is a tag-name position (refused in development).
|
|
1160
|
+
* `<plaintext>` never ends: everything after it is its text, as the parser reads it.
|
|
1161
|
+
*/
|
|
1162
|
+
rawEnd = /^plaintext$/i.test(match[2]) ? /(?!)/g : new RegExp(`</${match[2]}(?=[\\t\\n\\f\\r />]|$)`, 'gi');
|
|
1163
|
+
if (true ) {
|
|
1164
|
+
rawOpen = [i, match.index];
|
|
1165
|
+
rawName = match[2].toLowerCase();
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1004
1168
|
if (true )
|
|
1005
1169
|
tags[i] = match[2] ?? '';
|
|
1006
1170
|
regex = TAG_END;
|
|
@@ -1011,6 +1175,13 @@ class Template {
|
|
|
1011
1175
|
if (match[0] === '>') {
|
|
1012
1176
|
regex = rawEnd ?? TEXT_END;
|
|
1013
1177
|
nameEnd = -1;
|
|
1178
|
+
if (true && rawOpen !== undefined) {
|
|
1179
|
+
const [from, offset] = rawOpen;
|
|
1180
|
+
rawTag =
|
|
1181
|
+
from === i ? s.slice(offset, at)
|
|
1182
|
+
: strings[from].slice(offset) + MARKER + strings.slice(from + 1, i).map((t) => t + MARKER).join('') + s.slice(0, at);
|
|
1183
|
+
rawOpen = undefined;
|
|
1184
|
+
}
|
|
1014
1185
|
}
|
|
1015
1186
|
else if (match[1] === undefined)
|
|
1016
1187
|
nameEnd = -2;
|
|
@@ -1039,9 +1210,16 @@ class Template {
|
|
|
1039
1210
|
*/
|
|
1040
1211
|
if (true && i === count) {
|
|
1041
1212
|
if (regex !== TEXT_END && regex !== rawEnd && regex !== COMMENT_END && regex !== COMMENT2_END)
|
|
1042
|
-
throw new Error(misuse('renderer', 'unfinished-tag', true &&
|
|
1213
|
+
throw new Error(misuse('renderer', 'unfinished-tag', true && unfinishedTag()));
|
|
1043
1214
|
break;
|
|
1044
1215
|
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Development: a script hole is refused unless the script is a JSON data block, judged exactly as the server judges
|
|
1218
|
+
* it (`dataBlock`, on the start tag as written that opened it). PRODUCTION refuses the same holes after the parse,
|
|
1219
|
+
* below — cheaper (+35 B against +261 B for this scan's tracking), reading the type the parser decoded.
|
|
1220
|
+
*/
|
|
1221
|
+
if (true && regex === rawEnd && rawName === 'script' && (!dataBlock(rawTag) || rawTag.includes(MARKER)))
|
|
1222
|
+
throw new Error(misuse('renderer', 'script-hole', true && PROSE['script-hole']()));
|
|
1045
1223
|
if (regex === TEXT_END) {
|
|
1046
1224
|
markup += `${s}<?${MARKER}${i}>`;
|
|
1047
1225
|
kinds[i] = CHILD;
|
|
@@ -1210,10 +1388,43 @@ class Template {
|
|
|
1210
1388
|
? 2
|
|
1211
1389
|
: 3;
|
|
1212
1390
|
}
|
|
1213
|
-
/**
|
|
1214
|
-
|
|
1215
|
-
|
|
1391
|
+
/**
|
|
1392
|
+
* A raw-text element's markers arrived as characters: rebuild its content with anchors in their place. A
|
|
1393
|
+
* never-shown element is read as its MARKUP when the parser built elements in it (Chromium and WebKit parse a
|
|
1394
|
+
* template's `<noscript>` as markup, so a value written in an attribute there sits in a real attribute) and as
|
|
1395
|
+
* its text otherwise — the same source either way, written back as text.
|
|
1396
|
+
*/
|
|
1397
|
+
const source = RAW_TEXT_TAGS.test(el.localName) ? (NEVER_SHOWN.test(el.tagName) && el.firstElementChild !== null ? el.innerHTML : el.textContent) : '';
|
|
1398
|
+
if (source.includes(MARKER)) {
|
|
1399
|
+
/**
|
|
1400
|
+
* **A script hole is refused in EVERY build unless the script is an HTML JSON data block** (Brian, 2026-11-18).
|
|
1401
|
+
* A template's HTML script never runs on the live page, but a page saved from the DOM and served again (an
|
|
1402
|
+
* editor's publish) runs it; an SVG `<script>` from a template runs in Chromium and WebKit (BROWSER-LEDGER), so
|
|
1403
|
+
* it is refused even with a JSON type. `tagName` is upper case exactly for an HTML element (in an HTML document).
|
|
1404
|
+
* The type is read as the parser decoded it, so `application/json` passes here where the server (and the
|
|
1405
|
+
* development scan, above) refuses it: a genuine JSON block, which never runs — the one recorded difference. A
|
|
1406
|
+
* script carrying any binding of its own (`nodes` holds it: `?type`, `.type`, a spread) is refused too: it could
|
|
1407
|
+
* change the type after this judged it, and a saved page would carry the value as code.
|
|
1408
|
+
*/
|
|
1409
|
+
if (el.tagName === 'script' || (el.tagName === 'SCRIPT' && (!JSON_BLOCK.test(el.getAttribute('type') ?? '') || nodes.includes(el))))
|
|
1410
|
+
throw new Error(misuse('renderer', 'script-hole', true && PROSE['script-hole']()));
|
|
1411
|
+
const pieces = source.split(MARKER);
|
|
1216
1412
|
el.textContent = '';
|
|
1413
|
+
/**
|
|
1414
|
+
* An HTML style, JSON block (the script check above let only that script through) or never-shown element: its first
|
|
1415
|
+
* value owns the element's whole text (`RAW_*`), its statics the even pieces; the values after it are consumed.
|
|
1416
|
+
*/
|
|
1417
|
+
const raw = el.tagName === 'STYLE' ? RAW_STYLE : el.tagName === 'SCRIPT' ? RAW_JSON : NEVER_SHOWN.test(el.tagName) ? RAW_ENCODED : 0;
|
|
1418
|
+
if (raw !== 0) {
|
|
1419
|
+
const first = +pieces[1];
|
|
1420
|
+
nodes[first] = el;
|
|
1421
|
+
kinds[first] = raw;
|
|
1422
|
+
/** One value and no static text (`<style>${css}</style>`): no statics, so an unchanged value returns at once. */
|
|
1423
|
+
statics[first] = pieces.length === 3 && pieces[0] === '' && pieces[2] === '' ? null : pieces.filter((_, p) => p % 2 === 0);
|
|
1424
|
+
for (let p = 3; p < pieces.length; p += 2)
|
|
1425
|
+
kinds[+pieces[p]] = IGNORED;
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1217
1428
|
for (let p = 0; p < pieces.length; p++) {
|
|
1218
1429
|
if (p % 2 === 0) {
|
|
1219
1430
|
if (pieces[p])
|
|
@@ -1343,6 +1554,33 @@ const getTemplate = (result) => {
|
|
|
1343
1554
|
};
|
|
1344
1555
|
/** `${value}` rather than `String(value)`: a symbol throws here as it does at every other sink. */
|
|
1345
1556
|
const toText = (value) => (value == null ? '' : `${value}`);
|
|
1557
|
+
/**
|
|
1558
|
+
* **A value in a `<style>`, JSON block or never-shown element, as text** — the server's rule: nothing for `null`/`undefined`, a list its items'
|
|
1559
|
+
* text (nested lists flattened by the same rule), a template refused, anything else `String`. Cold: reached only when
|
|
1560
|
+
* such a text changes. One function, nothing single-use beside it (the minifier would paste it in as an IIFE).
|
|
1561
|
+
*/
|
|
1562
|
+
const textOf = (value) => {
|
|
1563
|
+
if (Array.isArray(value)) {
|
|
1564
|
+
let text = '';
|
|
1565
|
+
for (let i = 0; i < value.length; i++)
|
|
1566
|
+
text += textOf(value[i]);
|
|
1567
|
+
return text;
|
|
1568
|
+
}
|
|
1569
|
+
/** A tagged literal's template (strings owning `raw`; a JSON-shaped forgery is not one) is refused, as the server refuses it. */
|
|
1570
|
+
const strings = typeof value === 'object' && value !== null ? value.strings : undefined;
|
|
1571
|
+
if (Array.isArray(strings) && Object.hasOwn(strings, 'raw'))
|
|
1572
|
+
throw new Error(misuse('renderer', 'template-in-text', true && templateInText()));
|
|
1573
|
+
return toText(value);
|
|
1574
|
+
};
|
|
1575
|
+
/**
|
|
1576
|
+
* **A template placed in an HTML `<title>` or `<textarea>` is said, in development only** (Brian, 2026-11-18). Its elements
|
|
1577
|
+
* are never shown there (the element shows its text), and a page saved from the DOM reads them back as text. Nothing
|
|
1578
|
+
* unsafe happens, so production carries nothing: the renderer places it, as it always has. (The server refuses it —
|
|
1579
|
+
* `ssr-template-in-text` — because there a template's markup could END the element; an SVG `title` is markup.)
|
|
1580
|
+
*/
|
|
1581
|
+
const TEXT_ONLY = /^(?:TITLE|TEXTAREA)$/;
|
|
1582
|
+
/** Said once per element name — a list of templates in one `<textarea>` speaks once, not per item. */
|
|
1583
|
+
const sayTemplateInText = (host) => warnOnce('renderer', `<${host.localName}>`, 'template-in-text', true && (() => templateInText()), host.localName);
|
|
1346
1584
|
/**
|
|
1347
1585
|
* The record an `@event`, element-position or custom-element `.prop` binding holds in its node slot.
|
|
1348
1586
|
* For an event it is the LISTENER — a stable object, so swapping handlers never touches the DOM and a
|
|
@@ -1497,74 +1735,12 @@ const update = (instance, values) => {
|
|
|
1497
1735
|
*/
|
|
1498
1736
|
const warnBooleanChild = (value) => console.warn(diagnostic('renderer', 'a child position', 'boolean-child', true && PROSE['boolean-child'](String(value))));
|
|
1499
1737
|
/**
|
|
1500
|
-
* **Content in the wrong namespace does not render
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
* frame). Silent where HTML is correct — integration points (`<foreignObject>`, `<desc>`, `<title>`, MathML's token
|
|
1504
|
-
* elements, an HTML-encoded `<annotation-xml>`) and `<style>`/`<script>`, which never draw.
|
|
1738
|
+
* **Content in the wrong namespace does not render**: development names it at each insert (shared-utils'
|
|
1739
|
+
* `checkForeign`, which `@verajs/lite` says too); this renderer's other way to the right namespace is the namespaces
|
|
1740
|
+
* module, so it is the renderer's `retag` sentence.
|
|
1505
1741
|
*/
|
|
1506
|
-
const
|
|
1507
|
-
|
|
1508
|
-
const foreignHost = (parent) => {
|
|
1509
|
-
const element = parent;
|
|
1510
|
-
const namespace = element.namespaceURI;
|
|
1511
|
-
const svg = namespace === SVG_NS;
|
|
1512
|
-
if (!svg && namespace !== MATHML_NS)
|
|
1513
|
-
return null;
|
|
1514
|
-
const name = element.localName;
|
|
1515
|
-
if (svg)
|
|
1516
|
-
return name === 'foreignObject' || name === 'desc' || name === 'title' ? null : name;
|
|
1517
|
-
if (name === 'mi' || name === 'mo' || name === 'mn' || name === 'ms' || name === 'mtext')
|
|
1518
|
-
return null;
|
|
1519
|
-
if (name === 'annotation-xml') {
|
|
1520
|
-
/** The ATTRIBUTE — what the parser reads; `image/svg+xml` is MathML's own spelling for an SVG annotation. */
|
|
1521
|
-
const encoding = element.getAttribute('encoding')?.toLowerCase();
|
|
1522
|
-
return encoding === 'text/html' || encoding === 'application/xhtml+xml' || encoding === 'image/svg+xml' ? null : name;
|
|
1523
|
-
}
|
|
1524
|
-
return name;
|
|
1525
|
-
};
|
|
1526
|
-
/** The nodes an insert is about to place — a fragment empties as it is inserted, so they are read first. */
|
|
1527
|
-
const landing = (node) => (node.nodeType === 11 ? [...node.childNodes] : [node]);
|
|
1528
|
-
const checkForeign = (parent, nodes) => {
|
|
1529
|
-
const host = foreignHost(parent);
|
|
1530
|
-
if (host === null)
|
|
1531
|
-
return;
|
|
1532
|
-
const hostNamespace = parent.namespaceURI;
|
|
1533
|
-
for (const node of nodes) {
|
|
1534
|
-
if (node.nodeType !== 1)
|
|
1535
|
-
continue;
|
|
1536
|
-
const element = node;
|
|
1537
|
-
if (element.namespaceURI === hostNamespace)
|
|
1538
|
-
continue;
|
|
1539
|
-
const tag = element.localName;
|
|
1540
|
-
if (tag === 'style' || tag === 'script')
|
|
1541
|
-
continue;
|
|
1542
|
-
/** The parser itself opens SVG content for an `<svg>` inside `<annotation-xml>`, whatever the encoding. */
|
|
1543
|
-
if (host === 'annotation-xml' && tag === 'svg' && element.namespaceURI === SVG_NS)
|
|
1544
|
-
continue;
|
|
1545
|
-
const built = element.namespaceURI === MATHML_NS ? 'MathML' : element.namespaceURI === SVG_NS ? 'SVG' : 'HTML';
|
|
1546
|
-
/** The island and its placement are chosen by the HOST's namespace; the encoding follows the CONTENT. */
|
|
1547
|
-
const island = hostNamespace === MATHML_NS
|
|
1548
|
-
? `<mtext>, or <annotation-xml encoding="${built === 'SVG' ? 'image/svg+xml' : 'text/html'}">, ` +
|
|
1549
|
-
'inside a MathML container such as <mrow> or <math> rather than inside a token element'
|
|
1550
|
-
: 'a <foreignObject>, which has to sit in an element whose content model accepts one — a container such as ' +
|
|
1551
|
-
'<g> or <svg>, not a text, clipping, gradient or filter element';
|
|
1552
|
-
/** Keyed by host namespace AND content namespace: `<a>` is a real element in all three. */
|
|
1553
|
-
const seen = `${hostNamespace}${host}>${element.namespaceURI}${tag}`;
|
|
1554
|
-
/** `hasWarned` first: the advice below is built only for a case not yet said. */
|
|
1555
|
-
if (hasWarned('wrong-namespace', seen))
|
|
1556
|
-
continue;
|
|
1557
|
-
const advice = built === 'HTML'
|
|
1558
|
-
? `If it is meant to be an SVG or MathML element, the template holding it needs the svg\`…\` or mathml\`…\` tag ` +
|
|
1559
|
-
`at the call site — or wire @verajs/renderer/namespaces, which parses a template where it lands (compiled JSX ` +
|
|
1560
|
-
`wires it itself). A template built before it was wired keeps the namespace it was first built in. If it is ` +
|
|
1561
|
-
`genuinely HTML (a <div>, a custom element), it belongs in ${island}: tagging it will not help, and a custom ` +
|
|
1562
|
-
`element only upgrades in the HTML namespace.`
|
|
1563
|
-
: `The template's tag is already right — these two namespaces cannot nest directly. Put the ` +
|
|
1564
|
-
`${built === 'SVG' ? '<svg>' : '<math>'} root inside ${island}.`;
|
|
1565
|
-
warnOnce('renderer', `<${tag}>`, 'wrong-namespace', true && (() => PROSE['wrong-namespace'](tag, built, host, advice)), seen);
|
|
1566
|
-
}
|
|
1567
|
-
};
|
|
1742
|
+
const RETAG = ` — or wire @verajs/renderer/namespaces, which parses a template where it lands (compiled JSX ` +
|
|
1743
|
+
`wires it itself). A template built before it was wired keeps the namespace it was first built in`;
|
|
1568
1744
|
let profileHook = null;
|
|
1569
1745
|
|
|
1570
1746
|
const applierSwaps = /* @__PURE__ */ new WeakMap();
|
|
@@ -1625,12 +1801,39 @@ const commit = (template, bindings, i, kind, values) => {
|
|
|
1625
1801
|
* One test for the kinds decided before anything is computed — the same one comparison `REFUSED` alone cost. A
|
|
1626
1802
|
* `selectedIndex` has no statics and no URL: queued, as a select's value is. (Hydration never commits a selection:
|
|
1627
1803
|
* the server marked the option, and whatever the user chose before the script arrived stands.)
|
|
1804
|
+
*
|
|
1805
|
+
* A style's or JSON block's text (`RAW_STYLE`/`RAW_JSON`): composed, compared with the text last composed, and only
|
|
1806
|
+
* when it changed escaped and written whole — the server's bytes (`@verajs/ssr`'s `styleHole` and JSON rule).
|
|
1628
1807
|
*/
|
|
1629
1808
|
if (kind >= REFUSED) {
|
|
1630
1809
|
if (kind === SELECT_INDEX) {
|
|
1631
1810
|
bindings[slot + 1] = values[i];
|
|
1632
1811
|
(pendingSelects ??= []).push(LATER, [node, values[i]]);
|
|
1633
1812
|
}
|
|
1813
|
+
else if (kind !== REFUSED) {
|
|
1814
|
+
const parts = template.$J[i];
|
|
1815
|
+
let text;
|
|
1816
|
+
/**
|
|
1817
|
+
* Every render reaches here (these kinds sit past `LIVE`), so an unchanged text returns before any write: a lone
|
|
1818
|
+
* value by identity, as a plain text hole is skipped; statics and values by the composed text.
|
|
1819
|
+
*/
|
|
1820
|
+
if (parts === null) {
|
|
1821
|
+
if (values[i] === committed)
|
|
1822
|
+
return;
|
|
1823
|
+
text = textOf((bindings[slot + 1] = values[i]));
|
|
1824
|
+
if (kind === RAW_ENCODED)
|
|
1825
|
+
text = encodeText(text);
|
|
1826
|
+
}
|
|
1827
|
+
else {
|
|
1828
|
+
text = parts[0];
|
|
1829
|
+
for (let p = 1; p < parts.length; p++)
|
|
1830
|
+
text += (kind === RAW_ENCODED ? encodeText(textOf(values[i + p - 1])) : textOf(values[i + p - 1])) + parts[p];
|
|
1831
|
+
if (text === committed)
|
|
1832
|
+
return;
|
|
1833
|
+
bindings[slot + 1] = text;
|
|
1834
|
+
}
|
|
1835
|
+
node.textContent = kind === RAW_ENCODED ? text : /*@__NOINLINE__*/ closedRawText(text, kind === RAW_JSON);
|
|
1836
|
+
}
|
|
1634
1837
|
return;
|
|
1635
1838
|
}
|
|
1636
1839
|
const parts = template.$J[i];
|
|
@@ -1853,7 +2056,7 @@ class ChildPart {
|
|
|
1853
2056
|
const placed = true ? landing(node) : undefined;
|
|
1854
2057
|
(this.$w ?? this.$s.parentNode).insertBefore(node, this.$e);
|
|
1855
2058
|
if (true )
|
|
1856
|
-
checkForeign(this.$w ?? this.$s.parentNode, placed);
|
|
2059
|
+
checkForeign('renderer', this.$w ?? this.$s.parentNode, placed, RETAG);
|
|
1857
2060
|
}
|
|
1858
2061
|
/**
|
|
1859
2062
|
* Tells the CURRENT content that it is going away — the part itself stays, so what `hold()` parked here stays
|
|
@@ -1997,6 +2200,8 @@ class ChildPart {
|
|
|
1997
2200
|
if (this.$o !== EMPTY)
|
|
1998
2201
|
this._clear();
|
|
1999
2202
|
if (instance === undefined) {
|
|
2203
|
+
if (true && TEXT_ONLY.test((this.$w ?? this.$s.parentNode).tagName))
|
|
2204
|
+
sayTemplateInText(this.$w ?? this.$s.parentNode);
|
|
2000
2205
|
let template = getTemplate(result);
|
|
2001
2206
|
if (template.$X)
|
|
2002
2207
|
template = resolved(template, this.$w ?? this.$s.parentNode);
|
|
@@ -2065,6 +2270,8 @@ class ChildPart {
|
|
|
2065
2270
|
/** Creates one list item before `ref`. */
|
|
2066
2271
|
$c(value, parent, ref) {
|
|
2067
2272
|
if (value !== null && typeof value === 'object' && isTemplateResult(value)) {
|
|
2273
|
+
if (true && TEXT_ONLY.test(parent.tagName))
|
|
2274
|
+
sayTemplateInText(parent);
|
|
2068
2275
|
let template = getTemplate(value);
|
|
2069
2276
|
if (template.$X)
|
|
2070
2277
|
template = resolved(template, parent);
|
|
@@ -2072,7 +2279,7 @@ class ChildPart {
|
|
|
2072
2279
|
const instance = instantiate(template, value, passDoc);
|
|
2073
2280
|
into(parent, ref).insertBefore(instance.$R, ref);
|
|
2074
2281
|
if (true )
|
|
2075
|
-
checkForeign(parent, [instance.$R]);
|
|
2282
|
+
checkForeign('renderer', parent, [instance.$R], RETAG);
|
|
2076
2283
|
instance.$k = value.key;
|
|
2077
2284
|
/** Only a result marked `_$same$` (the keyed module marks its rows') records its identity. */
|
|
2078
2285
|
if (value._$same$ === 1)
|