@taggor/component 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -2
  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 +71 -3
@@ -0,0 +1,78 @@
1
+ import { createEdgeTransport } from "./edge-transport.js";
2
+ import { createTurnstile } from "./turnstile.js";
3
+ /** Waits before the 2nd and the 3rd attempt: a submission is tried at most three times. */
4
+ const RETRY_DELAYS_MS = Object.freeze([500, 1500]);
5
+ const NO_TOKEN = Object.freeze({
6
+ ok: false,
7
+ code: "captcha_failed",
8
+ fields: Object.freeze([]),
9
+ });
10
+ /** Waits, ending early when the signal aborts. */
11
+ function sleepFor(ms, signal) {
12
+ return new Promise((resolve) => {
13
+ const timer = setTimeout(done, ms);
14
+ function done() {
15
+ clearTimeout(timer);
16
+ signal?.removeEventListener("abort", done);
17
+ resolve();
18
+ }
19
+ signal?.addEventListener("abort", done, { once: true });
20
+ });
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 function createDataTransport(options) {
34
+ const edge = createEdgeTransport(options);
35
+ const sleep = options.sleep ?? sleepFor;
36
+ const turnstile = options.turnstile ??
37
+ (options.turnstileSiteKey === undefined
38
+ ? undefined
39
+ : createTurnstile({
40
+ siteKey: options.turnstileSiteKey,
41
+ nonce: options.nonce,
42
+ scriptUrl: options.scriptUrl,
43
+ }));
44
+ const attempt = async (collection, body, reuseToken, signal) => {
45
+ if (turnstile === undefined || (reuseToken && body.turnstile_token !== undefined)) {
46
+ return edge.submit(collection, body, signal);
47
+ }
48
+ const token = await turnstile.token(signal);
49
+ if (token === undefined)
50
+ return signal?.aborted ? networkError() : NO_TOKEN;
51
+ return edge.submit(collection, { ...body, turnstile_token: token }, signal);
52
+ };
53
+ return {
54
+ submit: async (collection, body, signal) => {
55
+ const stopped = () => signal?.aborted === true;
56
+ try {
57
+ let result = await attempt(collection, body, true, signal);
58
+ for (const delay of RETRY_DELAYS_MS) {
59
+ if (result.ok || result.code !== "network_error" || stopped())
60
+ break;
61
+ await sleep(delay, signal);
62
+ if (stopped())
63
+ break;
64
+ result = await attempt(collection, body, false, signal);
65
+ }
66
+ return result;
67
+ }
68
+ catch {
69
+ return networkError();
70
+ }
71
+ },
72
+ track: edge.track,
73
+ };
74
+ }
75
+ function networkError() {
76
+ return { ok: false, code: "network_error", fields: [] };
77
+ }
78
+ //# sourceMappingURL=data-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-client.js","sourceRoot":"","sources":["../src/data-client.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAEjE,2FAA2F;AAC3F,MAAM,eAAe,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAEtE,MAAM,QAAQ,GAAiB,MAAM,CAAC,MAAM,CAAC;IAC3C,EAAE,EAAE,KAAK;IACT,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC1B,CAAC,CAAC;AAsBH,kDAAkD;AAClD,SAAS,QAAQ,CAAC,EAAU,EAAE,MAAoB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnC,SAAS,IAAI;YACX,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3C,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA0B;IAC5D,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,Q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CAAC;oBACpC,IAAI,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,KAAK,eAAe,IAAI,OAAO,EAAE;wBAAE,MAAM;oBACrE,MAAM,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;oBAC3B,IAAI,OAAO,EAAE;wBAAE,MAAM;oBACrB,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC1D,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,YAAY,EAAE,CAAC;YACxB,CAAC;QACH,CAAC;QACD,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Type-level reading of a component's `data` declaration (TAG-203): which collections it can submit
3
+ * to and with which values, and which interactions it can track and with which props. The data
4
+ * hooks (`useTaggorData`, `useTrack`) are typed with these, so submitting to an undeclared
5
+ * collection, tracking an undeclared interaction or passing an undeclared prop is a compile error.
6
+ *
7
+ * Types only: nothing here exists at runtime.
8
+ */
9
+ import type { ComponentManifest } from "@taggor/contract";
10
+ import type { None } from "./none.js";
11
+ import type { ValueOf } from "./value-types.js";
12
+ /** The `data` map of a component, as the contract declares it (`collections` and `track`). */
13
+ export type DataDeclaration = NonNullable<ComponentManifest["data"]>;
14
+ /**
15
+ * What the data hooks need from the render context: the component's manifest, typed with its `data`
16
+ * declaration `D`. `RenderContext` is one; the hooks read `tag` and `data` at runtime.
17
+ */
18
+ export interface DataAnchor<D> {
19
+ readonly manifest: {
20
+ readonly tag: string;
21
+ readonly data?: D;
22
+ };
23
+ }
24
+ /** The `collections` map of `D`, or an empty map when it declares none. */
25
+ type CollectionsOf<D> = D extends {
26
+ readonly collections: infer C;
27
+ } ? C : None;
28
+ /** The `track` map of `D`, or an empty map when it declares none. */
29
+ type TrackEventsOf<D> = D extends {
30
+ readonly track: infer T;
31
+ } ? T : None;
32
+ /** Names of the collections declared in `D`. */
33
+ export type CollectionName<D> = keyof CollectionsOf<D> & string;
34
+ /** Names of the interactions declared in `D`'s `track`. */
35
+ export type TrackName<D> = keyof TrackEventsOf<D> & string;
36
+ /**
37
+ * The values a submission to the collection `C` of `D` carries: its `fields`, the ones in
38
+ * `required` mandatory, the others optional (the same shape `collectionDataSchema` checks).
39
+ */
40
+ export type SubmitValues<D, C extends CollectionName<D>> = CollectionsOf<D>[C] extends {
41
+ readonly fields: infer F;
42
+ } ? ValueOf<{
43
+ readonly type: "object";
44
+ readonly fields: F;
45
+ readonly required: CollectionsOf<D>[C] extends {
46
+ readonly required: infer R;
47
+ } ? R : [];
48
+ }> : never;
49
+ /** The props of an interaction that declares none: only `{}` (an empty `None` would take any). */
50
+ type NoProps = Readonly<Record<string, never>>;
51
+ /** The props of the tracked interaction `K` of `D`: every declared prop, all optional. */
52
+ export type TrackProps<D, K extends TrackName<D>> = TrackEventsOf<D>[K] extends {
53
+ readonly props: infer P;
54
+ } ? ValueOf<{
55
+ readonly type: "object";
56
+ readonly fields: P;
57
+ }> : NoProps;
58
+ export {};
59
+ //# sourceMappingURL=data-declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-declaration.d.ts","sourceRoot":"","sources":["../src/data-declaration.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,8FAA8F;AAC9F,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,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;AAClG,KAAK,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAE/C,0FAA0F;AAC1F,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;IAC9E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CACzB,GACG,OAAO,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,GACxD,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-declaration.js","sourceRoot":"","sources":["../src/data-declaration.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Friendly messages for data API errors (TAG-203), in pt-BR and en: the data API answers with a
3
+ * `code` (`packages/contract/SPEC.md` §5, "Erros") and the SDK, not the server, turns it into the
4
+ * text a visitor reads. The tables are typed against the contract's `DataErrorCode`, so a code
5
+ * added there fails the typecheck here until it has a message in both languages.
6
+ */
7
+ import type { SubmitErrorCode } from "./data-transport.js";
8
+ /** The languages the SDK has messages for. */
9
+ export type MessageLocale = "pt-BR" | "en";
10
+ /**
11
+ * Whether `code` is an error code the SDK knows (one of the data API's, or its own).
12
+ *
13
+ * Inputs: any value (e.g. the `code` of a server answer). Output: a type guard. Errors: none.
14
+ * Side effects: none.
15
+ */
16
+ export declare function isSubmitErrorCode(code: unknown): code is SubmitErrorCode;
17
+ /**
18
+ * Picks the message language for a component from the same candidates `useLocale` reads, in the
19
+ * contract's order (`localeCandidates`, TAG-230): the element's `locale` attribute, the nearest
20
+ * `lang`, `<html lang>`, the browser language. The first one in Portuguese gives pt-BR, the first
21
+ * one in English gives en, and one in neither (`fr`) is skipped; none: en.
22
+ *
23
+ * Inputs: the host element, if any (without one, only `navigator.language` counts). Output: a
24
+ * `MessageLocale`. Errors: none. Side effects: reads attributes and `navigator.language`.
25
+ */
26
+ export declare function messageLocale(element: Element | undefined): MessageLocale;
27
+ /**
28
+ * The friendly message of an error code.
29
+ *
30
+ * Inputs: a known code and a language. Output: the message. Errors: none. Side effects: none.
31
+ */
32
+ export declare function errorMessage(code: SubmitErrorCode, locale: MessageLocale): string;
33
+ //# sourceMappingURL=data-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-errors.d.ts","sourceRoot":"","sources":["../src/data-errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,8CAA8C;AAC9C,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,IAAI,CAAC;AAsC3C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,eAAe,CAExE;AAKD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,aAAa,CASzE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,CAEjF"}
@@ -0,0 +1,73 @@
1
+ import { localeCandidates } from "./locale.js";
2
+ /** One message per error code, per language. */
3
+ const MESSAGES = {
4
+ "pt-BR": {
5
+ validation_failed: "Confira os campos destacados.",
6
+ collection_not_found: "Este formulário não está disponível.",
7
+ read_not_allowed: "Estes dados não podem ser lidos.",
8
+ event_not_declared: "Esta ação não está disponível.",
9
+ origin_not_allowed: "Este formulário não está liberado neste site.",
10
+ rate_limited: "Muitas tentativas. Aguarde um pouco e tente de novo.",
11
+ captcha_failed: "Não conseguimos confirmar que você não é um robô. Tente de novo.",
12
+ payload_too_large: "O conteúdo enviado é grande demais.",
13
+ consent_required: "Aceite a política de privacidade.",
14
+ // Same words as `unavailable` on purpose (TAG-730): the visitor cannot act on a cap, and a new
15
+ // sentence would push the data module over its size ceiling.
16
+ daily_cap_reached: "O envio não está disponível agora.",
17
+ consent_unverifiable: "Este formulário não está disponível agora.",
18
+ network_error: "Não foi possível enviar. Verifique sua conexão e tente de novo.",
19
+ unavailable: "O envio não está disponível agora.",
20
+ },
21
+ en: {
22
+ validation_failed: "Please check the highlighted fields.",
23
+ collection_not_found: "This form is not available.",
24
+ read_not_allowed: "This data cannot be read.",
25
+ event_not_declared: "This action is not available.",
26
+ origin_not_allowed: "This form is not enabled on this site.",
27
+ rate_limited: "Too many attempts. Please wait a moment and try again.",
28
+ captcha_failed: "We could not confirm you are not a robot. Please try again.",
29
+ payload_too_large: "What you sent is too large.",
30
+ consent_required: "Please accept the privacy policy.",
31
+ daily_cap_reached: "Sending is not available right now.",
32
+ consent_unverifiable: "This form is not available right now.",
33
+ network_error: "Could not send. Check your connection and try again.",
34
+ unavailable: "Sending is not available right now.",
35
+ },
36
+ };
37
+ /**
38
+ * Whether `code` is an error code the SDK knows (one of the data API's, or its own).
39
+ *
40
+ * Inputs: any value (e.g. the `code` of a server answer). Output: a type guard. Errors: none.
41
+ * Side effects: none.
42
+ */
43
+ export function isSubmitErrorCode(code) {
44
+ return typeof code === "string" && Object.hasOwn(MESSAGES.en, code);
45
+ }
46
+ /** A tag in Portuguese or English: what `matchLocale` would match to `["pt-BR", "en"]`. */
47
+ const SUPPORTED = /^(pt|en)([-_]|$)/i;
48
+ /**
49
+ * Picks the message language for a component from the same candidates `useLocale` reads, in the
50
+ * contract's order (`localeCandidates`, TAG-230): the element's `locale` attribute, the nearest
51
+ * `lang`, `<html lang>`, the browser language. The first one in Portuguese gives pt-BR, the first
52
+ * one in English gives en, and one in neither (`fr`) is skipped; none: en.
53
+ *
54
+ * Inputs: the host element, if any (without one, only `navigator.language` counts). Output: a
55
+ * `MessageLocale`. Errors: none. Side effects: reads attributes and `navigator.language`.
56
+ */
57
+ export function messageLocale(element) {
58
+ // A regex for the two fixed tags instead of `resolveLocale`: same answer, and `matchLocale`
59
+ // would add ~50 B gz more to every component that submits (TAG-230 measurement, decision 29).
60
+ const tag = (element
61
+ ? localeCandidates(element)
62
+ : [typeof navigator === "undefined" ? "" : navigator.language]).find((candidate) => SUPPORTED.test(candidate));
63
+ return tag?.toLowerCase().startsWith("pt") ? "pt-BR" : "en";
64
+ }
65
+ /**
66
+ * The friendly message of an error code.
67
+ *
68
+ * Inputs: a known code and a language. Output: the message. Errors: none. Side effects: none.
69
+ */
70
+ export function errorMessage(code, locale) {
71
+ return MESSAGES[locale][code];
72
+ }
73
+ //# sourceMappingURL=data-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-errors.js","sourceRoot":"","sources":["../src/data-errors.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK/C,gDAAgD;AAChD,MAAM,QAAQ,GAA+E;IAC3F,OAAO,EAAE;QACP,iBAAiB,EAAE,+BAA+B;QAClD,oBAAoB,EAAE,sCAAsC;QAC5D,gBAAgB,EAAE,kCAAkC;QACpD,kBAAkB,EAAE,gCAAgC;QACpD,kBAAkB,EAAE,+CAA+C;QACnE,YAAY,EAAE,sDAAsD;QACpE,cAAc,EAAE,kEAAkE;QAClF,iBAAiB,EAAE,qCAAqC;QACxD,gBAAgB,EAAE,mCAAmC;QACrD,+FAA+F;QAC/F,6DAA6D;QAC7D,iBAAiB,EAAE,oCAAoC;QACvD,oBAAoB,EAAE,4CAA4C;QAClE,aAAa,EAAE,iEAAiE;QAChF,WAAW,EAAE,oCAAoC;KAClD;IACD,EAAE,EAAE;QACF,iBAAiB,EAAE,sCAAsC;QACzD,oBAAoB,EAAE,6BAA6B;QACnD,gBAAgB,EAAE,2BAA2B;QAC7C,kBAAkB,EAAE,+BAA+B;QACnD,kBAAkB,EAAE,wCAAwC;QAC5D,YAAY,EAAE,wDAAwD;QACtE,cAAc,EAAE,6DAA6D;QAC7E,iBAAiB,EAAE,6BAA6B;QAChD,gBAAgB,EAAE,mCAAmC;QACrD,iBAAiB,EAAE,qCAAqC;QACxD,oBAAoB,EAAE,uCAAuC;QAC7D,aAAa,EAAE,sDAAsD;QACrE,WAAW,EAAE,qCAAqC;KACnD;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,2FAA2F;AAC3F,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,OAA4B;IACxD,4FAA4F;IAC5F,8FAA8F;IAC9F,MAAM,GAAG,GAAG,CACV,OAAO;QACL,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC;QAC3B,CAAC,CAAC,CAAC,OAAO,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CACjE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,SAAmB,CAAC,CAAuB,CAAC;IACjF,OAAO,GAAG,EAAE,WAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAqB,EAAE,MAAqB;IACvE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The data transport (TAG-203): the port through which the data hooks reach the data API of the
3
+ * contract (`packages/contract/SPEC.md` §5). The runtime injects one per component in
4
+ * `ComponentHost.transport`: `createEdgeTransport` on a visitor's page, `createMemoryTransport` in
5
+ * tests and in `taggor dev`. The hooks never build URLs or call `fetch` themselves, so they stay
6
+ * testable without a network and the edge's routes can change behind this interface.
7
+ *
8
+ * Types only: nothing here exists at runtime.
9
+ */
10
+ import type { DataErrorCode, SubmitRequest, TrackRequest } from "@taggor/contract";
11
+ /**
12
+ * Why a submission failed: a code of the data API (`validation_failed`, `rate_limited`…) or one
13
+ * the SDK adds — `network_error` (no answer, or an answer that is not the data API's),
14
+ * `unavailable` (the component has no transport, e.g. rendered outside the runtime) and
15
+ * `consent_unverifiable` (TAG-728: the server answered `consent_required` for a reason in the site's
16
+ * setup, a `consent.*` field such as the missing privacy policy URL, which the visitor cannot fix).
17
+ */
18
+ export type SubmitErrorCode = DataErrorCode | "network_error" | "unavailable" | "consent_unverifiable";
19
+ /** A per-field problem reported by the server (`fields` of the data API error). */
20
+ export interface FieldProblem {
21
+ /** The field's path in `data` (`email`, `tags.0`). */
22
+ readonly path: string;
23
+ /** The server's message for it. */
24
+ readonly message: string;
25
+ }
26
+ /** The outcome of one submission as a transport reports it. Never a thrown error. */
27
+ export type SubmitResult = {
28
+ readonly ok: true;
29
+ } | {
30
+ readonly ok: false;
31
+ readonly code: SubmitErrorCode;
32
+ readonly fields: readonly FieldProblem[];
33
+ };
34
+ /** What kind of browser event a `track` call reports (TAG-820); `custom` when absent. */
35
+ export type TrackedEventKind = "interaction" | "custom";
36
+ /**
37
+ * What the SDK hands to `DataTransport.track`: the contract's `TrackRequest` (its `component` is
38
+ * optional here) plus what the beacon to `POST /e/` needs, so the component's bundle stays small and
39
+ * the transport (the lazy data module) decides. `kind`: a `track` call is `custom`; absent means
40
+ * `interaction`, a declared event the component emitted. `manifest`: the component's own
41
+ * declaration (the transport checks an `interaction` name against its `events` and samples with the
42
+ * contract's `shouldSendEvent` and its `eventSampleRate`). `host`: the component's host, whose
43
+ * `element` the transport gives to `window.taggor.get` to read the published version hash. Props
44
+ * never leave the page: the beacon holds only the kind, the hash and the declared name.
45
+ */
46
+ export interface TrackedEvent extends Omit<TrackRequest, "component"> {
47
+ readonly component?: string | undefined;
48
+ readonly kind?: TrackedEventKind | undefined;
49
+ readonly manifest?: unknown;
50
+ readonly host?: {
51
+ readonly element?: unknown;
52
+ } | undefined;
53
+ }
54
+ /**
55
+ * Sends data API calls for one component on one site.
56
+ *
57
+ * - `submit(collection, body, signal?)`: sends one submission (`POST /d/<siteKey>/<collection>`
58
+ * on the edge). Output: a promise of `SubmitResult` that never rejects; every failure is a
59
+ * result. `signal` (TAG-317, the mount's `ComponentHost.signal`) cancels the request when the
60
+ * component is unmounted; a cancelled submission resolves like a failed request (`network_error`).
61
+ * - `track(body)`: reports one event (an emitted declared event or a `track` call, TAG-820) to
62
+ * `POST /e/<siteKey>`, fire-and-forget, at most `EVENT_BEACON_CAP_PER_PAGE` per kind. Output:
63
+ * none. Errors: never throws. Side effects: a `keepalive` request to the edge, without
64
+ * credentials or referrer.
65
+ *
66
+ * Implementations must not write cookies, `localStorage`, `sessionStorage` or any visitor
67
+ * identifier (golden rule 6), and must send no credentials.
68
+ */
69
+ export interface DataTransport {
70
+ readonly submit: (collection: string, body: SubmitRequest, signal?: AbortSignal) => Promise<SubmitResult>;
71
+ readonly track: (body: TrackedEvent) => void;
72
+ }
73
+ //# sourceMappingURL=data-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-transport.d.ts","sourceRoot":"","sources":["../src/data-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACzB,aAAa,GAAG,eAAe,GAAG,aAAa,GAAG,sBAAsB,CAAC;AAE3E,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,qFAAqF;AACrF,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CAC1C,CAAC;AAEN,yFAAyF;AACzF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,QAAQ,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;IACnE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC;CAC5D;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,CACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CAC9C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-transport.js","sourceRoot":"","sources":["../src/data-transport.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Debug warnings of the data hooks (TAG-203): a call the SDK ignores (an undeclared interaction,
3
+ * prop or collection) is silent on a visitor's page and logged only when the runtime's debug mode
4
+ * (TAG-315) marks the host with `debug: true`.
5
+ */
6
+ import type { ComponentHost } from "./host.js";
7
+ /**
8
+ * Logs `message` with `console.warn` when the host is in debug mode.
9
+ *
10
+ * Inputs: the component's host (or `undefined` outside the runtime) and the message. Output: none.
11
+ * Errors: none. Side effects: one `console.warn` in debug mode, nothing otherwise.
12
+ */
13
+ export declare function debugWarn(host: ComponentHost | undefined, message: string): void;
14
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEhF"}
package/dist/debug.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Logs `message` with `console.warn` when the host is in debug mode.
3
+ *
4
+ * Inputs: the component's host (or `undefined` outside the runtime) and the message. Output: none.
5
+ * Errors: none. Side effects: one `console.warn` in debug mode, nothing otherwise.
6
+ */
7
+ export function debugWarn(host, message) {
8
+ if (host?.debug === true)
9
+ console.warn(`[taggor] ${message}`);
10
+ }
11
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAA+B,EAAE,OAAe;IACxE,IAAI,IAAI,EAAE,KAAK,KAAK,IAAI;QAAE,OAAO,CAAC,IAAI,CAAC,YAAY,OAAO,EAAE,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * `defineTaggorComponent` (TAG-202): turns an author's declaration into a `ComponentDefinition`, the inert
3
+ * object the builder reads the manifest from (`extractManifest`, `@taggor/component/build`) and the
4
+ * runtime mounts (`createComponentElement`, TAG-302).
5
+ *
6
+ * Nothing happens at import or at definition time (golden rule 2): no `customElements.define`, no
7
+ * global, no DOM access, no validation that could throw on a visitor's page. Registering the tag is
8
+ * the runtime's job (ADR 0018); validating the manifest is the builder's (`extractManifest`).
9
+ * TAG-203: the `data` declaration is typed (`D`), and `render`'s context carries the frozen
10
+ * manifest, which the data hooks read and are typed by. TAG-206: `parts`, `cssVars` and `tag` are
11
+ * typed too (`R`, `C`, `T`): `styles` may be a function of the component's `Theme` (`cssVar`, `part`),
12
+ * `render`'s context carries the same helpers, and the literal tag types the DOM event names
13
+ * (`ComponentEventMap`). TAG-211: `locales` (`{ default, messages }`, typed `M`) declares the message
14
+ * catalogs; it stays in the frozen manifest at no cost to `defineTaggorComponent`, `useLocale` reads it
15
+ * from `render`'s context, and the builder's `extractManifest` turns it into the contract's
16
+ * `{ supported, default }`. TAG-232: `ComponentPropsOf` and `ComponentEventsOf` read the manifest's
17
+ * `props` and `events`, so a component with `locales` keeps its typed props and events.
18
+ */
19
+ import { type ComponentChildren, type FunctionComponent } from "preact";
20
+ import type { ComponentManifest } from "@taggor/contract";
21
+ import type { DataDeclaration } from "./data-declaration.js";
22
+ import type { Emit, EventsDeclaration } from "./events.js";
23
+ import { type ComponentHost } from "./host.js";
24
+ import type { MessagesDeclaration } from "./messages.js";
25
+ import type { None } from "./none.js";
26
+ import type { PropsDeclaration, PropsOf } from "./props.js";
27
+ import { type CssVarsDeclaration, type PartsDeclaration, type Theme } from "./theming.js";
28
+ import type { LocalesDraft } from "./use-locale.js";
29
+ /** Brand of every `ComponentDefinition`; `extractManifest` and the runtime check it. */
30
+ export declare const COMPONENT_KIND = "taggor.component";
31
+ /** The `slots` map of a component: slot name (kebab-case, `default` for the unnamed slot) → info. */
32
+ export type SlotsDeclaration = NonNullable<ComponentManifest["slots"]>;
33
+ /**
34
+ * What `render` receives besides the props: the typed `emit`, the manifest and the theming
35
+ * helpers (`cssVar`, `part`, TAG-206) of the component's `cssVars` and `parts`.
36
+ */
37
+ export interface RenderContext<E, D = DataDeclaration, R = PartsDeclaration, C = CssVarsDeclaration, M = MessagesDeclaration> extends Theme<R, C> {
38
+ /** Emits a declared event; undeclared names and wrong payloads are compile errors. */
39
+ readonly emit: Emit<E>;
40
+ /**
41
+ * The component's own declaration (frozen). Pass the whole context to `useTaggorData` and
42
+ * `useTrack` (TAG-203): they read `tag` and `data` from it, and its type `D` is what makes an
43
+ * undeclared collection or interaction a compile error. `useLocale` (TAG-211) reads `locales`
44
+ * from it the same way.
45
+ */
46
+ readonly manifest: ComponentManifestDraft<unknown, E, unknown, D, R, C, string, M>;
47
+ }
48
+ /** The manifest fields an author writes (everything but `contractVersion`, set at extraction). */
49
+ export interface ComponentManifestDraft<P, E, S, D = DataDeclaration, R = PartsDeclaration, C = CssVarsDeclaration, T extends string = string, M = MessagesDeclaration> {
50
+ readonly name: string;
51
+ readonly tag: T;
52
+ readonly title: string;
53
+ readonly description: string;
54
+ /** Workspace-scoped package ranges (TAG-210); the builder checks ownership and resolves them. */
55
+ readonly libraries?: ComponentManifest["libraries"];
56
+ readonly props?: P;
57
+ readonly events?: E;
58
+ readonly slots?: S;
59
+ readonly parts?: R;
60
+ readonly cssVars?: C;
61
+ readonly data?: D;
62
+ readonly size?: ComponentManifest["size"];
63
+ readonly permissions?: ComponentManifest["permissions"];
64
+ /**
65
+ * The message catalogs by language tag and the default language (TAG-211); `useLocale` picks
66
+ * one. Not the contract's shape: `extractManifest` writes `{ supported, default }` from it.
67
+ */
68
+ readonly locales?: LocalesDraft<M>;
69
+ /**
70
+ * A form field component (TAG-314, contract 1.4): the element takes part in the page's `<form>`
71
+ * (`useFormField` sets what it submits under the element's `name`, and its validity).
72
+ */
73
+ readonly formAssociated?: boolean;
74
+ /**
75
+ * Whether focusing the element (or clicking one of its labels) focuses the component's first
76
+ * focusable element (TAG-314); defaults to `formAssociated`.
77
+ */
78
+ readonly delegatesFocus?: boolean;
79
+ /**
80
+ * The share of `interaction` and `custom` events the browser sends, from 0.001 to 1 (TAG-819,
81
+ * contract 1.10); omitted means all. `render`, `error` and `conversion` are never sampled. The
82
+ * edge weights each stored event by `1 / eventSampleRate`, so totals stay estimates of the real
83
+ * count. A data declaration only: nothing here runs in the browser (the runtime reads it).
84
+ */
85
+ readonly eventSampleRate?: number;
86
+ }
87
+ /** The argument of `defineTaggorComponent`: the manifest fields, the styles and the render function. */
88
+ export interface ComponentOptions<P, E, S, D = DataDeclaration, R = PartsDeclaration, C = CssVarsDeclaration, T extends string = string, M = MessagesDeclaration> extends ComponentManifestDraft<P, E, S, D, R, C, T, M> {
89
+ /**
90
+ * CSS text adopted by the component's shadow root (never by the page): one text, a list, or a
91
+ * function of the component's `Theme` returning either (`({ cssVar }) => \`a { color:
92
+ * ${cssVar("--fs-primary-color")} }\``), called once by `defineTaggorComponent`.
93
+ */
94
+ readonly styles?: string | readonly string[] | ((theme: Theme<R, C>) => string | readonly string[]);
95
+ /**
96
+ * Renders the component (a Preact function component body: hooks are allowed). Receives the props
97
+ * typed from `props` and the typed `emit`.
98
+ */
99
+ readonly render: (props: PropsOf<P>, context: RenderContext<E, D, R, C, M>) => ComponentChildren;
100
+ }
101
+ /** The Preact props of a definition's component, as the runtime passes them. */
102
+ export interface ComponentViewProps<Props> {
103
+ readonly host: ComponentHost;
104
+ readonly props: Props;
105
+ }
106
+ /**
107
+ * A defined component: inert data plus a component. The runtime mounts it with
108
+ * `render(h(definition.component, { host, props }), host.shadowRoot)`, after adopting `styles` in
109
+ * the shadow root and coercing `props` from the manifest.
110
+ */
111
+ export interface ComponentDefinition<P = PropsDeclaration, E = EventsDeclaration, S = SlotsDeclaration, D = DataDeclaration, R = PartsDeclaration, C = CssVarsDeclaration, T extends string = string, M = MessagesDeclaration> {
112
+ readonly kind: typeof COMPONENT_KIND;
113
+ readonly manifest: ComponentManifestDraft<P, E, S, D, R, C, T, M>;
114
+ readonly styles: readonly string[];
115
+ readonly component: FunctionComponent<ComponentViewProps<PropsOf<P>>>;
116
+ }
117
+ /**
118
+ * The props `render` receives for the definition `D` (for tests, wrappers and host pages).
119
+ *
120
+ * Read from the manifest's own `props` field, not by matching `D` against `ComponentDefinition` with
121
+ * `unknown` or default parameters: `LocalesDraft<M>` is invariant in `M` (`default` is `keyof M`),
122
+ * so a component with `locales` would not match and this would be `never` (TAG-232).
123
+ */
124
+ export type ComponentPropsOf<D> = D extends {
125
+ readonly manifest: {
126
+ readonly props?: infer P;
127
+ };
128
+ } ? PropsOf<P> : never;
129
+ /**
130
+ * The `events` declaration of the definition `D` (`Emit<ComponentEventsOf<D>>` is its `emit`). Read
131
+ * from the manifest's `events` field like `ComponentPropsOf`, so `locales` does not turn it into
132
+ * `never` (TAG-232).
133
+ */
134
+ export type ComponentEventsOf<D> = D extends {
135
+ readonly manifest: {
136
+ readonly events?: infer E;
137
+ };
138
+ } ? E : never;
139
+ /**
140
+ * Declares a component.
141
+ *
142
+ * Inputs: the manifest fields (`name`, `tag`, `title`, `description` and the optional `props`,
143
+ * `events`, `slots`, `parts`, `cssVars`, `data`, `size`, `permissions`, `locales`), optional
144
+ * `styles` and
145
+ * `render`. Prop types are inferred from `props` (`prop.number({ default: 1.2 })` gives
146
+ * `rate: number`), `emit` only accepts the names in `events`, and the data hooks given the render
147
+ * context only accept the collections and interactions in `data` (TAG-203); `cssVar` and `part`
148
+ * (in `render`'s context and in a `styles` function) only accept the names in `cssVars` and
149
+ * `parts` (TAG-206); `t` of `useLocale` only accepts keys of the `locales` catalogs, and its
150
+ * `default` must be one of their languages (TAG-211). Output: a frozen
151
+ * `ComponentDefinition`. Errors: none at runtime (the manifest is checked by `extractManifest` at
152
+ * build time). Side effects: none; nothing is registered.
153
+ */
154
+ export declare function defineTaggorComponent<const P extends PropsDeclaration = None, const E extends EventsDeclaration = None, const S extends SlotsDeclaration = None, const D extends DataDeclaration = None, const R extends PartsDeclaration = None, const C extends CssVarsDeclaration = None, const T extends string = string, const M extends MessagesDeclaration = None>(options: ComponentOptions<P, E, S, D, R, C, T, M>): ComponentDefinition<P, E, S, D, R, C, T, M>;
155
+ /**
156
+ * Whether a value is a `ComponentDefinition` made by `defineTaggorComponent` (or shaped like one).
157
+ *
158
+ * Inputs: any value. Output: true when it is an object with the `kind` brand, a `manifest`
159
+ * object and a `component` function. Errors: none. Side effects: reads three properties.
160
+ */
161
+ export declare function isComponentDefinition(value: unknown): value is ComponentDefinition;
162
+ //# sourceMappingURL=define-component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-component.d.ts","sourceRoot":"","sources":["../src/define-component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAK,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,wFAAwF;AACxF,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD,qGAAqG;AACrG,MAAM,MAA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