@taggor/component 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 (169) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -0
  3. package/assets.d.ts +35 -0
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/assets.d.ts +26 -0
  6. package/dist/assets.d.ts.map +1 -0
  7. package/dist/assets.js +14 -0
  8. package/dist/assets.js.map +1 -0
  9. package/dist/bounded-json.d.ts +21 -0
  10. package/dist/bounded-json.d.ts.map +1 -0
  11. package/dist/bounded-json.js +55 -0
  12. package/dist/bounded-json.js.map +1 -0
  13. package/dist/build/check-messages.d.ts +41 -0
  14. package/dist/build/check-messages.d.ts.map +1 -0
  15. package/dist/build/check-messages.js +142 -0
  16. package/dist/build/check-messages.js.map +1 -0
  17. package/dist/build/extract-manifest.d.ts +48 -0
  18. package/dist/build/extract-manifest.d.ts.map +1 -0
  19. package/dist/build/extract-manifest.js +81 -0
  20. package/dist/build/extract-manifest.js.map +1 -0
  21. package/dist/build/extract-styles.d.ts +36 -0
  22. package/dist/build/extract-styles.d.ts.map +1 -0
  23. package/dist/build/extract-styles.js +48 -0
  24. package/dist/build/extract-styles.js.map +1 -0
  25. package/dist/build/find-definition.d.ts +14 -0
  26. package/dist/build/find-definition.d.ts.map +1 -0
  27. package/dist/build/find-definition.js +23 -0
  28. package/dist/build/find-definition.js.map +1 -0
  29. package/dist/build/index.d.ts +10 -0
  30. package/dist/build/index.d.ts.map +1 -0
  31. package/dist/build/index.js +10 -0
  32. package/dist/build/index.js.map +1 -0
  33. package/dist/consent.d.ts +100 -0
  34. package/dist/consent.d.ts.map +1 -0
  35. package/dist/consent.js +147 -0
  36. package/dist/consent.js.map +1 -0
  37. package/dist/data-client.d.ts +34 -0
  38. package/dist/data-client.d.ts.map +1 -0
  39. package/dist/data-client.js +78 -0
  40. package/dist/data-client.js.map +1 -0
  41. package/dist/data-declaration.d.ts +59 -0
  42. package/dist/data-declaration.d.ts.map +1 -0
  43. package/dist/data-declaration.js +2 -0
  44. package/dist/data-declaration.js.map +1 -0
  45. package/dist/data-errors.d.ts +33 -0
  46. package/dist/data-errors.d.ts.map +1 -0
  47. package/dist/data-errors.js +73 -0
  48. package/dist/data-errors.js.map +1 -0
  49. package/dist/data-transport.d.ts +73 -0
  50. package/dist/data-transport.d.ts.map +1 -0
  51. package/dist/data-transport.js +2 -0
  52. package/dist/data-transport.js.map +1 -0
  53. package/dist/debug.d.ts +14 -0
  54. package/dist/debug.d.ts.map +1 -0
  55. package/dist/debug.js +11 -0
  56. package/dist/debug.js.map +1 -0
  57. package/dist/define-component.d.ts +162 -0
  58. package/dist/define-component.d.ts.map +1 -0
  59. package/dist/define-component.js +79 -0
  60. package/dist/define-component.js.map +1 -0
  61. package/dist/define-library.d.ts +24 -0
  62. package/dist/define-library.d.ts.map +1 -0
  63. package/dist/define-library.js +24 -0
  64. package/dist/define-library.js.map +1 -0
  65. package/dist/edge-transport.d.ts +25 -0
  66. package/dist/edge-transport.d.ts.map +1 -0
  67. package/dist/edge-transport.js +94 -0
  68. package/dist/edge-transport.js.map +1 -0
  69. package/dist/events.d.ts +50 -0
  70. package/dist/events.d.ts.map +1 -0
  71. package/dist/events.js +2 -0
  72. package/dist/events.js.map +1 -0
  73. package/dist/form-field.d.ts +59 -0
  74. package/dist/form-field.d.ts.map +1 -0
  75. package/dist/form-field.js +114 -0
  76. package/dist/form-field.js.map +1 -0
  77. package/dist/host.d.ts +45 -0
  78. package/dist/host.d.ts.map +1 -0
  79. package/dist/host.js +30 -0
  80. package/dist/host.js.map +1 -0
  81. package/dist/index.d.ts +46 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +38 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/intl-format.d.ts +37 -0
  86. package/dist/intl-format.d.ts.map +1 -0
  87. package/dist/intl-format.js +56 -0
  88. package/dist/intl-format.js.map +1 -0
  89. package/dist/issued-proofs.d.ts +19 -0
  90. package/dist/issued-proofs.d.ts.map +1 -0
  91. package/dist/issued-proofs.js +19 -0
  92. package/dist/issued-proofs.js.map +1 -0
  93. package/dist/locale.d.ts +28 -0
  94. package/dist/locale.d.ts.map +1 -0
  95. package/dist/locale.js +62 -0
  96. package/dist/locale.js.map +1 -0
  97. package/dist/memory-transport.d.ts +39 -0
  98. package/dist/memory-transport.d.ts.map +1 -0
  99. package/dist/memory-transport.js +34 -0
  100. package/dist/memory-transport.js.map +1 -0
  101. package/dist/messages.d.ts +34 -0
  102. package/dist/messages.d.ts.map +1 -0
  103. package/dist/messages.js +54 -0
  104. package/dist/messages.js.map +1 -0
  105. package/dist/none.d.ts +7 -0
  106. package/dist/none.d.ts.map +1 -0
  107. package/dist/none.js +6 -0
  108. package/dist/none.js.map +1 -0
  109. package/dist/props.d.ts +89 -0
  110. package/dist/props.d.ts.map +1 -0
  111. package/dist/props.js +25 -0
  112. package/dist/props.js.map +1 -0
  113. package/dist/slots.d.ts +26 -0
  114. package/dist/slots.d.ts.map +1 -0
  115. package/dist/slots.js +70 -0
  116. package/dist/slots.js.map +1 -0
  117. package/dist/submit-result.d.ts +19 -0
  118. package/dist/submit-result.d.ts.map +1 -0
  119. package/dist/submit-result.js +58 -0
  120. package/dist/submit-result.js.map +1 -0
  121. package/dist/testing/form-internals.d.ts +59 -0
  122. package/dist/testing/form-internals.d.ts.map +1 -0
  123. package/dist/testing/form-internals.js +150 -0
  124. package/dist/testing/form-internals.js.map +1 -0
  125. package/dist/testing/index.d.ts +15 -0
  126. package/dist/testing/index.d.ts.map +1 -0
  127. package/dist/testing/index.js +14 -0
  128. package/dist/testing/index.js.map +1 -0
  129. package/dist/testing/mount-component.d.ts +105 -0
  130. package/dist/testing/mount-component.d.ts.map +1 -0
  131. package/dist/testing/mount-component.js +270 -0
  132. package/dist/testing/mount-component.js.map +1 -0
  133. package/dist/testing/visitor.d.ts +23 -0
  134. package/dist/testing/visitor.d.ts.map +1 -0
  135. package/dist/testing/visitor.js +34 -0
  136. package/dist/testing/visitor.js.map +1 -0
  137. package/dist/theming.d.ts +42 -0
  138. package/dist/theming.d.ts.map +1 -0
  139. package/dist/theming.js +19 -0
  140. package/dist/theming.js.map +1 -0
  141. package/dist/turnstile.d.ts +60 -0
  142. package/dist/turnstile.d.ts.map +1 -0
  143. package/dist/turnstile.js +179 -0
  144. package/dist/turnstile.js.map +1 -0
  145. package/dist/use-font.d.ts +65 -0
  146. package/dist/use-font.d.ts.map +1 -0
  147. package/dist/use-font.js +145 -0
  148. package/dist/use-font.js.map +1 -0
  149. package/dist/use-locale.d.ts +46 -0
  150. package/dist/use-locale.d.ts.map +1 -0
  151. package/dist/use-locale.js +57 -0
  152. package/dist/use-locale.js.map +1 -0
  153. package/dist/use-taggor-data.d.ts +72 -0
  154. package/dist/use-taggor-data.d.ts.map +1 -0
  155. package/dist/use-taggor-data.js +179 -0
  156. package/dist/use-taggor-data.js.map +1 -0
  157. package/dist/use-track.d.ts +17 -0
  158. package/dist/use-track.d.ts.map +1 -0
  159. package/dist/use-track.js +64 -0
  160. package/dist/use-track.js.map +1 -0
  161. package/dist/value-types.d.ts +69 -0
  162. package/dist/value-types.d.ts.map +1 -0
  163. package/dist/value-types.js +15 -0
  164. package/dist/value-types.js.map +1 -0
  165. package/dist/visitor-action.d.ts +49 -0
  166. package/dist/visitor-action.d.ts.map +1 -0
  167. package/dist/visitor-action.js +77 -0
  168. package/dist/visitor-action.js.map +1 -0
  169. package/package.json +74 -1
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `extractManifest` (TAG-202): the manifest of a built component, as the builder stores it with the
3
+ * version (TAG-401). It reads the declaration the author passed to `defineTaggorComponent` from the
4
+ * evaluated entry module, adds `contractVersion` and validates the result with the contract's
5
+ * reference validator (`parseManifest`, Zod) and its JSON form (`parseManifestJson`, the 64 KB
6
+ * bound the API applies), so what the builder stores is exactly what the API and the runtime accept.
7
+ *
8
+ * The explicit declaration is the only source: nothing is inferred by analysing the author's code
9
+ * (the old prototype read props from the TypeScript of the default export, which broke on any
10
+ * unusual code and could disagree with what the runtime coerced).
11
+ *
12
+ * TAG-211: the author's `locales` (`{ default, messages }`) becomes the contract's
13
+ * `{ supported, default }`, `supported` being the catalog languages in declaration order; the
14
+ * catalogs themselves stay in the bundle (`checkMessages` reviews them).
15
+ *
16
+ * TAG-213: `assets` (contract 1.3) is the builder's, never the author's: a declared one is
17
+ * dropped, and the builder passes the files it resolved as `options.assets`.
18
+ *
19
+ * Build-time only (it pulls Zod): never import this from code that ships to the browser.
20
+ */
21
+ import { type ManifestParseResult } from "@taggor/contract";
22
+ /** What an author's `locales` must look like (shared with `checkMessages`). */
23
+ export declare const LOCALES_SHAPE_MESSAGE = "locales must be { default, messages }, with one message catalog per language tag";
24
+ /** What the builder adds to the author's declaration (TAG-213). */
25
+ export interface ExtractOptions {
26
+ /**
27
+ * The manifest's `assets`: the files the bundle imports, keyed by the SHA-256 of their bytes,
28
+ * `{ type, size }` each (contract 1.3). Absent: the manifest has no `assets`.
29
+ */
30
+ readonly assets?: unknown;
31
+ }
32
+ /**
33
+ * Extracts and validates the manifest of a component.
34
+ *
35
+ * Inputs: the evaluated entry module of a component (its namespace object, whose `default` export is
36
+ * the `defineTaggorComponent` result) or the definition itself. The entry is the customer's code and is
37
+ * treated as untrusted data: only its declaration is read, never called.
38
+ * Output: `{ ok: true, manifest }` with the validated manifest (contract v1, `contractVersion` set
39
+ * to the newest this contract implements; `locales` as `{ supported, default }`), or
40
+ * `{ ok: false, issues }` with every problem and its
41
+ * path (`props.rate.default`); an entry without a definition, or one whose declaration cannot be
42
+ * read, is one issue at the empty path, and `locales` without a `messages` object one issue at
43
+ * `locales`. `options.assets` (from the builder) becomes `assets` and is validated with the rest;
44
+ * an `assets` in the author's declaration is ignored, whatever it holds. Errors: never throws.
45
+ * Side effects: none.
46
+ */
47
+ export declare function extractManifest(entry: unknown, options?: ExtractOptions): ManifestParseResult;
48
+ //# sourceMappingURL=extract-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-manifest.d.ts","sourceRoot":"","sources":["../../src/build/extract-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAQ1B,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB,qFACkD,CAAC;AAerF,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,mBAAmB,CAyBjG"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * `extractManifest` (TAG-202): the manifest of a built component, as the builder stores it with the
3
+ * version (TAG-401). It reads the declaration the author passed to `defineTaggorComponent` from the
4
+ * evaluated entry module, adds `contractVersion` and validates the result with the contract's
5
+ * reference validator (`parseManifest`, Zod) and its JSON form (`parseManifestJson`, the 64 KB
6
+ * bound the API applies), so what the builder stores is exactly what the API and the runtime accept.
7
+ *
8
+ * The explicit declaration is the only source: nothing is inferred by analysing the author's code
9
+ * (the old prototype read props from the TypeScript of the default export, which broke on any
10
+ * unusual code and could disagree with what the runtime coerced).
11
+ *
12
+ * TAG-211: the author's `locales` (`{ default, messages }`) becomes the contract's
13
+ * `{ supported, default }`, `supported` being the catalog languages in declaration order; the
14
+ * catalogs themselves stay in the bundle (`checkMessages` reviews them).
15
+ *
16
+ * TAG-213: `assets` (contract 1.3) is the builder's, never the author's: a declared one is
17
+ * dropped, and the builder passes the files it resolved as `options.assets`.
18
+ *
19
+ * Build-time only (it pulls Zod): never import this from code that ships to the browser.
20
+ */
21
+ import { CONTRACT_VERSION, parseManifest, parseManifestJson, } from "@taggor/contract";
22
+ import { findDefinition } from "./find-definition.js";
23
+ function failure(message) {
24
+ return { ok: false, issues: [{ path: "", message }] };
25
+ }
26
+ /** What an author's `locales` must look like (shared with `checkMessages`). */
27
+ export const LOCALES_SHAPE_MESSAGE = "locales must be { default, messages }, with one message catalog per language tag";
28
+ /**
29
+ * The contract's `locales` from the author's: `supported` lists the keys of `messages`, so the
30
+ * schema then checks the tags and `default`. `undefined` when it is not `{ messages: {…} }`.
31
+ */
32
+ function contractLocales(locales) {
33
+ const messages = typeof locales === "object" && locales !== null
34
+ ? locales.messages
35
+ : undefined;
36
+ if (typeof messages !== "object" || messages === null)
37
+ return undefined;
38
+ return { supported: Object.keys(messages), default: locales.default };
39
+ }
40
+ /**
41
+ * Extracts and validates the manifest of a component.
42
+ *
43
+ * Inputs: the evaluated entry module of a component (its namespace object, whose `default` export is
44
+ * the `defineTaggorComponent` result) or the definition itself. The entry is the customer's code and is
45
+ * treated as untrusted data: only its declaration is read, never called.
46
+ * Output: `{ ok: true, manifest }` with the validated manifest (contract v1, `contractVersion` set
47
+ * to the newest this contract implements; `locales` as `{ supported, default }`), or
48
+ * `{ ok: false, issues }` with every problem and its
49
+ * path (`props.rate.default`); an entry without a definition, or one whose declaration cannot be
50
+ * read, is one issue at the empty path, and `locales` without a `messages` object one issue at
51
+ * `locales`. `options.assets` (from the builder) becomes `assets` and is validated with the rest;
52
+ * an `assets` in the author's declaration is ignored, whatever it holds. Errors: never throws.
53
+ * Side effects: none.
54
+ */
55
+ export function extractManifest(entry, options = {}) {
56
+ try {
57
+ const definition = findDefinition(entry);
58
+ if (definition === undefined) {
59
+ return failure("the entry must export a component made with defineTaggorComponent as its default export");
60
+ }
61
+ const draft = { ...definition.manifest };
62
+ // Only the builder knows which files the bundle imports; the author cannot declare them.
63
+ delete draft["assets"];
64
+ if (options.assets !== undefined)
65
+ draft["assets"] = options.assets;
66
+ if (draft["locales"] !== undefined) {
67
+ draft["locales"] = contractLocales(draft["locales"]);
68
+ if (draft["locales"] === undefined) {
69
+ return { ok: false, issues: [{ path: "locales", message: LOCALES_SHAPE_MESSAGE }] };
70
+ }
71
+ }
72
+ const parsed = parseManifest({ contractVersion: CONTRACT_VERSION, ...draft });
73
+ // Round trip through JSON: the stored manifest is JSON, and the API reads it with this bound.
74
+ return parsed.ok ? parseManifestJson(JSON.stringify(parsed.manifest)) : parsed;
75
+ }
76
+ catch {
77
+ // A hostile or broken entry (throwing getter, proxy) must not crash the build worker.
78
+ return failure("the component declaration could not be read as plain data");
79
+ }
80
+ }
81
+ //# sourceMappingURL=extract-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-manifest.js","sourceRoot":"","sources":["../../src/build/extract-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GAElB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,SAAS,OAAO,CAAC,OAAe;IAC9B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACxD,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,MAAM,qBAAqB,GAChC,kFAAkF,CAAC;AAErF;;;GAGG;AACH,SAAS,eAAe,CAAC,OAAgB;IACvC,MAAM,QAAQ,GACZ,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAC7C,CAAC,CAAE,OAAkC,CAAC,QAAQ;QAC9C,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACxE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAG,OAAiC,CAAC,OAAO,EAAE,CAAC;AACnG,CAAC;AAWD;;;;;;;;;;;;;;GA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extraction: most texts and most UTF-16 units of all of them together. */
2
+ export interface StylesBudget {
3
+ readonly maxCount: number;
4
+ readonly maxChars: number;
5
+ }
6
+ /** What `extractStyles` found. */
7
+ export type StylesExtraction = {
8
+ readonly ok: true;
9
+ readonly styles: readonly string[];
10
+ } | {
11
+ readonly ok: false;
12
+ readonly problem: "too-large";
13
+ /** How many texts there are and their total length, past the budget. */
14
+ readonly count: number;
15
+ readonly chars: number;
16
+ } | {
17
+ readonly ok: false;
18
+ readonly problem: "not-text";
19
+ /** Index of the first entry that is not a string. */
20
+ readonly index: number;
21
+ } | {
22
+ readonly ok: false;
23
+ readonly problem: "unreadable";
24
+ };
25
+ /**
26
+ * Extracts the styles of a component, within a budget.
27
+ *
28
+ * Inputs: the evaluated entry module (or the definition itself) and the budget. Output:
29
+ * `{ ok: true, styles }` with a copy of the definition's texts (empty when the entry has no
30
+ * definition or no styles: `extractManifest` reports the missing definition), `too-large` with
31
+ * the count and total length when either is over the budget, `not-text` with the index of the
32
+ * first entry that is not a string, or `unreadable` when reading them threw (a hostile getter or
33
+ * proxy). Errors: never throws. Side effects: reads the definition's `styles`.
34
+ */
35
+ export declare function extractStyles(entry: unknown, budget: StylesBudget): StylesExtraction;
36
+ //# sourceMappingURL=extract-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-styles.d.ts","sourceRoot":"","sources":["../../src/build/extract-styles.ts"],"names":[],"mappings":"AAiBA,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,kCAAkC;AAClC,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACzD;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC;AAE3D;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,gBAAgB,CAiBpF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `extractStyles` (TAG-424): the CSS texts a component passes to `defineTaggorComponent({ styles })`, read
3
+ * from the evaluated entry module so the builder can check them like the component's `.css` files
4
+ * (`checkStyleReferences`, TAG-423). The texts only exist once the module runs (`styles` may be a
5
+ * function of the theme), so they leave the extraction process next to the manifest.
6
+ *
7
+ * The result is plain JSON data and bounded: past the caller's count or character budget only
8
+ * the totals come back, never the texts, so the builder can say `SOURCE_TOO_LARGE` instead of
9
+ * killing a process that printed too much. A text that is not a string (untyped code) is named
10
+ * by its index: the runtime refuses such a definition, so the builder fails it too.
11
+ *
12
+ * Build-time only, like `extractManifest`. The entry is untrusted: a hostile module shares the
13
+ * realm with this code and can forge the answer, so the builder treats it as untrusted text and
14
+ * the check it feeds is a quality gate, not a security barrier.
15
+ */
16
+ import { findDefinition } from "./find-definition.js";
17
+ /**
18
+ * Extracts the styles of a component, within a budget.
19
+ *
20
+ * Inputs: the evaluated entry module (or the definition itself) and the budget. Output:
21
+ * `{ ok: true, styles }` with a copy of the definition's texts (empty when the entry has no
22
+ * definition or no styles: `extractManifest` reports the missing definition), `too-large` with
23
+ * the count and total length when either is over the budget, `not-text` with the index of the
24
+ * first entry that is not a string, or `unreadable` when reading them threw (a hostile getter or
25
+ * proxy). Errors: never throws. Side effects: reads the definition's `styles`.
26
+ */
27
+ export function extractStyles(entry, budget) {
28
+ try {
29
+ const styles = findDefinition(entry)?.styles ?? [];
30
+ if (!Array.isArray(styles))
31
+ return { ok: false, problem: "unreadable" };
32
+ let chars = 0;
33
+ for (let index = 0; index < styles.length; index += 1) {
34
+ const text = styles[index];
35
+ if (typeof text !== "string")
36
+ return { ok: false, problem: "not-text", index };
37
+ chars += text.length;
38
+ }
39
+ if (styles.length > budget.maxCount || chars > budget.maxChars) {
40
+ return { ok: false, problem: "too-large", count: styles.length, chars };
41
+ }
42
+ return { ok: true, styles: [...styles] };
43
+ }
44
+ catch {
45
+ return { ok: false, problem: "unreadable" };
46
+ }
47
+ }
48
+ //# sourceMappingURL=extract-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-styles.js","sourceRoot":"","sources":["../../src/build/extract-styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA0BtD;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,MAAoB;IAChE,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;QAC5D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QACxE,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,GAAY,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;YAC/E,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC/D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAC1E,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,GAAI,MAAmB,CAAC,EAAE,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAC9C,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Where the builder finds a component's definition in its evaluated entry module (TAG-202; shared by
3
+ * `extractManifest` and, since TAG-211, `checkMessages`).
4
+ */
5
+ import { type ComponentDefinition } from "../define-component.js";
6
+ /**
7
+ * The definition in an entry: the value itself, or the `default` export of a module namespace.
8
+ *
9
+ * Inputs: any value (the customer's module, untrusted). Output: the definition, or `undefined`.
10
+ * Errors: a throwing getter or proxy trap propagates; callers wrap the call in `try`. Side
11
+ * effects: reads `default` and the definition's brand.
12
+ */
13
+ export declare function findDefinition(entry: unknown): ComponentDefinition | undefined;
14
+ //# sourceMappingURL=find-definition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-definition.d.ts","sourceRoot":"","sources":["../../src/build/find-definition.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEzF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,GAAG,SAAS,CAO9E"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Where the builder finds a component's definition in its evaluated entry module (TAG-202; shared by
3
+ * `extractManifest` and, since TAG-211, `checkMessages`).
4
+ */
5
+ import { isComponentDefinition } from "../define-component.js";
6
+ /**
7
+ * The definition in an entry: the value itself, or the `default` export of a module namespace.
8
+ *
9
+ * Inputs: any value (the customer's module, untrusted). Output: the definition, or `undefined`.
10
+ * Errors: a throwing getter or proxy trap propagates; callers wrap the call in `try`. Side
11
+ * effects: reads `default` and the definition's brand.
12
+ */
13
+ export function findDefinition(entry) {
14
+ if (isComponentDefinition(entry))
15
+ return entry;
16
+ if (typeof entry === "object" && entry !== null && Object.hasOwn(entry, "default")) {
17
+ const exported = entry.default;
18
+ if (isComponentDefinition(exported))
19
+ return exported;
20
+ }
21
+ return undefined;
22
+ }
23
+ //# sourceMappingURL=find-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-definition.js","sourceRoot":"","sources":["../../src/build/find-definition.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,qBAAqB,EAA4B,MAAM,wBAAwB,CAAC;AAEzF;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,qBAAqB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;QACnF,MAAM,QAAQ,GAAI,KAA8B,CAAC,OAAO,CAAC;QACzD,IAAI,qBAAqB,CAAC,QAAQ,CAAC;YAAE,OAAO,QAAQ,CAAC;IACvD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@taggor/component/build` (TAG-202): helpers that run in the builder and in the CLI at build time,
3
+ * never in a visitor's browser. They may import Zod through `@taggor/contract`. TAG-211 added
4
+ * `checkMessages`, the review of the component's message catalogs (missing keys warn); TAG-424
5
+ * `extractStyles`, the `defineTaggorComponent` styles the builder checks like the component's CSS files.
6
+ */
7
+ export { MESSAGE_CHECK_MAX_FINDINGS, checkMessages, type MessageFinding, type MessageFindingCode, } from "./check-messages.js";
8
+ export { extractManifest, type ExtractOptions } from "./extract-manifest.js";
9
+ export { extractStyles, type StylesBudget, type StylesExtraction } from "./extract-styles.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,0BAA0B,EAC1B,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@taggor/component/build` (TAG-202): helpers that run in the builder and in the CLI at build time,
3
+ * never in a visitor's browser. They may import Zod through `@taggor/contract`. TAG-211 added
4
+ * `checkMessages`, the review of the component's message catalogs (missing keys warn); TAG-424
5
+ * `extractStyles`, the `defineTaggorComponent` styles the builder checks like the component's CSS files.
6
+ */
7
+ export { MESSAGE_CHECK_MAX_FINDINGS, checkMessages, } from "./check-messages.js";
8
+ export { extractManifest } from "./extract-manifest.js";
9
+ export { extractStyles } from "./extract-styles.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,0BAA0B,EAC1B,aAAa,GAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAuB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAA4C,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The visitor's consent (TAG-212): `useConsent` keeps whether the visitor ticked the consent box
3
+ * of a component that collects personal data (`data.personal` in the manifest) and builds the proof
4
+ * that goes with each submission; `<Consent>` is the accessible checkbox that shows the default
5
+ * text, "Li e aceito a política de privacidade de <site>." or "I have read and accept the privacy
6
+ * policy of <site>.", with the link from the prop `data.privacyPolicyUrl` names.
7
+ *
8
+ * The proof is `{ given: true, text_hash, locale }` (the contract's `ConsentProof`): `text_hash`
9
+ * is the SHA-256, in lowercase hex, of the label exactly as shown, a line feed and the policy URL
10
+ * (`packages/contract/SPEC.md` §5), so the controller can tell which text was accepted. The box
11
+ * starts unticked and only the visitor ticks it (LGPD: consent is an affirmative act). Nothing is
12
+ * stored: no cookie, no storage, no identifier (golden rule 6). Unused, the module stays out of a
13
+ * component's bundle (`sideEffects: false`, `bundle.test.ts`).
14
+ *
15
+ * TAG-237: "only the visitor ticks it" is enforced at run time too. `setGiven(true)` is recorded
16
+ * only synchronously inside a trusted visitor action in the component's shadow root (a click, a key,
17
+ * or the `change`, `input` or `submit` one of them fires; `visitor-action.ts`); anywhere else (an
18
+ * effect, a timer, `el.click()`, `dispatchEvent`) it is refused, with a warning in debug mode.
19
+ * `setGiven(false)` is always recorded: withdrawing consent needs no proof of anything.
20
+ */
21
+ import { type VNode } from "preact";
22
+ import type { ConsentProof } from "@taggor/contract";
23
+ import type { DataAnchor } from "./data-declaration.js";
24
+ import { type MessageLocale } from "./data-errors.js";
25
+ /** The consent label in three pieces: the text before the link, the link's text, the rest. */
26
+ export type ConsentLabel = readonly [before: string, link: string, after: string];
27
+ /**
28
+ * The default consent label of a language for a site.
29
+ *
30
+ * Inputs: the language and the site's name (the page's host name; empty leaves it out). Output:
31
+ * the label in three pieces, the middle one being the link's text; joined, they are the text the
32
+ * visitor reads. Errors: none. Side effects: none.
33
+ */
34
+ export declare function consentLabel(locale: MessageLocale, site: string): ConsentLabel;
35
+ /**
36
+ * The `text_hash` of a consent: SHA-256 of the UTF-8 of `text`, a line feed and `policyUrl` (empty
37
+ * when absent), in lowercase hex.
38
+ *
39
+ * Inputs: the label as the visitor read it and the policy URL. Output: a promise of the 64-character
40
+ * hash, or of `undefined` where the browser has no `crypto.subtle` (pages outside a secure context,
41
+ * plain `http:`). Errors: never rejects. Side effects: none.
42
+ */
43
+ export declare function consentTextHash(text: string, policyUrl: string | undefined): Promise<string | undefined>;
44
+ /** What `useConsent` returns; give it to `<Consent>` and its `proof` to `submit`. */
45
+ export interface ConsentState {
46
+ /** Whether the visitor ticked the box. Starts false. */
47
+ readonly given: boolean;
48
+ /**
49
+ * Records the visitor's choice (`<Consent>` calls it; a custom checkbox may too, from its
50
+ * `onChange` or `onClick`). `true` is recorded only when called synchronously inside a trusted
51
+ * visitor action in the component (TAG-237); anywhere else it changes nothing (debug mode warns).
52
+ */
53
+ readonly setGiven: (given: boolean) => void;
54
+ /** The language the label is shown in (pt-BR or en: the `locale` attribute, then `lang`; TAG-230). */
55
+ readonly locale: MessageLocale;
56
+ /** The label to show, in three pieces (the middle one is the link to the policy). */
57
+ readonly label: ConsentLabel;
58
+ /** The privacy policy's address (an `http(s)` URL), or undefined when the site has none set. */
59
+ readonly policyUrl: string | undefined;
60
+ /**
61
+ * The proof for `submit(values, { consent: proof })`: set once the box is ticked, the label
62
+ * hashed and the site has a policy URL (consent to a policy nobody can read is not informed),
63
+ * undefined otherwise (a submission to a personal component then fails with
64
+ * `consent_required` without sending anything). Frozen; only this very object counts: a copy or a
65
+ * proof written by hand is refused by `submit` (TAG-237).
66
+ */
67
+ readonly proof: ConsentProof | undefined;
68
+ }
69
+ /**
70
+ * Keeps the visitor's consent for a component that collects personal data.
71
+ *
72
+ * Inputs: the render context (`render`'s second argument) and the component's props (`render`'s first
73
+ * argument), from which the value of the prop named by `data.privacyPolicyUrl` is read. Output: a
74
+ * `ConsentState`. Errors: none; without a policy URL the label has no link and there is never
75
+ * a proof (security review of TAG-212), and without `crypto.subtle` there is never a proof (both
76
+ * logged in debug mode only); `setGiven(true)` outside a visitor's action is refused (TAG-237;
77
+ * logged in debug mode). Side effects: hashes the label once per label and URL, after render;
78
+ * at the first render, starts recording the visitor's actions in the host's shadow root until the
79
+ * host's signal aborts (`watchVisitorActions`); records each proof it builds as issued
80
+ * (`issued-proofs.ts`, in memory); writes nothing anywhere.
81
+ */
82
+ export declare function useConsent<D>(context: DataAnchor<D>, props: object): ConsentState;
83
+ /** Props of `<Consent>`. */
84
+ export interface ConsentProps {
85
+ /** The state from `useConsent`. */
86
+ readonly consent: ConsentState;
87
+ }
88
+ /**
89
+ * The consent checkbox: a native, required checkbox inside its `<label>`, so it is reachable with
90
+ * Tab, toggled with Space and named by its text; the policy link opens in a new tab.
91
+ *
92
+ * Inputs: `{ consent }`. Output: the `<label>` element. Errors: none. Side effects: ticking or
93
+ * unticking calls `consent.setGiven`. A tick it refuses (a script's `el.click()`, TAG-237) leaves
94
+ * the native box ticked until the next render puts back the recorded state; there is no proof
95
+ * meanwhile, so nothing personal is sent (`consent_required`). Undoing it on the spot would cost
96
+ * bytes in every consent component and protect nothing: only the component's own code clicks that way,
97
+ * and that code could draw any box it likes.
98
+ */
99
+ export declare function Consent({ consent }: ConsentProps): VNode;
100
+ //# sourceMappingURL=consent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAK,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAiB,KAAK,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+1,147 @@
1
+ /**
2
+ * The visitor's consent (TAG-212): `useConsent` keeps whether the visitor ticked the consent box
3
+ * of a component that collects personal data (`data.personal` in the manifest) and builds the proof
4
+ * that goes with each submission; `<Consent>` is the accessible checkbox that shows the default
5
+ * text, "Li e aceito a política de privacidade de <site>." or "I have read and accept the privacy
6
+ * policy of <site>.", with the link from the prop `data.privacyPolicyUrl` names.
7
+ *
8
+ * The proof is `{ given: true, text_hash, locale }` (the contract's `ConsentProof`): `text_hash`
9
+ * is the SHA-256, in lowercase hex, of the label exactly as shown, a line feed and the policy URL
10
+ * (`packages/contract/SPEC.md` §5), so the controller can tell which text was accepted. The box
11
+ * starts unticked and only the visitor ticks it (LGPD: consent is an affirmative act). Nothing is
12
+ * stored: no cookie, no storage, no identifier (golden rule 6). Unused, the module stays out of a
13
+ * component's bundle (`sideEffects: false`, `bundle.test.ts`).
14
+ *
15
+ * TAG-237: "only the visitor ticks it" is enforced at run time too. `setGiven(true)` is recorded
16
+ * only synchronously inside a trusted visitor action in the component's shadow root (a click, a key,
17
+ * or the `change`, `input` or `submit` one of them fires; `visitor-action.ts`); anywhere else (an
18
+ * effect, a timer, `el.click()`, `dispatchEvent`) it is refused, with a warning in debug mode.
19
+ * `setGiven(false)` is always recorded: withdrawing consent needs no proof of anything.
20
+ */
21
+ import { h } from "preact";
22
+ import { useContext, useEffect, useState } from "preact/hooks";
23
+ import { messageLocale } from "./data-errors.js";
24
+ import { debugWarn } from "./debug.js";
25
+ import { HostContext } from "./host.js";
26
+ import { issuedProofs } from "./issued-proofs.js";
27
+ import { watchVisitorActions } from "./visitor-action.js";
28
+ /** The default label of each language, before the site's name is added. */
29
+ const LABELS = {
30
+ "pt-BR": ["Li e aceito a ", "política de privacidade", " de "],
31
+ en: ["I have read and accept the ", "privacy policy", " of "],
32
+ };
33
+ /** Only a web link may become the policy's `href` (never `javascript:`, even from untyped code). */
34
+ const WEB_URL = /^https?:\/\//i;
35
+ /**
36
+ * The default consent label of a language for a site.
37
+ *
38
+ * Inputs: the language and the site's name (the page's host name; empty leaves it out). Output:
39
+ * the label in three pieces, the middle one being the link's text; joined, they are the text the
40
+ * visitor reads. Errors: none. Side effects: none.
41
+ */
42
+ export function consentLabel(locale, site) {
43
+ const [before, link, of] = LABELS[locale];
44
+ return [before, link, site === "" ? "." : `${of}${site}.`];
45
+ }
46
+ /**
47
+ * The `text_hash` of a consent: SHA-256 of the UTF-8 of `text`, a line feed and `policyUrl` (empty
48
+ * when absent), in lowercase hex.
49
+ *
50
+ * Inputs: the label as the visitor read it and the policy URL. Output: a promise of the 64-character
51
+ * hash, or of `undefined` where the browser has no `crypto.subtle` (pages outside a secure context,
52
+ * plain `http:`). Errors: never rejects. Side effects: none.
53
+ */
54
+ export async function consentTextHash(text, policyUrl) {
55
+ try {
56
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${text}\n${policyUrl ?? ""}`));
57
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
58
+ }
59
+ catch {
60
+ return undefined;
61
+ }
62
+ }
63
+ /**
64
+ * Keeps the visitor's consent for a component that collects personal data.
65
+ *
66
+ * Inputs: the render context (`render`'s second argument) and the component's props (`render`'s first
67
+ * argument), from which the value of the prop named by `data.privacyPolicyUrl` is read. Output: a
68
+ * `ConsentState`. Errors: none; without a policy URL the label has no link and there is never
69
+ * a proof (security review of TAG-212), and without `crypto.subtle` there is never a proof (both
70
+ * logged in debug mode only); `setGiven(true)` outside a visitor's action is refused (TAG-237;
71
+ * logged in debug mode). Side effects: hashes the label once per label and URL, after render;
72
+ * at the first render, starts recording the visitor's actions in the host's shadow root until the
73
+ * host's signal aborts (`watchVisitorActions`); records each proof it builds as issued
74
+ * (`issued-proofs.ts`, in memory); writes nothing anywhere.
75
+ */
76
+ export function useConsent(context, props) {
77
+ const host = useContext(HostContext);
78
+ const [given, record] = useState(false);
79
+ // At the first render, not in an effect: a click right after the first paint is already seen.
80
+ const [inVisitorAction] = useState(() => watchVisitorActions(host?.shadowRoot, host?.signal));
81
+ const [hashed, setHashed] = useState(undefined);
82
+ const locale = messageLocale(host?.element);
83
+ // `location` is null in a document without a browsing context, whatever the DOM types say.
84
+ const site = host?.element.ownerDocument.location?.hostname ?? "";
85
+ const label = consentLabel(locale, site);
86
+ const name = context.manifest.data
87
+ ?.privacyPolicyUrl;
88
+ const value = typeof name === "string" && Object.hasOwn(props, name)
89
+ ? props[name]
90
+ : undefined;
91
+ const policyUrl = typeof value === "string" && WEB_URL.test(value) ? value : undefined;
92
+ const key = `${label.join("")}\n${policyUrl ?? ""}`;
93
+ useEffect(() => {
94
+ if (policyUrl === undefined)
95
+ debugWarn(host, "consent label without a privacy policy link: no proof, nothing is sent");
96
+ let live = true;
97
+ void consentTextHash(label.join(""), policyUrl).then((hash) => {
98
+ if (hash === undefined)
99
+ debugWarn(host, "consent cannot be proven: no crypto.subtle (https)");
100
+ else if (live)
101
+ setHashed({ key, hash });
102
+ });
103
+ return () => {
104
+ live = false;
105
+ };
106
+ }, [key]);
107
+ // The hash must be of the label shown now: a language or URL change waits for its own hash.
108
+ // No policy URL, no proof: the visitor could not read what they would be accepting.
109
+ // Frozen and recorded as issued: `submit` sends only a proof built here (TAG-237).
110
+ const proof = given && policyUrl !== undefined && hashed?.key === key
111
+ ? Object.freeze({ given: true, text_hash: hashed.hash, locale })
112
+ : undefined;
113
+ if (proof)
114
+ issuedProofs.add(proof);
115
+ const setGiven = (value) => {
116
+ if (!value || inVisitorAction())
117
+ record(value);
118
+ else
119
+ debugWarn(host, "consent refused: not a visitor's action");
120
+ };
121
+ return { given, setGiven, locale, label, policyUrl, proof };
122
+ }
123
+ /**
124
+ * The consent checkbox: a native, required checkbox inside its `<label>`, so it is reachable with
125
+ * Tab, toggled with Space and named by its text; the policy link opens in a new tab.
126
+ *
127
+ * Inputs: `{ consent }`. Output: the `<label>` element. Errors: none. Side effects: ticking or
128
+ * unticking calls `consent.setGiven`. A tick it refuses (a script's `el.click()`, TAG-237) leaves
129
+ * the native box ticked until the next render puts back the recorded state; there is no proof
130
+ * meanwhile, so nothing personal is sent (`consent_required`). Undoing it on the spot would cost
131
+ * bytes in every consent component and protect nothing: only the component's own code clicks that way,
132
+ * and that code could draw any box it likes.
133
+ */
134
+ export function Consent({ consent }) {
135
+ const [before, link, after] = consent.label;
136
+ return h("label", null, h("input", {
137
+ type: "checkbox",
138
+ required: true,
139
+ checked: consent.given,
140
+ onChange: (event) => {
141
+ consent.setGiven(event.currentTarget.checked);
142
+ },
143
+ }), before, consent.policyUrl === undefined
144
+ ? link
145
+ : h("a", { href: consent.policyUrl, target: "_blank", rel: "noopener noreferrer" }, link), after);
146
+ }
147
+ //# sourceMappingURL=consent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.js","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,CAAC,EAAc,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAI/D,OAAO,EAAE,aAAa,EAAsB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK1D,2EAA2E;AAC3E,MAAM,MAAM,GAAkD;IAC5D,OAAO,EAAE,CAAC,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,CAAC;IAC9D,EAAE,EAAE,CAAC,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,CAAC;CAC9D,CAAC;AAEF,oGAAoG;AACpG,MAAM,OAAO,GAAG,eAAe,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB,EAAE,I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ACtE,CAAC;KACF,CAAC,EACF,MAAM,EACN,OAAO,CAAC,SAAS,KAAK,SAAS;QAC7B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,qBAAqB,EAAE,EAAE,IAAI,CAAC,EAC3F,KAAK,CACN,CAAC;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { DataTransport } from "./data-transport.js";
2
+ import { type Turnstile } from "./turnstile.js";
3
+ /** What `createDataTransport` needs. */
4
+ export interface DataClientOptions {
5
+ /** Origin of the edge, e.g. `https://cdn.example.com`. */
6
+ readonly baseUrl: string;
7
+ /** The public key of the site. */
8
+ readonly siteKey: string;
9
+ /** The site's Turnstile public key; without one no token is attached (the edge decides). */
10
+ readonly turnstileSiteKey?: string | undefined;
11
+ /** The page's CSP nonce for the Turnstile script (TAG-310; see `createTurnstile`). */
12
+ readonly nonce?: string | undefined;
13
+ /** The loader's Trusted Types script URL maker (TAG-310; see `createTurnstile`). */
14
+ readonly scriptUrl?: ((url: string, origin: string) => unknown) | undefined;
15
+ /** Replaces the global `fetch` (tests). */
16
+ readonly fetch?: typeof fetch | undefined;
17
+ /** Replaces the Turnstile client (tests). */
18
+ readonly turnstile?: Turnstile | undefined;
19
+ /** Waits `ms` or until `signal` aborts (tests inject an instant one). */
20
+ readonly sleep?: ((ms: number, signal?: AbortSignal) => Promise<void>) | undefined;
21
+ }
22
+ /**
23
+ * Creates the data transport of a site.
24
+ *
25
+ * Inputs: `DataClientOptions`. Output: a `DataTransport` whose `submit` attaches a fresh
26
+ * Turnstile token to each attempt (the first attempt keeps a token the caller put in the body),
27
+ * answers `captcha_failed` without sending when no token could be had, and retries a
28
+ * `network_error` after 0.5 s and 1.5 s with the same body, stopping at once when `signal`
29
+ * aborts; `track` is the edge transport's. Errors: none, ever. Side effects: network requests
30
+ * (the edge's, and Turnstile's through its script), a Turnstile host `<div>` while a challenge
31
+ * runs.
32
+ */
33
+ export declare function createDataTransport(options: DataClientOptions): DataTransport;
34
+ //# sourceMappingURL=data-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-client.d.ts","sourceRoot":"","sources":["../src/data-client.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAWjE,wCAAwC;AACxC,MAAM,WAAW,iBAAiB;IAChC,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kCAAkC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4FAA4F;IAC5F,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,sFAAsF;IACtF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,oFAAoF;IACpF,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5E,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,CAAC;IAC1C,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC3C,yEAAyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CACpF;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa,CA6C7E"}