@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.
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/assets.d.ts +35 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/assets.d.ts +26 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +14 -0
- package/dist/assets.js.map +1 -0
- package/dist/bounded-json.d.ts +21 -0
- package/dist/bounded-json.d.ts.map +1 -0
- package/dist/bounded-json.js +55 -0
- package/dist/bounded-json.js.map +1 -0
- package/dist/build/check-messages.d.ts +41 -0
- package/dist/build/check-messages.d.ts.map +1 -0
- package/dist/build/check-messages.js +142 -0
- package/dist/build/check-messages.js.map +1 -0
- package/dist/build/extract-manifest.d.ts +48 -0
- package/dist/build/extract-manifest.d.ts.map +1 -0
- package/dist/build/extract-manifest.js +81 -0
- package/dist/build/extract-manifest.js.map +1 -0
- package/dist/build/extract-styles.d.ts +36 -0
- package/dist/build/extract-styles.d.ts.map +1 -0
- package/dist/build/extract-styles.js +48 -0
- package/dist/build/extract-styles.js.map +1 -0
- package/dist/build/find-definition.d.ts +14 -0
- package/dist/build/find-definition.d.ts.map +1 -0
- package/dist/build/find-definition.js +23 -0
- package/dist/build/find-definition.js.map +1 -0
- package/dist/build/index.d.ts +10 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +10 -0
- package/dist/build/index.js.map +1 -0
- package/dist/consent.d.ts +100 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +147 -0
- package/dist/consent.js.map +1 -0
- package/dist/data-client.d.ts +34 -0
- package/dist/data-client.d.ts.map +1 -0
- package/dist/data-client.js +78 -0
- package/dist/data-client.js.map +1 -0
- package/dist/data-declaration.d.ts +59 -0
- package/dist/data-declaration.d.ts.map +1 -0
- package/dist/data-declaration.js +2 -0
- package/dist/data-declaration.js.map +1 -0
- package/dist/data-errors.d.ts +33 -0
- package/dist/data-errors.d.ts.map +1 -0
- package/dist/data-errors.js +73 -0
- package/dist/data-errors.js.map +1 -0
- package/dist/data-transport.d.ts +73 -0
- package/dist/data-transport.d.ts.map +1 -0
- package/dist/data-transport.js +2 -0
- package/dist/data-transport.js.map +1 -0
- package/dist/debug.d.ts +14 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +11 -0
- package/dist/debug.js.map +1 -0
- package/dist/define-component.d.ts +162 -0
- package/dist/define-component.d.ts.map +1 -0
- package/dist/define-component.js +79 -0
- package/dist/define-component.js.map +1 -0
- package/dist/define-library.d.ts +24 -0
- package/dist/define-library.d.ts.map +1 -0
- package/dist/define-library.js +24 -0
- package/dist/define-library.js.map +1 -0
- package/dist/edge-transport.d.ts +25 -0
- package/dist/edge-transport.d.ts.map +1 -0
- package/dist/edge-transport.js +94 -0
- package/dist/edge-transport.js.map +1 -0
- package/dist/events.d.ts +50 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/form-field.d.ts +59 -0
- package/dist/form-field.d.ts.map +1 -0
- package/dist/form-field.js +114 -0
- package/dist/form-field.js.map +1 -0
- package/dist/host.d.ts +45 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +30 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/intl-format.d.ts +37 -0
- package/dist/intl-format.d.ts.map +1 -0
- package/dist/intl-format.js +56 -0
- package/dist/intl-format.js.map +1 -0
- package/dist/issued-proofs.d.ts +19 -0
- package/dist/issued-proofs.d.ts.map +1 -0
- package/dist/issued-proofs.js +19 -0
- package/dist/issued-proofs.js.map +1 -0
- package/dist/locale.d.ts +28 -0
- package/dist/locale.d.ts.map +1 -0
- package/dist/locale.js +62 -0
- package/dist/locale.js.map +1 -0
- package/dist/memory-transport.d.ts +39 -0
- package/dist/memory-transport.d.ts.map +1 -0
- package/dist/memory-transport.js +34 -0
- package/dist/memory-transport.js.map +1 -0
- package/dist/messages.d.ts +34 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +54 -0
- package/dist/messages.js.map +1 -0
- package/dist/none.d.ts +7 -0
- package/dist/none.d.ts.map +1 -0
- package/dist/none.js +6 -0
- package/dist/none.js.map +1 -0
- package/dist/props.d.ts +89 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +25 -0
- package/dist/props.js.map +1 -0
- package/dist/slots.d.ts +26 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +70 -0
- package/dist/slots.js.map +1 -0
- package/dist/submit-result.d.ts +19 -0
- package/dist/submit-result.d.ts.map +1 -0
- package/dist/submit-result.js +58 -0
- package/dist/submit-result.js.map +1 -0
- package/dist/testing/form-internals.d.ts +59 -0
- package/dist/testing/form-internals.d.ts.map +1 -0
- package/dist/testing/form-internals.js +150 -0
- package/dist/testing/form-internals.js.map +1 -0
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +14 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mount-component.d.ts +105 -0
- package/dist/testing/mount-component.d.ts.map +1 -0
- package/dist/testing/mount-component.js +270 -0
- package/dist/testing/mount-component.js.map +1 -0
- package/dist/testing/visitor.d.ts +23 -0
- package/dist/testing/visitor.d.ts.map +1 -0
- package/dist/testing/visitor.js +34 -0
- package/dist/testing/visitor.js.map +1 -0
- package/dist/theming.d.ts +42 -0
- package/dist/theming.d.ts.map +1 -0
- package/dist/theming.js +19 -0
- package/dist/theming.js.map +1 -0
- package/dist/turnstile.d.ts +60 -0
- package/dist/turnstile.d.ts.map +1 -0
- package/dist/turnstile.js +179 -0
- package/dist/turnstile.js.map +1 -0
- package/dist/use-font.d.ts +65 -0
- package/dist/use-font.d.ts.map +1 -0
- package/dist/use-font.js +145 -0
- package/dist/use-font.js.map +1 -0
- package/dist/use-locale.d.ts +46 -0
- package/dist/use-locale.d.ts.map +1 -0
- package/dist/use-locale.js +57 -0
- package/dist/use-locale.js.map +1 -0
- package/dist/use-taggor-data.d.ts +72 -0
- package/dist/use-taggor-data.d.ts.map +1 -0
- package/dist/use-taggor-data.js +179 -0
- package/dist/use-taggor-data.js.map +1 -0
- package/dist/use-track.d.ts +17 -0
- package/dist/use-track.d.ts.map +1 -0
- package/dist/use-track.js +64 -0
- package/dist/use-track.js.map +1 -0
- package/dist/value-types.d.ts +69 -0
- package/dist/value-types.d.ts.map +1 -0
- package/dist/value-types.js +15 -0
- package/dist/value-types.js.map +1 -0
- package/dist/visitor-action.d.ts +49 -0
- package/dist/visitor-action.d.ts.map +1 -0
- package/dist/visitor-action.js +77 -0
- package/dist/visitor-action.js.map +1 -0
- package/package.json +74 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @taggor/component (TAG-202): the authoring SDK a component's code imports. `defineTaggorComponent` declares a
|
|
3
|
+
* component (manifest fields, styles, render), `prop.<type>()` declares props whose value types
|
|
4
|
+
* `render` receives, `emit` (in `render`'s context) only accepts declared events, and `useHost` /
|
|
5
|
+
* `useSlot` reach the custom element, its shadow root and its slotted content. TAG-203 added the
|
|
6
|
+
* data hooks: `useTaggorData` (submit to a declared collection) and `useTrack` (measure a declared
|
|
7
|
+
* interaction), over the `DataTransport` the runtime injects (`createEdgeTransport`,
|
|
8
|
+
* `createMemoryTransport`). Unused hooks and transports are dropped by tree-shaking. TAG-206 added
|
|
9
|
+
* theming (`cssVar` and `part`, typed by `cssVars` and `parts`) and the host page event types
|
|
10
|
+
* (`ComponentEventMap`). TAG-212 added consent for components that collect personal data: `useConsent`
|
|
11
|
+
* and the `<Consent>` checkbox, whose proof `useTaggorData` requires and sends. TAG-211 added
|
|
12
|
+
* i18n: `useLocale` (the visitor's language among the component's message catalogs, `t` and thin
|
|
13
|
+
* `Intl` helpers), dropped by tree-shaking from components that do not call it. TAG-213 added
|
|
14
|
+
* assets: the `ImageUrl`/`FontUrl` types of asset imports (declared for `*.svg`, `*.woff2`… in
|
|
15
|
+
* `@taggor/component/assets`) and `useFont`/`fontFamily`, which add a component's font to the document
|
|
16
|
+
* without any CSS there. TAG-314 added form field components: `useFormField` sets what a component with
|
|
17
|
+
* `formAssociated: true` submits with the page's `<form>`, and its validity.
|
|
18
|
+
*
|
|
19
|
+
* This entry goes into every component bundle, so it has no side effects (`sideEffects: false`,
|
|
20
|
+
* nothing registered or assigned to a global), imports no Zod (only `import type` from
|
|
21
|
+
* `@taggor/contract`) and stays under the size budget of `size-limit` in package.json. Build-time
|
|
22
|
+
* helpers (`extractManifest`, which validates with Zod) live in `@taggor/component/build`.
|
|
23
|
+
*/
|
|
24
|
+
export type { AssetUrl, FontUrl, ImageUrl } from "./assets.js";
|
|
25
|
+
export { defineLibrary, isLibraryDefinition, type LibraryDefinition } from "./define-library.js";
|
|
26
|
+
export { Consent, consentLabel, consentTextHash, useConsent, type ConsentLabel, type ConsentProps, type ConsentState, } from "./consent.js";
|
|
27
|
+
export { COMPONENT_KIND, defineTaggorComponent, isComponentDefinition, type RenderContext, type SlotsDeclaration, type ComponentViewProps, type ComponentDefinition, type ComponentEventsOf, type ComponentManifestDraft, type ComponentOptions, type ComponentPropsOf, } from "./define-component.js";
|
|
28
|
+
export type { CollectionName, DataAnchor, DataDeclaration, SubmitValues, TrackName, TrackProps, } from "./data-declaration.js";
|
|
29
|
+
export type { DataTransport, FieldProblem, SubmitErrorCode, SubmitResult, TrackedEvent, TrackedEventKind, } from "./data-transport.js";
|
|
30
|
+
export { createEdgeTransport, type EdgeTransportOptions } from "./edge-transport.js";
|
|
31
|
+
export type { Emit, EventDetail, EventsDeclaration, ManifestEventMap, ComponentEventMap, } from "./events.js";
|
|
32
|
+
export { useFormField, type FormFieldOptions, type FormFieldState } from "./form-field.js";
|
|
33
|
+
export { useHost, type HostAccess, type ComponentHost } from "./host.js";
|
|
34
|
+
export { createMemoryTransport, type MemoryResponder, type MemoryTransport, type RecordedSubmission, } from "./memory-transport.js";
|
|
35
|
+
export type { Message, MessageCatalog, MessageKey, MessageVars, MessagesDeclaration, PluralCategory, PluralMessage, Translate, } from "./messages.js";
|
|
36
|
+
export { formatCurrency, formatDate, formatNumber } from "./intl-format.js";
|
|
37
|
+
export type { None } from "./none.js";
|
|
38
|
+
export { prop, type AnyPropDeclaration, type PropOptions, type PropValueOf, type PropsDeclaration, type PropsOf, } from "./props.js";
|
|
39
|
+
export { DEFAULT_SLOT, slotHasContent, useSlot, type SlotState } from "./slots.js";
|
|
40
|
+
export { useTaggorData, type FieldErrors, type SubmitError, type SubmitOptions, type SubmitOutcome, type SubmitStatus, type TaggorData, } from "./use-taggor-data.js";
|
|
41
|
+
export type { CssVarName, CssVarsDeclaration, PartName, PartsDeclaration, Theme, } from "./theming.js";
|
|
42
|
+
export { fontFamily, useFont, type FontDeclaration } from "./use-font.js";
|
|
43
|
+
export { useLocale, type Locale, type LocaleAnchor, type LocalesDraft } from "./use-locale.js";
|
|
44
|
+
export { useTrack, type Track } from "./use-track.js";
|
|
45
|
+
export type { ValueOf } from "./value-types.js";
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,EACf,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,cAAc,EACd,UAAU,EACV,eAAe,EACf,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACrF,YAAY,EACV,IAAI,EACJ,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,OAAO,EACP,cAAc,EACd,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5E,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,IAAI,EACJ,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,OAAO,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EACL,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,gBAAgB,EAChB,KAAK,GACN,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @taggor/component (TAG-202): the authoring SDK a component's code imports. `defineTaggorComponent` declares a
|
|
3
|
+
* component (manifest fields, styles, render), `prop.<type>()` declares props whose value types
|
|
4
|
+
* `render` receives, `emit` (in `render`'s context) only accepts declared events, and `useHost` /
|
|
5
|
+
* `useSlot` reach the custom element, its shadow root and its slotted content. TAG-203 added the
|
|
6
|
+
* data hooks: `useTaggorData` (submit to a declared collection) and `useTrack` (measure a declared
|
|
7
|
+
* interaction), over the `DataTransport` the runtime injects (`createEdgeTransport`,
|
|
8
|
+
* `createMemoryTransport`). Unused hooks and transports are dropped by tree-shaking. TAG-206 added
|
|
9
|
+
* theming (`cssVar` and `part`, typed by `cssVars` and `parts`) and the host page event types
|
|
10
|
+
* (`ComponentEventMap`). TAG-212 added consent for components that collect personal data: `useConsent`
|
|
11
|
+
* and the `<Consent>` checkbox, whose proof `useTaggorData` requires and sends. TAG-211 added
|
|
12
|
+
* i18n: `useLocale` (the visitor's language among the component's message catalogs, `t` and thin
|
|
13
|
+
* `Intl` helpers), dropped by tree-shaking from components that do not call it. TAG-213 added
|
|
14
|
+
* assets: the `ImageUrl`/`FontUrl` types of asset imports (declared for `*.svg`, `*.woff2`… in
|
|
15
|
+
* `@taggor/component/assets`) and `useFont`/`fontFamily`, which add a component's font to the document
|
|
16
|
+
* without any CSS there. TAG-314 added form field components: `useFormField` sets what a component with
|
|
17
|
+
* `formAssociated: true` submits with the page's `<form>`, and its validity.
|
|
18
|
+
*
|
|
19
|
+
* This entry goes into every component bundle, so it has no side effects (`sideEffects: false`,
|
|
20
|
+
* nothing registered or assigned to a global), imports no Zod (only `import type` from
|
|
21
|
+
* `@taggor/contract`) and stays under the size budget of `size-limit` in package.json. Build-time
|
|
22
|
+
* helpers (`extractManifest`, which validates with Zod) live in `@taggor/component/build`.
|
|
23
|
+
*/
|
|
24
|
+
export { defineLibrary, isLibraryDefinition } from "./define-library.js";
|
|
25
|
+
export { Consent, consentLabel, consentTextHash, useConsent, } from "./consent.js";
|
|
26
|
+
export { COMPONENT_KIND, defineTaggorComponent, isComponentDefinition, } from "./define-component.js";
|
|
27
|
+
export { createEdgeTransport } from "./edge-transport.js";
|
|
28
|
+
export { useFormField } from "./form-field.js";
|
|
29
|
+
export { useHost } from "./host.js";
|
|
30
|
+
export { createMemoryTransport, } from "./memory-transport.js";
|
|
31
|
+
export { formatCurrency, formatDate, formatNumber } from "./intl-format.js";
|
|
32
|
+
export { prop, } from "./props.js";
|
|
33
|
+
export { DEFAULT_SLOT, slotHasContent, useSlot } from "./slots.js";
|
|
34
|
+
export { useTaggorData, } from "./use-taggor-data.js";
|
|
35
|
+
export { fontFamily, useFont } from "./use-font.js";
|
|
36
|
+
export { useLocale } from "./use-locale.js";
|
|
37
|
+
export { useTrack } from "./use-track.js";
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAA0B,MAAM,qBAAqB,CAAC;AACjG,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,EACf,UAAU,GAIX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,qBAAqB,GAStB,MAAM,uBAAuB,CAAC;AAiB/B,OAAO,EAAE,mBAAmB,EAA6B,MAAM,qBAAqB,CAAC;AAQrF,OAAO,EAAE,YAAY,EAA8C,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAuC,MAAM,WAAW,CAAC;AACzE,OAAO,EACL,qBAAqB,GAItB,MAAM,uBAAuB,CAAC;AAW/B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EACL,IAAI,GAML,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAkB,MAAM,YAAY,CAAC;AACnF,OAAO,EACL,aAAa,GAOd,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAwB,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAqD,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin helpers over the browser's `Intl` (TAG-211): numbers, money and dates in the component's
|
|
3
|
+
* language, with no formatting library in the bundle. `useLocale` hands them out bound to the
|
|
4
|
+
* chosen language.
|
|
5
|
+
*
|
|
6
|
+
* None of them throws (golden rule 2): `Intl` throws `RangeError` for an unknown currency code,
|
|
7
|
+
* a bad option or an invalid date, and a component must not fall into its fallback for a price.
|
|
8
|
+
* Each one degrades to a plain rendering instead.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Formats a number for `locale` (`1234.5` → `1.234,5` in pt-BR).
|
|
12
|
+
*
|
|
13
|
+
* Inputs: a language tag, the number and optional `Intl.NumberFormat` options. Output: the
|
|
14
|
+
* formatted text; when `Intl` refuses the tag or the options, `String(value)`. Errors: none.
|
|
15
|
+
* Side effects: none.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatNumber(locale: string, value: number, options?: Intl.NumberFormatOptions): string;
|
|
18
|
+
/**
|
|
19
|
+
* Formats an amount of money (`49.9, "BRL"` → `R$ 49,90` in pt-BR, `R$49.90` in en).
|
|
20
|
+
*
|
|
21
|
+
* Inputs: a language tag, the amount, an ISO 4217 currency code and optional
|
|
22
|
+
* `Intl.NumberFormat` options (`style` and `currency` are set here). Output: the formatted text;
|
|
23
|
+
* when `Intl` refuses the code or the options, the code and the plain number (`XYZ 49.9`), so the
|
|
24
|
+
* currency is never lost. Errors: none. Side effects: none.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatCurrency(locale: string, value: number, currency: string, options?: Intl.NumberFormatOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* Formats a date (`"2026-10-30"` → `30/10/2026` in pt-BR, `10/30/2026` in en).
|
|
29
|
+
*
|
|
30
|
+
* Inputs: a language tag, a `Date`, a timestamp or a date text, and optional
|
|
31
|
+
* `Intl.DateTimeFormat` options. A calendar date (`YYYY-MM-DD`, what a `date` prop holds) is shown
|
|
32
|
+
* as that day everywhere: it is formatted in UTC unless the options set `timeZone`, since
|
|
33
|
+
* `new Date("2026-10-30")` is midnight UTC, which is still the 29th west of Greenwich. Output: the
|
|
34
|
+
* formatted text; an invalid date, tag or option gives `""`. Errors: none. Side effects: none.
|
|
35
|
+
*/
|
|
36
|
+
export declare function formatDate(locale: string, value: Date | number | string, options?: Intl.DateTimeFormatOptions): string;
|
|
37
|
+
//# sourceMappingURL=intl-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl-format.d.ts","sourceRoot":"","sources":["../src/intl-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GACjC,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GACjC,MAAM,CAKR;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC7B,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GACnC,MAAM,CAUR"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin helpers over the browser's `Intl` (TAG-211): numbers, money and dates in the component's
|
|
3
|
+
* language, with no formatting library in the bundle. `useLocale` hands them out bound to the
|
|
4
|
+
* chosen language.
|
|
5
|
+
*
|
|
6
|
+
* None of them throws (golden rule 2): `Intl` throws `RangeError` for an unknown currency code,
|
|
7
|
+
* a bad option or an invalid date, and a component must not fall into its fallback for a price.
|
|
8
|
+
* Each one degrades to a plain rendering instead.
|
|
9
|
+
*/
|
|
10
|
+
/** A calendar date as the contract's `date` prop gives it (`YYYY-MM-DD`). */
|
|
11
|
+
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
12
|
+
/** Runs one `Intl` call; what it throws gives `fallback` instead. */
|
|
13
|
+
function safely(format, fallback) {
|
|
14
|
+
try {
|
|
15
|
+
return format();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return fallback;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Formats a number for `locale` (`1234.5` → `1.234,5` in pt-BR).
|
|
23
|
+
*
|
|
24
|
+
* Inputs: a language tag, the number and optional `Intl.NumberFormat` options. Output: the
|
|
25
|
+
* formatted text; when `Intl` refuses the tag or the options, `String(value)`. Errors: none.
|
|
26
|
+
* Side effects: none.
|
|
27
|
+
*/
|
|
28
|
+
export function formatNumber(locale, value, options) {
|
|
29
|
+
return safely(() => new Intl.NumberFormat(locale, options).format(value), String(value));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Formats an amount of money (`49.9, "BRL"` → `R$ 49,90` in pt-BR, `R$49.90` in en).
|
|
33
|
+
*
|
|
34
|
+
* Inputs: a language tag, the amount, an ISO 4217 currency code and optional
|
|
35
|
+
* `Intl.NumberFormat` options (`style` and `currency` are set here). Output: the formatted text;
|
|
36
|
+
* when `Intl` refuses the code or the options, the code and the plain number (`XYZ 49.9`), so the
|
|
37
|
+
* currency is never lost. Errors: none. Side effects: none.
|
|
38
|
+
*/
|
|
39
|
+
export function formatCurrency(locale, value, currency, options) {
|
|
40
|
+
return safely(() => new Intl.NumberFormat(locale, { ...options, style: "currency", currency }).format(value), `${currency} ${String(value)}`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Formats a date (`"2026-10-30"` → `30/10/2026` in pt-BR, `10/30/2026` in en).
|
|
44
|
+
*
|
|
45
|
+
* Inputs: a language tag, a `Date`, a timestamp or a date text, and optional
|
|
46
|
+
* `Intl.DateTimeFormat` options. A calendar date (`YYYY-MM-DD`, what a `date` prop holds) is shown
|
|
47
|
+
* as that day everywhere: it is formatted in UTC unless the options set `timeZone`, since
|
|
48
|
+
* `new Date("2026-10-30")` is midnight UTC, which is still the 29th west of Greenwich. Output: the
|
|
49
|
+
* formatted text; an invalid date, tag or option gives `""`. Errors: none. Side effects: none.
|
|
50
|
+
*/
|
|
51
|
+
export function formatDate(locale, value, options) {
|
|
52
|
+
// `test` reads a Date or a timestamp as text ("Fri Oct 30…", "1793…"), which never matches.
|
|
53
|
+
const day = DATE_ONLY.test(value);
|
|
54
|
+
return safely(() => new Intl.DateTimeFormat(locale, day ? { timeZone: "UTC", ...options } : options).format(new Date(value)), "");
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=intl-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl-format.js","sourceRoot":"","sources":["../src/intl-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,6EAA6E;AAC7E,MAAM,SAAS,GAAG,qBAAqB,CAAC;AAExC,qEAAqE;AACrE,SAAS,MAAM,CAAC,MAAoB,EAAE,QAAgB;IACpD,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,KAAa,EACb,OAAkC;IAElC,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,KAAa,EACb,QAAgB,EAChB,OAAkC;IAElC,OAAO,MAAM,CACX,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC9F,GAAG,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAC/B,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,MAAc,EACd,KAA6B,EAC7B,OAAoC;IAEpC,4FAA4F;IAC5F,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC;IAC5C,OAAO,MAAM,CACX,GAAG,EAAE,CACH,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CACrF,IAAI,IAAI,CAAC,KAAK,CAAC,CAChB,EACH,EAAE,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consent proofs this copy of the SDK issued (TAG-237, security review M1): `useConsent` adds
|
|
3
|
+
* every proof it builds, and `useTaggorData`'s `submit` sends personal data only with a proof in
|
|
4
|
+
* the set. A proof written by hand, `{ given: true, text_hash: await consentTextHash(…), locale }`,
|
|
5
|
+
* is a plain object that was never added, so it ends in `consent_required` like a missing one.
|
|
6
|
+
*
|
|
7
|
+
* A `WeakSet` keeps no proof alive and has no global name: each component's bundle has its own copy
|
|
8
|
+
* of the SDK, so one component can never vouch for another's proof.
|
|
9
|
+
*
|
|
10
|
+
* Scope (re-review of TAG-237): this stops the naive forgery, not a component that subverts its own
|
|
11
|
+
* realm on purpose. The set lives in the untrusted bundle: a component can replace
|
|
12
|
+
* `WeakSet.prototype.has` or `add` (looked up at call time), reach Preact's hook state to get a
|
|
13
|
+
* proof issued, or skip the SDK and call the ingest itself. Against that, the gate, the AUP and the
|
|
14
|
+
* server-side check of the proof (TAG-703) apply; threat model §6, residual 3. A proof the component
|
|
15
|
+
* kept stays in the set after the visitor unticks the box (residual 1).
|
|
16
|
+
*/
|
|
17
|
+
/** Proofs `useConsent` built for a ticked box (frozen objects). */
|
|
18
|
+
export declare const issuedProofs: WeakSet<object>;
|
|
19
|
+
//# sourceMappingURL=issued-proofs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issued-proofs.d.ts","sourceRoot":"","sources":["../src/issued-proofs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,mEAAmE;AACnE,eAAO,MAAM,YAAY,EAAE,OAAO,CAAC,MAAM,CAAiC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consent proofs this copy of the SDK issued (TAG-237, security review M1): `useConsent` adds
|
|
3
|
+
* every proof it builds, and `useTaggorData`'s `submit` sends personal data only with a proof in
|
|
4
|
+
* the set. A proof written by hand, `{ given: true, text_hash: await consentTextHash(…), locale }`,
|
|
5
|
+
* is a plain object that was never added, so it ends in `consent_required` like a missing one.
|
|
6
|
+
*
|
|
7
|
+
* A `WeakSet` keeps no proof alive and has no global name: each component's bundle has its own copy
|
|
8
|
+
* of the SDK, so one component can never vouch for another's proof.
|
|
9
|
+
*
|
|
10
|
+
* Scope (re-review of TAG-237): this stops the naive forgery, not a component that subverts its own
|
|
11
|
+
* realm on purpose. The set lives in the untrusted bundle: a component can replace
|
|
12
|
+
* `WeakSet.prototype.has` or `add` (looked up at call time), reach Preact's hook state to get a
|
|
13
|
+
* proof issued, or skip the SDK and call the ingest itself. Against that, the gate, the AUP and the
|
|
14
|
+
* server-side check of the proof (TAG-703) apply; threat model §6, residual 3. A proof the component
|
|
15
|
+
* kept stays in the set after the visitor unticks the box (residual 1).
|
|
16
|
+
*/
|
|
17
|
+
/** Proofs `useConsent` built for a ticked box (frozen objects). */
|
|
18
|
+
export const issuedProofs = /* @__PURE__ */ new WeakSet();
|
|
19
|
+
//# sourceMappingURL=issued-proofs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issued-proofs.js","sourceRoot":"","sources":["../src/issued-proofs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,YAAY,GAAoB,eAAe,CAAC,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The supported tag a language tag asks for.
|
|
3
|
+
*
|
|
4
|
+
* Inputs: a candidate (any value: an attribute may be absent or empty) and the supported tags.
|
|
5
|
+
* Output: the supported tag equal to the candidate without case (`pt-br` → `pt-BR`), else the
|
|
6
|
+
* first supported tag with the same language (`pt-PT` or `pt_BR` → `pt-BR`, `en-GB` → `en`), else
|
|
7
|
+
* `undefined` (also for anything that is not a non-empty text). Errors: none. Side effects: none.
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchLocale(candidate: unknown, supported: readonly string[]): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Picks the component's language from the candidates, in order.
|
|
12
|
+
*
|
|
13
|
+
* Inputs: the candidates (`localeCandidates`), the supported tags and the default. Output: the
|
|
14
|
+
* first candidate's match (`matchLocale`), or `fallback` when none matches. Errors: none. Side
|
|
15
|
+
* effects: none.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveLocale(candidates: readonly unknown[], supported: readonly string[], fallback: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* The language candidates a page offers to `element`, in the order of the contract.
|
|
20
|
+
*
|
|
21
|
+
* Inputs: the component's custom element. Output: its `locale` attribute, the `lang` of the nearest
|
|
22
|
+
* element that has one (itself included; it stops at a shadow root), the `lang` of the document's
|
|
23
|
+
* `<html>` (for a component inside another component's shadow root) and `navigator.language`; absent
|
|
24
|
+
* ones are `null` or `undefined`. Errors: none in a browser (`navigator` exists). Side effects:
|
|
25
|
+
* reads attributes and `navigator`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function localeCandidates(element: Element): readonly unknown[];
|
|
28
|
+
//# sourceMappingURL=locale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAQhG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,SAAS,OAAO,EAAE,EAC9B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,QAAQ,EAAE,MAAM,GACf,MAAM,CAMR;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,OAAO,EAAE,CAOrE"}
|
package/dist/locale.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which language a component speaks (TAG-211): the candidates a page offers, in the order of the
|
|
3
|
+
* contract (`SPEC.md` §3, `locales`), and the pure choice of one of the languages the component
|
|
4
|
+
* ships messages for.
|
|
5
|
+
*
|
|
6
|
+
* Order: the element's `locale` attribute, the nearest `lang` (the element's own included) and the
|
|
7
|
+
* `<html>` one, `navigator.language`, and finally the declared default. The first candidate that
|
|
8
|
+
* matches a supported tag wins; a candidate that matches none (a page in French for a component in
|
|
9
|
+
* Portuguese and English) is skipped, not fatal.
|
|
10
|
+
*/
|
|
11
|
+
import { LOCALE_ATTRIBUTE } from "@taggor/contract/zod-free";
|
|
12
|
+
/** The language part of a tag (`pt` of `pt-br` or `pt_br`). */
|
|
13
|
+
const language = (tag) => tag.split(/[-_]/)[0];
|
|
14
|
+
/**
|
|
15
|
+
* The supported tag a language tag asks for.
|
|
16
|
+
*
|
|
17
|
+
* Inputs: a candidate (any value: an attribute may be absent or empty) and the supported tags.
|
|
18
|
+
* Output: the supported tag equal to the candidate without case (`pt-br` → `pt-BR`), else the
|
|
19
|
+
* first supported tag with the same language (`pt-PT` or `pt_BR` → `pt-BR`, `en-GB` → `en`), else
|
|
20
|
+
* `undefined` (also for anything that is not a non-empty text). Errors: none. Side effects: none.
|
|
21
|
+
*/
|
|
22
|
+
export function matchLocale(candidate, supported) {
|
|
23
|
+
// An empty text has the language "", which no tag of the contract has.
|
|
24
|
+
if (typeof candidate !== "string")
|
|
25
|
+
return undefined;
|
|
26
|
+
const wanted = candidate.toLowerCase();
|
|
27
|
+
return (supported.find((tag) => tag.toLowerCase() === wanted) ??
|
|
28
|
+
supported.find((tag) => language(tag.toLowerCase()) === language(wanted)));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Picks the component's language from the candidates, in order.
|
|
32
|
+
*
|
|
33
|
+
* Inputs: the candidates (`localeCandidates`), the supported tags and the default. Output: the
|
|
34
|
+
* first candidate's match (`matchLocale`), or `fallback` when none matches. Errors: none. Side
|
|
35
|
+
* effects: none.
|
|
36
|
+
*/
|
|
37
|
+
export function resolveLocale(candidates, supported, fallback) {
|
|
38
|
+
for (const candidate of candidates) {
|
|
39
|
+
const match = matchLocale(candidate, supported);
|
|
40
|
+
if (match !== undefined)
|
|
41
|
+
return match;
|
|
42
|
+
}
|
|
43
|
+
return fallback;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The language candidates a page offers to `element`, in the order of the contract.
|
|
47
|
+
*
|
|
48
|
+
* Inputs: the component's custom element. Output: its `locale` attribute, the `lang` of the nearest
|
|
49
|
+
* element that has one (itself included; it stops at a shadow root), the `lang` of the document's
|
|
50
|
+
* `<html>` (for a component inside another component's shadow root) and `navigator.language`; absent
|
|
51
|
+
* ones are `null` or `undefined`. Errors: none in a browser (`navigator` exists). Side effects:
|
|
52
|
+
* reads attributes and `navigator`.
|
|
53
|
+
*/
|
|
54
|
+
export function localeCandidates(element) {
|
|
55
|
+
return [
|
|
56
|
+
element.getAttribute(LOCALE_ATTRIBUTE),
|
|
57
|
+
element.closest("[lang]")?.getAttribute("lang"),
|
|
58
|
+
document.documentElement.lang,
|
|
59
|
+
navigator.language,
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,+DAA+D;AAC/D,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAsB,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3E;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,SAAkB,EAAE,SAA4B;IAC1E,uEAAuE;IACvE,IAAI,OAAO,SAAS,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IACvC,OAAO,CACL,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;QACrD,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,CAC1E,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,UAA8B,EAC9B,SAA4B,EAC5B,QAAgB;IAEhB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAChD,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;IACxC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,OAAO;QACL,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC;QACtC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC;QAC/C,QAAQ,CAAC,eAAe,CAAC,IAAI;QAC7B,SAAS,CAAC,QAAQ;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-memory data transport (TAG-203): records submissions and tracked interactions instead of
|
|
3
|
+
* sending them, for unit tests, `@taggor/component/testing` (TAG-209) and `taggor dev`. Each
|
|
4
|
+
* submission is answered by a `respond` function, so a test can play an accepted submission, a
|
|
5
|
+
* validation error, a network failure or a slow server.
|
|
6
|
+
*/
|
|
7
|
+
import type { SubmitRequest } from "@taggor/contract";
|
|
8
|
+
import type { DataTransport, SubmitResult, TrackedEvent } from "./data-transport.js";
|
|
9
|
+
/** One recorded submission. */
|
|
10
|
+
export interface RecordedSubmission {
|
|
11
|
+
readonly collection: string;
|
|
12
|
+
readonly body: SubmitRequest;
|
|
13
|
+
}
|
|
14
|
+
/** Decides the answer to one submission; may be async to play a slow server. */
|
|
15
|
+
export type MemoryResponder = (submission: RecordedSubmission) => SubmitResult | Promise<SubmitResult>;
|
|
16
|
+
/** A `DataTransport` that keeps what it receives. */
|
|
17
|
+
export interface MemoryTransport extends DataTransport {
|
|
18
|
+
/** Every submission received, in order. */
|
|
19
|
+
readonly submissions: readonly RecordedSubmission[];
|
|
20
|
+
/** Every `track` call received (kind `custom`), in order: what a component's `useTrack` sent. */
|
|
21
|
+
readonly tracked: readonly TrackedEvent[];
|
|
22
|
+
/**
|
|
23
|
+
* Every declared event the component emitted that reached the transport (TAG-820, kind
|
|
24
|
+
* `interaction`), in order. Kept apart from `tracked` so the tests of a component that counts its
|
|
25
|
+
* tracked calls keep meaning what they say.
|
|
26
|
+
*/
|
|
27
|
+
readonly interactions: readonly TrackedEvent[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates an in-memory transport.
|
|
31
|
+
*
|
|
32
|
+
* Inputs: an optional `respond` (default: accept everything). Output: a `MemoryTransport` whose
|
|
33
|
+
* `submit` records the call and resolves to what `respond` returns (a throwing or rejecting
|
|
34
|
+
* `respond` resolves to `network_error`, like a failed request), and whose `track` records the
|
|
35
|
+
* body in `tracked` (a `track` call) or `interactions` (an emitted declared event). Errors: none.
|
|
36
|
+
* Side effects: appends to `submissions`, `tracked` and `interactions` only.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createMemoryTransport(respond?: MemoryResponder): MemoryTransport;
|
|
39
|
+
//# sourceMappingURL=memory-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-transport.d.ts","sourceRoot":"","sources":["../src/memory-transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAErF,+BAA+B;AAC/B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC9B;AAED,gFAAgF;AAChF,MAAM,MAAM,eAAe,GAAG,CAC5B,UAAU,EAAE,kBAAkB,KAC3B,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE1C,qDAAqD;AACrD,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACpD,iGAAiG;IACjG,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,SAAS,YAAY,EAAE,CAAC;CAChD;AAID;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,eAAwB,GAAG,eAAe,CAqBxF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const accept = () => ({ ok: true });
|
|
2
|
+
/**
|
|
3
|
+
* Creates an in-memory transport.
|
|
4
|
+
*
|
|
5
|
+
* Inputs: an optional `respond` (default: accept everything). Output: a `MemoryTransport` whose
|
|
6
|
+
* `submit` records the call and resolves to what `respond` returns (a throwing or rejecting
|
|
7
|
+
* `respond` resolves to `network_error`, like a failed request), and whose `track` records the
|
|
8
|
+
* body in `tracked` (a `track` call) or `interactions` (an emitted declared event). Errors: none.
|
|
9
|
+
* Side effects: appends to `submissions`, `tracked` and `interactions` only.
|
|
10
|
+
*/
|
|
11
|
+
export function createMemoryTransport(respond = accept) {
|
|
12
|
+
const submissions = [];
|
|
13
|
+
const tracked = [];
|
|
14
|
+
const interactions = [];
|
|
15
|
+
return {
|
|
16
|
+
submissions,
|
|
17
|
+
tracked,
|
|
18
|
+
interactions,
|
|
19
|
+
submit: async (collection, body) => {
|
|
20
|
+
const submission = { collection, body };
|
|
21
|
+
submissions.push(submission);
|
|
22
|
+
try {
|
|
23
|
+
return await respond(submission);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return { ok: false, code: "network_error", fields: [] };
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
track: (body) => {
|
|
30
|
+
(body.kind === "custom" ? tracked : interactions).push(body);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=memory-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-transport.js","sourceRoot":"","sources":["../src/memory-transport.ts"],"names":[],"mappings":"AAmCA,MAAM,MAAM,GAAoB,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAA2B,MAAM;IACrE,MAAM,WAAW,GAAyB,EAAE,CAAC;IAC7C,MAAM,OAAO,GAAmB,EAAE,CAAC;IACnC,MAAM,YAAY,GAAmB,EAAE,CAAC;IACxC,OAAO;QACL,WAAW;QACX,OAAO;QACP,YAAY;QACZ,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE;YACjC,MAAM,UAAU,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;YACxC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC7B,IAAI,CAAC;gBACH,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;YAC1D,CAAC;QACH,CAAC;QACD,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;YACd,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The plural categories of `Intl.PluralRules`; `other` is the one every language has. */
|
|
2
|
+
export type PluralCategory = Intl.LDMLPluralRule;
|
|
3
|
+
/** A message with plural forms, chosen by the `count` variable; `other` is mandatory. */
|
|
4
|
+
export type PluralMessage = {
|
|
5
|
+
readonly other: string;
|
|
6
|
+
} & {
|
|
7
|
+
readonly [C in Exclude<PluralCategory, "other">]?: string;
|
|
8
|
+
};
|
|
9
|
+
/** One message: a text with `{name}` placeholders, or its plural forms. */
|
|
10
|
+
export type Message = string | PluralMessage;
|
|
11
|
+
/** The messages of one language, by key (`"total"`, `"form.title"`); flat, no nesting. */
|
|
12
|
+
export type MessageCatalog = Readonly<Record<string, Message>>;
|
|
13
|
+
/** The catalogs of a component, by language tag (`{ "pt-BR": ptBR, en }`). */
|
|
14
|
+
export type MessagesDeclaration = Readonly<Record<string, MessageCatalog>>;
|
|
15
|
+
/** Values of the placeholders of a message; numbers are formatted for the language. */
|
|
16
|
+
export type MessageVars = Readonly<Record<string, string | number>>;
|
|
17
|
+
/** Every key of any catalog of `M` (a key missing in one language falls back to the default). */
|
|
18
|
+
export type MessageKey<M> = {
|
|
19
|
+
[L in keyof M]: keyof M[L] & string;
|
|
20
|
+
}[keyof M];
|
|
21
|
+
/** Looks up a message; typed so only keys of the component's catalogs compile. */
|
|
22
|
+
export type Translate<M> = (key: MessageKey<M>, vars?: MessageVars) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Creates the `t` of one language.
|
|
25
|
+
*
|
|
26
|
+
* Inputs: the chosen language tag, the catalogs and the default language. Output: `t(key, vars?)`, which
|
|
27
|
+
* returns the message of `locale`, else of `fallback`, else the key itself; a plural message gives
|
|
28
|
+
* the form `Intl.PluralRules` of `locale` selects for `vars.count` (`other` without a count or
|
|
29
|
+
* without that form), and each `{name}` with an own `vars` entry is replaced by it (numbers
|
|
30
|
+
* formatted for `locale`); an unknown placeholder stays as written. Errors: none: a malformed
|
|
31
|
+
* message from untyped code (no text `other`, not a text) counts as missing. Side effects: none.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createTranslate<M>(locale: string, messages: M | undefined, fallback: string): Translate<M>;
|
|
34
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAaA,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AAEjD,yFAAyF;AACzF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IACvD,QAAQ,EAAE,CAAC,IAAI,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM;CAC1D,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC;AAE7C,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/D,8EAA8E;AAC9E,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;AAE3E,uFAAuF;AACvF,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;AAEpE,iGAAiG;AACjG,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM;CAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7E,kFAAkF;AAClF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC;AAS9E;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,CAAC,GAAG,SAAS,EACvB,QAAQ,EAAE,MAAM,GACf,SAAS,CAAC,CAAC,CAAC,CAyBd"}
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message catalogs of a component (TAG-211): one flat JSON object per language, imported by the
|
|
3
|
+
* component's code and declared in `defineTaggorComponent({ locales: { default, messages } })`, and `t`, the
|
|
4
|
+
* lookup that turns a key and its variables into text.
|
|
5
|
+
*
|
|
6
|
+
* A message is a text with `{name}` placeholders, or a plural form object (`{ one, other }`, the
|
|
7
|
+
* categories of `Intl.PluralRules`) chosen by the `count` variable. Nothing is evaluated: a
|
|
8
|
+
* placeholder is only replaced by the variable's value, and the result is text that Preact renders
|
|
9
|
+
* as a text node, never as HTML (golden rule 5). `t` never throws: a key missing in the chosen
|
|
10
|
+
* language falls back to the default language, then to the key itself.
|
|
11
|
+
*/
|
|
12
|
+
import { formatNumber } from "./intl-format.js";
|
|
13
|
+
/** `{name}`: letters, digits and underscores. */
|
|
14
|
+
const PLACEHOLDER = /\{(\w+)\}/g;
|
|
15
|
+
/** The own entry `key` of `catalog`; throws when `catalog` is `undefined` or `null`. */
|
|
16
|
+
const entry = (catalog, key) => Object.hasOwn(catalog, key) ? catalog[key] : undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the `t` of one language.
|
|
19
|
+
*
|
|
20
|
+
* Inputs: the chosen language tag, the catalogs and the default language. Output: `t(key, vars?)`, which
|
|
21
|
+
* returns the message of `locale`, else of `fallback`, else the key itself; a plural message gives
|
|
22
|
+
* the form `Intl.PluralRules` of `locale` selects for `vars.count` (`other` without a count or
|
|
23
|
+
* without that form), and each `{name}` with an own `vars` entry is replaced by it (numbers
|
|
24
|
+
* formatted for `locale`); an unknown placeholder stays as written. Errors: none: a malformed
|
|
25
|
+
* message from untyped code (no text `other`, not a text) counts as missing. Side effects: none.
|
|
26
|
+
*/
|
|
27
|
+
export function createTranslate(locale, messages, fallback) {
|
|
28
|
+
return (key, vars) => {
|
|
29
|
+
try {
|
|
30
|
+
// Throws without catalogs, or without the chosen one (only for untyped code): then the key.
|
|
31
|
+
const message = (entry(entry(messages, locale), key) ??
|
|
32
|
+
entry(entry(messages, fallback), key));
|
|
33
|
+
const plural = message;
|
|
34
|
+
// `select(undefined)` is "other"; a missing form falls back to `other`, a missing message
|
|
35
|
+
// or a form that is not text throws below and lands in the catch.
|
|
36
|
+
const text = typeof message === "string"
|
|
37
|
+
? message
|
|
38
|
+
: // Own forms only: a form inherited from a polluted Object.prototype never shows.
|
|
39
|
+
(entry(plural, new Intl.PluralRules(locale).select(vars?.["count"])) ??
|
|
40
|
+
plural.other);
|
|
41
|
+
return text.replace(PLACEHOLDER, (written, name) => {
|
|
42
|
+
const value = entry(vars ?? {}, name);
|
|
43
|
+
if (value === undefined)
|
|
44
|
+
return written;
|
|
45
|
+
// `replace` turns what the callback returns into text, whatever untyped code passed.
|
|
46
|
+
return typeof value === "number" ? formatNumber(locale, value) : value;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return key;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA4BhD,iDAAiD;AACjD,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC,wFAAwF;AACxF,MAAM,KAAK,GAAG,CAAC,OAAgB,EAAE,GAAW,EAAW,EAAE,CACvD,MAAM,CAAC,MAAM,CAAC,OAAiB,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,OAAmC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAEhG;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,QAAuB,EACvB,QAAgB;IAEhB,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACnB,IAAI,CAAC;YACH,4FAA4F;YAC5F,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC;gBAClD,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAY,CAAC;YACpD,MAAM,MAAM,GAAG,OAAwB,CAAC;YACxC,0FAA0F;YAC1F,kEAAkE;YAClE,MAAM,IAAI,GACR,OAAO,OAAO,KAAK,QAAQ;gBACzB,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,iFAAiF;oBAChF,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAW,CAAC,CAAC;wBAC7E,MAAM,CAAC,KAAK,CAAY,CAAC;YACjC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,IAAY,EAAE,EAAE;gBACzD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,IAAI,CAAoC,CAAC;gBACzE,IAAI,KAAK,KAAK,SAAS;oBAAE,OAAO,OAAO,CAAC;gBACxC,qFAAqF;gBACrF,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACzE,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/none.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `None` (TAG-202, moved here by TAG-203 so the data types can use it without importing
|
|
3
|
+
* `define-component.ts`): the empty declaration map. Types only.
|
|
4
|
+
*/
|
|
5
|
+
/** An empty declaration map: the type of `props`, `events`, `slots` or `data` when omitted. */
|
|
6
|
+
export type None = Readonly<Record<never, never>>;
|
|
7
|
+
//# sourceMappingURL=none.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"none.d.ts","sourceRoot":"","sources":["../src/none.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+FAA+F;AAE/F,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC"}
|
package/dist/none.js
ADDED
package/dist/none.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"none.js","sourceRoot":"","sources":["../src/none.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|