@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.5

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -10
  3. package/dist/abi/canvas-live.d.ts +49 -0
  4. package/dist/abi/canvas-live.js +88 -0
  5. package/dist/abi/cart.d.ts +48 -0
  6. package/dist/abi/cart.js +321 -0
  7. package/dist/abi/convert.d.ts +192 -0
  8. package/dist/abi/convert.js +670 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +198 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/page-data.d.ts +209 -0
  14. package/dist/abi/page-data.js +583 -0
  15. package/dist/abi/page.d.ts +23 -0
  16. package/dist/abi/page.js +46 -0
  17. package/dist/abi/referrals.d.ts +23 -0
  18. package/dist/abi/referrals.js +89 -0
  19. package/dist/abi/rewards.d.ts +27 -0
  20. package/dist/abi/rewards.js +82 -0
  21. package/dist/abi/seo.d.ts +47 -0
  22. package/dist/abi/seo.js +68 -0
  23. package/dist/abi/shell.d.ts +22 -0
  24. package/dist/abi/shell.js +10 -0
  25. package/dist/abi/wire.d.ts +38 -0
  26. package/dist/abi/wire.js +84 -0
  27. package/dist/build.d.ts +113 -0
  28. package/dist/build.js +294 -0
  29. package/dist/client.d.ts +19 -0
  30. package/dist/client.js +76 -0
  31. package/dist/contract.d.ts +6 -0
  32. package/dist/contract.js +6 -0
  33. package/dist/headless/ai.d.ts +132 -0
  34. package/dist/headless/ai.js +99 -0
  35. package/dist/headless/hooks.d.ts +273 -0
  36. package/dist/headless/hooks.js +533 -0
  37. package/dist/headless/i18n.d.ts +13 -0
  38. package/dist/headless/i18n.js +45 -0
  39. package/dist/headless/index.d.ts +36 -0
  40. package/dist/headless/index.js +38 -0
  41. package/dist/headless/money.d.ts +25 -0
  42. package/dist/headless/money.js +61 -0
  43. package/dist/headless/page.d.ts +43 -0
  44. package/dist/headless/page.js +53 -0
  45. package/dist/headless/platform.d.ts +55 -0
  46. package/dist/headless/platform.js +77 -0
  47. package/dist/headless/primitives/cart.d.ts +90 -0
  48. package/dist/headless/primitives/cart.js +153 -0
  49. package/dist/headless/primitives/collection.d.ts +68 -0
  50. package/dist/headless/primitives/collection.js +80 -0
  51. package/dist/headless/primitives/product.d.ts +101 -0
  52. package/dist/headless/primitives/product.js +117 -0
  53. package/dist/headless/primitives/storefront.d.ts +106 -0
  54. package/dist/headless/primitives/storefront.js +186 -0
  55. package/dist/headless/primitives/util.d.ts +19 -0
  56. package/dist/headless/primitives/util.js +42 -0
  57. package/dist/headless/strings.d.ts +9 -0
  58. package/dist/headless/strings.js +186 -0
  59. package/dist/headless/structured-data.d.ts +31 -0
  60. package/dist/headless/structured-data.js +57 -0
  61. package/dist/headless/theme.d.ts +99 -0
  62. package/dist/headless/theme.js +54 -0
  63. package/dist/index.d.ts +20 -0
  64. package/dist/index.js +18 -553
  65. package/dist/runtime/data/StoreProvider.d.ts +56 -0
  66. package/dist/runtime/data/StoreProvider.js +308 -0
  67. package/dist/runtime/data/handle.d.ts +14 -0
  68. package/dist/runtime/data/handle.js +16 -0
  69. package/dist/runtime/data/routes.d.ts +87 -0
  70. package/dist/runtime/data/routes.js +154 -0
  71. package/dist/runtime/data/to-ui.d.ts +258 -0
  72. package/dist/runtime/data/to-ui.js +820 -0
  73. package/dist/runtime/entries/register.d.ts +9 -0
  74. package/dist/runtime/entries/register.js +9 -0
  75. package/dist/runtime/entries/sections.d.ts +16 -0
  76. package/dist/runtime/entries/sections.js +19 -0
  77. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  78. package/dist/runtime/kit/SectionTree.js +100 -0
  79. package/dist/runtime/kit/analytics.d.ts +63 -0
  80. package/dist/runtime/kit/analytics.js +233 -0
  81. package/dist/runtime/kit/cart.d.ts +186 -0
  82. package/dist/runtime/kit/cart.js +545 -0
  83. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  84. package/dist/runtime/kit/composition.js +3 -0
  85. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  86. package/dist/runtime/kit/config.js +6 -0
  87. package/dist/runtime/kit/consent.d.ts +29 -0
  88. package/dist/runtime/kit/consent.js +159 -0
  89. package/dist/runtime/kit/contract/content.d.ts +164 -0
  90. package/dist/runtime/kit/contract/content.js +83 -0
  91. package/dist/runtime/kit/contract/field-types.d.ts +290 -0
  92. package/dist/runtime/kit/contract/field-types.js +129 -0
  93. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  94. package/dist/runtime/kit/contract/groups.js +402 -0
  95. package/dist/runtime/kit/contract/index.d.ts +33 -0
  96. package/dist/runtime/kit/contract/index.js +33 -0
  97. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  98. package/dist/runtime/kit/contract/transform.js +133 -0
  99. package/dist/runtime/kit/contract/validate.d.ts +67 -0
  100. package/dist/runtime/kit/contract/validate.js +388 -0
  101. package/dist/runtime/kit/data.d.ts +636 -0
  102. package/dist/runtime/kit/data.js +1117 -0
  103. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  104. package/dist/runtime/kit/defineSection.js +10 -0
  105. package/dist/{types → runtime/kit}/dynamic-source.d.ts +4 -4
  106. package/dist/runtime/kit/dynamic-source.js +143 -0
  107. package/dist/runtime/kit/index.d.ts +24 -0
  108. package/dist/runtime/kit/index.js +24 -0
  109. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  110. package/dist/runtime/kit/jsx-to-json.js +28 -0
  111. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  112. package/dist/runtime/kit/mount.js +124 -0
  113. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  114. package/dist/runtime/kit/registry.js +12 -0
  115. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  116. package/dist/runtime/kit/ssg.js +56 -0
  117. package/dist/runtime/kit/storefront.d.ts +566 -0
  118. package/dist/runtime/kit/storefront.js +723 -0
  119. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  120. package/dist/runtime/kit/theme-context.js +25 -0
  121. package/dist/runtime/kit/types.d.ts +142 -0
  122. package/dist/runtime/kit/types.js +1 -0
  123. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  124. package/dist/runtime/platform/TrackingPixels.js +63 -0
  125. package/dist/runtime/platform/environment.d.ts +68 -0
  126. package/dist/runtime/platform/environment.js +85 -0
  127. package/dist/runtime/platform/locale.d.ts +27 -0
  128. package/dist/runtime/platform/locale.js +42 -0
  129. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  130. package/dist/runtime/platform/route-analytics.js +72 -0
  131. package/dist/runtime/platform/safe-href.d.ts +25 -0
  132. package/dist/runtime/platform/safe-href.js +69 -0
  133. package/dist/runtime/platform/safe-values.d.ts +37 -0
  134. package/dist/runtime/platform/safe-values.js +140 -0
  135. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  136. package/dist/runtime/render/SectionRenderer.js +111 -0
  137. package/dist/runtime/render/listing-query.d.ts +47 -0
  138. package/dist/runtime/render/listing-query.js +114 -0
  139. package/dist/runtime/render/localized-copy.d.ts +86 -0
  140. package/dist/runtime/render/localized-copy.js +129 -0
  141. package/dist/runtime/render/product-listing.d.ts +11 -0
  142. package/dist/runtime/render/product-listing.js +240 -0
  143. package/dist/runtime/render/section-actions.d.ts +48 -0
  144. package/dist/runtime/render/section-actions.js +170 -0
  145. package/dist/runtime/render/starter.d.ts +11 -0
  146. package/dist/runtime/render/starter.js +81 -0
  147. package/dist/runtime/seo/head.d.ts +87 -0
  148. package/dist/runtime/seo/head.js +224 -0
  149. package/dist/runtime/seo/structured-data.d.ts +22 -0
  150. package/dist/runtime/seo/structured-data.js +115 -0
  151. package/dist/runtime/shell/PageShell.d.ts +18 -0
  152. package/dist/runtime/shell/PageShell.js +113 -0
  153. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  154. package/dist/runtime/shell/RuntimeBridge.js +85 -0
  155. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  156. package/dist/runtime/shell/overlay-state.js +59 -0
  157. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  158. package/dist/runtime/shell/preview-mode.js +11 -0
  159. package/dist/runtime/shell/spa-router.d.ts +14 -0
  160. package/dist/runtime/shell/spa-router.js +76 -0
  161. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  162. package/dist/runtime/shell/url-redirects.js +37 -0
  163. package/dist/runtime/slots.d.ts +74 -0
  164. package/dist/runtime/slots.js +16 -0
  165. package/dist/runtime.d.ts +34 -0
  166. package/dist/runtime.js +40 -0
  167. package/dist/sdk/index.d.ts +24 -0
  168. package/dist/sdk/index.js +24 -0
  169. package/dist/sdk/referrals.d.ts +62 -0
  170. package/dist/sdk/referrals.js +20 -0
  171. package/dist/sdk/rewards.d.ts +85 -0
  172. package/dist/sdk/rewards.js +29 -0
  173. package/dist/sdk/runtime-context.d.ts +135 -0
  174. package/dist/sdk/runtime-context.js +73 -0
  175. package/dist/sdk/schema.d.ts +197 -0
  176. package/dist/sdk/schema.js +121 -0
  177. package/dist/sdk/server-render.d.ts +8 -0
  178. package/dist/sdk/server-render.js +12 -0
  179. package/dist/sdk/store-lookup.d.ts +27 -0
  180. package/dist/sdk/store-lookup.js +29 -0
  181. package/dist/sdk/store.d.ts +115 -0
  182. package/dist/sdk/store.js +1 -0
  183. package/dist/sdk/sx.d.ts +40 -0
  184. package/dist/sdk/sx.js +112 -0
  185. package/dist/sdk/theme.d.ts +152 -0
  186. package/dist/sdk/theme.js +10 -0
  187. package/dist/sdk/types.d.ts +470 -0
  188. package/dist/sdk/types.js +7 -0
  189. package/dist/server.d.ts +65 -0
  190. package/dist/server.js +370 -0
  191. package/docs/headless-api.md +220 -0
  192. package/package.json +77 -23
  193. package/dist/index.js.map +0 -1
  194. package/dist/ssg-BZ5FYTw7.js +0 -1802
  195. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  196. package/dist/ssg.js +0 -8
  197. package/dist/ssg.js.map +0 -1
  198. package/dist/types/cart.d.ts +0 -86
  199. package/dist/types/data.d.ts +0 -357
  200. package/dist/types/editor.d.ts +0 -5
  201. package/dist/types/index.d.ts +0 -20
  202. package/dist/types/preview-bridge.d.ts +0 -9
  203. package/dist/types/storefront.d.ts +0 -333
  204. package/dist/types/types.d.ts +0 -44
