@tanqory/theme-kit 2.0.0-alpha.17 → 2.0.0-alpha.19

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 (92) hide show
  1. package/README.md +4 -1
  2. package/dist/abi/canvas-live.d.ts +7 -2
  3. package/dist/abi/canvas-live.js +8 -3
  4. package/dist/abi/cart.d.ts +5 -4
  5. package/dist/abi/cart.js +14 -5
  6. package/dist/abi/convert.d.ts +18 -2
  7. package/dist/abi/convert.js +56 -4
  8. package/dist/abi/data-api.js +4 -0
  9. package/dist/abi/page-data.d.ts +11 -3
  10. package/dist/abi/page-data.js +71 -3
  11. package/dist/abi/wire.d.ts +8 -0
  12. package/dist/abi/wire.js +32 -2
  13. package/dist/build.d.ts +7 -2
  14. package/dist/build.js +96 -5
  15. package/dist/chunks.d.ts +23 -0
  16. package/dist/chunks.js +41 -0
  17. package/dist/client.d.ts +7 -0
  18. package/dist/client.js +16 -2
  19. package/dist/headless/hooks.js +5 -1
  20. package/dist/headless/index.d.ts +8 -1
  21. package/dist/headless/index.js +11 -1
  22. package/dist/headless/lazy-component.d.ts +72 -0
  23. package/dist/headless/lazy-component.js +225 -0
  24. package/dist/headless/lazy-section.d.ts +38 -0
  25. package/dist/headless/lazy-section.js +97 -0
  26. package/dist/headless/model.d.ts +73 -0
  27. package/dist/headless/model.js +115 -0
  28. package/dist/headless/money.d.ts +1 -9
  29. package/dist/headless/money.js +24 -22
  30. package/dist/headless/page.d.ts +2 -0
  31. package/dist/headless/primitives/storefront.js +2 -1
  32. package/dist/headless/strings.js +8 -0
  33. package/dist/headless/tanqory-money.generated.d.ts +493 -0
  34. package/dist/headless/tanqory-money.generated.js +507 -0
  35. package/dist/headless/theme.d.ts +13 -3
  36. package/dist/headless/theme.js +12 -4
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.js +3 -0
  39. package/dist/runtime/data/StoreProvider.js +10 -3
  40. package/dist/runtime/data/to-ui.d.ts +12 -7
  41. package/dist/runtime/data/to-ui.js +48 -16
  42. package/dist/runtime/kit/cart.d.ts +10 -3
  43. package/dist/runtime/kit/contract/content.d.ts +14 -0
  44. package/dist/runtime/kit/contract/content.js +13 -0
  45. package/dist/runtime/kit/contract/field-types.d.ts +26 -3
  46. package/dist/runtime/kit/contract/field-types.js +11 -1
  47. package/dist/runtime/kit/contract/validate.d.ts +2 -0
  48. package/dist/runtime/kit/contract/validate.js +49 -9
  49. package/dist/runtime/kit/data.d.ts +12 -0
  50. package/dist/runtime/kit/data.js +36 -22
  51. package/dist/runtime/kit/dynamic-source.d.ts +12 -0
  52. package/dist/runtime/kit/dynamic-source.js +17 -0
  53. package/dist/runtime/kit/storefront.d.ts +14 -1
  54. package/dist/runtime/kit/types.d.ts +8 -0
  55. package/dist/runtime/render/SectionRenderer.js +44 -11
  56. package/dist/runtime/render/resolved.d.ts +47 -0
  57. package/dist/runtime/render/resolved.js +80 -0
  58. package/dist/runtime/render/section-actions.d.ts +2 -1
  59. package/dist/runtime/render/section-actions.js +4 -1
  60. package/dist/runtime/render/starter.js +19 -4
  61. package/dist/runtime/seo/head.d.ts +1 -1
  62. package/dist/runtime/shell/PageShell.js +6 -1
  63. package/dist/runtime/shell/RuntimeBridge.d.ts +4 -0
  64. package/dist/runtime/shell/RuntimeBridge.js +37 -6
  65. package/dist/runtime/slots.d.ts +1 -1
  66. package/dist/sdk/font-hooks.d.ts +7 -0
  67. package/dist/sdk/font-hooks.js +21 -0
  68. package/dist/sdk/fonts.d.ts +144 -0
  69. package/dist/sdk/fonts.js +241 -0
  70. package/dist/sdk/index.d.ts +7 -1
  71. package/dist/sdk/index.js +11 -1
  72. package/dist/sdk/motion-hooks.d.ts +23 -0
  73. package/dist/sdk/motion-hooks.js +46 -0
  74. package/dist/sdk/motion.d.ts +78 -0
  75. package/dist/sdk/motion.js +292 -0
  76. package/dist/sdk/runtime-context.d.ts +32 -4
  77. package/dist/sdk/schema.d.ts +47 -4
  78. package/dist/sdk/schema.js +47 -0
  79. package/dist/sdk/store-lookup.d.ts +5 -0
  80. package/dist/sdk/store-lookup.js +19 -0
  81. package/dist/sdk/store.d.ts +15 -0
  82. package/dist/sdk/sx.d.ts +5 -0
  83. package/dist/sdk/sx.js +7 -2
  84. package/dist/sdk/theme.d.ts +21 -0
  85. package/dist/sdk/theme.js +17 -0
  86. package/dist/sdk/types.d.ts +36 -4
  87. package/dist/server.d.ts +5 -4
  88. package/dist/server.js +76 -20
  89. package/dist/vite-chunks.d.ts +10 -0
  90. package/dist/vite-chunks.js +44 -0
  91. package/docs/headless-api.md +33 -3
  92. package/package.json +10 -18
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Fonts for a theme (TS-7, 2026-11-19): the platform catalogue first, a font the theme ships under assets/ second, the
3
+ * device's own faces third. One setting helper for each place a font is chosen, and one hook that makes the choice
4
+ * load:
5
+ *
6
+ * fontSetting({ label, default: 'Prompt' }) a theme setting (defineSettings): the editor's font picker
7
+ * field.font('Prompt', { label }) a section or block setting, the same picker
8
+ * const family = useFont(settings.headingFont) the CSS font-family stack, and the font loads
9
+ *
10
+ * Where each font comes from, and why no rule of the storefront has to change:
11
+ *
12
+ * catalogue The edge's same-origin `/_tq/fonts/*` (storefront-edge core/fonts-route.ts), which fetches Google Fonts
13
+ * (all SIL Open Font License) and rewrites every file URL to `/_tq/fonts/s/...`. The page never names
14
+ * another host. On the server the kit puts `@import url("/_tq/fonts/css2?...")` in its own inline
15
+ * `<style>`, which is announced by hash like every other block (theme-abi §5 `style-src-elem 'self'`);
16
+ * there is no `<link>`, so §10.2's "every `<link rel=stylesheet>` under assets.base with integrity"
17
+ * does not apply, and §10.5 allows a style request to same-origin `/_tq/*`. In the browser (a font the
18
+ * merchant picks on the editor canvas, which the server did not import) the kit reads the same CSS with
19
+ * `fetch` (connect-src 'self', §10.5 `/_tq/*`), keeps only `@font-face` rules whose every declaration
20
+ * matches a fixed grammar and whose `src` is a `/_tq/fonts/s/` file, and inserts the rebuilt rules into
21
+ * a constructed stylesheet (CSSOM, which CSP does not govern). A constructed sheet cannot `@import`:
22
+ * CSSOM §6.1.2 insertRule step 5 "If parsed rule is an @import rule, and the constructed flag is set,
23
+ * throw a SyntaxError", and replace()/replaceSync() drop them (read 2026-11-19), hence the fetch.
24
+ * theme A WOFF2 file the theme ships under assets/ (checked before the build, @tanqory/theme-standard
25
+ * woff2.js) with the theme's own `@font-face` in its CSS; the build serves it from the asset base as
26
+ * `font/woff2` (§5 `font-src`). The kit only names the family.
27
+ * system The device's faces (`system-sans`, `system-serif`, `system-mono`, `system-rounded`): nothing loads.
28
+ *
29
+ * Every family name the kit writes into CSS matches FAMILY_NAME (letters, digits, spaces, hyphens), so a value never
30
+ * leaves its declaration.
31
+ */
32
+ import type { SettingSpec } from './theme.js';
33
+ export type FontScript = 'latin' | 'thai';
34
+ export type FontFallback = 'sans-serif' | 'serif' | 'monospace';
35
+ /** A family of the platform catalogue (served by the edge's `/_tq/fonts`). */
36
+ export interface CatalogueFont {
37
+ readonly family: string;
38
+ /** The writing systems its files cover (the editor's font picker tags Thai). */
39
+ readonly scripts: readonly FontScript[];
40
+ readonly fallback: FontFallback;
41
+ }
42
+ /**
43
+ * The platform catalogue. Each family was requested through the Dev edge's `/_tq/fonts/css2` with weights 400-700 on
44
+ * 2026-11-19 and answered 200 `text/css` with `@font-face` rules and `font/woff2` files (scratchpad font-probe.sh).
45
+ * The Thai families are the ones Nova V3 offers (themes/nova-v3/src/styles/fonts.ts) plus Mitr.
46
+ */
47
+ export declare const FONT_CATALOGUE: readonly CatalogueFont[];
48
+ /** The weights the kit asks the catalogue for (every catalogue family has them; probed 2026-11-19). */
49
+ export declare const FONT_WEIGHTS: readonly [400, 500, 600, 700];
50
+ /** The device's own faces: the value is the id, the stack is what the page uses. The editor shows the same four. */
51
+ export declare const SYSTEM_FONTS: readonly [{
52
+ readonly value: "system-sans";
53
+ readonly label: "System sans-serif";
54
+ readonly stack: "system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif";
55
+ }, {
56
+ readonly value: "system-serif";
57
+ readonly label: "System serif";
58
+ readonly stack: "ui-serif, Georgia, \"Times New Roman\", serif";
59
+ }, {
60
+ readonly value: "system-mono";
61
+ readonly label: "System monospace";
62
+ readonly stack: "ui-monospace, \"SF Mono\", Menlo, Consolas, monospace";
63
+ }, {
64
+ readonly value: "system-rounded";
65
+ readonly label: "System rounded";
66
+ readonly stack: "ui-rounded, \"SF Pro Rounded\", system-ui, sans-serif";
67
+ }];
68
+ /** A family the theme ships itself: a WOFF2 under assets/ and an `@font-face` for `family` in the theme's CSS. */
69
+ export interface ThemeFont {
70
+ readonly family: string;
71
+ /** The picker's name for it; the family when absent. */
72
+ readonly label?: string;
73
+ readonly scripts?: readonly FontScript[];
74
+ readonly fallback?: FontFallback;
75
+ }
76
+ /** A family name the kit writes into CSS: what the edge's `/_tq/fonts` grammar allows for a name, nothing that quotes. */
77
+ export declare const FAMILY_NAME: RegExp;
78
+ /** Families in one `/_tq/fonts/css2` request at most (the edge's MAX_FAMILIES). */
79
+ export declare const FAMILIES_PER_REQUEST = 8;
80
+ export declare const FONTS_CSS_PATH = "/_tq/fonts/css2";
81
+ /** True when `family` is in the platform catalogue. */
82
+ export declare const isCatalogueFont: (family: unknown) => family is string;
83
+ /** One option of a font setting, with the editor's picker hints (`group`, `scripts`). */
84
+ export interface FontOption {
85
+ readonly value: string;
86
+ readonly label: string;
87
+ readonly group: 'Library' | 'Theme' | 'System' | 'Default';
88
+ readonly scripts?: readonly FontScript[];
89
+ }
90
+ export interface FontOptionsInput {
91
+ /** Fonts the theme ships (assets/*.woff2 + its own `@font-face`). */
92
+ readonly themeFonts?: readonly ThemeFont[];
93
+ /** Only these catalogue families (in this order); every family when absent. */
94
+ readonly catalogue?: readonly string[];
95
+ /** Offer the device's faces (default true). */
96
+ readonly system?: boolean;
97
+ /** An empty value ("not set") and its label, e.g. "Same as body font". */
98
+ readonly unset?: string;
99
+ }
100
+ /** The options of a font setting: the catalogue first, then the theme's own fonts, then the device's faces. */
101
+ export declare function fontOptions(input?: FontOptionsInput): FontOption[];
102
+ /**
103
+ * The CSS `font-family` value of a font setting's value: a catalogue or theme family with its fallback, a system face's
104
+ * stack; undefined for '' (not set) or anything else (a value no option offers is never written into CSS).
105
+ */
106
+ export declare function fontStack(value: unknown, themeFonts?: readonly ThemeFont[]): string | undefined;
107
+ /** The same-origin stylesheet URL(s) of catalogue families, at most FAMILIES_PER_REQUEST each. */
108
+ export declare function fontCssHrefs(families: Iterable<string>): string[];
109
+ /** The inline CSS the server emits for the catalogue families a render used: `@import` lines only. */
110
+ export declare function fontImportCss(families: Iterable<string>): string;
111
+ /** id of the server's `<style>` holding the page's font `@import`s. */
112
+ export declare const FONT_IMPORTS_ID = "tq-font-imports";
113
+ /**
114
+ * The `@font-face` rules of a `/_tq/fonts/css2` answer for `family`, rebuilt from declarations that each match DECL
115
+ * (and a `font-family` equal to `family`). A rule with any other declaration, or none of `src`, is dropped whole.
116
+ */
117
+ export declare function safeFontFaces(css: string, family: string): string[];
118
+ /** Loads a catalogue family in the browser when the page does not have it yet (no-op on the server and for others). */
119
+ export declare function loadCatalogueFont(family: string): Promise<boolean>;
120
+ /** For tests: forget what the browser loader has seen. */
121
+ export declare function resetFontLoader(): void;
122
+ /** The editor's picker hints of a font select: its group and scripts per option (the ABI manifest keeps value/label). */
123
+ export interface FontEditorHints {
124
+ readonly control: 'font';
125
+ readonly weight_setting?: string;
126
+ readonly options: Readonly<Record<string, {
127
+ readonly group: string;
128
+ readonly scripts?: readonly FontScript[];
129
+ }>>;
130
+ }
131
+ export declare const fontEditorHints: (options: readonly FontOption[], weightSetting?: string) => FontEditorHints;
132
+ export interface FontSettingInput extends FontOptionsInput {
133
+ readonly label: string;
134
+ readonly group?: string;
135
+ readonly info?: string;
136
+ /** A catalogue, theme or system value; the first catalogue family when absent ('' when `unset` is given). */
137
+ readonly default?: string;
138
+ /** The id of the select setting holding this font's weight (the picker sets both). */
139
+ readonly weightSetting?: string;
140
+ }
141
+ /** A theme setting (defineSettings) the editor draws as its font picker: the catalogue, the theme's fonts, the device's. */
142
+ export declare function fontSetting(input: FontSettingInput): SettingSpec;
143
+ /** What a font select may hold: '' (when offered), a catalogue family, a system face, or a theme family name. */
144
+ export declare function fontValueProblem(value: string, themeFamilies: ReadonlySet<string>): string | null;
@@ -0,0 +1,241 @@
1
+ /**
2
+ * The platform catalogue. Each family was requested through the Dev edge's `/_tq/fonts/css2` with weights 400-700 on
3
+ * 2026-11-19 and answered 200 `text/css` with `@font-face` rules and `font/woff2` files (scratchpad font-probe.sh).
4
+ * The Thai families are the ones Nova V3 offers (themes/nova-v3/src/styles/fonts.ts) plus Mitr.
5
+ */
6
+ export const FONT_CATALOGUE = Object.freeze([
7
+ { family: 'Noto Sans Thai', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
8
+ { family: 'Noto Serif Thai', scripts: ['thai', 'latin'], fallback: 'serif' },
9
+ { family: 'IBM Plex Sans Thai', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
10
+ { family: 'Sarabun', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
11
+ { family: 'Prompt', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
12
+ { family: 'Kanit', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
13
+ { family: 'Anuphan', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
14
+ { family: 'Mitr', scripts: ['thai', 'latin'], fallback: 'sans-serif' },
15
+ { family: 'Geist', scripts: ['latin'], fallback: 'sans-serif' },
16
+ { family: 'Inter', scripts: ['latin'], fallback: 'sans-serif' },
17
+ { family: 'DM Sans', scripts: ['latin'], fallback: 'sans-serif' },
18
+ { family: 'Space Grotesk', scripts: ['latin'], fallback: 'sans-serif' },
19
+ { family: 'Fraunces', scripts: ['latin'], fallback: 'serif' },
20
+ { family: 'Playfair Display', scripts: ['latin'], fallback: 'serif' },
21
+ { family: 'Lora', scripts: ['latin'], fallback: 'serif' },
22
+ { family: 'Libre Baskerville', scripts: ['latin'], fallback: 'serif' },
23
+ { family: 'Geist Mono', scripts: ['latin'], fallback: 'monospace' },
24
+ ].map((f) => Object.freeze({ ...f, scripts: Object.freeze([...f.scripts]) })));
25
+ /** The weights the kit asks the catalogue for (every catalogue family has them; probed 2026-11-19). */
26
+ export const FONT_WEIGHTS = Object.freeze([400, 500, 600, 700]);
27
+ /** The device's own faces: the value is the id, the stack is what the page uses. The editor shows the same four. */
28
+ export const SYSTEM_FONTS = Object.freeze([
29
+ { value: 'system-sans', label: 'System sans-serif', stack: 'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif' },
30
+ { value: 'system-serif', label: 'System serif', stack: 'ui-serif, Georgia, "Times New Roman", serif' },
31
+ { value: 'system-mono', label: 'System monospace', stack: 'ui-monospace, "SF Mono", Menlo, Consolas, monospace' },
32
+ { value: 'system-rounded', label: 'System rounded', stack: 'ui-rounded, "SF Pro Rounded", system-ui, sans-serif' },
33
+ ]);
34
+ /** A family name the kit writes into CSS: what the edge's `/_tq/fonts` grammar allows for a name, nothing that quotes. */
35
+ export const FAMILY_NAME = /^[A-Za-z0-9][A-Za-z0-9 -]{0,63}$/;
36
+ /** Families in one `/_tq/fonts/css2` request at most (the edge's MAX_FAMILIES). */
37
+ export const FAMILIES_PER_REQUEST = 8;
38
+ export const FONTS_CSS_PATH = '/_tq/fonts/css2';
39
+ const BY_FAMILY = new Map(FONT_CATALOGUE.map((f) => [f.family, f]));
40
+ const SYSTEM = new Map(SYSTEM_FONTS.map((f) => [f.value, f.stack]));
41
+ /** True when `family` is in the platform catalogue. */
42
+ export const isCatalogueFont = (family) => typeof family === 'string' && BY_FAMILY.has(family);
43
+ /** The options of a font setting: the catalogue first, then the theme's own fonts, then the device's faces. */
44
+ export function fontOptions(input = {}) {
45
+ const out = [];
46
+ if (input.unset)
47
+ out.push({ value: '', label: input.unset, group: 'Default' });
48
+ const families = input.catalogue ?? FONT_CATALOGUE.map((f) => f.family);
49
+ for (const family of families) {
50
+ const f = BY_FAMILY.get(family);
51
+ if (!f)
52
+ throw new Error(`fontOptions: "${family}" is not in the platform catalogue (FONT_CATALOGUE)`);
53
+ out.push({ value: f.family, label: f.family, group: 'Library', scripts: f.scripts });
54
+ }
55
+ for (const t of input.themeFonts ?? []) {
56
+ if (!FAMILY_NAME.test(t.family))
57
+ throw new Error(`fontOptions: theme font "${t.family}": a family name is letters, digits, spaces and hyphens`);
58
+ if (BY_FAMILY.has(t.family) || SYSTEM.has(t.family))
59
+ throw new Error(`fontOptions: theme font "${t.family}" has the name of a catalogue or system font`);
60
+ out.push({ value: t.family, label: t.label ?? t.family, group: 'Theme', ...(t.scripts ? { scripts: t.scripts } : {}) });
61
+ }
62
+ if (input.system !== false)
63
+ for (const s of SYSTEM_FONTS)
64
+ out.push({ value: s.value, label: s.label, group: 'System' });
65
+ const seen = new Set();
66
+ for (const o of out) {
67
+ if (seen.has(o.value))
68
+ throw new Error(`fontOptions: "${o.value}" is offered twice`);
69
+ seen.add(o.value);
70
+ }
71
+ return out;
72
+ }
73
+ const quoted = (family) => `"${family}"`;
74
+ /**
75
+ * The CSS `font-family` value of a font setting's value: a catalogue or theme family with its fallback, a system face's
76
+ * stack; undefined for '' (not set) or anything else (a value no option offers is never written into CSS).
77
+ */
78
+ export function fontStack(value, themeFonts = []) {
79
+ if (typeof value !== 'string' || value === '')
80
+ return undefined;
81
+ const system = SYSTEM.get(value);
82
+ if (system)
83
+ return system;
84
+ const c = BY_FAMILY.get(value);
85
+ if (c)
86
+ return `${quoted(c.family)}, ${c.fallback}`;
87
+ const t = themeFonts.find((f) => f.family === value);
88
+ if (t && FAMILY_NAME.test(t.family))
89
+ return `${quoted(t.family)}, ${t.fallback ?? 'sans-serif'}`;
90
+ return undefined;
91
+ }
92
+ /** The same-origin stylesheet URL(s) of catalogue families, at most FAMILIES_PER_REQUEST each. */
93
+ export function fontCssHrefs(families) {
94
+ const list = [...new Set([...families].filter((f) => BY_FAMILY.has(f)))].sort();
95
+ const out = [];
96
+ for (let i = 0; i < list.length; i += FAMILIES_PER_REQUEST) {
97
+ const q = list.slice(i, i + FAMILIES_PER_REQUEST).map((f) => `family=${f.replace(/ /g, '+')}:wght@${FONT_WEIGHTS.join(';')}`);
98
+ out.push(`${FONTS_CSS_PATH}?${q.join('&')}&display=swap`);
99
+ }
100
+ return out;
101
+ }
102
+ /** The inline CSS the server emits for the catalogue families a render used: `@import` lines only. */
103
+ export function fontImportCss(families) {
104
+ return fontCssHrefs(families).map((h) => `@import url("${h}");`).join('');
105
+ }
106
+ /** id of the server's `<style>` holding the page's font `@import`s. */
107
+ export const FONT_IMPORTS_ID = 'tq-font-imports';
108
+ // ── browser: a catalogue family the server did not import ─────────────────────────────────────────────────────────
109
+ const DECL = {
110
+ 'font-style': /^(normal|italic)$/,
111
+ 'font-weight': /^[1-9]00( [1-9]00)?$/,
112
+ 'font-display': /^(auto|block|swap|fallback|optional)$/,
113
+ 'font-stretch': /^[0-9]{1,3}%( [0-9]{1,3}%)?$/,
114
+ src: /^url\(\/_tq\/fonts\/s\/[a-z0-9]+\/v[0-9]+\/[A-Za-z0-9_-]+(\.[0-9]{1,3})?\.(woff2|woff|ttf)\) format\('(woff2|woff|truetype)'\)$/,
115
+ 'unicode-range': /^U\+[0-9A-Fa-f?]{1,6}(-[0-9A-Fa-f]{1,6})?(, U\+[0-9A-Fa-f?]{1,6}(-[0-9A-Fa-f]{1,6})?)*$/,
116
+ };
117
+ /**
118
+ * The `@font-face` rules of a `/_tq/fonts/css2` answer for `family`, rebuilt from declarations that each match DECL
119
+ * (and a `font-family` equal to `family`). A rule with any other declaration, or none of `src`, is dropped whole.
120
+ */
121
+ export function safeFontFaces(css, family) {
122
+ if (!BY_FAMILY.has(family) || css.length > 256 * 1024)
123
+ return [];
124
+ const out = [];
125
+ for (const m of css.replace(/\/\*[^*]*\*\//g, '').matchAll(/@font-face\s*\{([^{}]*)\}/g)) {
126
+ const decls = [];
127
+ let ok = true;
128
+ let named = false;
129
+ let src = false;
130
+ for (const part of m[1].split(';')) {
131
+ const d = part.trim();
132
+ if (!d)
133
+ continue;
134
+ const at = d.indexOf(':');
135
+ if (at < 0) {
136
+ ok = false;
137
+ break;
138
+ }
139
+ const prop = d.slice(0, at).trim().toLowerCase();
140
+ const value = d.slice(at + 1).trim();
141
+ if (prop === 'font-family') {
142
+ if (value !== `'${family}'` && value !== `"${family}"`) {
143
+ ok = false;
144
+ break;
145
+ }
146
+ named = true;
147
+ decls.push(`font-family:${quoted(family)}`);
148
+ continue;
149
+ }
150
+ const re = DECL[prop];
151
+ if (!re || !re.test(value)) {
152
+ ok = false;
153
+ break;
154
+ }
155
+ if (prop === 'src')
156
+ src = true;
157
+ decls.push(`${prop}:${value}`);
158
+ }
159
+ if (ok && named && src)
160
+ out.push(`@font-face{${decls.join(';')}}`);
161
+ }
162
+ return out;
163
+ }
164
+ let loaded = null;
165
+ let sheet = null;
166
+ function serverImported() {
167
+ const s = new Set();
168
+ const text = typeof document === 'undefined' ? '' : (document.getElementById(FONT_IMPORTS_ID)?.textContent ?? '');
169
+ for (const m of text.matchAll(/family=([A-Za-z0-9+ -]+):/g))
170
+ s.add(m[1].replace(/\+/g, ' '));
171
+ return s;
172
+ }
173
+ /** Loads a catalogue family in the browser when the page does not have it yet (no-op on the server and for others). */
174
+ export async function loadCatalogueFont(family) {
175
+ if (typeof document === 'undefined' || typeof fetch !== 'function' || !BY_FAMILY.has(family))
176
+ return false;
177
+ loaded ??= serverImported();
178
+ if (loaded.has(family))
179
+ return true;
180
+ loaded.add(family);
181
+ try {
182
+ const res = await fetch(fontCssHrefs([family])[0], { credentials: 'same-origin' });
183
+ if (!res.ok || !/^text\/css\b/i.test(res.headers.get('content-type') ?? ''))
184
+ return false;
185
+ const rules = safeFontFaces(await res.text(), family);
186
+ if (!rules.length)
187
+ return false;
188
+ if (!sheet && typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in document) {
189
+ sheet = new CSSStyleSheet();
190
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
191
+ }
192
+ if (!sheet)
193
+ return false;
194
+ for (const r of rules) {
195
+ try {
196
+ sheet.insertRule(r, sheet.cssRules.length);
197
+ }
198
+ catch {
199
+ /* a rule the browser rejects is not applied */
200
+ }
201
+ }
202
+ return true;
203
+ }
204
+ catch {
205
+ loaded.delete(family);
206
+ return false;
207
+ }
208
+ }
209
+ /** For tests: forget what the browser loader has seen. */
210
+ export function resetFontLoader() {
211
+ loaded = null;
212
+ sheet = null;
213
+ }
214
+ export const fontEditorHints = (options, weightSetting) => ({
215
+ control: 'font',
216
+ ...(weightSetting ? { weight_setting: weightSetting } : {}),
217
+ options: Object.fromEntries(options.map((o) => [o.value, { group: o.group, ...(o.scripts ? { scripts: o.scripts } : {}) }])),
218
+ });
219
+ /** A theme setting (defineSettings) the editor draws as its font picker: the catalogue, the theme's fonts, the device's. */
220
+ export function fontSetting(input) {
221
+ const options = fontOptions(input);
222
+ const def = input.default ?? (input.unset ? '' : options.find((o) => o.group === 'Library')?.value ?? options[0].value);
223
+ if (!options.some((o) => o.value === def))
224
+ throw new Error(`fontSetting: the default "${def}" is not one of its options`);
225
+ return {
226
+ type: 'select',
227
+ control: 'font',
228
+ ...(input.weightSetting ? { weight_setting: input.weightSetting } : {}),
229
+ label: input.label,
230
+ ...(input.group ? { group: input.group } : {}),
231
+ ...(input.info ? { info: input.info } : {}),
232
+ default: def,
233
+ options: options.map((o) => ({ value: o.value, label: o.label, group: o.group, ...(o.scripts ? { scripts: o.scripts } : {}) })),
234
+ };
235
+ }
236
+ /** What a font select may hold: '' (when offered), a catalogue family, a system face, or a theme family name. */
237
+ export function fontValueProblem(value, themeFamilies) {
238
+ if (value === '' || BY_FAMILY.has(value) || SYSTEM.has(value) || themeFamilies.has(value))
239
+ return null;
240
+ return FAMILY_NAME.test(value) ? `"${value}" is neither a catalogue font, a system face nor one of the theme's fonts` : `"${value}" is not a font family name (letters, digits, spaces, hyphens)`;
241
+ }
@@ -7,8 +7,9 @@
7
7
  * types Product, Collection, Cart, Menu, … — the data a theme renders
8
8
  * rewards useRewards(), earnPoints(): the store's loyalty program, browser-only
9
9
  * referrals useReferrals(), shareTargets(): the shopper's referral link and the friend offer, browser-only
10
- * store StoreContext + imageFor / menuFor / collectionFor / productFor … —
10
+ * store StoreContext + imageFor / menuFor / collectionFor / productFor / productsFor … —
11
11
  * read what the runtime put in the context
12
+ * sources useSourceText(): text that names dynamic sources, read against the page's resources
12
13
  *
13
14
  * Nothing here fetches or knows how the platform works.
14
15
  */
@@ -24,3 +25,8 @@ export { ServerRenderProvider, useServerRender } from './server-render.js';
24
25
  export * from './rewards.js';
25
26
  export * from './referrals.js';
26
27
  export { sx, cx as sxJoin, collectStyles, STYLE_RULES_ID } from './sx.js';
28
+ export { setCssVars, cssVarValue, prefersReducedMotion, onReducedMotionChange, reveal, exit, scrollProgress, presetFrames, type CssVars, type MotionPreset, type MotionOptions, type RevealOptions, type ScrollProgressOptions } from './motion.js';
29
+ export { useCssVars, useReducedMotion, useReveal, useScrollProgress } from './motion-hooks.js';
30
+ export { FONT_CATALOGUE, SYSTEM_FONTS, FONT_WEIGHTS, FONT_IMPORTS_ID, fontSetting, fontOptions, fontStack, fontCssHrefs, fontImportCss, safeFontFaces, loadCatalogueFont, isCatalogueFont, type CatalogueFont, type ThemeFont, type FontOption, type FontScript, type FontSettingInput, type FontEditorHints } from './fonts.js';
31
+ export { useFont } from './font-hooks.js';
32
+ export { sourceText, useSourceText } from '../runtime/kit/dynamic-source.js';
package/dist/sdk/index.js CHANGED
@@ -7,8 +7,9 @@
7
7
  * types Product, Collection, Cart, Menu, … — the data a theme renders
8
8
  * rewards useRewards(), earnPoints(): the store's loyalty program, browser-only
9
9
  * referrals useReferrals(), shareTargets(): the shopper's referral link and the friend offer, browser-only
10
- * store StoreContext + imageFor / menuFor / collectionFor / productFor … —
10
+ * store StoreContext + imageFor / menuFor / collectionFor / productFor / productsFor … —
11
11
  * read what the runtime put in the context
12
+ * sources useSourceText(): text that names dynamic sources, read against the page's resources
12
13
  *
13
14
  * Nothing here fetches or knows how the platform works.
14
15
  */
@@ -24,3 +25,12 @@ export { ServerRenderProvider, useServerRender } from './server-render.js';
24
25
  export * from './rewards.js';
25
26
  export * from './referrals.js';
26
27
  export { sx, cx as sxJoin, collectStyles, STYLE_RULES_ID } from './sx.js';
28
+ // Continuous values (CSS custom properties through the CSSOM) and motion (Web Animations, scroll progress), with
29
+ // prefers-reduced-motion honoured. Browser-only; no-ops on the server.
30
+ export { setCssVars, cssVarValue, prefersReducedMotion, onReducedMotionChange, reveal, exit, scrollProgress, presetFrames } from './motion.js';
31
+ export { useCssVars, useReducedMotion, useReveal, useScrollProgress } from './motion-hooks.js';
32
+ // Fonts: the platform catalogue (same-origin /_tq/fonts), a theme's own assets/*.woff2, the device's faces.
33
+ export { FONT_CATALOGUE, SYSTEM_FONTS, FONT_WEIGHTS, FONT_IMPORTS_ID, fontSetting, fontOptions, fontStack, fontCssHrefs, fontImportCss, safeFontFaces, loadCatalogueFont, isCatalogueFont } from './fonts.js';
34
+ export { useFont } from './font-hooks.js';
35
+ // Text that names dynamic sources (`{{ product.title }}`) read against the page's resources.
36
+ export { sourceText, useSourceText } from '../runtime/kit/dynamic-source.js';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * React hooks over `motion.ts`: each runs in an effect only (never during the server render, so nothing of it is in the
3
+ * server HTML), and undoes itself when the component unmounts or its inputs change.
4
+ *
5
+ * const ref = useRef<HTMLDivElement>(null)
6
+ * useReveal(ref, { preset: 'fade-up' })
7
+ * useScrollProgress(ref, { cssVar: '--tq-progress' }) // CSS: transform: translateY(calc(var(--tq-progress) * -40px))
8
+ * useCssVars(ref, { '--drag-x': x }) // a value that changes every frame
9
+ */
10
+ import { type RefObject } from 'react';
11
+ import { type CssVars, type RevealOptions, type ScrollProgressOptions } from './motion.js';
12
+ /** Custom properties of the element, written after each render that changes them (setCssVars). */
13
+ export declare function useCssVars(ref: RefObject<Element | null>, vars: CssVars): void;
14
+ /** The shopper's reduced-motion setting, following changes; false on the server and on the first render. */
15
+ export declare function useReducedMotion(): boolean;
16
+ /** The element fades or slides in when it comes on screen (reveal). */
17
+ export declare function useReveal(ref: RefObject<Element | null>, o?: RevealOptions): void;
18
+ /**
19
+ * How far the element has travelled through the screen (0 to 1, scrollProgress). With `cssVar` the value is written to
20
+ * that custom property and the hook answers nothing that re-renders (the cheap way: CSS reads the variable); without it,
21
+ * the value is React state, updated at most once a frame.
22
+ */
23
+ export declare function useScrollProgress(ref: RefObject<Element | null>, o?: ScrollProgressOptions): number | null;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * React hooks over `motion.ts`: each runs in an effect only (never during the server render, so nothing of it is in the
3
+ * server HTML), and undoes itself when the component unmounts or its inputs change.
4
+ *
5
+ * const ref = useRef<HTMLDivElement>(null)
6
+ * useReveal(ref, { preset: 'fade-up' })
7
+ * useScrollProgress(ref, { cssVar: '--tq-progress' }) // CSS: transform: translateY(calc(var(--tq-progress) * -40px))
8
+ * useCssVars(ref, { '--drag-x': x }) // a value that changes every frame
9
+ */
10
+ import { useEffect, useState } from 'react';
11
+ import { onReducedMotionChange, prefersReducedMotion, reveal, scrollProgress, setCssVars } from './motion.js';
12
+ /** Custom properties of the element, written after each render that changes them (setCssVars). */
13
+ export function useCssVars(ref, vars) {
14
+ const key = JSON.stringify(vars);
15
+ useEffect(() => {
16
+ setCssVars(ref.current, vars);
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
18
+ }, [ref, key]);
19
+ }
20
+ /** The shopper's reduced-motion setting, following changes; false on the server and on the first render. */
21
+ export function useReducedMotion() {
22
+ const [reduce, setReduce] = useState(false);
23
+ useEffect(() => {
24
+ setReduce(prefersReducedMotion());
25
+ return onReducedMotionChange(setReduce);
26
+ }, []);
27
+ return reduce;
28
+ }
29
+ /** The element fades or slides in when it comes on screen (reveal). */
30
+ export function useReveal(ref, o = {}) {
31
+ const key = JSON.stringify(o);
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ useEffect(() => reveal(ref.current, o), [ref, key]);
34
+ }
35
+ /**
36
+ * How far the element has travelled through the screen (0 to 1, scrollProgress). With `cssVar` the value is written to
37
+ * that custom property and the hook answers nothing that re-renders (the cheap way: CSS reads the variable); without it,
38
+ * the value is React state, updated at most once a frame.
39
+ */
40
+ export function useScrollProgress(ref, o = {}) {
41
+ const [p, setP] = useState(null);
42
+ const key = JSON.stringify(o);
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ useEffect(() => scrollProgress(ref.current, o.cssVar ? null : setP, o), [ref, key]);
45
+ return o.cssVar ? null : p;
46
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Continuous values and motion for themes, under the platform CSP (theme-abi §5: `style-src-attr 'none'`, no
3
+ * 'unsafe-inline', script CSP unchanged).
4
+ *
5
+ * CSS VARIABLES. A value that changes with every scroll or drag frame cannot be a class (`sx()` makes one class per
6
+ * value). `setCssVars(el, { '--progress': 0.42 })` writes custom properties through the CSSOM
7
+ * (`CSSStyleDeclaration.setProperty`). CSP governs style *attributes* the parser reads from markup and `<style>`
8
+ * elements; it does not govern the CSSOM: CSP Level 2 §7.16 and CSP Level 3 §6.1.15 (`style-src-attr` "governs the
9
+ * behaviour of style attributes") restrict a style attribute the user agent would apply from the document, and the only
10
+ * CSSOM gating either spec names is `cssText` setters and `insertRule` under `'unsafe-eval'` (CSP3 §6.1.13 item 4,
11
+ * CSP2 §7.16; an editor's note there, which browsers do not apply). `setProperty` is neither, and this module never
12
+ * uses `cssText`, `insertRule` or `setAttribute('style')`.
13
+ * Checked in Chromium 148 and WebKit 26.4 under the storefront's own policy (2026-11-19): `setProperty('--w', '42px')`
14
+ * applies; a `style` attribute in markup or set with `setAttribute` is refused. A variable is never in the server HTML
15
+ * (where it would be a refused attribute): only browser code calls this, and only names that start with `--`.
16
+ *
17
+ * MOTION. `reveal()` (an element entering the screen) and `exit()` (leaving, before it is removed) run on the Web
18
+ * Animations API (`Element.animate`), which writes no attribute at all; `scrollProgress()` reports how far an element
19
+ * has travelled through the screen, for scroll-linked effects, and can write it to a variable. Everything honours
20
+ * `prefers-reduced-motion: reduce` (Media Queries Level 5 §11.6): no movement, only the end state (a reveal shows at
21
+ * once, an exit removes at once), and scroll-linked values still report (the theme decides what they do) unless the
22
+ * caller asks for `staticWhenReduced`. Every function is a no-op on the server.
23
+ */
24
+ /** The string a variable is set to, or null when the value is refused (valueScan). */
25
+ export declare function cssVarValue(value: unknown): string | null;
26
+ export type CssVars = Readonly<Record<string, number | string | null | undefined>>;
27
+ /**
28
+ * Set (or, with null / undefined, remove) custom properties on an element, in one frame. A name that is not a custom
29
+ * property or a value the grammar refuses is skipped, never escaped into place. Answers the names written.
30
+ */
31
+ export declare function setCssVars(el: Element | null | undefined, vars: CssVars): string[];
32
+ /** The shopper asked for less motion (their system setting). false on the server. */
33
+ export declare function prefersReducedMotion(): boolean;
34
+ /** Calls `cb` when the setting changes; answers the function that stops it. */
35
+ export declare function onReducedMotionChange(cb: (reduce: boolean) => void): () => void;
36
+ export type MotionPreset = 'fade' | 'fade-up' | 'fade-down' | 'slide-left' | 'slide-right' | 'scale';
37
+ export interface MotionOptions {
38
+ preset?: MotionPreset;
39
+ /** ms, 0 to 2000. Default 500 (a reveal) and 250 (an exit). */
40
+ duration?: number;
41
+ /** ms, 0 to 2000. */
42
+ delay?: number;
43
+ /** A CSS easing; default the platform's `cubic-bezier(.2,.7,.2,1)`. */
44
+ easing?: string;
45
+ /** How far a slide or fade-up moves, in px (0 to 200). Default 24. */
46
+ distance?: number;
47
+ }
48
+ export interface RevealOptions extends MotionOptions {
49
+ /** The part of the element that must be on screen, 0 to 1. Default 0.15. */
50
+ threshold?: number;
51
+ /** Reveal once (default), or every time it comes back on screen. */
52
+ once?: boolean;
53
+ }
54
+ /** The keyframes of a preset, from hidden to shown. */
55
+ export declare function presetFrames(preset?: MotionPreset, distance?: number): Keyframe[];
56
+ /**
57
+ * Fades or slides an element in when it comes on screen (IntersectionObserver), with the Web Animations API. Reduced
58
+ * motion: it is shown at once. Answers the function that stops watching. An element that is never on screen stays as
59
+ * the theme's CSS draws it (the animation's first frame is applied only when it runs), so no content is hidden for good.
60
+ */
61
+ export declare function reveal(el: Element | null | undefined, o?: RevealOptions): () => void;
62
+ /**
63
+ * Plays an element's exit (the preset backwards) and resolves when it is done, so the caller can remove it then (a
64
+ * drawer, a toast, a dismissed card). Reduced motion or no Web Animations: resolves at once.
65
+ */
66
+ export declare function exit(el: Element | null | undefined, o?: MotionOptions): Promise<void>;
67
+ export interface ScrollProgressOptions {
68
+ /** Also write the progress (0 to 1, 4 decimals) to this custom property of the element, e.g. `--tq-progress`. */
69
+ cssVar?: string;
70
+ /** With reduced motion: report 1 once and stop (the end state), instead of following the scroll. */
71
+ staticWhenReduced?: boolean;
72
+ }
73
+ /**
74
+ * How far an element has travelled through the screen: 0 when its top meets the bottom of the screen, 1 when its bottom
75
+ * leaves the top (the same range as CSS `view()` timelines, Scroll-driven Animations §3.2). Computed at most once a
76
+ * frame, only while the element is near the screen. Answers the function that stops it.
77
+ */
78
+ export declare function scrollProgress(el: Element | null | undefined, cb: ((progress: number) => void) | null, o?: ScrollProgressOptions): () => void;