@tanqory/theme-kit 0.1.0 → 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 (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -10
  3. package/dist/abi/canvas-live.d.ts +72 -0
  4. package/dist/abi/canvas-live.js +159 -0
  5. package/dist/abi/cart.d.ts +60 -0
  6. package/dist/abi/cart.js +396 -0
  7. package/dist/abi/convert.d.ts +360 -0
  8. package/dist/abi/convert.js +1330 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +213 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/labels.d.ts +3 -0
  14. package/dist/abi/labels.js +34 -0
  15. package/dist/abi/page-data.d.ts +264 -0
  16. package/dist/abi/page-data.js +746 -0
  17. package/dist/abi/page.d.ts +28 -0
  18. package/dist/abi/page.js +57 -0
  19. package/dist/abi/referrals.d.ts +23 -0
  20. package/dist/abi/referrals.js +89 -0
  21. package/dist/abi/rewards.d.ts +27 -0
  22. package/dist/abi/rewards.js +82 -0
  23. package/dist/abi/seo.d.ts +47 -0
  24. package/dist/abi/seo.js +68 -0
  25. package/dist/abi/shell.d.ts +23 -0
  26. package/dist/abi/shell.js +10 -0
  27. package/dist/abi/state-pack.d.ts +17 -0
  28. package/dist/abi/state-pack.js +43 -0
  29. package/dist/abi/wire.d.ts +46 -0
  30. package/dist/abi/wire.js +114 -0
  31. package/dist/build.d.ts +121 -0
  32. package/dist/build.js +401 -0
  33. package/dist/chunks.d.ts +23 -0
  34. package/dist/chunks.js +41 -0
  35. package/dist/client.d.ts +26 -0
  36. package/dist/client.js +101 -0
  37. package/dist/contract.d.ts +6 -0
  38. package/dist/contract.js +6 -0
  39. package/dist/headless/ai.d.ts +132 -0
  40. package/dist/headless/ai.js +99 -0
  41. package/dist/headless/hooks.d.ts +276 -0
  42. package/dist/headless/hooks.js +544 -0
  43. package/dist/headless/i18n.d.ts +13 -0
  44. package/dist/headless/i18n.js +45 -0
  45. package/dist/headless/index.d.ts +44 -0
  46. package/dist/headless/index.js +48 -0
  47. package/dist/headless/lazy-component.d.ts +72 -0
  48. package/dist/headless/lazy-component.js +225 -0
  49. package/dist/headless/lazy-section.d.ts +38 -0
  50. package/dist/headless/lazy-section.js +97 -0
  51. package/dist/headless/model.d.ts +73 -0
  52. package/dist/headless/model.js +115 -0
  53. package/dist/headless/money.d.ts +17 -0
  54. package/dist/headless/money.js +63 -0
  55. package/dist/headless/page.d.ts +45 -0
  56. package/dist/headless/page.js +53 -0
  57. package/dist/headless/platform.d.ts +55 -0
  58. package/dist/headless/platform.js +77 -0
  59. package/dist/headless/primitives/cart.d.ts +90 -0
  60. package/dist/headless/primitives/cart.js +153 -0
  61. package/dist/headless/primitives/collection.d.ts +68 -0
  62. package/dist/headless/primitives/collection.js +80 -0
  63. package/dist/headless/primitives/product.d.ts +101 -0
  64. package/dist/headless/primitives/product.js +117 -0
  65. package/dist/headless/primitives/storefront.d.ts +106 -0
  66. package/dist/headless/primitives/storefront.js +187 -0
  67. package/dist/headless/primitives/util.d.ts +19 -0
  68. package/dist/headless/primitives/util.js +42 -0
  69. package/dist/headless/strings.d.ts +9 -0
  70. package/dist/headless/strings.js +198 -0
  71. package/dist/headless/structured-data.d.ts +31 -0
  72. package/dist/headless/structured-data.js +57 -0
  73. package/dist/headless/tanqory-money.generated.d.ts +493 -0
  74. package/dist/headless/tanqory-money.generated.js +507 -0
  75. package/dist/headless/theme.d.ts +109 -0
  76. package/dist/headless/theme.js +62 -0
  77. package/dist/index.d.ts +21 -0
  78. package/dist/index.js +21 -553
  79. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  80. package/dist/runtime/data/StoreProvider.js +380 -0
  81. package/dist/runtime/data/handle.d.ts +14 -0
  82. package/dist/runtime/data/handle.js +16 -0
  83. package/dist/runtime/data/routes.d.ts +87 -0
  84. package/dist/runtime/data/routes.js +158 -0
  85. package/dist/runtime/data/to-ui.d.ts +286 -0
  86. package/dist/runtime/data/to-ui.js +1009 -0
  87. package/dist/runtime/entries/register.d.ts +9 -0
  88. package/dist/runtime/entries/register.js +9 -0
  89. package/dist/runtime/entries/sections.d.ts +16 -0
  90. package/dist/runtime/entries/sections.js +19 -0
  91. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  92. package/dist/runtime/kit/SectionTree.js +100 -0
  93. package/dist/runtime/kit/analytics.d.ts +63 -0
  94. package/dist/runtime/kit/analytics.js +250 -0
  95. package/dist/runtime/kit/cart.d.ts +222 -0
  96. package/dist/runtime/kit/cart.js +545 -0
  97. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  98. package/dist/runtime/kit/composition.js +3 -0
  99. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  100. package/dist/runtime/kit/config.js +6 -0
  101. package/dist/runtime/kit/consent.d.ts +29 -0
  102. package/dist/runtime/kit/consent.js +159 -0
  103. package/dist/runtime/kit/contract/content.d.ts +213 -0
  104. package/dist/runtime/kit/contract/content.js +119 -0
  105. package/dist/runtime/kit/contract/field-types.d.ts +360 -0
  106. package/dist/runtime/kit/contract/field-types.js +216 -0
  107. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  108. package/dist/runtime/kit/contract/groups.js +402 -0
  109. package/dist/runtime/kit/contract/index.d.ts +33 -0
  110. package/dist/runtime/kit/contract/index.js +33 -0
  111. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  112. package/dist/runtime/kit/contract/transform.js +133 -0
  113. package/dist/runtime/kit/contract/validate.d.ts +77 -0
  114. package/dist/runtime/kit/contract/validate.js +520 -0
  115. package/dist/runtime/kit/data.d.ts +732 -0
  116. package/dist/runtime/kit/data.js +1131 -0
  117. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  118. package/dist/runtime/kit/defineSection.js +10 -0
  119. package/dist/runtime/kit/dynamic-source.d.ts +118 -0
  120. package/dist/runtime/kit/dynamic-source.js +311 -0
  121. package/dist/runtime/kit/index.d.ts +24 -0
  122. package/dist/runtime/kit/index.js +24 -0
  123. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  124. package/dist/runtime/kit/jsx-to-json.js +28 -0
  125. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  126. package/dist/runtime/kit/mount.js +124 -0
  127. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  128. package/dist/runtime/kit/registry.js +12 -0
  129. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  130. package/dist/runtime/kit/ssg.js +56 -0
  131. package/dist/runtime/kit/storefront.d.ts +652 -0
  132. package/dist/runtime/kit/storefront.js +723 -0
  133. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  134. package/dist/runtime/kit/theme-context.js +25 -0
  135. package/dist/runtime/kit/types.d.ts +155 -0
  136. package/dist/runtime/kit/types.js +1 -0
  137. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  138. package/dist/runtime/platform/TrackingPixels.js +63 -0
  139. package/dist/runtime/platform/environment.d.ts +68 -0
  140. package/dist/runtime/platform/environment.js +85 -0
  141. package/dist/runtime/platform/locale.d.ts +27 -0
  142. package/dist/runtime/platform/locale.js +42 -0
  143. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  144. package/dist/runtime/platform/route-analytics.js +72 -0
  145. package/dist/runtime/platform/safe-href.d.ts +25 -0
  146. package/dist/runtime/platform/safe-href.js +69 -0
  147. package/dist/runtime/platform/safe-values.d.ts +37 -0
  148. package/dist/runtime/platform/safe-values.js +140 -0
  149. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  150. package/dist/runtime/render/SectionRenderer.js +199 -0
  151. package/dist/runtime/render/listing-query.d.ts +52 -0
  152. package/dist/runtime/render/listing-query.js +122 -0
  153. package/dist/runtime/render/localized-copy.d.ts +86 -0
  154. package/dist/runtime/render/localized-copy.js +129 -0
  155. package/dist/runtime/render/product-listing.d.ts +11 -0
  156. package/dist/runtime/render/product-listing.js +243 -0
  157. package/dist/runtime/render/resolved.d.ts +47 -0
  158. package/dist/runtime/render/resolved.js +80 -0
  159. package/dist/runtime/render/section-actions.d.ts +67 -0
  160. package/dist/runtime/render/section-actions.js +205 -0
  161. package/dist/runtime/render/starter.d.ts +11 -0
  162. package/dist/runtime/render/starter.js +96 -0
  163. package/dist/runtime/seo/head.d.ts +115 -0
  164. package/dist/runtime/seo/head.js +281 -0
  165. package/dist/runtime/seo/structured-data.d.ts +83 -0
  166. package/dist/runtime/seo/structured-data.js +252 -0
  167. package/dist/runtime/shell/PageShell.d.ts +18 -0
  168. package/dist/runtime/shell/PageShell.js +118 -0
  169. package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
  170. package/dist/runtime/shell/RuntimeBridge.js +124 -0
  171. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  172. package/dist/runtime/shell/overlay-state.js +59 -0
  173. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  174. package/dist/runtime/shell/preview-mode.js +11 -0
  175. package/dist/runtime/shell/spa-router.d.ts +14 -0
  176. package/dist/runtime/shell/spa-router.js +76 -0
  177. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  178. package/dist/runtime/shell/url-redirects.js +37 -0
  179. package/dist/runtime/slots.d.ts +74 -0
  180. package/dist/runtime/slots.js +16 -0
  181. package/dist/runtime.d.ts +34 -0
  182. package/dist/runtime.js +40 -0
  183. package/dist/sdk/app-block.d.ts +29 -0
  184. package/dist/sdk/app-block.js +22 -0
  185. package/dist/sdk/font-hooks.d.ts +7 -0
  186. package/dist/sdk/font-hooks.js +21 -0
  187. package/dist/sdk/fonts.d.ts +144 -0
  188. package/dist/sdk/fonts.js +241 -0
  189. package/dist/sdk/index.d.ts +32 -0
  190. package/dist/sdk/index.js +36 -0
  191. package/dist/sdk/motion-hooks.d.ts +23 -0
  192. package/dist/sdk/motion-hooks.js +46 -0
  193. package/dist/sdk/motion.d.ts +78 -0
  194. package/dist/sdk/motion.js +292 -0
  195. package/dist/sdk/referrals.d.ts +62 -0
  196. package/dist/sdk/referrals.js +20 -0
  197. package/dist/sdk/rewards.d.ts +85 -0
  198. package/dist/sdk/rewards.js +29 -0
  199. package/dist/sdk/runtime-context.d.ts +230 -0
  200. package/dist/sdk/runtime-context.js +73 -0
  201. package/dist/sdk/schema.d.ts +249 -0
  202. package/dist/sdk/schema.js +168 -0
  203. package/dist/sdk/server-render.d.ts +8 -0
  204. package/dist/sdk/server-render.js +12 -0
  205. package/dist/sdk/store-lookup.d.ts +32 -0
  206. package/dist/sdk/store-lookup.js +48 -0
  207. package/dist/sdk/store.d.ts +164 -0
  208. package/dist/sdk/store.js +5 -0
  209. package/dist/sdk/sx.d.ts +45 -0
  210. package/dist/sdk/sx.js +117 -0
  211. package/dist/sdk/theme.d.ts +212 -0
  212. package/dist/sdk/theme.js +27 -0
  213. package/dist/sdk/types.d.ts +789 -0
  214. package/dist/sdk/types.js +7 -0
  215. package/dist/server.d.ts +112 -0
  216. package/dist/server.js +589 -0
  217. package/dist/vite-chunks.d.ts +10 -0
  218. package/dist/vite-chunks.js +44 -0
  219. package/docs/headless-api.md +250 -0
  220. package/package.json +72 -26
  221. package/dist/index.js.map +0 -1
  222. package/dist/ssg-BZ5FYTw7.js +0 -1802
  223. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  224. package/dist/ssg.js +0 -8
  225. package/dist/ssg.js.map +0 -1
  226. package/dist/types/cart.d.ts +0 -86
  227. package/dist/types/data.d.ts +0 -357
  228. package/dist/types/dynamic-source.d.ts +0 -84
  229. package/dist/types/editor.d.ts +0 -5
  230. package/dist/types/index.d.ts +0 -20
  231. package/dist/types/preview-bridge.d.ts +0 -9
  232. package/dist/types/storefront.d.ts +0 -333
  233. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,168 @@
1
+ /**
2
+ * The settings schema DSL — the ONE place a Nova section or block declares its
3
+ * persisted settings in code. Everything else is derived from it:
4
+ *
5
+ * schema ──► TypeScript prop types (SettingsOf<typeof schema>)
6
+ * ──► the adapter (resolveSettings: defaults, legacy, coercion)
7
+ * ──► Storybook controls (stories/argTypes.ts)
8
+ * ──► contract drift validation (validate.ts, against generated/*.json)
9
+ *
10
+ * Option IDs here are the PERSISTED IDs (what a store's saved JSON holds), never
11
+ * display labels. Labels come from the approved contract at display time.
12
+ */
13
+ import { fontEditorHints, fontOptions } from './fonts.js';
14
+ /**
15
+ * The most handles a resource list holds: 50, the editor's and studio-api's cap (the reference platform's list
16
+ * settings take 50; the Theme ABI allows 64). A theme may set a lower `max`, never a higher one.
17
+ */
18
+ export const RESOURCE_LIST_MAX = 50;
19
+ function select(options, def, opts) {
20
+ return { control: 'select', options, default: def, binding: 'prop', ...opts };
21
+ }
22
+ function simple(control) {
23
+ function make(def, opts) {
24
+ return { control, default: def ?? (control === 'boolean' ? false : ''), binding: 'prop', ...opts };
25
+ }
26
+ return make;
27
+ }
28
+ function resource(control, def = '', opts) {
29
+ return { control, default: def, binding: 'adapter', ...opts };
30
+ }
31
+ /** A hand-picked list of resources: handles in the merchant's order, at most `max` (default and cap 50). Starts empty. */
32
+ function resourceList(items, opts = {}) {
33
+ const { max, ...rest } = opts;
34
+ const cap = typeof max === 'number' && Number.isInteger(max) && max > 0 ? Math.min(max, RESOURCE_LIST_MAX) : RESOURCE_LIST_MAX;
35
+ return { control: 'list', items, max: cap, default: [], binding: 'adapter', ...rest };
36
+ }
37
+ export const field = {
38
+ select,
39
+ boolean: simple('boolean'),
40
+ text: simple('text'),
41
+ textarea: simple('textarea'),
42
+ richtext: simple('richtext'),
43
+ url: simple('url'),
44
+ color: simple('color'),
45
+ range(def, min, max, step, opts = {}) {
46
+ return { control: 'range', default: def, min, max, step, binding: 'prop', ...opts };
47
+ },
48
+ /** A number input (contract control "number") — same resolution as range. */
49
+ number(def, min, max, step, opts = {}) {
50
+ return { control: 'number', default: def, min, max, step, binding: 'prop', ...opts };
51
+ },
52
+ /**
53
+ * A font (fonts.ts): the platform catalogue first, then the theme's own fonts (`themeFonts`), then the device's
54
+ * faces; the editor draws it as its font picker. Render it with `useFont(settings.key, themeFonts)`.
55
+ */
56
+ font(def, opts = {}) {
57
+ const { themeFonts, catalogue, system, unset, weightSetting, ...rest } = opts;
58
+ const options = fontOptions({ themeFonts, catalogue, system, unset });
59
+ if (!options.some((o) => o.value === def))
60
+ throw new Error(`field.font: the default "${def}" is not one of its options`);
61
+ return {
62
+ control: 'select',
63
+ options: options.map((o) => o.value),
64
+ optionLabels: Object.fromEntries(options.map((o) => [o.value, o.label])),
65
+ default: def,
66
+ binding: 'prop',
67
+ editor: fontEditorHints(options, weightSetting),
68
+ ...rest,
69
+ };
70
+ },
71
+ /** A data picker: the persisted value is a handle/id; the adapter resolves it. */
72
+ resource,
73
+ /** A multi picker: the persisted value is a list of handles; the adapter resolves them. */
74
+ resourceList,
75
+ /**
76
+ * A 3D model setting (field-type registry 4, theme-abi §2.6): the editor lists the store's MODEL_3D files; the value is
77
+ * the .glb file's https URL. Show it with `<ModelViewer media={{ src: value }} />`. The manifest declares field-type registry 4 for it (set by
78
+ * `buildManifest` when the theme names none).
79
+ */
80
+ model(opts = {}) {
81
+ return { control: 'model', default: '', binding: 'prop', ...opts };
82
+ },
83
+ };
84
+ export function defineSchema(meta, fields) {
85
+ return { ...meta, fields };
86
+ }
87
+ function snapTo(value, snap) {
88
+ return snap.reduce((best, s) => (Math.abs(s - value) < Math.abs(best - value) ? s : best), snap[0]);
89
+ }
90
+ /**
91
+ * The adapter core: saved JSON settings → typed, complete settings.
92
+ *
93
+ * - missing → the field default
94
+ * - a legacy option → the option it renders as (issue: legacy-value)
95
+ * - an unknown option → the default (issue: unknown-option), never a crash
96
+ * - "true"/"false"/"32" strings → boolean / number (issue: coerced)
97
+ * - LEGACY-HIDDEN fields keep their saved value (that is the point of them)
98
+ * - a resource list → its non-empty handles, trimmed, in order; anything but a list → [] (issue: coerced)
99
+ */
100
+ export function resolveSettings(schema, raw) {
101
+ const input = raw ?? {};
102
+ const settings = {};
103
+ const handles = {};
104
+ const issues = [];
105
+ for (const [key, f] of Object.entries(schema.fields)) {
106
+ const has = Object.prototype.hasOwnProperty.call(input, key) && input[key] !== undefined && input[key] !== null;
107
+ let value = has ? input[key] : f.default;
108
+ if (f.control === 'select') {
109
+ const opts = f.options;
110
+ if (typeof value === 'number')
111
+ value = String(value);
112
+ if (!opts.includes(value)) {
113
+ const legacy = f.legacy?.[value];
114
+ if (legacy !== undefined) {
115
+ issues.push({ key, code: 'legacy-value', value, resolved: legacy });
116
+ value = legacy;
117
+ }
118
+ else {
119
+ if (has)
120
+ issues.push({ key, code: 'unknown-option', value, resolved: f.default });
121
+ value = f.default;
122
+ }
123
+ }
124
+ }
125
+ else if (f.control === 'boolean') {
126
+ if (typeof value === 'string') {
127
+ issues.push({ key, code: 'coerced', value, resolved: value === 'true' });
128
+ value = value === 'true';
129
+ }
130
+ else
131
+ value = Boolean(value);
132
+ }
133
+ else if (f.control === 'range' || f.control === 'number') {
134
+ let n = typeof value === 'number' ? value : Number(value);
135
+ if (typeof value === 'string')
136
+ issues.push({ key, code: 'coerced', value, resolved: n });
137
+ if (!Number.isFinite(n))
138
+ n = f.default;
139
+ const clamped = Math.min(f.max, Math.max(f.min, n));
140
+ if (clamped !== n)
141
+ issues.push({ key, code: 'out-of-range', value: n, resolved: clamped });
142
+ value = f.snap ? snapTo(clamped, f.snap) : clamped;
143
+ }
144
+ else if (f.control === 'list') {
145
+ if (!Array.isArray(value))
146
+ issues.push({ key, code: 'coerced', value, resolved: [] });
147
+ value = Array.isArray(value) ? value.flatMap((h) => (typeof h === 'string' && h.trim() ? [h.trim()] : [])) : [];
148
+ }
149
+ else {
150
+ value = typeof value === 'string' ? value : String(value ?? '');
151
+ }
152
+ if (f.legacyHidden && !has)
153
+ continue; // a legacy field that was never saved stays absent
154
+ if (f.binding === 'adapter')
155
+ handles[key] = value;
156
+ else
157
+ settings[key] = value;
158
+ }
159
+ for (const key of Object.keys(input)) {
160
+ if (!(key in schema.fields))
161
+ issues.push({ key, code: 'unknown-setting', value: input[key] });
162
+ }
163
+ return { settings: settings, handles: handles, issues };
164
+ }
165
+ /** Defaults of a schema — what a brand-new section renders with. */
166
+ export function defaultsOf(schema) {
167
+ return resolveSettings(schema, {}).settings;
168
+ }
@@ -0,0 +1,8 @@
1
+ /** Set by the platform's server `render()` around the page; never in the browser. */
2
+ export declare const ServerRenderProvider: import("react").Provider<boolean>;
3
+ /**
4
+ * True while the platform renders this page on the server; false in the browser — the hydrating first render
5
+ * included. For markup the platform adds to the delivered page after the server render (the gateway's form
6
+ * fields): the browser renders it so its tree matches the page it received, the server never does.
7
+ */
8
+ export declare function useServerRender(): boolean;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from 'react';
2
+ const ServerRenderContext = createContext(false);
3
+ /** Set by the platform's server `render()` around the page; never in the browser. */
4
+ export const ServerRenderProvider = ServerRenderContext.Provider;
5
+ /**
6
+ * True while the platform renders this page on the server; false in the browser — the hydrating first render
7
+ * included. For markup the platform adds to the delivered page after the server render (the gateway's form
8
+ * fields): the browser renders it so its tree matches the page it received, the server never does.
9
+ */
10
+ export function useServerRender() {
11
+ return useContext(ServerRenderContext) || typeof document === 'undefined';
12
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Reading the store context: a saved handle → the object the runtime already
3
+ * put in the context (an image, a menu, a collection …). WHERE the data comes
4
+ * from is the runtime's job; these only look it up, the same way for every
5
+ * theme, including the platform rule that an unpublished or deleted handle is
6
+ * "unavailable", not missing. Nothing here fetches.
7
+ */
8
+ import type { StoreContext } from './store.js';
9
+ import type { Collection, Image, Link, Menu, Video, Product } from './types.js';
10
+ /** An image handle → the image, or null. */
11
+ export declare const imageFor: (store: StoreContext, handle: string | undefined) => Image | null;
12
+ /** A video handle → the video, or null. */
13
+ export declare const videoFor: (store: StoreContext, handle: string | undefined) => Video | null;
14
+ /** A menu handle → the menu, or null. */
15
+ export declare const menuFor: (store: StoreContext, handle: string | undefined) => Menu | null;
16
+ /** A collection handle → the collection; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
17
+ export declare function collectionFor(store: StoreContext, handle: string | undefined, fallback?: Collection): {
18
+ collection: Collection | null;
19
+ unavailable: boolean;
20
+ };
21
+ /** A product handle → the product; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
22
+ export declare function productFor(store: StoreContext, handle: string | undefined, fallback?: Product): {
23
+ product: Product | null;
24
+ unavailable: boolean;
25
+ };
26
+ /**
27
+ * The handles of a resource list (`field.resourceList('product')`) → the products, in the merchant's order. A handle
28
+ * the store has no product for, an unpublished or deleted one, and a repeat are left out; nothing is invented.
29
+ */
30
+ export declare function productsFor(store: StoreContext, handles: readonly string[] | undefined): Product[];
31
+ /** Comma-separated collection handles (a multi-picker fallback) → links; typos and unavailable handles drop out. */
32
+ export declare function collectionLinksFor(store: StoreContext, handles: string): Link[];
@@ -0,0 +1,48 @@
1
+ /** An image handle → the image, or null. */
2
+ export const imageFor = (store, handle) => (handle ? (store.images?.[handle] ?? null) : null);
3
+ /** A video handle → the video, or null. */
4
+ export const videoFor = (store, handle) => (handle ? (store.videos?.[handle] ?? null) : null);
5
+ /** A menu handle → the menu, or null. */
6
+ export const menuFor = (store, handle) => (handle ? (store.menus[handle] ?? null) : null);
7
+ /** A collection handle → the collection; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
8
+ export function collectionFor(store, handle, fallback) {
9
+ if (handle && store.unavailableCollections?.includes(handle))
10
+ return { collection: null, unavailable: true };
11
+ return { collection: (handle ? store.collections?.[handle] : undefined) ?? fallback ?? null, unavailable: false };
12
+ }
13
+ /** A product handle → the product; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
14
+ export function productFor(store, handle, fallback) {
15
+ if (handle && store.unavailableProducts?.includes(handle))
16
+ return { product: null, unavailable: true };
17
+ return { product: (handle ? store.products?.[handle] : undefined) ?? fallback ?? null, unavailable: false };
18
+ }
19
+ /**
20
+ * The handles of a resource list (`field.resourceList('product')`) → the products, in the merchant's order. A handle
21
+ * the store has no product for, an unpublished or deleted one, and a repeat are left out; nothing is invented.
22
+ */
23
+ export function productsFor(store, handles) {
24
+ const out = [];
25
+ const seen = new Set();
26
+ for (const raw of handles ?? []) {
27
+ const handle = typeof raw === 'string' ? raw.trim() : '';
28
+ if (!handle || seen.has(handle) || store.unavailableProducts?.includes(handle))
29
+ continue;
30
+ const product = store.products?.[handle];
31
+ if (!product)
32
+ continue;
33
+ seen.add(handle);
34
+ out.push(product);
35
+ }
36
+ return out;
37
+ }
38
+ /** Comma-separated collection handles (a multi-picker fallback) → links; typos and unavailable handles drop out. */
39
+ export function collectionLinksFor(store, handles) {
40
+ return handles
41
+ .split(',')
42
+ .map((h) => h.trim())
43
+ .filter(Boolean)
44
+ .flatMap((h) => {
45
+ const c = store.collections?.[h];
46
+ return c && !store.unavailableCollections?.includes(h) ? [{ title: c.title, url: c.url }] : [];
47
+ });
48
+ }
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The store context a section's data binding reads: the store's data, already
3
+ * shaped as the types in ./types. The theme runtime builds it; a theme never
4
+ * fetches.
5
+ */
6
+ import type { Article, Blog, Cart, CustomerAccount, Policy, ReviewsData, SearchResults, SortOption, StoreLocation, UgcPost, BreadcrumbItem, Collection, Product, CartSummary, Customer, Image, Localization, Menu, Shop, Video, GiftCardBalance } from './types.js';
7
+ export interface SavedBlock {
8
+ /** The block's id in the saved content (`b-testimonial-1`): the editor selects a block by it (blockAttrs). */
9
+ id?: string;
10
+ type: string;
11
+ settings?: Record<string, unknown>;
12
+ /** A block that holds blocks (nested theme blocks): its own, in order. */
13
+ blocks?: SavedBlock[];
14
+ }
15
+ /**
16
+ * The attributes that make one rendered block selectable on the editor's canvas: spread them on the block's root
17
+ * element (`<li {...blockAttrs(b)}>`). The canvas bridge (storefront-edge editor-bridge) finds a block by
18
+ * `data-tq-node` inside its section's node, outlines it with `data-tq-type` as its label and scrolls to it, and a click
19
+ * inside it selects the block instead of the whole section. No id (a block from older content, a preview seed) gives
20
+ * nothing, so the section is selected as before.
21
+ */
22
+ export interface BlockRef {
23
+ id?: string;
24
+ type: string;
25
+ }
26
+ export declare function blockAttrs(block: {
27
+ id?: string | null;
28
+ type?: string | null;
29
+ } | null | undefined): {
30
+ 'data-tq-node'?: string;
31
+ 'data-tq-type'?: string;
32
+ };
33
+ export interface SavedSection {
34
+ type: string;
35
+ settings?: Record<string, unknown>;
36
+ blocks?: SavedBlock[];
37
+ }
38
+ export interface StoreContext {
39
+ shop: Shop;
40
+ menus: Record<string, Menu>;
41
+ images?: Record<string, Image>;
42
+ videos?: Record<string, Video>;
43
+ cart?: CartSummary;
44
+ customer?: Customer;
45
+ localization?: Localization | null;
46
+ /** Route context. */
47
+ breadcrumbs?: BreadcrumbItem[];
48
+ /**
49
+ * The route's base template (`index`, `product`, `collection`, `cart`, `page`, `search`, …; a template suffix is not
50
+ * part of it). A section that behaves differently on one kind of page reads it here: a product row beside the cart
51
+ * leaves out what cannot be added. Absent where the section renders with no route (the editor's single-section preview).
52
+ */
53
+ template?: string;
54
+ /** The page's first section is a hero with media (transparentOnHero). */
55
+ firstSectionIsHeroWithMedia?: boolean;
56
+ consentEnabled?: boolean;
57
+ brandColor?: string;
58
+ /** Collections by handle (collection pickers). */
59
+ collections?: Record<string, Collection>;
60
+ /** The route's collection on collection templates (collection-banner default). */
61
+ currentCollection?: Collection;
62
+ /** Handles that exist but are unpublished or deleted. */
63
+ unavailableCollections?: readonly string[];
64
+ /** The store's IANA time zone (promo-banner endsAt). */
65
+ timeZone?: string;
66
+ /** The store / server clock. */
67
+ clock?: () => number;
68
+ /** The shopper has not answered the cookie banner yet (the phone sticky bar waits). */
69
+ consentAnswered?: boolean;
70
+ /** The shopper's stored choice, when they made one (consent.get `known`). */
71
+ consentChoice?: {
72
+ analytics: boolean;
73
+ marketing: boolean;
74
+ preferences: boolean;
75
+ };
76
+ /** A sale-of-data opt-out applies where the shopper is (consent.get `regionRequiresOptOut`, board 35 #42). */
77
+ consentOptOut?: boolean;
78
+ /** Products by handle (product pickers). */
79
+ products?: Record<string, Product>;
80
+ /** The route's product on product templates. */
81
+ currentProduct?: Product;
82
+ /** The variant the product URL names (`?variant=`), as given; the section checks it belongs to the product. */
83
+ currentVariantId?: string;
84
+ /** Handles that exist but are unpublished or deleted. */
85
+ unavailableProducts?: readonly string[];
86
+ /** Pages by handle (size guide page). */
87
+ pages?: Record<string, {
88
+ title: string;
89
+ html: string;
90
+ }>;
91
+ /** Recommendations for the current product, by intent (platform). */
92
+ recommendations?: Partial<Record<'related' | 'complementary', Product[]>>;
93
+ /** This shopper's viewed products — null until the platform supports history + consent. */
94
+ recentlyViewed?: Product[] | null;
95
+ /** The store's newest collections (collection-list without blocks). */
96
+ newestCollections?: Collection[];
97
+ /** The page being rendered (page-body). */
98
+ currentPage?: {
99
+ title: string;
100
+ html: string;
101
+ };
102
+ /** The article being rendered and its blog (article-body). */
103
+ currentArticle?: Article & {
104
+ contentHtml?: string;
105
+ };
106
+ currentBlog?: {
107
+ title: string;
108
+ url: string;
109
+ };
110
+ /** The tag a blog page is filtered to (`/blogs/<blog>/tagged/<tag>`). */
111
+ currentTag?: string;
112
+ /** Blogs by handle (blog-posts). */
113
+ blogs?: Record<string, Blog>;
114
+ /** The current product's reviews from a reviews source — null until the platform has one (12F DATA REQUIREMENT). */
115
+ reviews?: ReviewsData | null;
116
+ /** A connected social feed for ugc-gallery source = feed — null until the platform has one. */
117
+ ugcFeed?: UgcPost[] | null;
118
+ /** 12G · the full cart for the cart page (the header only needs the summary above). */
119
+ currentCart?: Cart | null;
120
+ /**
121
+ * Whether the shopper's cart is known yet (board 35 #85): `loading` until the first `cart.get` answers (and in the
122
+ * server render, unless the platform resolved the cart), `failed` when that first load failed and is not retried,
123
+ * else `ready`. A cart not yet read is not an empty cart: a cart surface shows its loading state, never "Your cart
124
+ * is empty", until this is `ready`. Absent (fixtures, a host without a cart): treat as `ready`.
125
+ */
126
+ cartStatus?: 'loading' | 'ready' | 'failed';
127
+ /** The checkout app — the only place Checkout goes. */
128
+ checkoutUrl?: string;
129
+ /** Why a cart permalink the store could not open sent the shopper to the cart page (`unavailable`, `failed`), else null. */
130
+ cartLink?: string | null;
131
+ searchQuery?: string;
132
+ searchResults?: SearchResults | null;
133
+ searchSortOptions?: SortOption[];
134
+ /** The search page's current sort id (`?sort=`); 'relevance' when none. */
135
+ searchSort?: string;
136
+ /** The signed-in customer's account (accounts app); null when signed out. */
137
+ account?: CustomerAccount | null;
138
+ /**
139
+ * The Account BFF URL to frame on the customer route (`/account*`): render
140
+ * `<iframe data-tq-slot="account" src={accountUrl} sandbox="allow-scripts allow-forms allow-same-origin">`
141
+ * (Theme ABI v2 §4, the account slot). Sign-in, orders and addresses render inside that frame; customer data
142
+ * never reaches the theme. Absent on every other route and where the host has no account area.
143
+ */
144
+ accountUrl?: string;
145
+ /** Store policies by handle, and the route's policy on policy templates. */
146
+ policies?: Record<string, Policy>;
147
+ currentPolicy?: Policy | null;
148
+ locations?: StoreLocation[];
149
+ /** Platform form endpoints, when they exist (12G DATA REQUIREMENT). */
150
+ newsletterEndpoint?: string;
151
+ contactEndpoint?: string;
152
+ /** Where ANY declared native form of this page posts (the page's own path), when the platform takes form posts. */
153
+ formEndpoint?: string;
154
+ /** The route's captured segments (a manifest custom route `/gift-card/:id` ⇒ `{ id }`); `{}` on a built-in route. */
155
+ routeParams?: Readonly<Record<string, string>>;
156
+ /** The outcome of the platform form POST this page answers (ABI native forms). */
157
+ formResult?: {
158
+ formId: string;
159
+ status: 'ok' | 'invalid' | 'rate_limited' | 'unavailable' | 'expired';
160
+ email?: string;
161
+ discountCode?: string;
162
+ giftCard?: GiftCardBalance;
163
+ };
164
+ }
@@ -0,0 +1,5 @@
1
+ export function blockAttrs(block) {
2
+ if (!block || typeof block.id !== 'string' || !block.id)
3
+ return {};
4
+ return { 'data-tq-node': block.id, ...(typeof block.type === 'string' && block.type ? { 'data-tq-type': block.type } : {}) };
5
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Dynamic style values without `style=""` attributes.
3
+ *
4
+ * The platform's CSP carries `style-src-attr 'none'` and no 'unsafe-inline' (Theme ABI v2 §5), and
5
+ * conformance fails a page whose DOM holds a style attribute at all. So a value a component computes
6
+ * (a column count, a scrim, an aspect ratio, the theme settings' CSS variables) becomes a CLASS:
7
+ *
8
+ * <ul className={cx('nv-list', sx({ '--nv-cols': columns }))}>
9
+ *
10
+ * - The class name is a hash of the declarations: the server and the hydrating browser compute the
11
+ * same name from the same values, so hydration matches.
12
+ * - Server: the entry opens a sink for exactly one synchronous `renderToString` (`collectStyles`) and
13
+ * emits its rules as ONE hashed `<style>`. Nothing outlives the render — no module cache, so no
14
+ * value of one store can reach another store's page.
15
+ * - Browser: a rule the server block does not already hold is inserted through CSSOM (a constructed
16
+ * stylesheet), which CSP does not govern.
17
+ *
18
+ * A declaration whose value could leave its rule (`<`, `{`, `}`, `;`, `\`, a newline) is dropped,
19
+ * never escaped into place.
20
+ */
21
+ import type { CSSProperties } from 'react';
22
+ /** id of the server-emitted `<style>` that carries the page's rules. */
23
+ export declare const STYLE_RULES_ID = "tq-style-rules";
24
+ export interface StyleSink {
25
+ add(className: string, declarations: string): void;
26
+ /** A catalogue font family the render uses (fonts.ts useFont): the server imports it once. */
27
+ font?(family: string): void;
28
+ }
29
+ /** Declarations text of a style object (`prop:value;…`), unsafe values dropped. */
30
+ export declare function declarations(style: CSSProperties | Record<string, unknown>): string;
31
+ /**
32
+ * Run `render` (a synchronous `renderToString`) with a fresh sink and return its output plus the
33
+ * rules it used. The sink exists only for that call.
34
+ */
35
+ export declare function collectStyles<T>(render: () => T): {
36
+ result: T;
37
+ css: string;
38
+ fonts: string[];
39
+ };
40
+ /** `sx(style)` → a class name carrying those declarations (undefined for an empty style). */
41
+ export declare function sx(style: CSSProperties | Record<string, unknown> | null | undefined | false): string | undefined;
42
+ /** During a server render: note a catalogue font family the page uses (fonts.ts). No-op in the browser. */
43
+ export declare function registerFontFamily(family: string): void;
44
+ /** Join class names, skipping empty ones. */
45
+ export declare function cx(...names: Array<string | false | null | undefined>): string | undefined;
package/dist/sdk/sx.js ADDED
@@ -0,0 +1,117 @@
1
+ /** id of the server-emitted `<style>` that carries the page's rules. */
2
+ export const STYLE_RULES_ID = 'tq-style-rules';
3
+ const UNITLESS = new Set([
4
+ 'aspectRatio', 'flex', 'flexGrow', 'flexShrink', 'fontWeight', 'lineHeight', 'opacity', 'order', 'zIndex', 'zoom',
5
+ 'animationIterationCount', 'columnCount', 'gridColumn', 'gridRow', 'scale',
6
+ ]);
7
+ const UNSAFE = /[<>{};\\\n\r]/;
8
+ const hyphenate = (prop) => prop.startsWith('--') ? prop : prop.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).replace(/^ms-/, '-ms-');
9
+ /** Declarations text of a style object (`prop:value;…`), unsafe values dropped. */
10
+ export function declarations(style) {
11
+ const out = [];
12
+ for (const [prop, raw] of Object.entries(style)) {
13
+ if (raw === undefined || raw === null || raw === '' || typeof raw === 'boolean')
14
+ continue;
15
+ const value = typeof raw === 'number' && raw !== 0 && !prop.startsWith('--') && !UNITLESS.has(prop) ? `${raw}px` : String(raw);
16
+ if (UNSAFE.test(value) && !/^url\("[^"<>\\\n]*"\)$/.test(value))
17
+ continue;
18
+ out.push(`${hyphenate(prop)}:${value}`);
19
+ }
20
+ return out.join(';');
21
+ }
22
+ /** FNV-1a 32-bit, base36 — the same on the server and in the browser. */
23
+ function hash(text) {
24
+ let h = 0x811c9dc5;
25
+ for (let i = 0; i < text.length; i++) {
26
+ h ^= text.charCodeAt(i);
27
+ h = Math.imul(h, 0x01000193);
28
+ }
29
+ return (h >>> 0).toString(36);
30
+ }
31
+ // ── server: one sink per synchronous render ─────────────────────────────────
32
+ let serverSink = null;
33
+ /**
34
+ * Run `render` (a synchronous `renderToString`) with a fresh sink and return its output plus the
35
+ * rules it used. The sink exists only for that call.
36
+ */
37
+ export function collectStyles(render) {
38
+ const rules = new Map();
39
+ const fonts = new Set();
40
+ const prev = serverSink;
41
+ serverSink = { add: (c, d) => { if (!rules.has(c))
42
+ rules.set(c, d); }, font: (f) => fonts.add(f) };
43
+ try {
44
+ const result = render();
45
+ return { result, css: [...rules].map(([c, d]) => `.${c}{${d}}`).join(''), fonts: [...fonts].sort() };
46
+ }
47
+ finally {
48
+ serverSink = prev;
49
+ }
50
+ }
51
+ // ── browser: CSSOM ──────────────────────────────────────────────────────────
52
+ let browserSink = null;
53
+ function constructedSheet() {
54
+ if (typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in document) {
55
+ try {
56
+ const sheet = new CSSStyleSheet();
57
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
58
+ return sheet;
59
+ }
60
+ catch {
61
+ /* fall through */
62
+ }
63
+ }
64
+ // Environments without constructable stylesheets (jsdom in unit tests).
65
+ const el = document.createElement('style');
66
+ el.setAttribute('data-tq-rules', 'live');
67
+ document.head.appendChild(el);
68
+ return el.sheet;
69
+ }
70
+ function getBrowserSink() {
71
+ if (typeof document === 'undefined')
72
+ return null;
73
+ if (browserSink)
74
+ return browserSink;
75
+ const known = new Set();
76
+ const el = document.getElementById(STYLE_RULES_ID);
77
+ for (const m of (el?.textContent ?? '').matchAll(/\.(tqs-[a-z0-9]+)\{/g))
78
+ known.add(m[1]);
79
+ let sheet = null;
80
+ browserSink = {
81
+ add(className, decl) {
82
+ if (known.has(className))
83
+ return;
84
+ known.add(className);
85
+ sheet ??= constructedSheet();
86
+ if (!sheet)
87
+ return;
88
+ try {
89
+ sheet.insertRule(`.${className}{${decl}}`, sheet.cssRules.length);
90
+ }
91
+ catch {
92
+ /* a declaration the browser rejects is simply not applied */
93
+ }
94
+ },
95
+ };
96
+ return browserSink;
97
+ }
98
+ /** `sx(style)` → a class name carrying those declarations (undefined for an empty style). */
99
+ export function sx(style) {
100
+ if (!style)
101
+ return undefined;
102
+ const decl = declarations(style);
103
+ if (!decl)
104
+ return undefined;
105
+ const className = `tqs-${hash(decl)}`;
106
+ (serverSink ?? getBrowserSink())?.add(className, decl);
107
+ return className;
108
+ }
109
+ /** During a server render: note a catalogue font family the page uses (fonts.ts). No-op in the browser. */
110
+ export function registerFontFamily(family) {
111
+ serverSink?.font?.(family);
112
+ }
113
+ /** Join class names, skipping empty ones. */
114
+ export function cx(...names) {
115
+ const s = names.filter(Boolean).join(' ');
116
+ return s || undefined;
117
+ }