@taggor/runtime 0.0.0-reserved.0 → 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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/compat/before-compat.d.ts +5 -0
  5. package/dist/compat/before-compat.d.ts.map +1 -0
  6. package/dist/compat/before-compat.js +15 -0
  7. package/dist/compat/before-compat.js.map +1 -0
  8. package/dist/compat/index.d.ts +90 -0
  9. package/dist/compat/index.d.ts.map +1 -0
  10. package/dist/compat/index.js +67 -0
  11. package/dist/compat/index.js.map +1 -0
  12. package/dist/compat/scope.d.ts +81 -0
  13. package/dist/compat/scope.d.ts.map +1 -0
  14. package/dist/compat/scope.js +107 -0
  15. package/dist/compat/scope.js.map +1 -0
  16. package/dist/element/attributes.d.ts +103 -0
  17. package/dist/element/attributes.d.ts.map +1 -0
  18. package/dist/element/attributes.js +153 -0
  19. package/dist/element/attributes.js.map +1 -0
  20. package/dist/element/component-controller.d.ts +98 -0
  21. package/dist/element/component-controller.d.ts.map +1 -0
  22. package/dist/element/component-controller.js +472 -0
  23. package/dist/element/component-controller.js.map +1 -0
  24. package/dist/element/contract-gate.d.ts +29 -0
  25. package/dist/element/contract-gate.d.ts.map +1 -0
  26. package/dist/element/contract-gate.js +37 -0
  27. package/dist/element/contract-gate.js.map +1 -0
  28. package/dist/element/create-component-element.d.ts +93 -0
  29. package/dist/element/create-component-element.d.ts.map +1 -0
  30. package/dist/element/create-component-element.js +302 -0
  31. package/dist/element/create-component-element.js.map +1 -0
  32. package/dist/element/define-element.d.ts +43 -0
  33. package/dist/element/define-element.d.ts.map +1 -0
  34. package/dist/element/define-element.js +61 -0
  35. package/dist/element/define-element.js.map +1 -0
  36. package/dist/element/diagnostics.d.ts +35 -0
  37. package/dist/element/diagnostics.d.ts.map +1 -0
  38. package/dist/element/diagnostics.js +52 -0
  39. package/dist/element/diagnostics.js.map +1 -0
  40. package/dist/element/error-boundary.d.ts +41 -0
  41. package/dist/element/error-boundary.d.ts.map +1 -0
  42. package/dist/element/error-boundary.js +36 -0
  43. package/dist/element/error-boundary.js.map +1 -0
  44. package/dist/element/error-report.d.ts +9 -0
  45. package/dist/element/error-report.d.ts.map +1 -0
  46. package/dist/element/error-report.js +51 -0
  47. package/dist/element/error-report.js.map +1 -0
  48. package/dist/element/events.d.ts +69 -0
  49. package/dist/element/events.d.ts.map +1 -0
  50. package/dist/element/events.js +115 -0
  51. package/dist/element/events.js.map +1 -0
  52. package/dist/element/handler-guard.d.ts +54 -0
  53. package/dist/element/handler-guard.d.ts.map +1 -0
  54. package/dist/element/handler-guard.js +162 -0
  55. package/dist/element/handler-guard.js.map +1 -0
  56. package/dist/element/index.d.ts +9 -0
  57. package/dist/element/index.d.ts.map +1 -0
  58. package/dist/element/index.js +9 -0
  59. package/dist/element/index.js.map +1 -0
  60. package/dist/element/props-script.d.ts +37 -0
  61. package/dist/element/props-script.d.ts.map +1 -0
  62. package/dist/element/props-script.js +63 -0
  63. package/dist/element/props-script.js.map +1 -0
  64. package/dist/element/styles.d.ts +45 -0
  65. package/dist/element/styles.d.ts.map +1 -0
  66. package/dist/element/styles.js +66 -0
  67. package/dist/element/styles.js.map +1 -0
  68. package/dist/element/types.d.ts +148 -0
  69. package/dist/element/types.d.ts.map +1 -0
  70. package/dist/element/types.js +3 -0
  71. package/dist/element/types.js.map +1 -0
  72. package/dist/host/api.d.ts +40 -0
  73. package/dist/host/api.d.ts.map +1 -0
  74. package/dist/host/api.js +144 -0
  75. package/dist/host/api.js.map +1 -0
  76. package/dist/host/barrier.d.ts +27 -0
  77. package/dist/host/barrier.d.ts.map +1 -0
  78. package/dist/host/barrier.js +47 -0
  79. package/dist/host/barrier.js.map +1 -0
  80. package/dist/host/index.d.ts +11 -0
  81. package/dist/host/index.d.ts.map +1 -0
  82. package/dist/host/index.js +9 -0
  83. package/dist/host/index.js.map +1 -0
  84. package/dist/host/registry.d.ts +21 -0
  85. package/dist/host/registry.d.ts.map +1 -0
  86. package/dist/host/registry.js +29 -0
  87. package/dist/host/registry.js.map +1 -0
  88. package/dist/host/types.d.ts +54 -0
  89. package/dist/host/types.d.ts.map +1 -0
  90. package/dist/host/types.js +11 -0
  91. package/dist/host/types.js.map +1 -0
  92. package/dist/index.d.ts +13 -0
  93. package/dist/index.d.ts.map +1 -0
  94. package/dist/index.js +12 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/loader/config.d.ts +63 -0
  97. package/dist/loader/config.d.ts.map +1 -0
  98. package/dist/loader/config.js +115 -0
  99. package/dist/loader/config.js.map +1 -0
  100. package/dist/loader/entry.d.ts +2 -0
  101. package/dist/loader/entry.d.ts.map +1 -0
  102. package/dist/loader/entry.js +37 -0
  103. package/dist/loader/entry.js.map +1 -0
  104. package/dist/loader/lazy-transport.d.ts +26 -0
  105. package/dist/loader/lazy-transport.d.ts.map +1 -0
  106. package/dist/loader/lazy-transport.js +59 -0
  107. package/dist/loader/lazy-transport.js.map +1 -0
  108. package/dist/loader/loader-code.d.ts +2 -0
  109. package/dist/loader/loader-code.js +2 -0
  110. package/dist/loader/loading.d.ts +24 -0
  111. package/dist/loader/loading.d.ts.map +1 -0
  112. package/dist/loader/loading.js +29 -0
  113. package/dist/loader/loading.js.map +1 -0
  114. package/dist/loader/page-state.d.ts +66 -0
  115. package/dist/loader/page-state.d.ts.map +1 -0
  116. package/dist/loader/page-state.js +73 -0
  117. package/dist/loader/page-state.js.map +1 -0
  118. package/dist/loader/resilient-import.d.ts +32 -0
  119. package/dist/loader/resilient-import.d.ts.map +1 -0
  120. package/dist/loader/resilient-import.js +42 -0
  121. package/dist/loader/resilient-import.js.map +1 -0
  122. package/dist/loader/run.d.ts +45 -0
  123. package/dist/loader/run.d.ts.map +1 -0
  124. package/dist/loader/run.js +217 -0
  125. package/dist/loader/run.js.map +1 -0
  126. package/dist/loader/script-url.d.ts +50 -0
  127. package/dist/loader/script-url.d.ts.map +1 -0
  128. package/dist/loader/script-url.js +71 -0
  129. package/dist/loader/script-url.js.map +1 -0
  130. package/dist/loader/script.d.ts +31 -0
  131. package/dist/loader/script.d.ts.map +1 -0
  132. package/dist/loader/script.js +40 -0
  133. package/dist/loader/script.js.map +1 -0
  134. package/dist/server/render-fragment.d.ts +57 -0
  135. package/dist/server/render-fragment.d.ts.map +1 -0
  136. package/dist/server/render-fragment.js +182 -0
  137. package/dist/server/render-fragment.js.map +1 -0
  138. package/dist/server/ssr-code.d.ts +4 -0
  139. package/dist/server/ssr-code.js +3 -0
  140. package/dist/server/worker.d.ts +37 -0
  141. package/dist/server/worker.d.ts.map +1 -0
  142. package/dist/server/worker.js +71 -0
  143. package/dist/server/worker.js.map +1 -0
  144. package/package.json +89 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-component-element.d.ts","sourceRoot":"","sources":["../../src/element/create-component-element.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAiB,KAAK,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvF,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAGpB,2EAA2E;AAC3E,MAAM,WAAW,uBAAuB;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAC1C,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACjC,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IACpC,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,WAAW,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,4FAA4F;AAC5F,MAAM,MAAM,4BAA4B;AACtC,6CAA6C;AAC3C;IACE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;CAC5C;AACH;;;GAGG;GACD;IACE,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,eAAe,CAAC;IAC/C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,UAAU,EAAE,OAAO,WAAW,CAAC;CACzC;AACH;;;GAGG;GACD;IACE,QAAQ,CAAC,MAAM,EAAE,oBAAoB,GAAG,sBAAsB,GAAG,aAAa,CAAC;IAC/E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE,uBAA4B,GACpC,4BAA4B,CAmE9B"}
