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

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 (202) 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 +256 -0
  7. package/dist/abi/convert.d.ts +126 -0
  8. package/dist/abi/convert.js +493 -0
  9. package/dist/abi/data-api.d.ts +11 -0
  10. package/dist/abi/data-api.js +178 -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 +198 -0
  14. package/dist/abi/page-data.js +577 -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 +237 -0
  72. package/dist/runtime/data/to-ui.js +759 -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 +167 -0
  82. package/dist/runtime/kit/cart.js +544 -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/{types → runtime/kit}/data.d.ts +276 -7
  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/{types → runtime/kit}/storefront.d.ts +206 -7
  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 +44 -0
  144. package/dist/runtime/render/section-actions.js +169 -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 +82 -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 +120 -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 +395 -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/editor.d.ts +0 -5
  200. package/dist/types/index.d.ts +0 -20
  201. package/dist/types/preview-bridge.d.ts +0 -9
  202. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Cookie-consent state — the single source of truth the storefront consults
3
+ * before running any tracking (analytics beacon, marketing pixels), so the
4
+ * shopper's choice is actually ENFORCED.
5
+ *
6
+ * Model: two purposes, `analytics` + `marketing`. The decision persists in
7
+ * localStorage (`tq-cookie-consent`) and a `tq-consent-change` event lets
8
+ * subscribers (pixels, analytics) react live to Accept/Decline/Manage.
9
+ *
10
+ * DENY-UNTIL-DECIDED IS THE DEFAULT (journey-matrix 0.5). This gate used to start
11
+ * "no banner required → everything allowed", set from the MERCHANT's toggle, so an EU
12
+ * shopper in a shop whose owner never enabled the banner was tracked with no consent,
13
+ * and so was everyone before shop data arrived. The mode is now decided by the SERVER
14
+ * from the shopper's jurisdiction (`shop.cookieBanner.mode`) and the merchant's toggle
15
+ * can only add protection. Until that verdict arrives the mode is OPT_IN.
16
+ *
17
+ * Gate semantics (`hasConsent`):
18
+ * - GPC signalled → MARKETING is denied in every mode, even after an accept-all (analytics unaffected).
19
+ * - mode NONE (no consent statute applies to this shopper) → allowed.
20
+ * - mode OPT_IN + undecided → denied (GDPR/ePrivacy/UK/CH/LGPD/PDPA/Quebec, and unknown location).
21
+ * - mode OPT_OUT + undecided → allowed, except MARKETING when the shopper sends
22
+ * Global Privacy Control (a decline without a click). US opt-out states.
23
+ * - decided → the stored purpose flag, in every mode.
24
+ */
25
+ const KEY = 'tq-cookie-consent';
26
+ const EVENT = 'tq-consent-change';
27
+ // Fail closed until the theme has the shop's verdict.
28
+ let mode = 'OPT_IN';
29
+ /**
30
+ * True once an AUTHORITATIVE verdict for THIS shopper has set the mode (the LIVE per-request answer). A snapshot or a
31
+ * default never arms it. The banner is shown only when armed — so a not-yet-armed gate is closed AND silent.
32
+ */
33
+ let armed = false;
34
+ const MODE_EVENT = 'tq-consent-mode';
35
+ const announce = () => {
36
+ try {
37
+ window.dispatchEvent(new CustomEvent(MODE_EVENT));
38
+ }
39
+ catch {
40
+ /* SSR / no window */
41
+ }
42
+ };
43
+ /** Set the mode from an authoritative (live) verdict. The ONLY way the gate opens — components must not call it. */
44
+ export function setConsentMode(m) {
45
+ mode = m;
46
+ armed = true;
47
+ announce();
48
+ }
49
+ /** Force the gate closed (OPT_IN) and un-armed — the SSG boot, until the live answer arrives. */
50
+ export function holdConsentClosed() {
51
+ mode = 'OPT_IN';
52
+ armed = false;
53
+ announce();
54
+ }
55
+ export function getConsentMode() {
56
+ return mode;
57
+ }
58
+ export function isConsentArmed() {
59
+ return armed;
60
+ }
61
+ /** Subscribe to mode/armed changes (banner display); returns an unsubscribe fn. */
62
+ export function onConsentModeChange(cb) {
63
+ try {
64
+ window.addEventListener(MODE_EVENT, cb);
65
+ return () => window.removeEventListener(MODE_EVENT, cb);
66
+ }
67
+ catch {
68
+ return () => { };
69
+ }
70
+ }
71
+ /** Back-compat for callers that only know a boolean: true → OPT_IN, false → NONE. */
72
+ export function setBannerRequired(v) {
73
+ setConsentMode(v ? 'OPT_IN' : 'NONE');
74
+ }
75
+ export function isBannerRequired() {
76
+ return mode !== 'NONE';
77
+ }
78
+ /**
79
+ * The mode for a loaded shop. The server's `cookieBanner.mode` is authoritative; an older API that only sends `enabled`
80
+ * is read as before (enabled → OPT_IN); anything missing or unrecognised is OPT_IN, never permissive.
81
+ */
82
+ export function consentModeFromShop(shop) {
83
+ const cb = shop
84
+ ?.cookieBanner;
85
+ if (!cb || typeof cb !== 'object')
86
+ return 'OPT_IN';
87
+ if (cb.mode === 'OPT_IN' || cb.mode === 'OPT_OUT' || cb.mode === 'NONE')
88
+ return cb.mode;
89
+ if (cb.mode !== undefined && cb.mode !== null)
90
+ return 'OPT_IN';
91
+ return cb.enabled ? 'OPT_IN' : 'NONE';
92
+ }
93
+ function gpcSignalled() {
94
+ try {
95
+ return navigator.globalPrivacyControl === true;
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ }
101
+ /** The stored decision, or null when the shopper hasn't chosen yet. */
102
+ export function getConsent() {
103
+ try {
104
+ const raw = localStorage.getItem(KEY);
105
+ if (!raw)
106
+ return null;
107
+ if (raw === 'accepted')
108
+ return { analytics: true, marketing: true };
109
+ if (raw === 'declined')
110
+ return { analytics: false, marketing: false };
111
+ const p = JSON.parse(raw);
112
+ return { analytics: !!p.analytics, marketing: !!p.marketing };
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ }
118
+ export function hasDecided() {
119
+ return getConsent() !== null;
120
+ }
121
+ export function setConsent(c) {
122
+ try {
123
+ localStorage.setItem(KEY, JSON.stringify(c));
124
+ }
125
+ catch {
126
+ /* private mode — the choice just won't persist across reloads */
127
+ }
128
+ try {
129
+ window.dispatchEvent(new CustomEvent(EVENT, { detail: c }));
130
+ }
131
+ catch {
132
+ /* SSR / no window */
133
+ }
134
+ }
135
+ /** True when `purpose` may run right now (see gate semantics above). */
136
+ export function hasConsent(purpose) {
137
+ // Global Privacy Control is honoured EVERYWHERE and beats even a stored "accept all": marketing is never allowed while
138
+ // the browser signals GPC (conservative reading, matches admin-api's "GPC always wins"; analytics is unaffected).
139
+ if (purpose === 'marketing' && gpcSignalled())
140
+ return false;
141
+ const c = getConsent();
142
+ // An explicit decision on this site beats every default.
143
+ if (c)
144
+ return c[purpose];
145
+ if (mode === 'NONE' || mode === 'OPT_OUT')
146
+ return true;
147
+ return false;
148
+ }
149
+ /** Subscribe to consent changes; returns an unsubscribe fn. */
150
+ export function onConsentChange(cb) {
151
+ const handler = (e) => cb(e.detail);
152
+ try {
153
+ window.addEventListener(EVENT, handler);
154
+ return () => window.removeEventListener(EVENT, handler);
155
+ }
156
+ catch {
157
+ return () => { };
158
+ }
159
+ }
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The content-tree contract: what a `templates/<slug>.json` may contain, and
3
+ * the node-identity rules every producer (Editor, AI, theme author) must follow.
4
+ *
5
+ * Node identity is the part that was never written down, and it is the part the
6
+ * round trip depends on. Today:
7
+ *
8
+ * - The Editor mints `${type}_${uuid8}` (`tanqory-template-context.tsx:379`)
9
+ * — stable and unique. Correct.
10
+ * - `blocksToStudio` (`editor-routes.mjs:49-62`) falls back to
11
+ * `` `${b.type}-${i}` `` for a block with no id — a POSITIONAL identity.
12
+ * Reorder the array on disk and `faq-item-0` now means a different question.
13
+ * - `themekitToStudio` falls back to `s.id ?? s.type` for a section — so two
14
+ * sections of the same type with no id COLLIDE in the `sections` map and the
15
+ * second silently overwrites the first.
16
+ *
17
+ * Both fallbacks are silent. Neither is safe for "AI edits one answer without
18
+ * clobbering the others", which is exactly what this contract has to make true.
19
+ * The rule below is therefore: **every node carries an explicit, stable id.**
20
+ */
21
+ /** A node in the content tree — a section instance or a child block. */
22
+ export interface ContractNode {
23
+ /** The section/block definition name this instantiates. */
24
+ type: string;
25
+ /** Stable identity. Required by this contract; see `mintNodeId`. */
26
+ id: string;
27
+ settings?: Record<string, unknown>;
28
+ blocks?: ContractNode[];
29
+ /**
30
+ * Layout slot. Nova's templates use this 43 times; nothing in the kit or the
31
+ * theme reads it, and the Editor's save round-trip currently DROPS it
32
+ * (neither `themekitToStudio` nor `studioToThemekit` mentions it).
33
+ * Declared here so it is a known key with known values — a converter that
34
+ * preserves the contract's keys preserves this one.
35
+ */
36
+ area?: TemplateArea;
37
+ }
38
+ export type TemplateArea = 'header' | 'template' | 'footer';
39
+ export declare const TEMPLATE_AREAS: readonly TemplateArea[];
40
+ /** A template document as stored at `templates/<slug>.json`. */
41
+ export interface ContractPageDoc {
42
+ sections: ContractNode[];
43
+ /**
44
+ * Content-format version.
45
+ * absent / 1 — inline header + footer sections in every template (legacy;
46
+ * still fully supported, resolved as an implicit per-page copy)
47
+ * 2 — `groups` bindings: header/footer come from a shared
48
+ * `groups/<name>.json` unless the page overrides them.
49
+ * A future shape change bumps this and gets a migration, instead of silently
50
+ * orphaning a merchant's customisation the way a path-prefix merge does.
51
+ */
52
+ contentVersion?: number;
53
+ /**
54
+ * Shared-slot bindings (content version 2). See `groups.ts` for the shape.
55
+ * Declared here as `unknown` so the base document type stays independent of
56
+ * the group module; `GroupedPageDoc` narrows it.
57
+ */
58
+ groups?: unknown;
59
+ }
60
+ export declare const CURRENT_CONTENT_VERSION = 2;
61
+ /**
62
+ * Node ids must be URL-safe, stable across saves, and unique within their
63
+ * parent. Readable prefixes are deliberate: `faq-item_a1b2c3d4` is greppable in
64
+ * a diff, which matters when the thing being diffed is a merchant's content.
65
+ */
66
+ export declare const NODE_ID_PATTERN: RegExp;
67
+ /**
68
+ * Mint a stable node id. Matches the Editor's own scheme
69
+ * (`tanqory-template-context.tsx:379`) so a node authored by AI and a node
70
+ * authored by a human are indistinguishable downstream.
71
+ */
72
+ export declare function mintNodeId(type: string, rand?: () => string): string;
73
+ /**
74
+ * What a section definition promises. This is `SectionDef` minus `component` —
75
+ * the serialisable half — plus the two things the platform needs and no
76
+ * existing artifact carries: the context a section requires, and which runtimes
77
+ * it works against.
78
+ */
79
+ export interface SectionContract {
80
+ name: string;
81
+ title: string;
82
+ /** One line for the inserter; see `SectionDef.description`. */
83
+ description?: string;
84
+ category?: string;
85
+ icon?: string;
86
+ attributes: Record<string, AttrContract>;
87
+ /** Block types that may nest inside. Empty/absent = a leaf section. */
88
+ allowedBlocks?: string[];
89
+ /** Starting compositions. `presets[0]` is what the inserter should seed. */
90
+ presets?: SectionPresetContract[];
91
+ /**
92
+ * Route context the section needs to render meaningfully — e.g. a PDP section
93
+ * needs `product`. When the validator is told which context the template
94
+ * provides, placing a section outside its context is an ERROR (the section
95
+ * would render a not-found state on every visit); with no context supplied
96
+ * it degrades to a warning, since the caller has not said where this is.
97
+ */
98
+ requiresContext?: readonly ContextKind[];
99
+ /**
100
+ * What kind of unit this is. Explicit, because `category` is a DISPLAY
101
+ * grouping for the inserter and was being read as a placement rule
102
+ * (`category === 'block'` decided which picker offered it).
103
+ * section — a top-level page unit
104
+ * block — only nests inside a parent that lists it in `allowedBlocks`
105
+ * layout — chrome: header/footer/announcement; lives in a shared group
106
+ * Absent = derived: `category: 'block'` → block; `area` declared → layout;
107
+ * otherwise section.
108
+ */
109
+ role?: SectionRole;
110
+ /**
111
+ * Default slot for a layout section — where the editor files it when added
112
+ * without one, and where the AI should place it. Also the only slot it may
113
+ * be placed in unless `placement.areas` widens that.
114
+ */
115
+ area?: TemplateArea;
116
+ /** Where this unit may be placed. Every list is an allowlist; absent = anywhere of its role. */
117
+ placement?: PlacementContract;
118
+ }
119
+ export type SectionRole = 'section' | 'block' | 'layout';
120
+ export declare const SECTION_ROLES: readonly SectionRole[];
121
+ export interface PlacementContract {
122
+ /** Slots this unit may occupy. A block ignores this (its parent decides). */
123
+ areas?: readonly TemplateArea[];
124
+ /** Base template slugs (`product`, `collection`, …) it may appear on. */
125
+ templates?: readonly string[];
126
+ /** For a block: the parent types that may host it (mirrors the parents' `allowedBlocks`). */
127
+ parents?: readonly string[];
128
+ }
129
+ /** The effective role, applying the documented fallbacks for definitions that predate `role`. */
130
+ export declare function roleOf(def: Pick<SectionContract, 'role' | 'category' | 'area' | 'name'>): SectionRole;
131
+ /**
132
+ * The route context a template provides, from its base slug. `product.bundle`
133
+ * is still a product page. Used as the validator's default `context` when a
134
+ * caller names the template rather than listing kinds by hand.
135
+ */
136
+ export declare function templateContext(slug: string): ContextKind[];
137
+ export type ContextKind = 'product' | 'collection' | 'page' | 'blog' | 'article' | 'cart' | 'search' | 'customer' | 'policy';
138
+ export declare const CONTEXT_KINDS: readonly ContextKind[];
139
+ export interface SectionPresetContract {
140
+ name?: string;
141
+ settings?: Record<string, unknown>;
142
+ blocks?: Array<Omit<ContractNode, 'id'> & {
143
+ id?: string;
144
+ }>;
145
+ }
146
+ /** One editor-facing setting. Mirrors `AttrSpec`, stated structurally. */
147
+ export interface AttrContract {
148
+ type: string;
149
+ default?: unknown;
150
+ label?: string;
151
+ info?: string;
152
+ placeholder?: string;
153
+ group?: string;
154
+ dynamic?: boolean;
155
+ visible_if?: string | Record<string, unknown>;
156
+ min?: number;
157
+ max?: number;
158
+ step?: number;
159
+ unit?: string;
160
+ options?: Array<{
161
+ value: string;
162
+ label: string;
163
+ }>;
164
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The content-tree contract: what a `templates/<slug>.json` may contain, and
3
+ * the node-identity rules every producer (Editor, AI, theme author) must follow.
4
+ *
5
+ * Node identity is the part that was never written down, and it is the part the
6
+ * round trip depends on. Today:
7
+ *
8
+ * - The Editor mints `${type}_${uuid8}` (`tanqory-template-context.tsx:379`)
9
+ * — stable and unique. Correct.
10
+ * - `blocksToStudio` (`editor-routes.mjs:49-62`) falls back to
11
+ * `` `${b.type}-${i}` `` for a block with no id — a POSITIONAL identity.
12
+ * Reorder the array on disk and `faq-item-0` now means a different question.
13
+ * - `themekitToStudio` falls back to `s.id ?? s.type` for a section — so two
14
+ * sections of the same type with no id COLLIDE in the `sections` map and the
15
+ * second silently overwrites the first.
16
+ *
17
+ * Both fallbacks are silent. Neither is safe for "AI edits one answer without
18
+ * clobbering the others", which is exactly what this contract has to make true.
19
+ * The rule below is therefore: **every node carries an explicit, stable id.**
20
+ */
21
+ export const TEMPLATE_AREAS = ['header', 'template', 'footer'];
22
+ export const CURRENT_CONTENT_VERSION = 2;
23
+ /**
24
+ * Node ids must be URL-safe, stable across saves, and unique within their
25
+ * parent. Readable prefixes are deliberate: `faq-item_a1b2c3d4` is greppable in
26
+ * a diff, which matters when the thing being diffed is a merchant's content.
27
+ */
28
+ export const NODE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
29
+ /**
30
+ * Mint a stable node id. Matches the Editor's own scheme
31
+ * (`tanqory-template-context.tsx:379`) so a node authored by AI and a node
32
+ * authored by a human are indistinguishable downstream.
33
+ */
34
+ export function mintNodeId(type, rand = defaultRand) {
35
+ const base = String(type).replace(/[^a-z0-9]/gi, '-').replace(/^-+|-+$/g, '') || 'node';
36
+ return `${base}_${rand()}`;
37
+ }
38
+ function defaultRand() {
39
+ const c = globalThis.crypto;
40
+ if (c?.randomUUID)
41
+ return c.randomUUID().slice(0, 8);
42
+ return Math.random().toString(36).slice(2, 10).padEnd(8, '0');
43
+ }
44
+ export const SECTION_ROLES = ['section', 'block', 'layout'];
45
+ /** The effective role, applying the documented fallbacks for definitions that predate `role`. */
46
+ export function roleOf(def) {
47
+ if (def.role)
48
+ return def.role;
49
+ if (def.category === 'block')
50
+ return 'block';
51
+ if (def.area === 'header' || def.area === 'footer')
52
+ return 'layout';
53
+ if (def.name === 'header' || def.name === 'footer')
54
+ return 'layout';
55
+ return 'section';
56
+ }
57
+ /**
58
+ * The route context a template provides, from its base slug. `product.bundle`
59
+ * is still a product page. Used as the validator's default `context` when a
60
+ * caller names the template rather than listing kinds by hand.
61
+ */
62
+ export function templateContext(slug) {
63
+ const base = String(slug ?? '').split('.')[0] ?? '';
64
+ switch (base) {
65
+ case 'product': return ['product'];
66
+ case 'collection': return ['collection'];
67
+ case 'page': return ['page'];
68
+ case 'blog': return ['blog'];
69
+ case 'article': return ['article', 'blog'];
70
+ case 'cart': return ['cart'];
71
+ case 'search': return ['search'];
72
+ // A signed-in customer exists only on the account template; a policy body
73
+ // only under /policies/*. Sections that read them (AccountPage, PolicyPage)
74
+ // declared nothing, so the editor offered them everywhere and previewed
75
+ // them as "Loading your account…" forever — there was nothing to load.
76
+ case 'account': return ['customer'];
77
+ case 'policy': return ['policy'];
78
+ default: return [];
79
+ }
80
+ }
81
+ export const CONTEXT_KINDS = [
82
+ 'product', 'collection', 'page', 'blog', 'article', 'cart', 'search', 'customer', 'policy',
83
+ ];