package/dist/build.js ADDED
@@ -0,0 +1,294 @@
1
+ import { aiProfileOf, checkAiProfile } from './headless/ai.js';
2
+ import { KIT_STRINGS } from './headless/strings.js';
3
+ export { aiProfileOf, checkAiProfile } from './headless/ai.js';
4
+ export { KIT_STRINGS, kitStrings } from './headless/strings.js';
5
+ /** RFC 8785 JSON canonicalization: `manifest.json` is its JCS bytes plus one trailing LF. */
6
+ export { canonicalize } from './abi/jcs.js';
7
+ /** What the kit's server render reads (`ctx.data`, `ctx.actions`). `data:shop` is always declared (D6). */
8
+ export const SERVER_CAPABILITIES = [
9
+ 'data:shop',
10
+ 'data:localization',
11
+ 'data:catalog',
12
+ 'data:content',
13
+ 'data:search',
14
+ 'data:cart',
15
+ 'data:products.recommendations',
16
+ 'actions:cart',
17
+ 'actions:consent',
18
+ 'actions:form.submit',
19
+ ];
20
+ /** What the kit's browser runtime calls over `/_tq/data` and `/_tq/actions`. `data:shop` is always declared (D6). */
21
+ export const BROWSER_CAPABILITIES = [
22
+ 'data:shop',
23
+ 'data:localization',
24
+ 'data:catalog',
25
+ 'data:content',
26
+ 'data:search',
27
+ 'data:cart',
28
+ 'data:products.recommendations',
29
+ 'actions:cart',
30
+ 'actions:consent',
31
+ ];
32
+ /** The fields each platform form posts (`forms.<id>.fields`); `website` is the honeypot. */
33
+ export const FORM_FIELDS = {
34
+ newsletter: ['email', 'consent', 'website'],
35
+ contact: ['name', 'email', 'phone', 'message', 'website'],
36
+ };
37
+ /** Header (shared), the template's body, footer (shared): where `zone` header / main / footer place a section. */
38
+ export const DEFAULT_REGIONS = {
39
+ header: { title: 'Header', scope: 'shared' },
40
+ main: { title: 'Template', scope: 'template' },
41
+ footer: { title: 'Footer', scope: 'shared' },
42
+ };
43
+ const ZONE_REGION = { header: 'header', main: 'main', footer: 'footer' };
44
+ /** "buttonLabel" → "Button label". */
45
+ export function humanize(key) {
46
+ const words = key.replace(/[-_]+/g, ' ').replace(/([a-z0-9])([A-Z])/g, '$1 $2').trim().toLowerCase();
47
+ return words ? words[0].toUpperCase() + words.slice(1) : key;
48
+ }
49
+ const RESOLVED = new Set(['collection', 'product', 'page', 'blog', 'menu']);
50
+ /** A settings-DSL field as a manifest attribute (registry field spec). */
51
+ export function fieldSpecOf(key, f) {
52
+ const out = { type: f.control, label: f.label ?? humanize(key) };
53
+ if (f.info)
54
+ out.info = f.info;
55
+ if (f.placeholder)
56
+ out.placeholder = f.placeholder;
57
+ if (f.group)
58
+ out.group = f.group;
59
+ if (f.control === 'select') {
60
+ out.options = f.options.map((v) => ({ value: v, label: f.optionLabels?.[v] ?? humanize(v) }));
61
+ }
62
+ else if (f.control === 'range' || f.control === 'number') {
63
+ out.min = f.min;
64
+ out.max = f.max;
65
+ out.step = f.step;
66
+ if (f.control === 'range' && f.unit)
67
+ out.unit = f.unit;
68
+ }
69
+ if (RESOLVED.has(f.control))
70
+ out.resolve = true;
71
+ // "Not set" is an absent key: an empty default is no default.
72
+ if (f.default !== '' && f.default !== null && f.default !== undefined)
73
+ out.default = f.default;
74
+ return out;
75
+ }
76
+ function attributesOf(schema) {
77
+ const out = {};
78
+ for (const [k, f] of Object.entries(schema.fields))
79
+ if (!f.legacyHidden)
80
+ out[k] = fieldSpecOf(k, f);
81
+ return out;
82
+ }
83
+ /** A theme setting (`defineSettings`) as a manifest settings item. */
84
+ function settingItem(key, s) {
85
+ const out = { key, type: s.type, label: s.label ?? humanize(key) };
86
+ if (s.info)
87
+ out.info = s.info;
88
+ if (s.placeholder)
89
+ out.placeholder = s.placeholder;
90
+ if (s.options)
91
+ out.options = s.options.map((o) => ({ value: o.value, label: o.label }));
92
+ if (s.type === 'range' || s.type === 'number') {
93
+ if (s.min !== undefined)
94
+ out.min = s.min;
95
+ if (s.max !== undefined)
96
+ out.max = s.max;
97
+ if (s.step !== undefined)
98
+ out.step = s.step;
99
+ if (s.type === 'range' && s.unit)
100
+ out.unit = s.unit;
101
+ }
102
+ if (s.default !== '' && s.default !== null && s.default !== undefined)
103
+ out.default = s.default;
104
+ return out;
105
+ }
106
+ const cleanSettings = (settings) => Object.fromEntries(Object.entries(settings ?? {}).filter(([, v]) => v !== '' && v !== null && v !== undefined));
107
+ /** The manifest of a headless theme. */
108
+ export function buildManifest(input) {
109
+ const problems = [];
110
+ const check = (where, type, value, spec) => {
111
+ if (!input.checkValue)
112
+ return;
113
+ const r = input.checkValue(type, value, spec);
114
+ if (!r.ok)
115
+ problems.push(`${where} ${JSON.stringify(value).slice(0, 80)}: ${(r.errors ?? []).map((e) => `${e.message}${e.code ? ` (${e.code})` : ''}`).join('; ')}`);
116
+ };
117
+ // ── components ───────────────────────────────────────────────────────
118
+ const components = {};
119
+ const sections = input.theme.sections;
120
+ for (const s of sections) {
121
+ if (components[s.id])
122
+ problems.push(`sections: "${s.id}" is declared twice`);
123
+ const c = {
124
+ role: s.zone === 'main' ? 'section' : 'layout',
125
+ title: s.title ?? humanize(s.id),
126
+ attributes: attributesOf(s.schema),
127
+ regions: [ZONE_REGION[s.zone] ?? 'main'],
128
+ category: s.category,
129
+ };
130
+ if (s.description)
131
+ c.description = s.description;
132
+ if (s.icon)
133
+ c.icon = s.icon;
134
+ const blocks = s.blocks ?? [];
135
+ if (blocks.length)
136
+ c.children = blocks.map((b) => b.name);
137
+ if (s.requiresContext?.length)
138
+ c.requires = [...s.requiresContext];
139
+ if (s.presets?.length) {
140
+ c.presets = s.presets.map((p, pi) => {
141
+ const settings = cleanSettings(p.settings);
142
+ return {
143
+ name: p.name,
144
+ ...(Object.keys(settings).length ? { settings } : {}),
145
+ ...(p.blocks?.length ? { blocks: p.blocks.map((b, bi) => ({ type: b.type, id: `${s.id}-preset${pi}-${bi}`, ...(Object.keys(cleanSettings(b.settings)).length ? { settings: cleanSettings(b.settings) } : {}) })) } : {}),
146
+ };
147
+ });
148
+ }
149
+ components[s.id] = c;
150
+ for (const b of blocks) {
151
+ const existing = components[b.name];
152
+ if (existing && existing.role !== 'block') {
153
+ problems.push(`blocks: "${b.name}" is also a section type`);
154
+ continue;
155
+ }
156
+ const parents = new Set([...(existing?.parents ?? []), ...(b.parents ?? []), s.id]);
157
+ components[b.name] = { role: 'block', title: b.title ?? humanize(b.name), attributes: attributesOf(b), parents: [...parents], ...(b.description ? { description: b.description } : {}), ...(b.requiresContext?.length ? { requires: [...b.requiresContext] } : {}) };
158
+ }
159
+ }
160
+ // Defaults and preset values against their attributes.
161
+ for (const [cid, c] of Object.entries(components)) {
162
+ const attrs = c.attributes;
163
+ for (const [k, spec] of Object.entries(attrs))
164
+ if (spec.default !== undefined)
165
+ check(`components.${cid}.attributes.${k}.default`, String(spec.type), spec.default, spec);
166
+ c.presets?.forEach((p, i) => {
167
+ for (const [k, v] of Object.entries(p.settings ?? {})) {
168
+ const spec = attrs[k];
169
+ if (!spec)
170
+ problems.push(`components.${cid}.presets[${i}].settings.${k}: not an attribute of "${cid}"`);
171
+ else
172
+ check(`components.${cid}.presets[${i}].settings.${k}`, String(spec.type), v, spec);
173
+ }
174
+ for (const b of p.blocks ?? []) {
175
+ const bc = components[b.type];
176
+ if (!bc)
177
+ problems.push(`components.${cid}.presets[${i}].blocks: "${b.type}" is not a block`);
178
+ else
179
+ for (const [k, v] of Object.entries(b.settings ?? {})) {
180
+ const spec = bc.attributes[k];
181
+ if (!spec)
182
+ problems.push(`components.${cid}.presets[${i}].blocks.${b.type}.${k}: not an attribute`);
183
+ else
184
+ check(`components.${cid}.presets[${i}].blocks.${b.type}.${k}`, String(spec.type), v, spec);
185
+ }
186
+ }
187
+ });
188
+ }
189
+ // ── settings ─────────────────────────────────────────────────────────
190
+ const groups = new Map();
191
+ for (const [key, spec] of Object.entries(input.settings ?? {})) {
192
+ const g = spec.group ?? 'General';
193
+ if (!groups.has(g))
194
+ groups.set(g, []);
195
+ const item = settingItem(key, spec);
196
+ if (item.default !== undefined)
197
+ check(`settingsSchema.${g}.${key}.default`, spec.type, item.default, item);
198
+ groups.get(g).push(item);
199
+ }
200
+ const settingsSchema = [...groups].map(([group, items]) => ({ group, items }));
201
+ // ── routes, templates, regions ───────────────────────────────────────
202
+ const regions = input.regions ?? DEFAULT_REGIONS;
203
+ const templates = {};
204
+ const routes = {};
205
+ for (const [name, t] of Object.entries(input.templates)) {
206
+ const order = t.regions ?? ['header', 'main', 'footer'];
207
+ for (const r of order)
208
+ if (!regions[r])
209
+ problems.push(`templates.${name}: region "${r}" is not declared`);
210
+ templates[name] = { route: t.route, regions: [...order], ...(t.title ? { title: t.title } : {}) };
211
+ // The unsuffixed template of a kind is its default (`product.bundle` is chosen by templateSuffix).
212
+ if (!name.includes('.') && !routes[t.route])
213
+ routes[t.route] = name;
214
+ }
215
+ for (const [name, t] of Object.entries(input.templates))
216
+ if (!routes[t.route])
217
+ routes[t.route] = name;
218
+ for (const kind of Object.keys(routes))
219
+ if (kind.startsWith('custom:') && !input.customRoutes?.[kind.slice(7)])
220
+ problems.push(`routes.${kind}: no customRoutes.${kind.slice(7)}.path`);
221
+ // ── capabilities, forms, AI ──────────────────────────────────────────
222
+ const uniq = (a, b = []) => [...new Set([...a, ...b])];
223
+ const capabilities = { server: uniq(SERVER_CAPABILITIES, input.capabilities?.server), browser: uniq(BROWSER_CAPABILITIES, input.capabilities?.browser) };
224
+ const forms = {};
225
+ for (const id of ['newsletter', 'contact']) {
226
+ const f = input.forms?.[id];
227
+ if (!f)
228
+ continue;
229
+ forms[id] = { title: typeof f === 'object' ? f.title : humanize(id), fields: [...FORM_FIELDS[id]] };
230
+ }
231
+ const profile = input.aiProfile === false ? null : (input.aiProfile ?? aiProfileOf(sections));
232
+ if (profile)
233
+ problems.push(...checkAiProfile(profile, components));
234
+ const manifest = {
235
+ abi: '2.0',
236
+ name: input.name,
237
+ version: input.version,
238
+ engines: { 'tanqory-abi': '^2.0', 'tanqory-field-types': input.fieldTypes ?? '2' },
239
+ capabilities,
240
+ client: { hydration: 'full' },
241
+ ...(Object.keys(forms).length ? { forms } : {}),
242
+ contentVersion: input.contentVersion ?? 1,
243
+ routes,
244
+ ...(input.customRoutes ? { customRoutes: input.customRoutes } : {}),
245
+ templates,
246
+ regions,
247
+ components,
248
+ settingsSchema,
249
+ ...(profile ? { 'x-tanqory-ai': profile } : {}),
250
+ ...(input.extensions ?? {}),
251
+ };
252
+ return { manifest, problems };
253
+ }
254
+ const NODE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
255
+ /**
256
+ * Problems in starter content (a template's or region's sections): every node names a declared component, has an
257
+ * ABI node id, and holds only its component's attributes (each value through `checkValue` when given).
258
+ */
259
+ export function checkContent(where, nodes, manifest, checkValue) {
260
+ const problems = [];
261
+ const components = (manifest.components ?? {});
262
+ const walk = (list, at) => list.forEach((n, i) => {
263
+ const here = `${at}[${i}]`;
264
+ const c = n.type ? components[n.type] : undefined;
265
+ if (!c)
266
+ return void problems.push(`${here}: component "${n.type}" is not declared`);
267
+ if (!n.id || !NODE_ID.test(n.id) || n.id.length > 64)
268
+ problems.push(`${here}: node id ${JSON.stringify(n.id)} does not match the ABI id pattern`);
269
+ for (const [k, v] of Object.entries(n.settings ?? {})) {
270
+ const spec = c.attributes?.[k];
271
+ if (!spec)
272
+ problems.push(`${here}.settings.${k}: not an attribute of "${n.type}"`);
273
+ else if (checkValue) {
274
+ const r = checkValue(String(spec.type), v, spec);
275
+ if (!r.ok)
276
+ problems.push(`${here}.settings.${k} ${JSON.stringify(v).slice(0, 80)}: ${(r.errors ?? []).map((e) => e.message).join('; ')}`);
277
+ }
278
+ }
279
+ if (n.blocks)
280
+ walk(n.blocks, `${here}.blocks`);
281
+ });
282
+ walk(nodes, where);
283
+ return problems;
284
+ }
285
+ /**
286
+ * The theme's locale files with the kit's words underneath: every key the kit's primitives use exists in every
287
+ * language the kit has words for, and the theme's own values win.
288
+ */
289
+ export function withKitStrings(locales) {
290
+ const out = {};
291
+ for (const [lang, map] of Object.entries(locales))
292
+ out[lang] = { ...(KIT_STRINGS[lang] ?? KIT_STRINGS.en), ...map };
293
+ return out;
294
+ }
@@ -0,0 +1,19 @@
1
+ import { type ThemeBundle } from './runtime/slots.js';
2
+ import type { ContentNode } from './runtime/kit/types.js';
3
+ type Settings = Record<string, unknown>;
4
+ export interface HydrateOptions {
5
+ /** The theme bundle the server entry was built from (the same object `createRender` got). */
6
+ bundle: ThemeBundle;
7
+ /**
8
+ * The same node transform the server entry applies (`RenderOptions.transformNodes`), so the
9
+ * hydrated tree is the one the server rendered. Default: unchanged.
10
+ */
11
+ transformNodes?(nodes: ContentNode[], settings: Settings): ContentNode[];
12
+ }
13
+ /**
14
+ * Hydrates the server-rendered page. Call it once, at module scope of the theme's browser entry.
15
+ * Does nothing on a page without the server's state block.
16
+ */
17
+ export declare function hydrate(options: HydrateOptions): void;
18
+ export type { ThemeBundle } from './runtime/slots.js';
19
+ export type { ContentNode } from './runtime/kit/types.js';
package/dist/client.js ADDED
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * `@tanqory/theme-kit/client` — the Theme ABI v2 browser entry as a function: the one `isEntry`
4
+ * script of client/client-manifest.json calls `hydrate({ bundle })`.
5
+ *
6
+ * It hydrates exactly what `createRender` (./server) rendered: the page's content document and the
7
+ * data the server loaded are read back from the non-executable
8
+ * `<script type="application/json" id="tq-state">` block, so the first client render is built from
9
+ * the same bytes. Dynamic style values are class rules (sdk/sx.ts): the server block already holds
10
+ * the first render's, and a later one is inserted through CSSOM. After hydration the only requests
11
+ * are same-origin `/_tq/data/*` and `/_tq/actions/*` (abi/wire.ts).
12
+ *
13
+ * On the editor canvas (a preview render) the section nodes live in a store the platform's editor
14
+ * bridge feeds (`tq:canvas` events, announced with `tq:canvas-live`), so a setting edit re-renders
15
+ * its section without a reload (abi/canvas-live.ts). A theme does nothing to get this.
16
+ */
17
+ import { useSyncExternalStore } from 'react';
18
+ import { hydrateRoot } from 'react-dom/client';
19
+ import { setThemeBundle } from './runtime/slots.js';
20
+ import { sectionModules } from './runtime/entries/sections.js';
21
+ import { registerSections } from './runtime/kit/registry.js';
22
+ import { SectionTree } from './runtime/kit/SectionTree.js';
23
+ import { DataProvider } from './runtime/kit/data.js';
24
+ import { ThemeProvider } from './runtime/kit/theme-context.js';
25
+ import { PreviewModeProvider } from './runtime/shell/preview-mode.js';
26
+ import { localeStrings } from './runtime/platform/locale.js';
27
+ import { AbiShell } from './abi/shell.js';
28
+ import { createDataApi } from './abi/data-api.js';
29
+ import { AbiCartProvider } from './abi/cart.js';
30
+ import { AbiRewardsProvider, HOST_OFFERS_LOYALTY } from './abi/rewards.js';
31
+ import { keepRefCode } from './abi/referrals.js';
32
+ import { createAbiRemote } from './abi/wire.js';
33
+ import { connectCanvas, createCanvasStore } from './abi/canvas-live.js';
34
+ import { locationOf, nodesOf, notFoundTree } from './abi/page.js';
35
+ /**
36
+ * The editor canvas (a preview render): the section nodes live in a store the platform's editor
37
+ * bridge feeds, so a setting edit re-renders its section without a reload (abi/canvas-live.ts).
38
+ */
39
+ function LiveSectionTree({ store, settings, transform }) {
40
+ const nodes = useSyncExternalStore(store.subscribe, store.get, store.get);
41
+ return _jsx(SectionTree, { tree: transform(nodes, settings) });
42
+ }
43
+ /**
44
+ * Hydrates the server-rendered page. Call it once, at module scope of the theme's browser entry.
45
+ * Does nothing on a page without the server's state block.
46
+ */
47
+ export function hydrate(options) {
48
+ const { bundle } = options;
49
+ const transform = options.transformNodes ?? ((n) => n);
50
+ setThemeBundle(bundle);
51
+ registerSections(Object.values(sectionModules()).map((m) => m.default));
52
+ const LOCALE_MAPS = Object.fromEntries(Object.entries(bundle.locales).map(([path, mod]) => [path.match(/\/([^/]+)\.json$/)?.[1] ?? 'en', mod.default]));
53
+ const el = document.getElementById('tq-state');
54
+ const root = document.getElementById('root');
55
+ if (!el || !root)
56
+ return;
57
+ const state = JSON.parse(el.textContent ?? '{}');
58
+ const remote = createAbiRemote();
59
+ const data = createDataApi(state.data, remote);
60
+ const settings = state.settings ?? {};
61
+ const raw = nodesOf(state.page.regions);
62
+ const ui = state.ui ?? 'en';
63
+ const strings = localeStrings(ui, LOCALE_MAPS);
64
+ const location = locationOf(state.route.canonical, state.route.params ?? {}, state.listing ?? '');
65
+ const preview = state.preview === true;
66
+ // Preview only: never on a live storefront, whose page has no bridge to answer.
67
+ let canvas = null;
68
+ if (preview) {
69
+ canvas = createCanvasStore(raw);
70
+ connectCanvas(window, canvas, (type, detail) => new CustomEvent(type, { detail }));
71
+ }
72
+ // A `?ref=` visit keeps the friend's code for checkout even while the host has no referral ops.
73
+ if (!preview && !HOST_OFFERS_LOYALTY)
74
+ keepRefCode(window.location.search);
75
+ hydrateRoot(root, _jsx(PreviewModeProvider, { value: preview, children: _jsx(DataProvider, { value: data, children: _jsx(ThemeProvider, { settings: settings, locale: strings, children: _jsx(AbiCartProvider, { initial: state.data.cart, remote: remote, children: _jsx(AbiRewardsProvider, { remote: preview || !HOST_OFFERS_LOYALTY ? null : remote, children: _jsx(AbiShell, { location: location, locale: ui, contentLanguage: state.lang, settings: settings, preview: preview, children: canvas ? _jsx(LiveSectionTree, { store: canvas, settings: settings, transform: transform }) : _jsx(SectionTree, { tree: state.data.routeMissing ? notFoundTree(transform(raw, settings)) : transform(raw, settings) }) }) }) }) }) }) }));
76
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@tanqory/theme-kit/contract` — the content contract the editor and the runtime share: page and
3
+ * section-group documents, roles, validation and the content-version transforms. Pure (no React,
4
+ * no DOM), so build scripts and the manifest generator can load it in Node.
5
+ */
6
+ export * from './runtime/kit/contract/index.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@tanqory/theme-kit/contract` — the content contract the editor and the runtime share: page and
3
+ * section-group documents, roles, validation and the content-version transforms. Pure (no React,
4
+ * no DOM), so build scripts and the manifest generator can load it in Node.
5
+ */
6
+ export * from './runtime/kit/contract/index.js';
@@ -0,0 +1,132 @@
1
+ /**
2
+ * AI compatibility: which of a theme's own sections and settings play the roles Tanqory AI fills (a hero, the
3
+ * header menu, the footer menus and brand, product grids, text blocks), so AI can compose any theme, not one
4
+ * vocabulary. Declared per section with the `ai.*` helpers; the build prints the profile into the manifest as
5
+ * `x-tanqory-ai` (draft v0).
6
+ *
7
+ * defineSection({ type: 'hero', …, ai: ai.hero({ heading: 'heading', image: 'image', button: 'buttonLabel', link: 'buttonLink' }) })
8
+ * defineSection({ type: 'header', …, ai: ai.headerMenu('menu') })
9
+ * defineSection({ type: 'footer', …, ai: [ai.footerMenu('menu', { block: 'footer-menu' }), ai.footerBrand({ block: 'footer-brand' })] })
10
+ *
11
+ * Pure: no React, no DOM (the build loads it in Node).
12
+ */
13
+ export type AiRole = {
14
+ role: 'hero';
15
+ heading: string;
16
+ subheading?: string;
17
+ image?: string;
18
+ button?: string;
19
+ link?: string;
20
+ block?: string;
21
+ } | {
22
+ role: 'headerMenu';
23
+ setting: string;
24
+ block?: string;
25
+ } | {
26
+ role: 'footerMenu';
27
+ setting: string;
28
+ block?: string;
29
+ } | {
30
+ role: 'footerBrand';
31
+ block?: string;
32
+ } | {
33
+ role: 'productGrid';
34
+ setting: string;
35
+ heading?: string;
36
+ block?: string;
37
+ } | {
38
+ role: 'richText';
39
+ heading?: string;
40
+ body?: string;
41
+ block?: string;
42
+ };
43
+ /** Role declarations for `defineSection({ ai })`. Every key names one of the section's (or its block's) settings. */
44
+ export declare const ai: {
45
+ /** A hero: `heading` (text), and optionally `subheading`, `image` (image), `button` (text) and `link` (url). */
46
+ hero: (keys: {
47
+ heading: string;
48
+ subheading?: string;
49
+ image?: string;
50
+ button?: string;
51
+ link?: string;
52
+ block?: string;
53
+ }) => AiRole;
54
+ /** The header's main menu: a `menu` setting. */
55
+ headerMenu: (setting: string, opts?: {
56
+ block?: string;
57
+ }) => AiRole;
58
+ /** A footer menu: a `menu` setting, usually on a block. */
59
+ footerMenu: (setting: string, opts?: {
60
+ block?: string;
61
+ }) => AiRole;
62
+ /** The footer's brand area (the section or one of its blocks). */
63
+ footerBrand: (opts?: {
64
+ block?: string;
65
+ }) => AiRole;
66
+ /** A product grid: a `collection` or `product` setting, and its heading. */
67
+ productGrid: (setting: string, opts?: {
68
+ heading?: string;
69
+ block?: string;
70
+ }) => AiRole;
71
+ /** A text section: its `heading` and `body` settings. */
72
+ richText: (keys: {
73
+ heading?: string;
74
+ body?: string;
75
+ block?: string;
76
+ }) => AiRole;
77
+ };
78
+ /** `manifest["x-tanqory-ai"]` (draft v0). */
79
+ export interface AiProfile {
80
+ version: 0;
81
+ roles: {
82
+ hero?: {
83
+ component: string;
84
+ block?: string;
85
+ heading: string;
86
+ subheading?: string;
87
+ image?: string;
88
+ button?: string;
89
+ link?: string;
90
+ }[];
91
+ headerMenu?: {
92
+ component: string;
93
+ block?: string;
94
+ setting: string;
95
+ };
96
+ footerMenus?: {
97
+ component: string;
98
+ block?: string;
99
+ setting: string;
100
+ }[];
101
+ footerBrand?: {
102
+ component: string;
103
+ block?: string;
104
+ };
105
+ productGrid?: {
106
+ component: string;
107
+ block?: string;
108
+ setting: string;
109
+ heading?: string;
110
+ }[];
111
+ richText?: {
112
+ component: string;
113
+ block?: string;
114
+ heading?: string;
115
+ body?: string;
116
+ }[];
117
+ };
118
+ }
119
+ /** The profile from each section's `ai` roles, or null when no section declares one. */
120
+ export declare function aiProfileOf(sections: readonly {
121
+ id: string;
122
+ ai?: AiRole | readonly AiRole[];
123
+ }[]): AiProfile | null;
124
+ /**
125
+ * Problems with a profile against the manifest's components: every component/block it names must exist, and
126
+ * every setting must exist with a matching type (`menu` for menus, `collection`/`product` for product grids).
127
+ */
128
+ export declare function checkAiProfile(profile: AiProfile, components: Readonly<Record<string, {
129
+ attributes?: Readonly<Record<string, {
130
+ type?: string;
131
+ }>>;
132
+ }>>): string[];
@@ -0,0 +1,99 @@
1
+ /**
2
+ * AI compatibility: which of a theme's own sections and settings play the roles Tanqory AI fills (a hero, the
3
+ * header menu, the footer menus and brand, product grids, text blocks), so AI can compose any theme, not one
4
+ * vocabulary. Declared per section with the `ai.*` helpers; the build prints the profile into the manifest as
5
+ * `x-tanqory-ai` (draft v0).
6
+ *
7
+ * defineSection({ type: 'hero', …, ai: ai.hero({ heading: 'heading', image: 'image', button: 'buttonLabel', link: 'buttonLink' }) })
8
+ * defineSection({ type: 'header', …, ai: ai.headerMenu('menu') })
9
+ * defineSection({ type: 'footer', …, ai: [ai.footerMenu('menu', { block: 'footer-menu' }), ai.footerBrand({ block: 'footer-brand' })] })
10
+ *
11
+ * Pure: no React, no DOM (the build loads it in Node).
12
+ */
13
+ /** Role declarations for `defineSection({ ai })`. Every key names one of the section's (or its block's) settings. */
14
+ export const ai = {
15
+ /** A hero: `heading` (text), and optionally `subheading`, `image` (image), `button` (text) and `link` (url). */
16
+ hero: (keys) => ({ role: 'hero', ...keys }),
17
+ /** The header's main menu: a `menu` setting. */
18
+ headerMenu: (setting, opts = {}) => ({ role: 'headerMenu', setting, ...opts }),
19
+ /** A footer menu: a `menu` setting, usually on a block. */
20
+ footerMenu: (setting, opts = {}) => ({ role: 'footerMenu', setting, ...opts }),
21
+ /** The footer's brand area (the section or one of its blocks). */
22
+ footerBrand: (opts = {}) => ({ role: 'footerBrand', ...opts }),
23
+ /** A product grid: a `collection` or `product` setting, and its heading. */
24
+ productGrid: (setting, opts = {}) => ({ role: 'productGrid', setting, ...opts }),
25
+ /** A text section: its `heading` and `body` settings. */
26
+ richText: (keys) => ({ role: 'richText', ...keys }),
27
+ };
28
+ /** The profile from each section's `ai` roles, or null when no section declares one. */
29
+ export function aiProfileOf(sections) {
30
+ const roles = {};
31
+ for (const s of sections) {
32
+ for (const r of s.ai ? (Array.isArray(s.ai) ? s.ai : [s.ai]) : []) {
33
+ const { role, ...rest } = r;
34
+ const entry = { component: s.id, ...rest };
35
+ switch (role) {
36
+ case 'hero':
37
+ (roles.hero ??= []).push(entry);
38
+ break;
39
+ case 'headerMenu':
40
+ roles.headerMenu ??= entry;
41
+ break;
42
+ case 'footerMenu':
43
+ (roles.footerMenus ??= []).push(entry);
44
+ break;
45
+ case 'footerBrand':
46
+ roles.footerBrand ??= entry;
47
+ break;
48
+ case 'productGrid':
49
+ (roles.productGrid ??= []).push(entry);
50
+ break;
51
+ case 'richText':
52
+ (roles.richText ??= []).push(entry);
53
+ break;
54
+ }
55
+ }
56
+ }
57
+ return Object.keys(roles).length ? { version: 0, roles } : null;
58
+ }
59
+ /** Setting types each role key accepts (manifest field types). */
60
+ const ROLE_KEY_TYPES = {
61
+ heading: ['text', 'textarea', 'inline_richtext', 'richtext', 'heading'],
62
+ subheading: ['text', 'textarea', 'inline_richtext', 'richtext'],
63
+ body: ['richtext', 'textarea', 'text', 'inline_richtext'],
64
+ image: ['image'],
65
+ button: ['text'],
66
+ link: ['url', 'link'],
67
+ };
68
+ /**
69
+ * Problems with a profile against the manifest's components: every component/block it names must exist, and
70
+ * every setting must exist with a matching type (`menu` for menus, `collection`/`product` for product grids).
71
+ */
72
+ export function checkAiProfile(profile, components) {
73
+ const problems = [];
74
+ for (const [role, value] of Object.entries(profile.roles)) {
75
+ const list = (Array.isArray(value) ? value : [value]);
76
+ list.forEach((target, i) => {
77
+ const at = `x-tanqory-ai.roles.${role}${Array.isArray(value) ? `[${i}]` : ''}`;
78
+ if (!components[target.component])
79
+ return void problems.push(`${at}.component "${target.component}" is not a manifest component`);
80
+ if (target.block && !components[target.block])
81
+ return void problems.push(`${at}.block "${target.block}" is not a manifest component`);
82
+ const owner = target.block ?? target.component;
83
+ const attrs = components[owner]?.attributes ?? {};
84
+ for (const [key, name] of Object.entries(target)) {
85
+ if (key === 'component' || key === 'block')
86
+ continue;
87
+ const want = key === 'setting' ? (role === 'headerMenu' || role === 'footerMenus' ? ['menu'] : ['collection', 'product']) : ROLE_KEY_TYPES[key];
88
+ if (!want)
89
+ continue;
90
+ const a = attrs[name];
91
+ if (!a)
92
+ problems.push(`${at}.${key} "${name}" is not a setting of ${owner}`);
93
+ else if (!want.includes(String(a.type)))
94
+ problems.push(`${at}.${key} "${name}" has type ${a.type}; expected ${want.join('|')}`);
95
+ }
96
+ });
97
+ }
98
+ return problems;
99
+ }