@@ -0,0 +1,302 @@
1
+ /**
2
+ * `createComponentElement` (TAG-302): turns a component definition into a real Custom Element, an
3
+ * `HTMLElement` subclass registered with `customElements.define`, rendering a Preact component in
4
+ * an open shadow root, observing the attributes of the declared props and containing every
5
+ * failure behind an error boundary (ADR 0006, golden rules 2 and 5).
6
+ *
7
+ * The class is a thin adapter: each callback forwards to a `ComponentController`
8
+ * (`component-controller.ts`) inside a `try`, so a Custom Element callback never throws at the page.
9
+ * Nothing runs at import; the first call installs the event handler guard (`handler-guard.ts`).
10
+ * None of the old prototype's defects can come back: the element is really defined, CSS lives in
11
+ * the shadow root, attributes go through the contract's fixed parsers, and slots are native.
12
+ * TAG-303 put the contract version gate (`contract-gate.ts`) before registration and warns, in
13
+ * debug mode, about props whose type this runtime does not know. TAG-305 reads the declared events
14
+ * once per definition (`events.ts`) for the host's `emit`. TAG-304 defines one accessor per bound
15
+ * prop on the class prototype (`el.items = […]`, forwarded to the controller, never throwing), and
16
+ * leaves out, with an `unknown-prop-type` warning, a prop named like a member the element already has
17
+ * (the live `HTMLElement.prototype` chain, or a Custom Element callback such as
18
+ * `connectedCallback`, which is not on that prototype), so the definition, which is unvalidated
19
+ * component code, cannot shadow either. TAG-314: a definition whose manifest declares
20
+ * `formAssociated: true` gets a form-associated class (`static formAssociated`, the
21
+ * `formResetCallback`, `formDisabledCallback` and `formStateRestoreCallback` forwarded to the controller, which attaches the
22
+ * element's `ElementInternals`), and the shadow root delegates focus when `delegatesFocus` says so
23
+ * (by default, a form field does). TAG-324: that class also has the form field API of an `<input>`
24
+ * (`value`, `form`, `validationMessage`, `validity`, `checkValidity()`, `reportValidity()`),
25
+ * forwarded to the controller's internals and never throwing.
26
+ *
27
+ * TAG-214: connected elements are tracked in `liveComponents`, with their published `version` and
28
+ * contract version, for `window.taggor.get` and `components`.
29
+ */
30
+ import { CUSTOM_ELEMENT_MEMBERS, FORM_FIELD_ACCESSORS, FORM_FIELD_METHODS, } from "@taggor/contract/zod-free";
31
+ import { bindProps, browserColorCheck } from "./attributes.js";
32
+ import { liveComponents } from "../host/registry.js";
33
+ import { checkComponentContract } from "./contract-gate.js";
34
+ import { defineElement, GENERIC_TAG } from "./define-element.js";
35
+ import { readEventRoutes } from "./events.js";
36
+ import { guardDiagnostics, silentDiagnostics } from "./diagnostics.js";
37
+ import { reportFailure } from "./error-report.js";
38
+ import { installHandlerGuard } from "./handler-guard.js";
39
+ import { createComponentStyles } from "./styles.js";
40
+ import { COMPONENT_KIND, } from "./types.js";
41
+ import { createComponentController } from "./component-controller.js";
42
+ /**
43
+ * Creates and registers the Custom Element of a component.
44
+ *
45
+ * Inputs: a definition made by `defineTaggorComponent` (checked by shape: the `taggor.component` brand, a
46
+ * manifest with string `tag` and `name`, a `component` function, a `styles` array) and
47
+ * `ComponentElementOptions`. The contract version is checked first (`checkComponentContract`): a newer
48
+ * minor is mounted with a warning, an unusable version returns `unsupported-contract` without
49
+ * defining anything. Output: a `ComponentElementRegistration`. Errors: never throws; a bad
50
+ * definition or contract version, missing Custom Elements, a taken tag or a failing `define`
51
+ * become a warning and a status. Side effects: `customElements.define` (unless the tag is taken), Preact's
52
+ * `options.vnode` hook on the first call; each element attaches an open shadow root and renders
53
+ * when connected; a connected element is tracked in `liveComponents` (TAG-214).
54
+ */
55
+ export function createComponentElement(definition, options = {}) {
56
+ const guarded = guardDiagnostics(options.diagnostics ?? silentDiagnostics);
57
+ const { version, origin } = options;
58
+ // TAG-318: a published component's failures are also reported to the edge.
59
+ const diagnostics = typeof version === "string" && typeof origin === "string"
60
+ ? {
61
+ warn: guarded.warn,
62
+ reportError: (failure) => {
63
+ guarded.reportError(failure);
64
+ reportFailure(failure.tag, version, failure.phase, failure.error, origin);
65
+ },
66
+ }
67
+ : guarded;
68
+ const tag = tagOf(definition);
69
+ try {
70
+ if (!isMountable(definition)) {
71
+ diagnostics.warn({
72
+ code: "invalid-definition",
73
+ tag,
74
+ message: "not a component definition (expected the object returned by defineTaggorComponent)",
75
+ });
76
+ return { status: "invalid-definition", tag };
77
+ }
78
+ const declared = options.contractVersion ?? definition.manifest.contractVersion;
79
+ const contract = checkComponentContract(declared, options.servedOn);
80
+ if (contract.problem !== undefined) {
81
+ const message = contract.problem.code === "missing"
82
+ ? `${contract.problem.message}; the component is not mounted (pass the published manifest's version as createComponentElement's contractVersion option)`
83
+ : contract.problem.message;
84
+ diagnostics.warn({ code: "contract-version", tag, message });
85
+ }
86
+ if (!contract.usable)
87
+ return { status: "unsupported-contract", tag };
88
+ // The DOM lib declares both as always present; on a page without Custom Elements they are not.
89
+ const scope = globalThis;
90
+ const registry = options.registry ?? scope.customElements;
91
+ const Base = options.baseElement ?? scope.HTMLElement;
92
+ if (registry === undefined || typeof Base !== "function") {
93
+ diagnostics.warn({ code: "unsupported", tag, message: "this page has no Custom Elements" });
94
+ return { status: "unsupported", tag };
95
+ }
96
+ installHandlerGuard();
97
+ const element = componentElementClass(Base, definition, diagnostics, {
98
+ fallback: options.fallback ?? "light-dom",
99
+ nonce: options.styleNonce,
100
+ version: typeof version === "string" ? version : undefined,
101
+ // A usable version is a well-formed string (the gate refused anything else).
102
+ contractVersion: declared,
103
+ transport: options.transport,
104
+ siteDefaults: options.siteDefaults,
105
+ });
106
+ const outcome = defineElement(registry, tag, definition.manifest.name, element, diagnostics);
107
+ if (outcome === "defined")
108
+ return { status: "defined", tag, element };
109
+ return {
110
+ status: outcome === "collision" ? "collision" : "define-failed",
111
+ tag,
112
+ element,
113
+ genericTag: GENERIC_TAG,
114
+ };
115
+ }
116
+ catch (error) {
117
+ // Unreachable by design (every step above is total); kept so a future bug cannot break a page.
118
+ diagnostics.reportError({ tag, name: tag, phase: "lifecycle", error });
119
+ return { status: "invalid-definition", tag };
120
+ }
121
+ }
122
+ function tagOf(definition) {
123
+ try {
124
+ const tag = definition?.manifest?.tag;
125
+ return typeof tag === "string" ? tag : "(unknown)";
126
+ }
127
+ catch {
128
+ return "(unknown)";
129
+ }
130
+ }
131
+ function isMountable(value) {
132
+ if (typeof value !== "object" || value === null)
133
+ return false;
134
+ const candidate = value;
135
+ const manifest = candidate.manifest;
136
+ return (candidate.kind === COMPONENT_KIND &&
137
+ typeof candidate.component === "function" &&
138
+ Array.isArray(candidate.styles) &&
139
+ candidate.styles.every((css) => typeof css === "string") &&
140
+ typeof manifest === "object" &&
141
+ manifest !== null &&
142
+ typeof manifest["tag"] === "string" &&
143
+ typeof manifest["name"] === "string" &&
144
+ (manifest["props"] === undefined ||
145
+ (typeof manifest["props"] === "object" && manifest["props"] !== null)));
146
+ }
147
+ /** The element class of one definition; all instances share the bindings and stylesheets. */
148
+ function componentElementClass(Base, definition, diagnostics, { fallback, nonce, version, contractVersion, transport, siteDefaults }) {
149
+ const members = CUSTOM_ELEMENT_MEMBERS;
150
+ const { bindings, unknown } = bindProps(definition.manifest, (prop) => prop in Base.prototype || members.includes(prop), siteDefaults);
151
+ const attributes = Object.freeze(bindings.map((binding) => binding.attribute));
152
+ const styles = createComponentStyles(definition.styles, nonce);
153
+ const { tag, name } = definition.manifest;
154
+ for (const prop of unknown) {
155
+ diagnostics.warn({
156
+ code: "unknown-prop-type",
157
+ tag,
158
+ message: `prop "${prop}" has a type this runtime does not know or a reserved name; it is left out`,
159
+ });
160
+ }
161
+ const isColor = browserColorCheck();
162
+ // Read once: a manifest changed after this cannot widen what `emit` dispatches (TAG-305).
163
+ const events = readEventRoutes(definition.manifest.events);
164
+ // Read once too (TAG-314): `formAssociated` is read by `define` from the class, never again.
165
+ const formAssociated = definition.manifest.formAssociated === true;
166
+ // Component code, not a validated manifest: anything but a boolean counts as absent.
167
+ const delegates = definition.manifest.delegatesFocus;
168
+ const deps = Object.freeze({
169
+ definition,
170
+ bindings,
171
+ events,
172
+ styles,
173
+ diagnostics,
174
+ fallback,
175
+ isColor,
176
+ formAssociated,
177
+ delegatesFocus: typeof delegates === "boolean" ? delegates : formAssociated,
178
+ live: liveComponents,
179
+ version,
180
+ contractVersion,
181
+ transport,
182
+ });
183
+ const contained = (run) => {
184
+ try {
185
+ run();
186
+ }
187
+ catch (error) {
188
+ // The controller never throws; this only guards against a bug in it.
189
+ diagnostics.reportError({ tag, name, phase: "lifecycle", error });
190
+ }
191
+ };
192
+ return class TaggorComponentElement extends Base {
193
+ static get observedAttributes() {
194
+ return attributes;
195
+ }
196
+ /** Read by `customElements.define` (TAG-314): only a declared form field is associated. */
197
+ static formAssociated = formAssociated;
198
+ static {
199
+ if (formAssociated) {
200
+ // The form field API (TAG-324), as on an `<input>`, before the props: it wins over a prop
201
+ // of the same name. The getter is the field's; the setter sets the prop of that name, so
202
+ // `el.value = 3` on a field with a `value` prop (its initial value, like `<input value>`)
203
+ // sets the prop as before, and assigning another member is ignored instead of throwing.
204
+ for (const key of FORM_FIELD_ACCESSORS) {
205
+ Object.defineProperty(this.prototype, key, {
206
+ get() {
207
+ try {
208
+ return this.#controller.field(key);
209
+ }
210
+ catch {
211
+ return undefined;
212
+ }
213
+ },
214
+ set(value) {
215
+ try {
216
+ this.#controller.setProperty(key, value);
217
+ }
218
+ catch {
219
+ // Not an element of this class: nothing to set.
220
+ }
221
+ },
222
+ });
223
+ }
224
+ for (const key of FORM_FIELD_METHODS) {
225
+ // Writable like a native method: a page assigning it in strict mode must not throw.
226
+ Object.defineProperty(this.prototype, key, {
227
+ writable: true,
228
+ value() {
229
+ try {
230
+ return this.#controller.field(key, true);
231
+ }
232
+ catch {
233
+ return undefined;
234
+ }
235
+ },
236
+ });
237
+ }
238
+ }
239
+ // One accessor per bound prop (TAG-304), except where the field API is. The `try` covers a
240
+ // call on anything that is not an element of this class (the prototype itself, `Reflect.set`
241
+ // with another receiver): the private field read throws there, and an accessor must never
242
+ // throw at the page.
243
+ for (const { prop } of bindings) {
244
+ if (prop in this.prototype)
245
+ continue;
246
+ Object.defineProperty(this.prototype, prop, {
247
+ get() {
248
+ try {
249
+ return this.#controller.property(prop);
250
+ }
251
+ catch {
252
+ return undefined;
253
+ }
254
+ },
255
+ set(value) {
256
+ try {
257
+ this.#controller.setProperty(prop, value);
258
+ }
259
+ catch {
260
+ // Not an element of this class: nothing to set.
261
+ }
262
+ },
263
+ });
264
+ }
265
+ }
266
+ #controller = createComponentController(this, deps);
267
+ connectedCallback() {
268
+ contained(() => {
269
+ this.#controller.connect();
270
+ });
271
+ }
272
+ disconnectedCallback() {
273
+ contained(() => {
274
+ this.#controller.disconnect();
275
+ });
276
+ }
277
+ attributeChangedCallback(attribute, previous, next) {
278
+ contained(() => {
279
+ this.#controller.attributeChanged(attribute, previous, next);
280
+ });
281
+ }
282
+ // Called by the browser only on a form-associated class (TAG-314).
283
+ formResetCallback() {
284
+ contained(() => {
285
+ this.#controller.formReset();
286
+ });
287
+ }
288
+ formDisabledCallback() {
289
+ contained(() => {
290
+ this.#controller.formDisabled();
291
+ });
292
+ }
293
+ formStateRestoreCallback(state) {
294
+ if (typeof state !== "string")
295
+ return;
296
+ contained(() => {
297
+ this.#controller.r(state);
298
+ });
299
+ }
300
+ };
301
+ }
302
+ //# sourceMappingURL=create-component-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-component-element.js","sourceRoot":"","sources":["../../src/element/create-component-element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAwB,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,cAAc,GAIf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,yBAAyB,EAA4B,MAAM,2BAA2B,CAAC;AAgFhG;;;;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,KAAK,KAAK,QAAQ;gBAAE,OAAO;YACtC,SAAS,CAAC,GAAG,EAAE;gBACb,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Registering a component's tag without ever overwriting or throwing (TAG-302, ADR 0018 item 4).
3
+ *
4
+ * Before `define`, the registry is asked whether the tag exists; if another script (or another
5
+ * copy of the runtime) owns it, the runtime does not call `define`, warns and leaves the elements
6
+ * of that tag alone; the component stays available through the generic host
7
+ * `<taggor-component name="…">` (TAG-320). A `define` that throws anyway, because another script
8
+ * defined the tag between `get` and `define` (a race), becomes the same collision warning; any
9
+ * other throw (an invalid name, say) becomes a `define-failed` warning. Nothing reaches the page.
10
+ *
11
+ * TAG-320 (TAG-302 security review): a tag with the reserved `taggor-` prefix (`taggor-component`
12
+ * included) is refused with `define-failed` before the registry is touched, as defense in depth
13
+ * beyond the contract, which already refuses it: the definition is component code, not a validated
14
+ * manifest.
15
+ */
16
+ import type * as Contract from "@taggor/contract";
17
+ import type { RuntimeDiagnostics } from "./types.js";
18
+ /**
19
+ * The prefix Taggor keeps for its own elements. A copy of the contract's `RESERVED_TAG_PREFIX`
20
+ * (whose module carries Zod, which the runtime may only import as types); the type annotation
21
+ * fails the typecheck if the two ever differ.
22
+ */
23
+ export declare const RESERVED_TAG_PREFIX: typeof Contract.RESERVED_TAG_PREFIX;
24
+ /** The generic host tag that keeps a colliding component available (TAG-320, ADR 0018). */
25
+ export declare const GENERIC_TAG: string;
26
+ /** The part of `CustomElementRegistry` the runtime uses (injectable for tests). */
27
+ export interface ElementRegistry {
28
+ readonly get: (name: string) => CustomElementConstructor | undefined;
29
+ readonly define: (name: string, constructor: CustomElementConstructor) => void;
30
+ }
31
+ /** What happened to a tag. */
32
+ export type DefineOutcome = "defined" | "collision" | "failed";
33
+ /**
34
+ * Defines `tag` with `constructor` unless the tag is taken.
35
+ *
36
+ * Inputs: the registry, the tag, the component name (for the warning), the element class and the
37
+ * diagnostics (already guarded). Output: `"defined"`, `"collision"` (taken before or during the
38
+ * call) or `"failed"` (a tag with the reserved prefix, never passed to the registry, or `define`
39
+ * threw and the tag is still free). Errors: never throws. Side
40
+ * effects: `registry.define` on success; a warning otherwise.
41
+ */
42
+ export declare function defineElement(registry: ElementRegistry, tag: string, name: string, constructor: CustomElementConstructor, diagnostics: RuntimeDiagnostics): DefineOutcome;
43
+ //# sourceMappingURL=define-element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-element.d.ts","sourceRoot":"","sources":["../../src/element/define-element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,OAAO,QAAQ,CAAC,mBAA+B,CAAC;AAElF,2FAA2F;AAC3F,eAAO,MAAM,WAAW,QAAoC,CAAC;AAE7D,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,wBAAwB,GAAG,SAAS,CAAC;IACrE,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAChF;AAED,8BAA8B;AAC9B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE/D;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,wBAAwB,EACrC,WAAW,EAAE,kBAAkB,GAC9B,aAAa,CAkCf"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The prefix Taggor keeps for its own elements. A copy of the contract's `RESERVED_TAG_PREFIX`
3
+ * (whose module carries Zod, which the runtime may only import as types); the type annotation
4
+ * fails the typecheck if the two ever differ.
5
+ */
6
+ export const RESERVED_TAG_PREFIX = "taggor-";
7
+ /** The generic host tag that keeps a colliding component available (TAG-320, ADR 0018). */
8
+ export const GENERIC_TAG = `${RESERVED_TAG_PREFIX}component`;
9
+ /**
10
+ * Defines `tag` with `constructor` unless the tag is taken.
11
+ *
12
+ * Inputs: the registry, the tag, the component name (for the warning), the element class and the
13
+ * diagnostics (already guarded). Output: `"defined"`, `"collision"` (taken before or during the
14
+ * call) or `"failed"` (a tag with the reserved prefix, never passed to the registry, or `define`
15
+ * threw and the tag is still free). Errors: never throws. Side
16
+ * effects: `registry.define` on success; a warning otherwise.
17
+ */
18
+ export function defineElement(registry, tag, name, constructor, diagnostics) {
19
+ const collision = () => {
20
+ diagnostics.warn({
21
+ code: "tag-collision",
22
+ tag,
23
+ message: `the tag <${tag}> is already defined by another script; the runtime left it alone. ` +
24
+ `Use <${GENERIC_TAG} name="${name}"> for this component, or a workspace tag prefix.`,
25
+ });
26
+ return "collision";
27
+ };
28
+ const failed = (reason) => {
29
+ diagnostics.warn({
30
+ code: "define-failed",
31
+ tag,
32
+ message: `could not define <${tag}> (${reason}); use <${GENERIC_TAG} name="${name}">.`,
33
+ });
34
+ return "failed";
35
+ };
36
+ if (tag.startsWith(RESERVED_TAG_PREFIX))
37
+ return failed(`reserved prefix ${RESERVED_TAG_PREFIX}`);
38
+ try {
39
+ if (registry.get(tag) !== undefined)
40
+ return collision();
41
+ registry.define(tag, constructor);
42
+ return "defined";
43
+ }
44
+ catch (error) {
45
+ try {
46
+ if (registry.get(tag) !== undefined)
47
+ return collision();
48
+ }
49
+ catch {
50
+ // A registry whose get throws is treated like any other define failure.
51
+ }
52
+ return failed(describe(error));
53
+ }
54
+ }
55
+ /** A short, plain-text description of a thrown value (never its HTML). */
56
+ function describe(error) {
57
+ if (error instanceof Error)
58
+ return error.name;
59
+ return typeof error;
60
+ }
61
+ //# sourceMappingURL=define-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-element.js","sourceRoot":"","sources":["../../src/element/define-element.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAwC,SAAS,CAAC;AAElF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,mBAAmB,WAAW,CAAC;AAW7D;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAyB,EACzB,GAAW,EACX,IAAY,EACZ,WAAqC,EACrC,WAA+B;IAE/B,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,eAAe;YACrB,GAAG;YACH,OAAO,EACL,YAAY,GAAG,qEAAqE;gBACpF,QAAQ,WAAW,UAAU,IAAI,mDAAmD;SACvF,CAAC,CAAC;QACH,OAAO,WAAoB,CAAC;IAC9B,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;QAChC,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,eAAe;YACrB,GAAG;YACH,OAAO,EAAE,qBAAqB,GAAG,MAAM,MAAM,WAAW,WAAW,UAAU,IAAI,KAAK;SACvF,CAAC,CAAC;QACH,OAAO,QAAiB,CAAC;IAC3B,CAAC,CAAC;IAEF,IAAI,GAAG,CAAC,UAAU,CAAC,mBAAmB,CAAC;QAAE,OAAO,MAAM,CAAC,mBAAmB,mBAAmB,EAAE,CAAC,CAAC;IACjG,IAAI,CAAC;QACH,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,OAAO,SAAS,EAAE,CAAC;QACxD,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC;YACH,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,OAAO,SAAS,EAAE,CAAC;QAC1D,CAAC;QAAC,MAAM,CAAC;YACP,wEAAwE;QAC1E,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IAC9C,OAAO,OAAO,KAAK,CAAC;AACtB,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Diagnostics of the Custom Element wrapper (TAG-302): the silent default, the console sink for
3
+ * debug mode and the guard that keeps a throwing sink away from the page.
4
+ *
5
+ * Writing to the console never fires the page's `error` or `unhandledrejection` events, so debug
6
+ * mode can show warnings and caught failures without breaking golden rule 2. Turning debug mode on
7
+ * (`?taggor_debug=1`, `taggor.debug(true)`) is TAG-315; it passes `enabled`.
8
+ */
9
+ import type { RuntimeDiagnostics } from "./types.js";
10
+ /** Diagnostics that drop everything: the default outside debug mode. */
11
+ export declare const silentDiagnostics: RuntimeDiagnostics;
12
+ /** The console methods the debug sink uses. */
13
+ export interface DiagnosticsConsole {
14
+ readonly warn: (...data: unknown[]) => void;
15
+ readonly error: (...data: unknown[]) => void;
16
+ }
17
+ /**
18
+ * Diagnostics that print to the console while `enabled` (debug mode) and stay silent otherwise.
19
+ *
20
+ * Inputs: `enabled` and the console to write to (defaults to `globalThis.console`). Output:
21
+ * `RuntimeDiagnostics`; warnings go to `console.warn` as `[taggor] <tag>: <message>`, failures to
22
+ * `console.error` with the caught value. Errors: none. Side effects: console output when enabled.
23
+ */
24
+ export declare function consoleDiagnostics(options: {
25
+ readonly enabled: boolean;
26
+ readonly console?: DiagnosticsConsole;
27
+ }): RuntimeDiagnostics;
28
+ /**
29
+ * Wraps a diagnostics port so that neither function can throw.
30
+ *
31
+ * Inputs: any `RuntimeDiagnostics` (possibly hostile or buggy). Output: a port with the same
32
+ * behaviour whose calls swallow exceptions. Errors: none. Side effects: those of the wrapped port.
33
+ */
34
+ export declare function guardDiagnostics(diagnostics: RuntimeDiagnostics): RuntimeDiagnostics;
35
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/element/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAoC,MAAM,YAAY,CAAC;AAEvF,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,EAAE,kBAG9B,CAAC;AAEH,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CAC9C;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC;CACvC,GAAG,kBAAkB,CAWrB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,GAAG,kBAAkB,CAiBpF"}
@@ -0,0 +1,52 @@
1
+ /** Diagnostics that drop everything: the default outside debug mode. */
2
+ export const silentDiagnostics = Object.freeze({
3
+ warn: () => undefined,
4
+ reportError: () => undefined,
5
+ });
6
+ /**
7
+ * Diagnostics that print to the console while `enabled` (debug mode) and stay silent otherwise.
8
+ *
9
+ * Inputs: `enabled` and the console to write to (defaults to `globalThis.console`). Output:
10
+ * `RuntimeDiagnostics`; warnings go to `console.warn` as `[taggor] <tag>: <message>`, failures to
11
+ * `console.error` with the caught value. Errors: none. Side effects: console output when enabled.
12
+ */
13
+ export function consoleDiagnostics(options) {
14
+ if (!options.enabled)
15
+ return silentDiagnostics;
16
+ const sink = options.console ?? globalThis.console;
17
+ return Object.freeze({
18
+ warn: (warning) => {
19
+ sink.warn(`[taggor] ${warning.tag}: ${warning.message}`);
20
+ },
21
+ reportError: (failure) => {
22
+ sink.error(`[taggor] ${failure.tag}: component failed (${failure.phase})`, failure.error);
23
+ },
24
+ });
25
+ }
26
+ /**
27
+ * Wraps a diagnostics port so that neither function can throw.
28
+ *
29
+ * Inputs: any `RuntimeDiagnostics` (possibly hostile or buggy). Output: a port with the same
30
+ * behaviour whose calls swallow exceptions. Errors: none. Side effects: those of the wrapped port.
31
+ */
32
+ export function guardDiagnostics(diagnostics) {
33
+ return Object.freeze({
34
+ warn: (warning) => {
35
+ try {
36
+ diagnostics.warn(warning);
37
+ }
38
+ catch {
39
+ // A broken sink must not turn a warning into an error on the visitor's page.
40
+ }
41
+ },
42
+ reportError: (failure) => {
43
+ try {
44
+ diagnostics.reportError(failure);
45
+ }
46
+ catch {
47
+ // Same: the failure is already contained; losing its report is the lesser harm.
48
+ }
49
+ },
50
+ });
51
+ }
52
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/element/diagnostics.ts"],"names":[],"mappings":"AAUA,wEAAwE;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAuB,MAAM,CAAC,MAAM,CAAC;IACjE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS;IACrB,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS;CAC7B,CAAC,CAAC;AAQH;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAGlC;IACC,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,iBAAiB,CAAC;IAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,CAAC,OAAuB,EAAE,EAAE;YAChC,IAAI,CAAC,IAAI,CAAC,YAAY,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;QACD,WAAW,EAAE,CAAC,OAAyB,EAAE,EAAE;YACzC,IAAI,CAAC,KAAK,CAAC,YAAY,OAAO,CAAC,GAAG,uBAAuB,OAAO,CAAC,KAAK,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5F,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAA+B;IAC9D,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,CAAC,OAAuB,EAAE,EAAE;YAChC,IAAI,CAAC;gBACH,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;YAAC,MAAM,CAAC;gBACP,6EAA6E;YAC/E,CAAC;QACH,CAAC;QACD,WAAW,EAAE,CAAC,OAAyB,EAAE,EAAE;YACzC,IAAI,CAAC;gBACH,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC;gBACP,gFAAgF;YAClF,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Error boundary of a mounted component (TAG-302): the root component of every shadow root the
3
+ * runtime renders. It catches what Preact routes to boundaries (exceptions in render, in
4
+ * lifecycle methods and in hook effects and their cleanups) and then shows the fallback.
5
+ *
6
+ * The fallback is the element's light DOM through an unnamed `<slot>` (the content the page put
7
+ * inside the tag, visible before the upgrade too) or nothing. The component's styles are rendered
8
+ * here as well when the browser lacks constructable stylesheets, so a failed component drops them.
9
+ */
10
+ import { Component, type ComponentChildren } from "preact";
11
+ import type { FallbackMode } from "./types.js";
12
+ /** Props of `ComponentBoundary`. */
13
+ export interface ComponentBoundaryProps {
14
+ /** Set by the controller when a failure was caught outside Preact (event handlers). */
15
+ readonly failed: boolean;
16
+ readonly fallback: FallbackMode;
17
+ /** Called once per caught error; must not throw (the controller guards its diagnostics). */
18
+ readonly onError: (error: unknown) => void;
19
+ /** CSS rendered as `<style>` elements (only when adoptedStyleSheets is unavailable). */
20
+ readonly inlineStyles: readonly string[];
21
+ /** The page's CSP nonce for those `<style>` elements (TAG-308). */
22
+ readonly nonce?: string | undefined;
23
+ readonly children?: ComponentChildren;
24
+ }
25
+ interface ComponentBoundaryState {
26
+ readonly caught: boolean;
27
+ }
28
+ /**
29
+ * Renders the component, or its fallback once anything below it threw.
30
+ *
31
+ * Inputs: `ComponentBoundaryProps`. Output: the `<style>` elements and children while healthy; the
32
+ * fallback (`<slot>` or nothing) after a caught error or when `failed` is set. Errors: none of its
33
+ * own; an error below it is reported through `onError` and never rethrown. Side effects: state.
34
+ */
35
+ export declare class ComponentBoundary extends Component<ComponentBoundaryProps, ComponentBoundaryState> {
36
+ state: ComponentBoundaryState;
37
+ componentDidCatch(error: unknown): void;
38
+ render(): ComponentChildren;
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../src/element/error-boundary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAK,KAAK,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,uFAAuF;IACvF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,wFAAwF;IACxF,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,UAAU,sBAAsB;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,qBAAa,iBAAkB,SAAQ,SAAS,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;IACrF,KAAK,EAAE,sBAAsB,CAAqB;IAElD,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAOvC,MAAM,IAAI,iBAAiB;CAWrC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Error boundary of a mounted component (TAG-302): the root component of every shadow root the
3
+ * runtime renders. It catches what Preact routes to boundaries (exceptions in render, in
4
+ * lifecycle methods and in hook effects and their cleanups) and then shows the fallback.
5
+ *
6
+ * The fallback is the element's light DOM through an unnamed `<slot>` (the content the page put
7
+ * inside the tag, visible before the upgrade too) or nothing. The component's styles are rendered
8
+ * here as well when the browser lacks constructable stylesheets, so a failed component drops them.
9
+ */
10
+ import { Component, h } from "preact";
11
+ /**
12
+ * Renders the component, or its fallback once anything below it threw.
13
+ *
14
+ * Inputs: `ComponentBoundaryProps`. Output: the `<style>` elements and children while healthy; the
15
+ * fallback (`<slot>` or nothing) after a caught error or when `failed` is set. Errors: none of its
16
+ * own; an error below it is reported through `onError` and never rethrown. Side effects: state.
17
+ */
18
+ export class ComponentBoundary extends Component {
19
+ state = { caught: false };
20
+ componentDidCatch(error) {
21
+ // Always set state (even when already caught): Preact treats the error as handled only when
22
+ // the boundary is left dirty, otherwise it keeps looking upwards and finally rethrows.
23
+ this.setState({ caught: true });
24
+ this.props.onError(error);
25
+ }
26
+ render() {
27
+ if (this.state.caught || this.props.failed) {
28
+ return this.props.fallback === "light-dom" ? h("slot", null) : null;
29
+ }
30
+ return [
31
+ ...this.props.inlineStyles.map((css, index) => h("style", { key: `style-${String(index)}`, nonce: this.props.nonce }, css)),
32
+ this.props.children,
33
+ ];
34
+ }
35
+ }
36
+ //# sourceMappingURL=error-boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.js","sourceRoot":"","sources":["../../src/element/error-boundary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,CAAC,EAA0B,MAAM,QAAQ,CAAC;AAsB9D;;;;;;GAMG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAyD;IACrF,KAAK,GAA2B,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAElD,iBAAiB,CAAC,KAAc;QACvC,4FAA4F;QAC5F,uFAAuF;QACvF,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEQ,MAAM;QACb,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACtE,CAAC;QACD,OAAO;YACL,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAC5C,CAAC,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,SAAS,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,CAC5E;YACD,IAAI,CAAC,KAAK,CAAC,QAAQ;SACpB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reports one caught failure.
3
+ * Inputs: the component tag, the published version hash, the failure phase, the caught value and
4
+ * the delivery origin (the loader's runtime URL; never `import.meta.url`, which is a syntax error
5
+ * when a host page loads the bundle as a classic script and made props.e2e.ts fail, TAG-2522).
6
+ * Output: none. Errors: never throws. Side effects: at most one beacon and the per-tag counter.
7
+ */
8
+ export declare function reportFailure(tag: string, version: string, phase: string, error: unknown, origin: string): void;
9
+ //# sourceMappingURL=error-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-report.d.ts","sourceRoot":"","sources":["../../src/element/error-report.ts"],"names":[],"mappings":"AA6BA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,GACb,IAAI,CAwBN"}