@taggor/runtime 0.0.0-stage → 0.2.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 +49 -2
  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 +86 -3
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Component styles in the shadow root (TAG-302): the component's CSS is adopted by its own shadow root,
3
+ * never added to the page (the old prototype's global CSS defect).
4
+ *
5
+ * With constructable stylesheets (`new CSSStyleSheet()` + `adoptedStyleSheets`), one sheet per
6
+ * CSS text is built once per component definition and shared by its instances. Without them (old
7
+ * browsers), the error boundary renders `<style>` elements whose CSS is a text node, never parsed
8
+ * as HTML. `replaceSync` ignores `@import`, so adopted CSS cannot load another stylesheet; the
9
+ * `<style>` fallback does load it, subject to the page's `style-src` (TAG-308 review).
10
+ *
11
+ * TAG-308: every component starts with the runtime's minimal host reset (`HOST_RESET`), the first
12
+ * sheet, so the component's own `:host` rules (later in the same shadow tree) and the page's rules on
13
+ * the tag (the outer tree wins over `:host`) both override it. The `<style>` fallback carries the
14
+ * page's CSP nonce when the loader passes one (`createComponentElement`'s `styleNonce`); adopted
15
+ * sheets need none, because CSP's `style-src` does not govern constructed stylesheets.
16
+ */
17
+ /**
18
+ * The runtime's reset of every component host (TAG-308): a block box that contains its layout,
19
+ * paint and style (`contain: content`), and the `hidden` attribute still hiding it (an author
20
+ * `display` beats the user agent's `[hidden]` rule). A component whose content leaves its box
21
+ * (a fixed overlay, a dropdown) writes `:host { contain: none }`.
22
+ */
23
+ export declare const HOST_RESET = ":host{display:block;contain:content}:host([hidden]){display:none}";
24
+ /** How a component's CSS reaches its shadow roots. */
25
+ export interface ComponentStyles {
26
+ /** Adds the sheets to `root.adoptedStyleSheets`; returns false when unsupported. */
27
+ readonly adopt: (root: ShadowRoot) => boolean;
28
+ /** Removes this component's sheets from `root`, keeping any other sheet. */
29
+ readonly drop: (root: ShadowRoot) => void;
30
+ /** The CSS texts, `HOST_RESET` first, for the `<style>` fallback. */
31
+ readonly css: readonly string[];
32
+ /** The CSP nonce of the `<style>` fallback, when the page gave one (TAG-308). */
33
+ readonly nonce: string | undefined;
34
+ }
35
+ /**
36
+ * Creates the style handling of one component definition.
37
+ *
38
+ * Inputs: the definition's CSS texts and the page's CSP nonce, if any. Output: `ComponentStyles`
39
+ * whose `css` is `HOST_RESET` followed by the definition's texts; their sheets are built lazily
40
+ * on the first `adopt`, once per definition (one published version), and shared by every
41
+ * instance. Errors: `adopt` throws if the browser rejects the CSS (the controller treats it
42
+ * as a lifecycle failure). Side effects: `adopt`/`drop` assign `root.adoptedStyleSheets`.
43
+ */
44
+ export declare function createComponentStyles(componentCss: readonly string[], nonce?: string): ComponentStyles;
45
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/element/styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,sEAAsE,CAAC;AAE9F,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;IAC9C,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAC1C,qEAAqE;IACrE,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAUD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,KAAK,CAAC,EAAE,MAAM,GACb,eAAe,CAwBjB"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Component styles in the shadow root (TAG-302): the component's CSS is adopted by its own shadow root,
3
+ * never added to the page (the old prototype's global CSS defect).
4
+ *
5
+ * With constructable stylesheets (`new CSSStyleSheet()` + `adoptedStyleSheets`), one sheet per
6
+ * CSS text is built once per component definition and shared by its instances. Without them (old
7
+ * browsers), the error boundary renders `<style>` elements whose CSS is a text node, never parsed
8
+ * as HTML. `replaceSync` ignores `@import`, so adopted CSS cannot load another stylesheet; the
9
+ * `<style>` fallback does load it, subject to the page's `style-src` (TAG-308 review).
10
+ *
11
+ * TAG-308: every component starts with the runtime's minimal host reset (`HOST_RESET`), the first
12
+ * sheet, so the component's own `:host` rules (later in the same shadow tree) and the page's rules on
13
+ * the tag (the outer tree wins over `:host`) both override it. The `<style>` fallback carries the
14
+ * page's CSP nonce when the loader passes one (`createComponentElement`'s `styleNonce`); adopted
15
+ * sheets need none, because CSP's `style-src` does not govern constructed stylesheets.
16
+ */
17
+ /**
18
+ * The runtime's reset of every component host (TAG-308): a block box that contains its layout,
19
+ * paint and style (`contain: content`), and the `hidden` attribute still hiding it (an author
20
+ * `display` beats the user agent's `[hidden]` rule). A component whose content leaves its box
21
+ * (a fixed overlay, a dropdown) writes `:host { contain: none }`.
22
+ */
23
+ export const HOST_RESET = ":host{display:block;contain:content}:host([hidden]){display:none}";
24
+ /** The constructor of constructable stylesheets, when the browser has it. */
25
+ function sheetConstructor() {
26
+ const candidate = globalThis.CSSStyleSheet;
27
+ return typeof candidate === "function" && typeof candidate.prototype.replaceSync === "function"
28
+ ? candidate
29
+ : undefined;
30
+ }
31
+ /**
32
+ * Creates the style handling of one component definition.
33
+ *
34
+ * Inputs: the definition's CSS texts and the page's CSP nonce, if any. Output: `ComponentStyles`
35
+ * whose `css` is `HOST_RESET` followed by the definition's texts; their sheets are built lazily
36
+ * on the first `adopt`, once per definition (one published version), and shared by every
37
+ * instance. Errors: `adopt` throws if the browser rejects the CSS (the controller treats it
38
+ * as a lifecycle failure). Side effects: `adopt`/`drop` assign `root.adoptedStyleSheets`.
39
+ */
40
+ export function createComponentStyles(componentCss, nonce) {
41
+ let sheets;
42
+ const isOwn = (sheet) => sheets?.includes(sheet) === true;
43
+ const css = Object.freeze([HOST_RESET, ...componentCss]);
44
+ return Object.freeze({
45
+ css,
46
+ nonce,
47
+ adopt: (root) => {
48
+ const Sheet = sheetConstructor();
49
+ if (Sheet === undefined || !("adoptedStyleSheets" in root))
50
+ return false;
51
+ sheets ??= css.map((text) => {
52
+ const sheet = new Sheet();
53
+ sheet.replaceSync(text);
54
+ return sheet;
55
+ });
56
+ root.adoptedStyleSheets = [...root.adoptedStyleSheets.filter((s) => !isOwn(s)), ...sheets];
57
+ return true;
58
+ },
59
+ drop: (root) => {
60
+ if (sheets === undefined || !("adoptedStyleSheets" in root))
61
+ return;
62
+ root.adoptedStyleSheets = root.adoptedStyleSheets.filter((s) => !isOwn(s));
63
+ },
64
+ });
65
+ }
66
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/element/styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mEAAmE,CAAC;AAc9F,6EAA6E;AAC7E,SAAS,gBAAgB;IACvB,MAAM,SAAS,GAAI,UAAuD,CAAC,aAAa,CAAC;IACzF,OAAO,OAAO,SAAS,KAAK,UAAU,IAAI,OAAO,SAAS,CAAC,SAAS,CAAC,WAAW,KAAK,UAAU;QAC7F,CAAC,CAAC,SAAS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AC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Types of the Custom Element wrapper (TAG-302): what the runtime mounts (`MountableComponent`, the
3
+ * shape `defineTaggorComponent` of `@taggor/component` produces), what it gives the mounted component
4
+ * (`ComponentHost`) and the diagnostics port it reports through (`RuntimeDiagnostics`).
5
+ *
6
+ * The runtime does not depend on `@taggor/component`: the SDK depends on the runtime for its test
7
+ * helpers (`@taggor/component/testing`, TAG-209), so the definition is described here structurally. A `ComponentDefinition`
8
+ * is assignable to `MountableComponent`. TAG-303 added `contractVersion` and the coercion warnings;
9
+ * TAG-305 the `events` map and the `event-dropped` warning; TAG-304 the property and props script
10
+ * warnings; TAG-314 the form field declarations (`formAssociated`, `delegatesFocus`) and the host's
11
+ * `internals`. TAG-214 the `host-api` warning of `window.taggor`. TAG-709 the host's `transport`.
12
+ */
13
+ import type { EventDeclaration } from "@taggor/contract";
14
+ import type { PropDeclaration } from "@taggor/contract/zod-free";
15
+ /** Brand of every component definition (`COMPONENT_KIND` in `@taggor/component`). */
16
+ export declare const COMPONENT_KIND = "taggor.component";
17
+ /**
18
+ * What the runtime gives a mounted component, the same shape as `ComponentHost` in `@taggor/component`.
19
+ *
20
+ * - `element`: the custom element on the host page (its light DOM holds the slotted content).
21
+ * - `shadowRoot`: the component's own open shadow root, where the component renders.
22
+ * - `emit(name, detail)` (TAG-305): while the component is mounted, dispatches the declared event
23
+ * `name` on `element` as a `CustomEvent` named `<tag>:<name>`, with a validated, frozen copy of
24
+ * `detail` and the declared `bubbles`/`composed`. Anything else (an undeclared name, a detail
25
+ * the event's schema refuses, a call after the unmount or after a failure) is dropped with an
26
+ * `event-dropped` warning. Called as a plain function; never throws.
27
+ * - `signal` (TAG-317): aborted when the component is really unmounted (removed, not moved); the
28
+ * SDK's data transport passes it to `fetch`. A new signal per mount; `undefined` only on a
29
+ * page without `AbortController`.
30
+ * - `internals` (TAG-314): the element's `ElementInternals` when the manifest declares
31
+ * `formAssociated: true` (the SDK's `useFormField` sets the form value and validity through it);
32
+ * `undefined` otherwise, and on a browser without form-associated custom elements.
33
+ */
34
+ export interface ComponentHost {
35
+ readonly element: HTMLElement;
36
+ readonly shadowRoot: ShadowRoot;
37
+ readonly emit: (name: string, detail: unknown) => void;
38
+ readonly signal?: AbortSignal | undefined;
39
+ readonly internals?: ElementInternals | undefined;
40
+ /**
41
+ * The data transport of the component (TAG-709), opaque to the runtime: the loader gives components
42
+ * that declare `data` a lazy one (`loader/lazy-transport.ts`); the SDK's data hooks use it.
43
+ */
44
+ readonly transport?: unknown;
45
+ }
46
+ /**
47
+ * The manifest fields the wrapper reads. `contractVersion` is set at extraction (the SDK's draft
48
+ * has none), so the loader usually passes the published manifest's through
49
+ * `ComponentElementOptions.contractVersion`; it is read here only when that option is absent.
50
+ */
51
+ export interface MountableManifest {
52
+ readonly name: string;
53
+ readonly tag: string;
54
+ readonly contractVersion?: string | undefined;
55
+ readonly props?: Readonly<Record<string, PropDeclaration>> | undefined;
56
+ /** Declared events (TAG-305), read once when the element class is created. */
57
+ readonly events?: Readonly<Record<string, EventDeclaration>> | undefined;
58
+ /** A form field component (TAG-314, contract 1.4): the element is form-associated. */
59
+ readonly formAssociated?: boolean | undefined;
60
+ /** Whether the shadow root delegates focus (TAG-314); defaults to `formAssociated`. */
61
+ readonly delegatesFocus?: boolean | undefined;
62
+ }
63
+ /**
64
+ * A component the wrapper can mount: the inert object `defineTaggorComponent` returns.
65
+ *
66
+ * `component` is called by Preact with `{ host, props }`; its parameter is typed `never` so that
67
+ * any definition, whatever its prop types, is accepted (the runtime builds the props from the
68
+ * manifest, the SDK types them for the author).
69
+ */
70
+ export interface MountableComponent {
71
+ readonly kind: typeof COMPONENT_KIND;
72
+ readonly manifest: MountableManifest;
73
+ readonly styles: readonly string[];
74
+ readonly component: (props: never) => unknown;
75
+ }
76
+ /** Where a component failure was caught. */
77
+ export type FailurePhase =
78
+ /** Rendering or running an effect (Preact error boundary). */
79
+ "render"
80
+ /** A DOM event handler of the component, synchronous or a rejected promise it returned. */
81
+ | "handler"
82
+ /** A Custom Element callback: attaching the shadow root, styles, mount, update or unmount. */
83
+ | "lifecycle";
84
+ /** A component failure, sent to `RuntimeDiagnostics.reportError` instead of the page. */
85
+ export interface ComponentFailure {
86
+ readonly tag: string;
87
+ readonly name: string;
88
+ readonly phase: FailurePhase;
89
+ readonly error: unknown;
90
+ }
91
+ /** Why the runtime warns. */
92
+ export type WarningCode =
93
+ /** The tag was already defined by another script (or another copy of the runtime). */
94
+ "tag-collision"
95
+ /** `customElements.define` threw for another reason (an invalid name, for instance). */
96
+ | "define-failed"
97
+ /** The value given to `createComponentElement` is not a component definition. */
98
+ | "invalid-definition"
99
+ /** The page has no Custom Elements (no `customElements` or `HTMLElement`). */
100
+ | "unsupported"
101
+ /**
102
+ * The manifest's `contractVersion` (TAG-303): a newer minor (mounted, its additions ignored) or
103
+ * a version this runtime cannot mount (missing, malformed, newer major, unsupported major).
104
+ */
105
+ | "contract-version"
106
+ /**
107
+ * A prop declares a `type` this runtime does not know (a newer minor), or (TAG-304) is named
108
+ * like a member the element already has (the live `HTMLElement.prototype` chain or a Custom
109
+ * Element callback): the prop is absent, never installed as a property.
110
+ */
111
+ | "unknown-prop-type"
112
+ /** An attribute's text was refused by its prop type; the prop got its default (TAG-303). */
113
+ | "invalid-attribute"
114
+ /** A value assigned to a prop's property was refused; the prop got its default (TAG-304). */
115
+ | "invalid-property"
116
+ /**
117
+ * The `<script type="application/json" data-props>` child (TAG-304) was refused as a whole
118
+ * (prop `*`: too long, too deep, not JSON, not an object) or for one prop (its default).
119
+ */
120
+ | "invalid-props-script"
121
+ /**
122
+ * An `emit` was not dispatched (TAG-305): undeclared name, a detail its schema refuses, or the
123
+ * component is not mounted. The message never carries the refused value.
124
+ */
125
+ | "event-dropped"
126
+ /**
127
+ * A method of the host page API (`window.taggor`, TAG-214) got an argument it cannot use and
128
+ * returned `undefined`; `tag` is `"taggor"`.
129
+ */
130
+ | "host-api";
131
+ /** A warning for debug mode (TAG-315); the message is plain text, never HTML. */
132
+ export interface RuntimeWarning {
133
+ readonly code: WarningCode;
134
+ readonly tag: string;
135
+ readonly message: string;
136
+ }
137
+ /**
138
+ * The diagnostics port of the runtime. Both functions are called inside a `try`, so a throwing
139
+ * implementation never reaches the page. Debug mode (TAG-315) wires them to the console
140
+ * (`consoleDiagnostics`); production will send failures to telemetry.
141
+ */
142
+ export interface RuntimeDiagnostics {
143
+ readonly warn: (warning: RuntimeWarning) => void;
144
+ readonly reportError: (failure: ComponentFailure) => void;
145
+ }
146
+ /** What a failed component shows: its light DOM through a default `<slot>`, or nothing. */
147
+ export type FallbackMode = "light-dom" | "none";
148
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/element/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEjE,qFAAqF;AACrF,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAClD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO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BAA6B;AAC7B,MAAM,MAAM,WAAW;AACrB,sFAAsF;AACpF,eAAe;AACjB,wFAAwF;GACtF,eAAe;AACjB,iFAAiF;GAC/E,oBAAoB;AACtB,8EAA8E;GAC5E,aAAa;AACf;;;GAGG;GACD,kBAAkB;AACpB;;;;GAIG;GACD,mBAAmB;AACrB,4FAA4F;GAC1F,mBAAmB;AACrB,6FAA6F;GAC3F,kBAAkB;AACpB;;;GAGG;GACD,sBAAsB;AACxB;;;GAGG;GACD,eAAe;AACjB;;;GAGG;GACD,UAAU,CAAC;AAEf,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC3D;AAED,2FAA2F;AAC3F,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Brand of every component definition (`COMPONENT_KIND` in `@taggor/component`). */
2
+ export const COMPONENT_KIND = "taggor.component";
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/element/types.ts"],"names":[],"mappings":"AAeA,qFAAqF;AACrF,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { RuntimeDiagnostics } from "../element/types.js";
2
+ import type { InitialLoadBarrier } from "./barrier.js";
3
+ import type { ComponentInfoReader } from "./registry.js";
4
+ import type { TaggorHostApi } from "./types.js";
5
+ /** What `createHostApi` reads and where it reports. */
6
+ export interface HostApiOptions {
7
+ /**
8
+ * The runtime's `liveComponents`, once the loader imported the runtime; `undefined` before (the
9
+ * page has no component yet).
10
+ */
11
+ readonly live: () => ReadonlyMap<unknown, ComponentInfoReader> | undefined;
12
+ /** The barrier the loader announces the initial load to; `ready()` is its `ready`. */
13
+ readonly barrier: Pick<InitialLoadBarrier, "ready">;
14
+ /** Where the warnings about invalid calls go (default: silent; debug mode passes the console). */
15
+ readonly diagnostics?: RuntimeDiagnostics;
16
+ /** Where `on` listens (default: the page's `document`, read when `on` is called). */
17
+ readonly document?: Pick<Document, "addEventListener" | "removeEventListener">;
18
+ }
19
+ /**
20
+ * Creates the host page API.
21
+ *
22
+ * Inputs: `HostApiOptions`. Output: a frozen `TaggorHostApi` (contract in `types.ts`). Errors:
23
+ * none, and none of its methods throws. `get` and `components` only report elements still in the
24
+ * document; `on` only calls the handler for events that come from a live component element. Side effects: none until `on` is called, which adds one
25
+ * capture listener to the document per subscription (removed by the function it returns).
26
+ */
27
+ export declare function createHostApi(options: HostApiOptions): TaggorHostApi;
28
+ /**
29
+ * Installs the API as `taggor` on the page's global object, unless the page already has one.
30
+ *
31
+ * Inputs: the API and the global object (default `globalThis`). Output: `true` when installed;
32
+ * `false` when `taggor` already is an own property of the global (the page's own `var taggor`, or
33
+ * another Taggor snippet, which TAG-309 will index by version) or the global refuses it. Errors:
34
+ * none. Side effects: one writable, configurable, non-enumerable property. Not locked on purpose
35
+ * (TAG-214 review, A1): a non-configurable global would make a later classic script of the page
36
+ * that declares `taggor` (`const`, `let`, `class`, `function`) fail with a SyntaxError, and a
37
+ * strict-mode assignment throw, stopping the whole script. The API object itself is frozen.
38
+ */
39
+ export declare function installHostApi(api: TaggorHostApi, target?: object): boolean;
40
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/host/api.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAE/D,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,WAAW,CAAC,OAAO,EAAE,mBAAmB,CAAC,GAAG,SAAS,CAAC;IAC3E,sFAAsF;IACtF,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IACpD,kGAAkG;IAClG,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAC1C,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,qBAAqB,CAAC,CAAC;CAChF;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CAiFpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,GAAE,MAAmB,GAAG,OAAO,CAavF"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The host page API (TAG-214, ADR 0023): `createHostApi` builds the frozen `window.taggor` object
3
+ * (`version`, `ready`, `get`, `on`, `components`), and `installHostApi` puts it on the page, the only
4
+ * global Taggor creates.
5
+ *
6
+ * Not part of the runtime bundle (`bundle.test.ts` fences it out): the loader (TAG-301) bundles
7
+ * it, so `window.taggor` exists from the snippet's first run, before the runtime is downloaded,
8
+ * and the runtime only pays for its live component registry (`registry.ts`). The loader passes the
9
+ * runtime's `liveComponents` once it imported the runtime (`undefined` before: no component yet) and
10
+ * the initial-load barrier it announces to (`barrier.ts`).
11
+ *
12
+ * Every method is total (golden rule 2): it never throws at the page, whatever it is given (a
13
+ * Proxy, a revoked Proxy, a throwing getter, a primitive, a lost `this`); an invalid argument
14
+ * gives `undefined` and a `host-api` warning through the diagnostics port, which only debug mode
15
+ * prints (TAG-315). Nothing here touches the page's DOM except the listeners `on` adds.
16
+ */
17
+ import { CONTRACT_VERSION } from "@taggor/contract/zod-free";
18
+ import { guardDiagnostics, silentDiagnostics } from "../element/diagnostics.js";
19
+ /**
20
+ * Creates the host page API.
21
+ *
22
+ * Inputs: `HostApiOptions`. Output: a frozen `TaggorHostApi` (contract in `types.ts`). Errors:
23
+ * none, and none of its methods throws. `get` and `components` only report elements still in the
24
+ * document; `on` only calls the handler for events that come from a live component element. Side effects: none until `on` is called, which adds one
25
+ * capture listener to the document per subscription (removed by the function it returns).
26
+ */
27
+ export function createHostApi(options) {
28
+ const diagnostics = guardDiagnostics(options.diagnostics ?? silentDiagnostics);
29
+ /** Warns about an invalid call; the method then returns `undefined`. */
30
+ const refuse = (call) => {
31
+ diagnostics.warn({
32
+ code: "host-api",
33
+ tag: "taggor",
34
+ message: `taggor.${call}: invalid argument, returned undefined`,
35
+ });
36
+ };
37
+ /** The info of a live component element still in the document (TAG-214 review, A6). */
38
+ const connected = (info) => info?.element.isConnected === true ? info : undefined;
39
+ const read = (element) => {
40
+ try {
41
+ return connected(options.live()?.get(element)?.());
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ };
47
+ return Object.freeze({
48
+ version: CONTRACT_VERSION,
49
+ ready: () => options.barrier.ready(),
50
+ get: (element) => {
51
+ const info = read(element);
52
+ if (info === undefined)
53
+ refuse("get");
54
+ return info;
55
+ },
56
+ on: (tag, event, handler) => {
57
+ if (typeof tag !== "string" || typeof event !== "string" || typeof handler !== "function") {
58
+ refuse("on");
59
+ return undefined;
60
+ }
61
+ try {
62
+ const target = options.document ?? document;
63
+ const type = `${tag}:${event}`;
64
+ // One listener per call, so each subscription stops on its own, even for the same handler.
65
+ // Only events whose origin is a live component element reach the handler (TAG-214 review,
66
+ // A4): page code can still dispatch a forged event on a component element, so the handler
67
+ // checks the `detail` it uses.
68
+ const listener = (dispatched) => {
69
+ let fromComponent = false;
70
+ try {
71
+ fromComponent = read(dispatched.composedPath()[0]) !== undefined;
72
+ }
73
+ catch {
74
+ // A page that broke composedPath: not a component event as far as we can tell.
75
+ }
76
+ if (fromComponent)
77
+ handler(dispatched);
78
+ };
79
+ // Capture: a component event declared with `bubbles: false` still reaches the document.
80
+ target.addEventListener(type, listener, true);
81
+ return () => {
82
+ try {
83
+ target.removeEventListener(type, listener, true);
84
+ }
85
+ catch {
86
+ // A page that replaced removeEventListener; nothing more to do.
87
+ }
88
+ };
89
+ }
90
+ catch {
91
+ refuse("on");
92
+ return undefined;
93
+ }
94
+ },
95
+ components: () => {
96
+ const infos = [];
97
+ try {
98
+ for (const reader of options.live()?.values() ?? []) {
99
+ // One reader at a time: a bad entry never hides the others (TAG-214 review, A2).
100
+ try {
101
+ const info = connected(reader());
102
+ if (info !== undefined)
103
+ infos.push(info);
104
+ }
105
+ catch {
106
+ // Skip this entry.
107
+ }
108
+ }
109
+ }
110
+ catch {
111
+ // The loader's getter or the map's iterator failed: what was read so far.
112
+ }
113
+ return Object.freeze(infos);
114
+ },
115
+ });
116
+ }
117
+ /**
118
+ * Installs the API as `taggor` on the page's global object, unless the page already has one.
119
+ *
120
+ * Inputs: the API and the global object (default `globalThis`). Output: `true` when installed;
121
+ * `false` when `taggor` already is an own property of the global (the page's own `var taggor`, or
122
+ * another Taggor snippet, which TAG-309 will index by version) or the global refuses it. Errors:
123
+ * none. Side effects: one writable, configurable, non-enumerable property. Not locked on purpose
124
+ * (TAG-214 review, A1): a non-configurable global would make a later classic script of the page
125
+ * that declares `taggor` (`const`, `let`, `class`, `function`) fail with a SyntaxError, and a
126
+ * strict-mode assignment throw, stopping the whole script. The API object itself is frozen.
127
+ */
128
+ export function installHostApi(api, target = globalThis) {
129
+ try {
130
+ if (Object.hasOwn(target, "taggor"))
131
+ return false;
132
+ Object.defineProperty(target, "taggor", {
133
+ value: api,
134
+ writable: true,
135
+ configurable: true,
136
+ enumerable: false,
137
+ });
138
+ return true;
139
+ }
140
+ catch {
141
+ return false;
142
+ }
143
+ }
144
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/host/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAqBhF;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,OAAuB;IACnD,MAAM,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,IAAI,iBAAiB,CAAC,CAAC;IAC/E,wEAAwE;IACxE,MAAM,MAAM,GAAG,CAAC,IAAY,EAAQ,EAAE;QACpC,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,UAAU;YAChB,GAAG,EAAE,QAAQ;YACb,OAAO,EAAE,UAAU,IAAI,wCAAwC;SAChE,CAAC,CAAC;IACL,CAAC,CAAC;IACF,uFAAuF;IACvF,MAAM,SAAS,GAAG,CAAC,IAA+B,EAAE,EAAE,CACpD,IAAI,EAAE,OAAO,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,MAAM,IAAI,GAAG,CAAC,OAAgB,EAA6B,EAAE;QAC3D,IAAI,CAAC;YACH,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,gBAAgB;QACzB,KAAK,EAAE,GAA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,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The initial-load barrier behind `window.taggor.ready()` (TAG-214).
3
+ *
4
+ * The loader announces the tags it found in the page at the initial load (`expect`) and settles
5
+ * each one when `createComponentElement` returned for it (defined, collision, refused) or when it
6
+ * gave up on the tag's bundle (network error, timeout, a bundle that throws; TAG-307). `ready()`
7
+ * resolves once the announcement happened and nothing announced is pending; it never rejects, and
8
+ * each call gets its own promise. A
9
+ * tag settled before it is announced counts as settled, so the order of the loader's calls does
10
+ * not matter. Tags announced after the barrier opened (an SPA adding components) do not close it.
11
+ */
12
+ /** The loader's side (`expect`, `settle`) and the page's side (`ready`) of the barrier. */
13
+ export interface InitialLoadBarrier {
14
+ /** The tags of the initial load; may be called more than once before the barrier opens. */
15
+ readonly expect: (tags: Iterable<string>) => void;
16
+ /** One tag is done (registered, or given up). */
17
+ readonly settle: (tag: string) => void;
18
+ /** Resolves once announced and nothing is pending; a new promise per call. */
19
+ readonly ready: () => Promise<void>;
20
+ }
21
+ /**
22
+ * Creates a closed barrier.
23
+ *
24
+ * Inputs: none. Output: an `InitialLoadBarrier`. Errors: none. Side effects: none.
25
+ */
26
+ export declare function createInitialLoadBarrier(): InitialLoadBarrier;
27
+ //# sourceMappingURL=barrier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrier.d.ts","sourceRoot":"","sources":["../../src/host/barrier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,2FAA2F;AAC3F,MAAM,WAAW,kBAAkB;IACjC,2FAA2F;IAC3F,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAClD,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,kBAAkB,CA0B7D"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The initial-load barrier behind `window.taggor.ready()` (TAG-214).
3
+ *
4
+ * The loader announces the tags it found in the page at the initial load (`expect`) and settles
5
+ * each one when `createComponentElement` returned for it (defined, collision, refused) or when it
6
+ * gave up on the tag's bundle (network error, timeout, a bundle that throws; TAG-307). `ready()`
7
+ * resolves once the announcement happened and nothing announced is pending; it never rejects, and
8
+ * each call gets its own promise. A
9
+ * tag settled before it is announced counts as settled, so the order of the loader's calls does
10
+ * not matter. Tags announced after the barrier opened (an SPA adding components) do not close it.
11
+ */
12
+ /**
13
+ * Creates a closed barrier.
14
+ *
15
+ * Inputs: none. Output: an `InitialLoadBarrier`. Errors: none. Side effects: none.
16
+ */
17
+ export function createInitialLoadBarrier() {
18
+ const settled = new Set();
19
+ /** Undefined until the loader announces the initial load. */
20
+ let pending;
21
+ let open = () => undefined;
22
+ const barrier = new Promise((resolve) => {
23
+ open = resolve;
24
+ });
25
+ const check = () => {
26
+ if (pending?.size === 0)
27
+ open();
28
+ };
29
+ return Object.freeze({
30
+ expect: (tags) => {
31
+ pending ??= new Set();
32
+ for (const tag of tags)
33
+ if (!settled.has(tag))
34
+ pending.add(tag);
35
+ check();
36
+ },
37
+ settle: (tag) => {
38
+ settled.add(tag);
39
+ pending?.delete(tag);
40
+ check();
41
+ },
42
+ // A new promise per call (TAG-214 review, A3): the shared one never leaves this closure, so
43
+ // no caller can poison its `then` for the others.
44
+ ready: () => barrier.then(() => undefined),
45
+ });
46
+ }
47
+ //# sourceMappingURL=barrier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrier.js","sourceRoot":"","sources":["../../src/host/barrier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,6DAA6D;IAC7D,IAAI,OAAgC,CAAC;IACrC,IAAI,IAAI,GAAe,GAAG,EAAE,CAAC,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC5C,IAAI,GAAG,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,OAAO,EAAE,IAAI,KAAK,CAAC;YAAE,IAAI,EAAE,CAAC;IAClC,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,MAAM,EAAE,CAAC,IAAsB,EAAE,EAAE;YACjC,OAAO,KAAK,IAAI,GAAG,EAAE,CAAC;YACtB,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,MAAM,EAAE,CAAC,GAAW,EAAE,EAAE;YACtB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,KAAK,EAAE,CAAC;QACV,CAAC;QACD,4FAA4F;QAC5F,kDAAkD;QAClD,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;KAC3C,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The host page API (TAG-214, ADR 0023): `window.taggor` (`createHostApi`, `installHostApi`) and
3
+ * the initial-load barrier behind its `ready()` (`createInitialLoadBarrier`). The loader bundles
4
+ * this entry (`@taggor/runtime/host`); the runtime bundle only has the live component registry
5
+ * (`liveComponents`, exported by the main entry). See docs/agentes/runtime.md §2.18.
6
+ */
7
+ export { createHostApi, installHostApi, type HostApiOptions } from "./api.js";
8
+ export { createInitialLoadBarrier, type InitialLoadBarrier } from "./barrier.js";
9
+ export type { LiveComponents, ComponentInfoReader } from "./registry.js";
10
+ export type { TaggorHostApi, ComponentInfo, ComponentState } from "./types.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjF,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The host page API (TAG-214, ADR 0023): `window.taggor` (`createHostApi`, `installHostApi`) and
3
+ * the initial-load barrier behind its `ready()` (`createInitialLoadBarrier`). The loader bundles
4
+ * this entry (`@taggor/runtime/host`); the runtime bundle only has the live component registry
5
+ * (`liveComponents`, exported by the main entry). See docs/agentes/runtime.md §2.18.
6
+ */
7
+ export { createHostApi, installHostApi } from "./api.js";
8
+ export { createInitialLoadBarrier } from "./barrier.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAA2B,MAAM,cAAc,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The live component registry (TAG-214): the connected component elements of the page's runtime copies,
3
+ * each with the reader of its `ComponentInfo`. It is the only part of the host page API inside the
4
+ * runtime bundle (ADR 0023): the Custom Element wrapper keeps it, and `window.taggor`
5
+ * (`createHostApi`, which the loader bundles) reads it through the runtime module the loader
6
+ * imported.
7
+ *
8
+ * Holds strong references only to connected elements: the controller deletes an element when it
9
+ * really unmounts (TAG-317), so a removed element is not kept alive here; a move keeps it.
10
+ */
11
+ import type { ComponentInfo } from "./types.js";
12
+ /** Reads the current info of one element; never throws (the controller catches). */
13
+ export type ComponentInfoReader = () => ComponentInfo | undefined;
14
+ /** Connected component elements → the reader of their info, in connection order. */
15
+ export type LiveComponents = Map<HTMLElement, ComponentInfoReader>;
16
+ /**
17
+ * The live components of the page, shared by every component element of every runtime copy on it.
18
+ * Read-only for everyone but the controller (`component-controller.ts`).
19
+ */
20
+ export declare const liveComponents: LiveComponents;
21
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/host/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,MAAM,aAAa,GAAG,SAAS,CAAC;AAElE,oFAAoF;AACpF,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;AA0BnE;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,cAA+B,CAAC"}