@taggor/runtime 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +49 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/compat/before-compat.d.ts +5 -0
- package/dist/compat/before-compat.d.ts.map +1 -0
- package/dist/compat/before-compat.js +15 -0
- package/dist/compat/before-compat.js.map +1 -0
- package/dist/compat/index.d.ts +90 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +67 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/scope.d.ts +81 -0
- package/dist/compat/scope.d.ts.map +1 -0
- package/dist/compat/scope.js +107 -0
- package/dist/compat/scope.js.map +1 -0
- package/dist/element/attributes.d.ts +103 -0
- package/dist/element/attributes.d.ts.map +1 -0
- package/dist/element/attributes.js +153 -0
- package/dist/element/attributes.js.map +1 -0
- package/dist/element/component-controller.d.ts +98 -0
- package/dist/element/component-controller.d.ts.map +1 -0
- package/dist/element/component-controller.js +472 -0
- package/dist/element/component-controller.js.map +1 -0
- package/dist/element/contract-gate.d.ts +29 -0
- package/dist/element/contract-gate.d.ts.map +1 -0
- package/dist/element/contract-gate.js +37 -0
- package/dist/element/contract-gate.js.map +1 -0
- package/dist/element/create-component-element.d.ts +93 -0
- package/dist/element/create-component-element.d.ts.map +1 -0
- package/dist/element/create-component-element.js +302 -0
- package/dist/element/create-component-element.js.map +1 -0
- package/dist/element/define-element.d.ts +43 -0
- package/dist/element/define-element.d.ts.map +1 -0
- package/dist/element/define-element.js +61 -0
- package/dist/element/define-element.js.map +1 -0
- package/dist/element/diagnostics.d.ts +35 -0
- package/dist/element/diagnostics.d.ts.map +1 -0
- package/dist/element/diagnostics.js +52 -0
- package/dist/element/diagnostics.js.map +1 -0
- package/dist/element/error-boundary.d.ts +41 -0
- package/dist/element/error-boundary.d.ts.map +1 -0
- package/dist/element/error-boundary.js +36 -0
- package/dist/element/error-boundary.js.map +1 -0
- package/dist/element/error-report.d.ts +9 -0
- package/dist/element/error-report.d.ts.map +1 -0
- package/dist/element/error-report.js +51 -0
- package/dist/element/error-report.js.map +1 -0
- package/dist/element/events.d.ts +69 -0
- package/dist/element/events.d.ts.map +1 -0
- package/dist/element/events.js +115 -0
- package/dist/element/events.js.map +1 -0
- package/dist/element/handler-guard.d.ts +54 -0
- package/dist/element/handler-guard.d.ts.map +1 -0
- package/dist/element/handler-guard.js +162 -0
- package/dist/element/handler-guard.js.map +1 -0
- package/dist/element/index.d.ts +9 -0
- package/dist/element/index.d.ts.map +1 -0
- package/dist/element/index.js +9 -0
- package/dist/element/index.js.map +1 -0
- package/dist/element/props-script.d.ts +37 -0
- package/dist/element/props-script.d.ts.map +1 -0
- package/dist/element/props-script.js +63 -0
- package/dist/element/props-script.js.map +1 -0
- package/dist/element/styles.d.ts +45 -0
- package/dist/element/styles.d.ts.map +1 -0
- package/dist/element/styles.js +66 -0
- package/dist/element/styles.js.map +1 -0
- package/dist/element/types.d.ts +148 -0
- package/dist/element/types.d.ts.map +1 -0
- package/dist/element/types.js +3 -0
- package/dist/element/types.js.map +1 -0
- package/dist/host/api.d.ts +40 -0
- package/dist/host/api.d.ts.map +1 -0
- package/dist/host/api.js +144 -0
- package/dist/host/api.js.map +1 -0
- package/dist/host/barrier.d.ts +27 -0
- package/dist/host/barrier.d.ts.map +1 -0
- package/dist/host/barrier.js +47 -0
- package/dist/host/barrier.js.map +1 -0
- package/dist/host/index.d.ts +11 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +9 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/registry.d.ts +21 -0
- package/dist/host/registry.d.ts.map +1 -0
- package/dist/host/registry.js +29 -0
- package/dist/host/registry.js.map +1 -0
- package/dist/host/types.d.ts +54 -0
- package/dist/host/types.d.ts.map +1 -0
- package/dist/host/types.js +11 -0
- package/dist/host/types.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/config.d.ts +63 -0
- package/dist/loader/config.d.ts.map +1 -0
- package/dist/loader/config.js +115 -0
- package/dist/loader/config.js.map +1 -0
- package/dist/loader/entry.d.ts +2 -0
- package/dist/loader/entry.d.ts.map +1 -0
- package/dist/loader/entry.js +37 -0
- package/dist/loader/entry.js.map +1 -0
- package/dist/loader/lazy-transport.d.ts +26 -0
- package/dist/loader/lazy-transport.d.ts.map +1 -0
- package/dist/loader/lazy-transport.js +59 -0
- package/dist/loader/lazy-transport.js.map +1 -0
- package/dist/loader/loader-code.d.ts +2 -0
- package/dist/loader/loader-code.js +2 -0
- package/dist/loader/loading.d.ts +24 -0
- package/dist/loader/loading.d.ts.map +1 -0
- package/dist/loader/loading.js +29 -0
- package/dist/loader/loading.js.map +1 -0
- package/dist/loader/page-state.d.ts +66 -0
- package/dist/loader/page-state.d.ts.map +1 -0
- package/dist/loader/page-state.js +73 -0
- package/dist/loader/page-state.js.map +1 -0
- package/dist/loader/resilient-import.d.ts +32 -0
- package/dist/loader/resilient-import.d.ts.map +1 -0
- package/dist/loader/resilient-import.js +42 -0
- package/dist/loader/resilient-import.js.map +1 -0
- package/dist/loader/run.d.ts +45 -0
- package/dist/loader/run.d.ts.map +1 -0
- package/dist/loader/run.js +217 -0
- package/dist/loader/run.js.map +1 -0
- package/dist/loader/script-url.d.ts +50 -0
- package/dist/loader/script-url.d.ts.map +1 -0
- package/dist/loader/script-url.js +71 -0
- package/dist/loader/script-url.js.map +1 -0
- package/dist/loader/script.d.ts +31 -0
- package/dist/loader/script.d.ts.map +1 -0
- package/dist/loader/script.js +40 -0
- package/dist/loader/script.js.map +1 -0
- package/dist/server/render-fragment.d.ts +57 -0
- package/dist/server/render-fragment.d.ts.map +1 -0
- package/dist/server/render-fragment.js +182 -0
- package/dist/server/render-fragment.js.map +1 -0
- package/dist/server/ssr-code.d.ts +4 -0
- package/dist/server/ssr-code.js +3 -0
- package/dist/server/worker.d.ts +37 -0
- package/dist/server/worker.d.ts.map +1 -0
- package/dist/server/worker.js +71 -0
- package/dist/server/worker.js.map +1 -0
- package/package.json +86 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser half of the runtime error telemetry (TAG-318): a caught component failure becomes one
|
|
3
|
+
* `navigator.sendBeacon` to `POST /e/<siteKey>` of the delivery origin, where the edge validates,
|
|
4
|
+
* scrubs, hashes and records it (apps/edge `domain/error-event.ts` owns the wire format).
|
|
5
|
+
*
|
|
6
|
+
* Body: `error <versionHash> <phase> <frames> <message>`; `phase` is the failure phase
|
|
7
|
+
* (`render`, `handler`, `lifecycle`), `frames` the end of each stack line that names this component's
|
|
8
|
+
* bundle (`.js:1:2345)`, at most `RUNTIME_ERROR_MAX_FRAMES`) joined by commas, and `message` the
|
|
9
|
+
* first `RUNTIME_ERROR_MESSAGE_MAX` characters of the error message.
|
|
10
|
+
*
|
|
11
|
+
* Privacy (golden rule 6): never a URL, props, attribute values, form data or the page's own frames;
|
|
12
|
+
* only the lines that contain the version hash (the bundle's own URL) are kept, and the edge scrubs
|
|
13
|
+
* the message again before storing it.
|
|
14
|
+
*
|
|
15
|
+
* Bounded (golden rule 2): at most `RUNTIME_ERRORS_PER_COMPONENT_PER_PAGE` reports per component tag
|
|
16
|
+
* for the page's life, so a component in an error loop costs five beacons; every step is inside
|
|
17
|
+
* `try`, a page without `sendBeacon` sends nothing, and nothing here can throw at the page. The
|
|
18
|
+
* site key comes from the loader's shared page record (`Symbol.for("taggor.loader")`, claim
|
|
19
|
+
* `"<siteKey>\n<version>"`, `loader/page-state.ts`); a claim of another version or site is not ours
|
|
20
|
+
* to report on. Written tersely: the runtime is at its byte ceiling (ADR 0061).
|
|
21
|
+
*/
|
|
22
|
+
import { RUNTIME_ERROR_MAX_FRAMES, RUNTIME_ERROR_MESSAGE_MAX, RUNTIME_ERRORS_PER_COMPONENT_PER_PAGE, } from "@taggor/contract/zod-free";
|
|
23
|
+
const sent = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Reports one caught failure.
|
|
26
|
+
* Inputs: the component tag, the published version hash, the failure phase, the caught value and
|
|
27
|
+
* the delivery origin (the loader's runtime URL; never `import.meta.url`, which is a syntax error
|
|
28
|
+
* when a host page loads the bundle as a classic script and made props.e2e.ts fail, TAG-2522).
|
|
29
|
+
* Output: none. Errors: never throws. Side effects: at most one beacon and the per-tag counter.
|
|
30
|
+
*/
|
|
31
|
+
export function reportFailure(tag, version, phase, error, origin) {
|
|
32
|
+
try {
|
|
33
|
+
const n = sent.get(tag) ?? 0;
|
|
34
|
+
const [site, claimed] = String(globalThis[Symbol.for("taggor.loader")]?.tags.get(tag)).split("\n");
|
|
35
|
+
if (claimed !== version || n >= RUNTIME_ERRORS_PER_COMPONENT_PER_PAGE)
|
|
36
|
+
return;
|
|
37
|
+
sent.set(tag, n + 1);
|
|
38
|
+
const { message, stack } = error;
|
|
39
|
+
const frames = String(stack)
|
|
40
|
+
.split("\n")
|
|
41
|
+
.filter((line) => line.includes(version))
|
|
42
|
+
.map((line) => line.split(version)[1])
|
|
43
|
+
.slice(0, RUNTIME_ERROR_MAX_FRAMES)
|
|
44
|
+
.join();
|
|
45
|
+
navigator.sendBeacon(new URL(`/e/${site}`, origin), `error ${version} ${phase} ${frames} ${String(message).slice(0, RUNTIME_ERROR_MESSAGE_MAX)}`);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Telemetry never reaches the page.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=error-report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-report.js","sourceRoot":"","sources":["../../src/element/error-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,qCAAqC,GACtC,MAAM,2BAA2B,CAAC;AAEnC,MAAM,IAAI,GA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oCAAoC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component events (TAG-305): the host's `emit(name, detail)`, which dispatches a declared event on
|
|
3
|
+
* the host element as a `CustomEvent` named `<tag>:<event>`, so the page sees the host as `target`
|
|
4
|
+
* and never a node of the shadow root.
|
|
5
|
+
*
|
|
6
|
+
* TAG-320: the `<tag>` prefix is given at dispatch time by the caller, never read from the
|
|
7
|
+
* manifest here: the controller passes the tag the element's class is really registered under
|
|
8
|
+
* (its `localName`), so after a collision a component never dispatches events under the declared tag
|
|
9
|
+
* that belongs to another script.
|
|
10
|
+
*
|
|
11
|
+
* The component is untrusted code (golden rule 5), and an untyped JS component can call `emit` with
|
|
12
|
+
* anything, so nothing it passes reaches the page as is:
|
|
13
|
+
*
|
|
14
|
+
* - the declarations are read once, when the element class is created, into a `Map` of plain-data
|
|
15
|
+
* copies (`readEventRoutes`): mutating the manifest later, or a declaration that is a getter or
|
|
16
|
+
* a Proxy, cannot widen what is dispatched, and `Map` lookups never reach `Object.prototype`
|
|
17
|
+
* (`emit("constructor")` is undeclared, not a hit);
|
|
18
|
+
* - the `detail` is first copied as plain data (`structuredClone`: getters run once, a Proxy, a
|
|
19
|
+
* function or a DOM node is refused, an own `Symbol.iterator` is not carried over), then checked
|
|
20
|
+
* by the contract's `checkValue`, which builds a fresh value with only the declared keys; that
|
|
21
|
+
* value is deep-frozen (the contract's `deepFreeze`), so every page listener sees the same data
|
|
22
|
+
* and the component holds no reference to it. The value rule is the contract's, never
|
|
23
|
+
* re-implemented here.
|
|
24
|
+
* - without `structuredClone` (Chrome < 98, Firefox < 94, Safari < 15.4) nothing is dispatched
|
|
25
|
+
* (TAG-223): the declarations could not be copied, and checking the live component object would
|
|
26
|
+
* run its getters and Proxy traps again.
|
|
27
|
+
*
|
|
28
|
+
* A dropped `emit` comes back as a message for the debug log (`event-dropped`); it names the
|
|
29
|
+
* declared event and the contract's problem code, never the refused value or an undeclared name.
|
|
30
|
+
* A page listener that throws is page code: `dispatchEvent` reports it to the page's
|
|
31
|
+
* `window.onerror` and returns normally, so the component keeps running.
|
|
32
|
+
*/
|
|
33
|
+
import { type ValueSchema } from "@taggor/contract/zod-free";
|
|
34
|
+
/** One declared event, read once from the manifest. */
|
|
35
|
+
export interface EventRoute {
|
|
36
|
+
/** The declared value schema of `detail` (a plain-data copy). */
|
|
37
|
+
readonly detail: ValueSchema;
|
|
38
|
+
/** From the declaration; each is `true` unless declared `false`. */
|
|
39
|
+
readonly bubbles: boolean;
|
|
40
|
+
readonly composed: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** The declared events of a component, by manifest name (`submit`). */
|
|
43
|
+
export type EventRoutes = ReadonlyMap<string, EventRoute>;
|
|
44
|
+
/**
|
|
45
|
+
* Reads the `events` map of a manifest into `EventRoutes`.
|
|
46
|
+
*
|
|
47
|
+
* Inputs: the manifest's `events` (any value: the definition is component code). Output: one route per own key whose declaration is an object with an object `detail`;
|
|
48
|
+
* nothing for a missing or non-object map, one that cannot be copied as plain data, or a browser
|
|
49
|
+
* without `structuredClone` (every `emit` is then dropped as undeclared). Errors: none. Side
|
|
50
|
+
* effects: reads `events` once (getters and Proxy traps run once).
|
|
51
|
+
*/
|
|
52
|
+
export declare function readEventRoutes(events: unknown): EventRoutes;
|
|
53
|
+
/**
|
|
54
|
+
* Handles one `emit` call: dispatches the declared event `name` on `target`, or says why not.
|
|
55
|
+
*
|
|
56
|
+
* Inputs: the host element, the routes, the event tag (the tag the element is registered under,
|
|
57
|
+
* TAG-320), the `name` and `detail` the component passed (any values) and whether
|
|
58
|
+
* the component is mounted (connected and not failed). Output: `undefined` when a
|
|
59
|
+
* `CustomEvent` was dispatched (type `<tag>:<name>`, the declared `bubbles`/`composed`, and a
|
|
60
|
+
* `detail` that is a new, deep-frozen value holding only the declared data); otherwise the debug
|
|
61
|
+
* message: `name` not declared, the component not mounted, `detail` not plain data (or no
|
|
62
|
+
* `structuredClone`) or refused by the contract (its problem code), or `dispatchEvent` itself
|
|
63
|
+
* throwing (a page that replaced it).
|
|
64
|
+
* Errors: none. Side effects: reads `detail` once through `structuredClone`; `dispatchEvent`
|
|
65
|
+
* runs the page's listeners synchronously (an exception in one goes to the page's
|
|
66
|
+
* `window.onerror`, not here).
|
|
67
|
+
*/
|
|
68
|
+
export declare function emitEvent(target: EventTarget, routes: EventRoutes, tag: string, name: unknown, detail: unknown, mounted: boolean): string | undefined;
|
|
69
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/element/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAErF,uDAAuD;AACvD,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,uEAAuE;AACvE,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,WAAW,CAkB5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,OAAO,GACf,MAAM,GAAG,SAAS,CA6BpB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component events (TAG-305): the host's `emit(name, detail)`, which dispatches a declared event on
|
|
3
|
+
* the host element as a `CustomEvent` named `<tag>:<event>`, so the page sees the host as `target`
|
|
4
|
+
* and never a node of the shadow root.
|
|
5
|
+
*
|
|
6
|
+
* TAG-320: the `<tag>` prefix is given at dispatch time by the caller, never read from the
|
|
7
|
+
* manifest here: the controller passes the tag the element's class is really registered under
|
|
8
|
+
* (its `localName`), so after a collision a component never dispatches events under the declared tag
|
|
9
|
+
* that belongs to another script.
|
|
10
|
+
*
|
|
11
|
+
* The component is untrusted code (golden rule 5), and an untyped JS component can call `emit` with
|
|
12
|
+
* anything, so nothing it passes reaches the page as is:
|
|
13
|
+
*
|
|
14
|
+
* - the declarations are read once, when the element class is created, into a `Map` of plain-data
|
|
15
|
+
* copies (`readEventRoutes`): mutating the manifest later, or a declaration that is a getter or
|
|
16
|
+
* a Proxy, cannot widen what is dispatched, and `Map` lookups never reach `Object.prototype`
|
|
17
|
+
* (`emit("constructor")` is undeclared, not a hit);
|
|
18
|
+
* - the `detail` is first copied as plain data (`structuredClone`: getters run once, a Proxy, a
|
|
19
|
+
* function or a DOM node is refused, an own `Symbol.iterator` is not carried over), then checked
|
|
20
|
+
* by the contract's `checkValue`, which builds a fresh value with only the declared keys; that
|
|
21
|
+
* value is deep-frozen (the contract's `deepFreeze`), so every page listener sees the same data
|
|
22
|
+
* and the component holds no reference to it. The value rule is the contract's, never
|
|
23
|
+
* re-implemented here.
|
|
24
|
+
* - without `structuredClone` (Chrome < 98, Firefox < 94, Safari < 15.4) nothing is dispatched
|
|
25
|
+
* (TAG-223): the declarations could not be copied, and checking the live component object would
|
|
26
|
+
* run its getters and Proxy traps again.
|
|
27
|
+
*
|
|
28
|
+
* A dropped `emit` comes back as a message for the debug log (`event-dropped`); it names the
|
|
29
|
+
* declared event and the contract's problem code, never the refused value or an undeclared name.
|
|
30
|
+
* A page listener that throws is page code: `dispatchEvent` reports it to the page's
|
|
31
|
+
* `window.onerror` and returns normally, so the component keeps running.
|
|
32
|
+
*/
|
|
33
|
+
import { checkValue, deepFreeze } from "@taggor/contract/zod-free";
|
|
34
|
+
/**
|
|
35
|
+
* Reads the `events` map of a manifest into `EventRoutes`.
|
|
36
|
+
*
|
|
37
|
+
* Inputs: the manifest's `events` (any value: the definition is component code). Output: one route per own key whose declaration is an object with an object `detail`;
|
|
38
|
+
* nothing for a missing or non-object map, one that cannot be copied as plain data, or a browser
|
|
39
|
+
* without `structuredClone` (every `emit` is then dropped as undeclared). Errors: none. Side
|
|
40
|
+
* effects: reads `events` once (getters and Proxy traps run once).
|
|
41
|
+
*/
|
|
42
|
+
export function readEventRoutes(events) {
|
|
43
|
+
const routes = new Map();
|
|
44
|
+
try {
|
|
45
|
+
const copy = structuredClone(events);
|
|
46
|
+
if (!isObject(copy))
|
|
47
|
+
return routes;
|
|
48
|
+
for (const [name, declaration] of Object.entries(copy)) {
|
|
49
|
+
// A declaration without a `detail` schema is not dispatchable (the contract requires one).
|
|
50
|
+
if (!isObject(declaration) || !isObject(declaration["detail"]))
|
|
51
|
+
continue;
|
|
52
|
+
routes.set(name, {
|
|
53
|
+
detail: declaration["detail"],
|
|
54
|
+
bubbles: declaration["bubbles"] !== false,
|
|
55
|
+
composed: declaration["composed"] !== false,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Not plain data (a function, a Proxy), or no structuredClone: no event is dispatchable.
|
|
61
|
+
}
|
|
62
|
+
return routes;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Handles one `emit` call: dispatches the declared event `name` on `target`, or says why not.
|
|
66
|
+
*
|
|
67
|
+
* Inputs: the host element, the routes, the event tag (the tag the element is registered under,
|
|
68
|
+
* TAG-320), the `name` and `detail` the component passed (any values) and whether
|
|
69
|
+
* the component is mounted (connected and not failed). Output: `undefined` when a
|
|
70
|
+
* `CustomEvent` was dispatched (type `<tag>:<name>`, the declared `bubbles`/`composed`, and a
|
|
71
|
+
* `detail` that is a new, deep-frozen value holding only the declared data); otherwise the debug
|
|
72
|
+
* message: `name` not declared, the component not mounted, `detail` not plain data (or no
|
|
73
|
+
* `structuredClone`) or refused by the contract (its problem code), or `dispatchEvent` itself
|
|
74
|
+
* throwing (a page that replaced it).
|
|
75
|
+
* Errors: none. Side effects: reads `detail` once through `structuredClone`; `dispatchEvent`
|
|
76
|
+
* runs the page's listeners synchronously (an exception in one goes to the page's
|
|
77
|
+
* `window.onerror`, not here).
|
|
78
|
+
*/
|
|
79
|
+
export function emitEvent(target, routes, tag, name, detail, mounted) {
|
|
80
|
+
const route = typeof name === "string" ? routes.get(name) : undefined;
|
|
81
|
+
// The undeclared name is left out of the message: it is whatever the component passed.
|
|
82
|
+
if (route === undefined)
|
|
83
|
+
return "undeclared event dropped";
|
|
84
|
+
const dropped = `event "${name}" dropped: `;
|
|
85
|
+
// A late timer or promise of a component that left the page (or shows its fallback).
|
|
86
|
+
if (!mounted)
|
|
87
|
+
return `${dropped}not mounted`;
|
|
88
|
+
let outcome;
|
|
89
|
+
try {
|
|
90
|
+
outcome = checkValue(route.detail, structuredClone(detail));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// A Proxy, a function, a DOM node, a getter that throws, no structuredClone (or a malformed
|
|
94
|
+
// declared schema).
|
|
95
|
+
return `${dropped}not plain data`;
|
|
96
|
+
}
|
|
97
|
+
if (!outcome.ok)
|
|
98
|
+
return dropped + outcome.problem;
|
|
99
|
+
const { bubbles, composed } = route;
|
|
100
|
+
try {
|
|
101
|
+
target.dispatchEvent(new CustomEvent(`${tag}:${name}`, {
|
|
102
|
+
detail: deepFreeze(outcome.value),
|
|
103
|
+
bubbles,
|
|
104
|
+
composed,
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return `${dropped}dispatch failed`;
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
function isObject(value) {
|
|
113
|
+
return typeof value === "object" && value !== null;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL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I,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,uFAAuF;IACvF,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,0BAA0B,CAAC;IAC3D,MAAM,OAAO,GAAG,UAAU,IAAc,aAAa,CAAC;IACtD,qFAAqF;IACrF,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,OAAO,aAAa,CAAC;IAC7C,IAAI,OAAsC,CAAC;IAC3C,IAAI,CAAC;QACH,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,4FAA4F;QAC5F,oBAAoB;QACpB,OAAO,GAAG,OAAO,gBAAgB,CAAC;IACpC,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAClD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACpC,IAAI,CAAC;QACH,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,GAAG,GAAG,IAAI,IAAc,EAAE,EAAE;YAC1C,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;YACjC,OAAO;YACP,QAAQ;SACT,CAAC,CACH,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,OAAO,iBAAiB,CAAC;IACrC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event handler guard (TAG-302): routes an exception thrown by a component's DOM event handler to
|
|
3
|
+
* that component's error boundary instead of the page.
|
|
4
|
+
*
|
|
5
|
+
* Why: Preact's error boundaries catch render and effect errors, but an `onClick` that throws is
|
|
6
|
+
* called by the browser's event dispatch, which reports the exception to `window.onerror` (and a
|
|
7
|
+
* rejected promise from an async handler to `unhandledrejection`). The guard hooks Preact's
|
|
8
|
+
* public `options.vnode`: every `on*` function prop of a DOM vnode is replaced by a wrapper that
|
|
9
|
+
* calls it in a `try`, and on failure finds the component whose shadow root contains the event's
|
|
10
|
+
* `currentTarget` (walking out through nested shadow roots) and hands it the error.
|
|
11
|
+
*
|
|
12
|
+
* The hook is installed on the first `createComponentElement`, never at import (golden rule 2), and
|
|
13
|
+
* chains any `options.vnode` already set. It changes only the runtime's own copy of Preact, which
|
|
14
|
+
* is why component bundles must share it rather than bring their own (docs/agentes/runtime.md).
|
|
15
|
+
* An error from a handler outside every registered component is rethrown unchanged.
|
|
16
|
+
*
|
|
17
|
+
* TAG-317: a wrapper is stamped with a private class field (`WrapperStamp`), not tracked in a
|
|
18
|
+
* WeakSet or cached in a WeakMap per handler. Handlers are new closures on every render, and those weak
|
|
19
|
+
* tables grew the retained heap by about 14 bytes per mount even after the entries died
|
|
20
|
+
* (measured in Chromium by e2e/lifecycle.e2e.ts); the only per-root state left is
|
|
21
|
+
* `failureByRoot`, whose entries are deleted explicitly on unmount.
|
|
22
|
+
*/
|
|
23
|
+
import { options } from "preact";
|
|
24
|
+
/** Receives an error caught in a handler of one component. */
|
|
25
|
+
export type HandlerFailure = (error: unknown) => void;
|
|
26
|
+
type Handler = (this: unknown, ...args: unknown[]) => unknown;
|
|
27
|
+
/**
|
|
28
|
+
* Registers the shadow root of a mounted component, so errors from handlers inside it reach
|
|
29
|
+
* `onFailure`.
|
|
30
|
+
*
|
|
31
|
+
* Inputs: the component's shadow root and the function that fails the component. Output: a function
|
|
32
|
+
* that unregisters it (call it on unmount). Errors: none. Side effects: a WeakMap entry.
|
|
33
|
+
*/
|
|
34
|
+
export declare function registerComponentRoot(root: ShadowRoot, onFailure: HandlerFailure): () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Installs the guard on Preact's `options.vnode`, once per options object.
|
|
37
|
+
*
|
|
38
|
+
* Inputs: the Preact options to hook (the runtime's own by default; tests may pass a fresh one).
|
|
39
|
+
* Output: none. Errors: none. Side effects: sets `target.vnode`, keeping the previous hook.
|
|
40
|
+
*/
|
|
41
|
+
export declare function installHandlerGuard(target?: typeof options): void;
|
|
42
|
+
/**
|
|
43
|
+
* The guarded version of an event handler.
|
|
44
|
+
*
|
|
45
|
+
* Inputs: a handler. Output: a new wrapper (or the handler itself when it already is a wrapper,
|
|
46
|
+
* so a cloned vnode is never wrapped twice) that returns what the handler returns; a throw, or
|
|
47
|
+
* a rejection of a returned promise, goes to the component containing the event's `currentTarget`, or
|
|
48
|
+
* is rethrown when there is none. The component is resolved when the handler is called, so a promise
|
|
49
|
+
* that rejects after the element left the page (SPA navigation) still reaches it. Errors: only
|
|
50
|
+
* that rethrow. Side effects: none (the wrapper carries its own mark).
|
|
51
|
+
*/
|
|
52
|
+
export declare function guarded(handler: Handler): Handler;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=handler-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-guard.d.ts","sourceRoot":"","sources":["../../src/element/handler-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,OAAO,EAAc,MAAM,QAAQ,CAAC;AAE7C,8DAA8D;AAC9D,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAEtD,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAkC9D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,GAAG,MAAM,IAAI,CAK7F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,OAAO,OAAiB,GAAG,IAAI,CAQ1E;AAYD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAuBjD"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event handler guard (TAG-302): routes an exception thrown by a component's DOM event handler to
|
|
3
|
+
* that component's error boundary instead of the page.
|
|
4
|
+
*
|
|
5
|
+
* Why: Preact's error boundaries catch render and effect errors, but an `onClick` that throws is
|
|
6
|
+
* called by the browser's event dispatch, which reports the exception to `window.onerror` (and a
|
|
7
|
+
* rejected promise from an async handler to `unhandledrejection`). The guard hooks Preact's
|
|
8
|
+
* public `options.vnode`: every `on*` function prop of a DOM vnode is replaced by a wrapper that
|
|
9
|
+
* calls it in a `try`, and on failure finds the component whose shadow root contains the event's
|
|
10
|
+
* `currentTarget` (walking out through nested shadow roots) and hands it the error.
|
|
11
|
+
*
|
|
12
|
+
* The hook is installed on the first `createComponentElement`, never at import (golden rule 2), and
|
|
13
|
+
* chains any `options.vnode` already set. It changes only the runtime's own copy of Preact, which
|
|
14
|
+
* is why component bundles must share it rather than bring their own (docs/agentes/runtime.md).
|
|
15
|
+
* An error from a handler outside every registered component is rethrown unchanged.
|
|
16
|
+
*
|
|
17
|
+
* TAG-317: a wrapper is stamped with a private class field (`WrapperStamp`), not tracked in a
|
|
18
|
+
* WeakSet or cached in a WeakMap per handler. Handlers are new closures on every render, and those weak
|
|
19
|
+
* tables grew the retained heap by about 14 bytes per mount even after the entries died
|
|
20
|
+
* (measured in Chromium by e2e/lifecycle.e2e.ts); the only per-root state left is
|
|
21
|
+
* `failureByRoot`, whose entries are deleted explicitly on unmount.
|
|
22
|
+
*/
|
|
23
|
+
import { options } from "preact";
|
|
24
|
+
const failureByRoot = new WeakMap();
|
|
25
|
+
const guardedOptions = new WeakSet();
|
|
26
|
+
/**
|
|
27
|
+
* Stamps the wrappers this module makes with a private field, through the base class that
|
|
28
|
+
* returns the object it is given ("return override"). A private field is the one mark nothing
|
|
29
|
+
* outside this module can read or forge: `Object.getOwnPropertySymbols` does not list it, a Proxy
|
|
30
|
+
* never forwards it to its target nor answers for it through a trap, and an object inheriting
|
|
31
|
+
* from a wrapper does not have it. A symbol property, even compared with a private value, can be
|
|
32
|
+
* copied from a real wrapper's descriptor and replayed by a Proxy trap, so a handler could skip
|
|
33
|
+
* the guard and throw at the page (security review of TAG-317). No table, so nothing grows.
|
|
34
|
+
*/
|
|
35
|
+
// Return override: `new WrapperStamp(fn)` adds the private field to `fn` itself, because this
|
|
36
|
+
// base constructor returns the object it is given instead of a new one.
|
|
37
|
+
const Returning = function (target) {
|
|
38
|
+
return target;
|
|
39
|
+
};
|
|
40
|
+
class WrapperStamp extends Returning {
|
|
41
|
+
#stamped = true;
|
|
42
|
+
/** Whether `value` itself carries the stamp; never throws, never runs a Proxy trap. */
|
|
43
|
+
static carries(value) {
|
|
44
|
+
try {
|
|
45
|
+
return value.#stamped;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// A TypeError: the field is absent (any other object, a Proxy, an inheriting function).
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Registers the shadow root of a mounted component, so errors from handlers inside it reach
|
|
55
|
+
* `onFailure`.
|
|
56
|
+
*
|
|
57
|
+
* Inputs: the component's shadow root and the function that fails the component. Output: a function
|
|
58
|
+
* that unregisters it (call it on unmount). Errors: none. Side effects: a WeakMap entry.
|
|
59
|
+
*/
|
|
60
|
+
export function registerComponentRoot(root, onFailure) {
|
|
61
|
+
failureByRoot.set(root, onFailure);
|
|
62
|
+
return () => {
|
|
63
|
+
if (failureByRoot.get(root) === onFailure)
|
|
64
|
+
failureByRoot.delete(root);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Installs the guard on Preact's `options.vnode`, once per options object.
|
|
69
|
+
*
|
|
70
|
+
* Inputs: the Preact options to hook (the runtime's own by default; tests may pass a fresh one).
|
|
71
|
+
* Output: none. Errors: none. Side effects: sets `target.vnode`, keeping the previous hook.
|
|
72
|
+
*/
|
|
73
|
+
export function installHandlerGuard(target = options) {
|
|
74
|
+
if (guardedOptions.has(target))
|
|
75
|
+
return;
|
|
76
|
+
guardedOptions.add(target);
|
|
77
|
+
const previous = target.vnode?.bind(target);
|
|
78
|
+
target.vnode = (vnode) => {
|
|
79
|
+
if (typeof vnode.type === "string")
|
|
80
|
+
guardHandlers(vnode.props);
|
|
81
|
+
previous?.(vnode);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Replaces each `on*` function of a DOM vnode's props (Preact's rule for listeners). */
|
|
85
|
+
function guardHandlers(props) {
|
|
86
|
+
for (const key of Object.keys(props)) {
|
|
87
|
+
const value = props[key];
|
|
88
|
+
if (key.startsWith("on") && typeof value === "function") {
|
|
89
|
+
props[key] = guarded(value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The guarded version of an event handler.
|
|
95
|
+
*
|
|
96
|
+
* Inputs: a handler. Output: a new wrapper (or the handler itself when it already is a wrapper,
|
|
97
|
+
* so a cloned vnode is never wrapped twice) that returns what the handler returns; a throw, or
|
|
98
|
+
* a rejection of a returned promise, goes to the component containing the event's `currentTarget`, or
|
|
99
|
+
* is rethrown when there is none. The component is resolved when the handler is called, so a promise
|
|
100
|
+
* that rejects after the element left the page (SPA navigation) still reaches it. Errors: only
|
|
101
|
+
* that rethrow. Side effects: none (the wrapper carries its own mark).
|
|
102
|
+
*/
|
|
103
|
+
export function guarded(handler) {
|
|
104
|
+
if (isWrapper(handler))
|
|
105
|
+
return handler;
|
|
106
|
+
const wrapper = function (...args) {
|
|
107
|
+
// Resolve the owner before the handler runs: `currentTarget` is null once the dispatch is
|
|
108
|
+
// over, and the component unregisters its root on disconnect, which may happen before an async
|
|
109
|
+
// handler settles.
|
|
110
|
+
const target = currentTargetOf(args[0]);
|
|
111
|
+
const onFailure = target === null ? undefined : failureOf(target);
|
|
112
|
+
try {
|
|
113
|
+
const result = handler.apply(this, args);
|
|
114
|
+
if (isThenable(result)) {
|
|
115
|
+
return result.then(undefined, (error) => {
|
|
116
|
+
routeOrRethrow(onFailure, error);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
routeOrRethrow(onFailure, error);
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
new WrapperStamp(wrapper);
|
|
127
|
+
return wrapper;
|
|
128
|
+
}
|
|
129
|
+
function isWrapper(handler) {
|
|
130
|
+
return WrapperStamp.carries(handler);
|
|
131
|
+
}
|
|
132
|
+
function currentTargetOf(event) {
|
|
133
|
+
if (typeof event !== "object" || event === null || !("currentTarget" in event))
|
|
134
|
+
return null;
|
|
135
|
+
const target = event.currentTarget;
|
|
136
|
+
return typeof target === "object" && target !== null && "getRootNode" in target
|
|
137
|
+
? target
|
|
138
|
+
: null;
|
|
139
|
+
}
|
|
140
|
+
function isThenable(value) {
|
|
141
|
+
return ((typeof value === "object" || typeof value === "function") &&
|
|
142
|
+
value !== null &&
|
|
143
|
+
typeof value.then === "function");
|
|
144
|
+
}
|
|
145
|
+
function routeOrRethrow(onFailure, error) {
|
|
146
|
+
if (onFailure === undefined)
|
|
147
|
+
throw error;
|
|
148
|
+
onFailure(error);
|
|
149
|
+
}
|
|
150
|
+
/** The failure function of the innermost registered component that contains `node`. */
|
|
151
|
+
function failureOf(node) {
|
|
152
|
+
let current = node;
|
|
153
|
+
while (current !== null) {
|
|
154
|
+
const root = current.getRootNode();
|
|
155
|
+
const onFailure = failureByRoot.get(root);
|
|
156
|
+
if (onFailure !== undefined)
|
|
157
|
+
return onFailure;
|
|
158
|
+
current = "host" in root ? root.host : null;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=handler-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-guard.js","sourceRoot":"","sources":["../../src/element/handler-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,OAAO,EAAc,MAAM,QAAQ,CAAC;AAO7C,MAAM,aAAa,GAAG,IAAI,OAAO,EAAwB,CAAC;AAC1D,MAAM,cAAc,GAAG,IAAI,OAAO,EAAU,CAAC;AAE7C;;;;;;;;GAQG;AACH,8FAA8F;AAC9F,wEAAwE;AACxE,MAAM,SAAS,GAAG,UAAU,MAAc;IACxC,OAAO,MAAM,CAAC;AAChB,CAA8C,CAAC;AAE/C,MAAM,YAAa,SAAQ,SAAS;IACzB,QAAQ,GAAG,IAAI,CAAC;IAEzB,uFAAuF;IACvF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,IAAI,CAAC;YACH,OAAQ,KAAsB,CAAC,QAAQ,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,wFAAwF;YACxF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAgB,EAAE,SAAyB;IAC/E,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACnC,OAAO,GAAG,EAAE;QACV,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAyB,OAAO;IAClE,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC;QAAE,OAAO;IACvC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,IAAI,CA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K,IAAI,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QACnC,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC9C,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAE,IAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Custom Element wrapper of the runtime (TAG-302): `createComponentElement` and its types. See
|
|
3
|
+
* docs/agentes/runtime.md.
|
|
4
|
+
*/
|
|
5
|
+
export { createComponentElement, type ComponentElementOptions, type ComponentElementRegistration, } from "./create-component-element.js";
|
|
6
|
+
export { GENERIC_TAG, type ElementRegistry } from "./define-element.js";
|
|
7
|
+
export { consoleDiagnostics, silentDiagnostics, type DiagnosticsConsole } from "./diagnostics.js";
|
|
8
|
+
export { COMPONENT_KIND, type FailurePhase, type FallbackMode, type MountableManifest, type MountableComponent, type RuntimeDiagnostics, type RuntimeWarning, type WarningCode, type ComponentFailure, type ComponentHost, } from "./types.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/element/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,sBAAsB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,GAClC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Custom Element wrapper of the runtime (TAG-302): `createComponentElement` and its types. See
|
|
3
|
+
* docs/agentes/runtime.md.
|
|
4
|
+
*/
|
|
5
|
+
export { createComponentElement, } from "./create-component-element.js";
|
|
6
|
+
export { GENERIC_TAG } from "./define-element.js";
|
|
7
|
+
export { consoleDiagnostics, silentDiagnostics } from "./diagnostics.js";
|
|
8
|
+
export { COMPONENT_KIND, } from "./types.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/element/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,sBAAsB,GAGvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,WAAW,EAAwB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAA2B,MAAM,kBAAkB,CAAC;AAClG,OAAO,EACL,cAAc,GAUf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props from a `<script type="application/json" data-props>` child (TAG-304): how a CMS without
|
|
3
|
+
* JavaScript gives a component its `array` and `object` props (any prop, in fact) as one JSON object.
|
|
4
|
+
*
|
|
5
|
+
* ```html
|
|
6
|
+
* <price-table>
|
|
7
|
+
* <script type="application/json" data-props>{"plans": [{"name": "Pro", "price": 49}]}</script>
|
|
8
|
+
* </price-table>
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* The browser never runs a `type="application/json"` script (it is a data block), and nothing
|
|
12
|
+
* here runs or inserts it either (golden rule 5): only its `textContent` is read, bounded and
|
|
13
|
+
* parsed by the contract's `parseBoundedJson` (`RUNTIME_LIMITS.propsScriptMaxLength`, nesting `valueSchemaDepth`
|
|
14
|
+
* + 1 for the outer object), and each declared prop of the object goes through the same coercion
|
|
15
|
+
* as a property (`propertyValue`: `checkValue` builds a fresh value with only the declared
|
|
16
|
+
* fields). Undeclared keys are ignored; a refused entry gives the default. Only the first direct
|
|
17
|
+
* child matching `script[type="application/json" i][data-props]` counts; other scripts are
|
|
18
|
+
* ignored. When it is read (the first connect, and again at `DOMContentLoaded` if the document was
|
|
19
|
+
* still loading) is the controller's choice.
|
|
20
|
+
*/
|
|
21
|
+
import { type ValueProblem } from "@taggor/contract/zod-free";
|
|
22
|
+
import { type ColorCheck, type PropBinding } from "./attributes.js";
|
|
23
|
+
/** Receives each refusal: the prop (`*` for the whole script) and the contract's problem code. */
|
|
24
|
+
export type ScriptRefusal = (prop: string, problem: ValueProblem) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Reads the props of the `<script type="application/json" data-props>` child of `host`.
|
|
27
|
+
*
|
|
28
|
+
* Inputs: the host element, the bindings (`bindProps`), the browser's `ColorCheck` and `refuse`.
|
|
29
|
+
* Output: one entry per binding whose name is an own key of the script's JSON object: the coerced
|
|
30
|
+
* value, or the default when refused (`refuse(prop, problem)`). A text too long (`too-long`), too
|
|
31
|
+
* deep (`too-deep`), not JSON (`malformed`) or not an object (`wrong-type`) gives no entry and
|
|
32
|
+
* `refuse("*", problem)`. No such child gives an empty map. Errors: never throws (a page that
|
|
33
|
+
* broke `querySelector` gives no props). Side effects: reads the child's `textContent` and calls
|
|
34
|
+
* `refuse`; never executes, clones or inserts the child.
|
|
35
|
+
*/
|
|
36
|
+
export declare function readScriptProps(host: Element, bindings: readonly PropBinding[], isColor: ColorCheck, refuse: ScriptRefusal): ReadonlyMap<string, unknown>;
|
|
37
|
+
//# sourceMappingURL=props-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props-script.d.ts","sourceRoot":"","sources":["../../src/element/props-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnF,kGAAkG;AAClG,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,GACpB,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CA+B9B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props from a `<script type="application/json" data-props>` child (TAG-304): how a CMS without
|
|
3
|
+
* JavaScript gives a component its `array` and `object` props (any prop, in fact) as one JSON object.
|
|
4
|
+
*
|
|
5
|
+
* ```html
|
|
6
|
+
* <price-table>
|
|
7
|
+
* <script type="application/json" data-props>{"plans": [{"name": "Pro", "price": 49}]}</script>
|
|
8
|
+
* </price-table>
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* The browser never runs a `type="application/json"` script (it is a data block), and nothing
|
|
12
|
+
* here runs or inserts it either (golden rule 5): only its `textContent` is read, bounded and
|
|
13
|
+
* parsed by the contract's `parseBoundedJson` (`RUNTIME_LIMITS.propsScriptMaxLength`, nesting `valueSchemaDepth`
|
|
14
|
+
* + 1 for the outer object), and each declared prop of the object goes through the same coercion
|
|
15
|
+
* as a property (`propertyValue`: `checkValue` builds a fresh value with only the declared
|
|
16
|
+
* fields). Undeclared keys are ignored; a refused entry gives the default. Only the first direct
|
|
17
|
+
* child matching `script[type="application/json" i][data-props]` counts; other scripts are
|
|
18
|
+
* ignored. When it is read (the first connect, and again at `DOMContentLoaded` if the document was
|
|
19
|
+
* still loading) is the controller's choice.
|
|
20
|
+
*/
|
|
21
|
+
import { MANIFEST_LIMITS, RUNTIME_LIMITS, parseBoundedJson, } from "@taggor/contract/zod-free";
|
|
22
|
+
import { propertyValue } from "./attributes.js";
|
|
23
|
+
/** The selector of the props script: a direct child, its type compared without case. */
|
|
24
|
+
const PROPS_SCRIPT = ':scope>script[type="application/json" i][data-props]';
|
|
25
|
+
/**
|
|
26
|
+
* Reads the props of the `<script type="application/json" data-props>` child of `host`.
|
|
27
|
+
*
|
|
28
|
+
* Inputs: the host element, the bindings (`bindProps`), the browser's `ColorCheck` and `refuse`.
|
|
29
|
+
* Output: one entry per binding whose name is an own key of the script's JSON object: the coerced
|
|
30
|
+
* value, or the default when refused (`refuse(prop, problem)`). A text too long (`too-long`), too
|
|
31
|
+
* deep (`too-deep`), not JSON (`malformed`) or not an object (`wrong-type`) gives no entry and
|
|
32
|
+
* `refuse("*", problem)`. No such child gives an empty map. Errors: never throws (a page that
|
|
33
|
+
* broke `querySelector` gives no props). Side effects: reads the child's `textContent` and calls
|
|
34
|
+
* `refuse`; never executes, clones or inserts the child.
|
|
35
|
+
*/
|
|
36
|
+
export function readScriptProps(host, bindings, isColor, refuse) {
|
|
37
|
+
const values = new Map();
|
|
38
|
+
try {
|
|
39
|
+
const text = host.querySelector(PROPS_SCRIPT)?.textContent;
|
|
40
|
+
if (text != null) {
|
|
41
|
+
const json = parseBoundedJson(text, RUNTIME_LIMITS.propsScriptMaxLength, MANIFEST_LIMITS.valueSchemaDepth + 1);
|
|
42
|
+
const object = json.ok ? json.value : undefined;
|
|
43
|
+
if (typeof object !== "object" || object === null || Array.isArray(object)) {
|
|
44
|
+
refuse("*", json.ok ? "wrong-type" : json.problem);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
for (const binding of bindings) {
|
|
48
|
+
if (Object.hasOwn(object, binding.prop)) {
|
|
49
|
+
const { value, problem } = propertyValue(binding, object[binding.prop], isColor);
|
|
50
|
+
values.set(binding.prop, value);
|
|
51
|
+
if (problem !== undefined)
|
|
52
|
+
refuse(binding.prop, problem);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Only a page that replaced querySelector or textContent gets here: no props from the script.
|
|
60
|
+
}
|
|
61
|
+
return values;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=props-script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props-script.js","sourceRoot":"","sources":["../../src/element/props-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,GAEjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAqC,MAAM,iBAAiB,CAAC;AAEnF,wFAAwF;AACxF,MAAM,YAAY,GAAG,sDAAsD,CAAC;AAK5E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAa,EACb,QAAgC,EAChC,OAAmB,EACnB,MAAqB;IAErB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC;QAC3D,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,gBAAgB,CAC3B,IAAI,EACJ,cAAc,CAAC,oBAAoB,EACnC,eAAe,CAAC,gBAAgB,GAAG,CAAC,CACrC,CAAC;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;YAChD,IAAI,O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