@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
@@ -9,6 +9,12 @@ export declare function ThemeProvider({ settings, locale, children, }: {
9
9
  }): JSX.Element;
10
10
  /** Read global theme settings (values from config/settings.json). */
11
11
  export declare function useSettings(): Settings;
12
- /** Translate a key against the active locale (falls back to the key). */
13
- export declare function useT(): (key: string) => string;
12
+ /** The active locale's strings (the map `useT` reads). */
13
+ export declare function useLocaleStrings(): Locale;
14
+ /**
15
+ * Translate a key against the active locale. A missing string falls back to
16
+ * `fallback` when given, else to the key itself — so `t('x', 'Shop')` renders
17
+ * "Shop", where `t('x') || 'Shop'` never could (the key is truthy).
18
+ */
19
+ export declare function useT(): (key: string, fallback?: string) => string;
14
20
  export {};
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from 'react';
3
+ const SettingsContext = createContext({});
4
+ const LocaleContext = createContext({});
5
+ /** Provides global settings values + locale strings to the whole theme. */
6
+ export function ThemeProvider({ settings = {}, locale = {}, children, }) {
7
+ return (_jsx(SettingsContext.Provider, { value: settings, children: _jsx(LocaleContext.Provider, { value: locale, children: children }) }));
8
+ }
9
+ /** Read global theme settings (values from config/settings.json). */
10
+ export function useSettings() {
11
+ return useContext(SettingsContext);
12
+ }
13
+ /** The active locale's strings (the map `useT` reads). */
14
+ export function useLocaleStrings() {
15
+ return useContext(LocaleContext);
16
+ }
17
+ /**
18
+ * Translate a key against the active locale. A missing string falls back to
19
+ * `fallback` when given, else to the key itself — so `t('x', 'Shop')` renders
20
+ * "Shop", where `t('x') || 'Shop'` never could (the key is truthy).
21
+ */
22
+ export function useT() {
23
+ const locale = useContext(LocaleContext);
24
+ return (key, fallback) => locale[key] ?? fallback ?? key;
25
+ }
@@ -0,0 +1,155 @@
1
+ import type { FC, ReactNode } from 'react';
2
+ import type { AnyFieldType } from './contract/field-types.js';
3
+ import type { ContextKind, PlacementContract, SectionRole, TemplateArea } from './contract/content.js';
4
+ import type { GroupBinding, SectionGroupDoc } from './contract/groups.js';
5
+ /** A single editor-facing setting (= a section attribute). */
6
+ export interface AttrSpec {
7
+ /**
8
+ * The control the editor renders.
9
+ *
10
+ * DERIVED from `contract/field-types.ts` — the union is
11
+ * `FieldTypeId | FieldTypeAlias`, computed from the one table that also feeds
12
+ * the validator, studio-api's gate and the AI generator's allowlist. They
13
+ * cannot drift apart because they are not written down twice.
14
+ *
15
+ * Every id carries its own documentation in that table (what the control is,
16
+ * what the runtime value looks like, whether it can be bound to a dynamic
17
+ * source). Read it there rather than duplicating prose here.
18
+ */
19
+ type: AnyFieldType;
20
+ default?: unknown;
21
+ label?: string;
22
+ /**
23
+ * Editor panel heading this control is filed under (e.g. 'Brand', 'Header').
24
+ * Consumed by the theme-settings panel and by a theme's manifest generator,
25
+ * which groups `defineSettings({...})` entries by this key. Undeclared
26
+ * settings fall into 'General'.
27
+ */
28
+ group?: string;
29
+ /**
30
+ * Opt this setting into "Insert dynamic source" (the ⛁ binding UI): the
31
+ * merchant may bind it to a product/collection/shop property or metaobject
32
+ * field instead of typing a literal. See `dynamic-source.tsx`.
33
+ */
34
+ dynamic?: boolean;
35
+ /** Slider bounds — for type 'range'. */
36
+ min?: number;
37
+ max?: number;
38
+ step?: number;
39
+ unit?: string;
40
+ /** Placeholder / helper text shown in the editor control. */
41
+ placeholder?: string;
42
+ info?: string;
43
+ /** Conditional visibility (commerce-standard), e.g. `"{{ section.settings.x == 'y' }}"`. */
44
+ visible_if?: string;
45
+ /** For type 'select'/'radio' — the editor renders these as options. */
46
+ options?: {
47
+ value: string;
48
+ label: string;
49
+ }[];
50
+ /**
51
+ * For type 'list' — the element: `{ type: 'product' }` (a hand-picked list; `resolve: true` has the platform resolve
52
+ * each entry into the page's snapshot) or `{ type: 'color' }`.
53
+ */
54
+ items?: {
55
+ type: string;
56
+ resolve?: boolean;
57
+ };
58
+ }
59
+ /** Props every section component receives. `attributes` are resolved (defaults applied). */
60
+ export interface SectionProps {
61
+ attributes: Record<string, any>;
62
+ children?: ReactNode;
63
+ /**
64
+ * The saved node itself — passed only to a `raw` section, which resolves its
65
+ * own settings and blocks (defaults, legacy values, handles → data) instead of
66
+ * receiving pre-rendered children.
67
+ */
68
+ node?: ContentNode;
69
+ }
70
+ /**
71
+ * One section definition — serves all three consumers from a single source:
72
+ * - dev: write `component` (React, logic allowed)
73
+ * - editor: `attributes` → auto settings UI, `allowedBlocks` → nesting
74
+ * - storefront: `component` renders the node
75
+ */
76
+ export interface SectionDef {
77
+ name: string;
78
+ title: string;
79
+ /**
80
+ * One line for the inserter — what the section shows and when to use it
81
+ * ("A grid of products from one collection."). Searched alongside the title.
82
+ */
83
+ description?: string;
84
+ category?: string;
85
+ icon?: string;
86
+ attributes?: Record<string, AttrSpec>;
87
+ allowedBlocks?: string[];
88
+ /**
89
+ * Starting compositions offered when the section is inserted. `presets[0]` is
90
+ * the default: `renderSectionPreviewHTML` seeds the preview with its blocks so
91
+ * a block-composed section doesn't render empty in the inserter.
92
+ *
93
+ * Declared here because the runtime already reads it (`ssg.tsx`) — it was
94
+ * reached through a cast while the type omitted it, so every theme that
95
+ * shipped a preset failed `tsc` on its own section definitions.
96
+ */
97
+ presets?: SectionPreset[];
98
+ /**
99
+ * What kind of unit this is — `section` (page unit), `block` (nests inside a
100
+ * parent's `allowedBlocks`) or `layout` (header/footer chrome, lives in a
101
+ * shared group). Explicit, because `category` is a display grouping and was
102
+ * being read as a placement rule. Absent = derived; see contract `roleOf`.
103
+ */
104
+ role?: SectionRole;
105
+ /** Default slot for a layout section (`header` | `footer`). */
106
+ area?: TemplateArea;
107
+ /** Allowlists for where this unit may be placed. */
108
+ placement?: PlacementContract;
109
+ /** Route context this section needs (`product`, `collection`, …). */
110
+ requiresContext?: readonly ContextKind[];
111
+ /**
112
+ * The component takes the saved node (`node`) and resolves its own settings
113
+ * and blocks. SectionTree then passes the node through untouched and does not
114
+ * render the blocks as child sections.
115
+ */
116
+ raw?: boolean;
117
+ component: FC<SectionProps>;
118
+ }
119
+ /** One starting composition for a section (see `SectionDef.presets`). */
120
+ export interface SectionPreset {
121
+ /** Optional label shown in the inserter when a section offers several. */
122
+ name?: string;
123
+ /** Section settings this preset starts from. */
124
+ settings?: Record<string, unknown>;
125
+ /** Child block instances this preset starts from. */
126
+ blocks?: ContentNode[];
127
+ }
128
+ /** A node in the content tree (what the editor stores as JSON, never HTML). */
129
+ export interface ContentNode {
130
+ type: string;
131
+ id?: string;
132
+ settings?: Record<string, unknown>;
133
+ /** Nested child instances. */
134
+ blocks?: ContentNode[];
135
+ /** Layout slot: `header` | `template` | `footer`. */
136
+ area?: TemplateArea;
137
+ /**
138
+ * The theme-declared region (section group) this node came from, when it is not one the runtime places itself
139
+ * (header, main, footer): an `aside`, a custom group. Rendered as `data-tq-region` on the node's wrapper.
140
+ */
141
+ region?: string;
142
+ }
143
+ /** A node in the content tree — `area` is the layout slot it belongs to. */
144
+ /** A page = a route + its tree of section instances. */
145
+ export interface PageDoc {
146
+ sections: ContentNode[];
147
+ /**
148
+ * Shared header/footer bindings (content version 2): `"header"` references
149
+ * `groups/header.json`; `{ override: [...] }` is a page-specific composition.
150
+ * Absent → the page's inline header/footer sections are used (version 1).
151
+ */
152
+ groups?: Partial<Record<'header' | 'footer', GroupBinding>>;
153
+ contentVersion?: number;
154
+ }
155
+ export type { SectionGroupDoc };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Injects the store's CONNECTED tracking pixels (Settings → Customer events) on
3
+ * the live storefront. Each pixel's script is appended to <head> once. The code
4
+ * is the merchant's own snippet (configured in the Dashboard, so trusted).
5
+ *
6
+ * GATED ON CONSENT: pixels are marketing/tracking, so they only inject once the
7
+ * shopper has granted the `marketing` purpose (when the store's cookie banner is
8
+ * enabled — `hasConsent` is always true when no banner is in effect). If the
9
+ * shopper grants later, `onConsentChange` re-runs the injection.
10
+ *
11
+ * Deliberately INERT in the editor/preview planes — we never fire real tracking
12
+ * while a merchant edits the theme.
13
+ */
14
+ export declare function TrackingPixels(): null;
@@ -0,0 +1,63 @@
1
+ import { useEffect } from 'react';
2
+ import { useData } from '../kit/data.js';
3
+ import { hasConsent, onConsentChange } from '../kit/consent.js';
4
+ /**
5
+ * Injects the store's CONNECTED tracking pixels (Settings → Customer events) on
6
+ * the live storefront. Each pixel's script is appended to <head> once. The code
7
+ * is the merchant's own snippet (configured in the Dashboard, so trusted).
8
+ *
9
+ * GATED ON CONSENT: pixels are marketing/tracking, so they only inject once the
10
+ * shopper has granted the `marketing` purpose (when the store's cookie banner is
11
+ * enabled — `hasConsent` is always true when no banner is in effect). If the
12
+ * shopper grants later, `onConsentChange` re-runs the injection.
13
+ *
14
+ * Deliberately INERT in the editor/preview planes — we never fire real tracking
15
+ * while a merchant edits the theme.
16
+ */
17
+ export function TrackingPixels() {
18
+ const { pixels } = useData();
19
+ useEffect(() => {
20
+ if (!pixels)
21
+ return;
22
+ const isPreview = /^preview-/.test(window.location.hostname) ||
23
+ new URLSearchParams(window.location.search).has('preview') ||
24
+ new URLSearchParams(window.location.search).has('edit');
25
+ if (isPreview)
26
+ return;
27
+ let cancelled = false;
28
+ let cached = null;
29
+ const inject = () => {
30
+ if (cancelled || !cached || !hasConsent('marketing'))
31
+ return;
32
+ for (const p of cached) {
33
+ if (!p.code)
34
+ continue;
35
+ const id = `tq-pixel-${p.id}`;
36
+ if (document.getElementById(id))
37
+ continue;
38
+ const s = document.createElement('script');
39
+ s.id = id;
40
+ s.type = 'text/javascript';
41
+ s.text = p.code;
42
+ document.head.appendChild(s);
43
+ }
44
+ };
45
+ void pixels()
46
+ .then((list) => {
47
+ if (cancelled || !Array.isArray(list))
48
+ return;
49
+ cached = list;
50
+ inject();
51
+ })
52
+ .catch(() => {
53
+ /* tracking is best-effort — never break the page */
54
+ });
55
+ // Re-inject when the shopper grants marketing consent after page load.
56
+ const off = onConsentChange(() => inject());
57
+ return () => {
58
+ cancelled = true;
59
+ off();
60
+ };
61
+ }, [pixels]);
62
+ return null;
63
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Which plane is this render on?
3
+ *
4
+ * Three states the theme must keep apart — they used to be re-derived inline in
5
+ * the entry, the old layout and a product section with three
6
+ * slightly different expressions, which is how "editor convenience" behaviour
7
+ * (a section-setting product override, mock fixtures) leaked onto the published
8
+ * storefront.
9
+ *
10
+ * storefront — a real shopper on a published store. Live data, URL is
11
+ * canonical, no fixtures, no placeholders.
12
+ * editor — the Studio preview iframe. Overrides and placeholders are
13
+ * correct here; SPA routing and analytics are not.
14
+ * offline — `pnpm dev` with no backend configured. Mock fixtures, clearly
15
+ * marked, never reachable from a configured build.
16
+ *
17
+ * `isEditorPreview()` reads the URL, so call it inside render/effects, not at
18
+ * module scope (the value differs between SSG and the browser).
19
+ */
20
+ /** The rule itself, for a given location: the `preview-` host, or `?preview` on a dev build. */
21
+ export declare function isEditorPreviewAt(location: {
22
+ hostname: string;
23
+ search: string;
24
+ }, isDev: boolean): boolean;
25
+ /**
26
+ * True inside the Studio editor's preview iframe: the dedicated `preview-`
27
+ * host, or `?preview` on a dev build (the laptop loop). The same rule
28
+ * the editor runtime applies before accepting live settings, so a
29
+ * published store never enters editor mode because a visitor's URL carries
30
+ * `?preview` — that flag used to switch a live store to fixtures, silence its
31
+ * analytics and disable its navigation.
32
+ */
33
+ export declare function isEditorPreview(): boolean;
34
+ /** The store this page renders live data for. */
35
+ export interface RuntimeStore {
36
+ /** Backend origin; in a browser the page's own origin is used (same-origin `/api/v1`). */
37
+ backend: string;
38
+ id: string;
39
+ /** Publishable storefront key — safe to ship. */
40
+ token?: string;
41
+ }
42
+ /**
43
+ * Which store this page renders live data for, or null for an offline/mock page.
44
+ *
45
+ * Two sources, in order:
46
+ * 1. Build-time variables (`VITE_TANQORY_BACKEND` + `VITE_TANQORY_STORE_ID`) —
47
+ * a bundle built for ONE store.
48
+ * 2. The server's handoff (`window.__TQ_STATE__.store`) — a v2 theme is built
49
+ * once and served for any store, so the SSR entry (`server-entry.ts`) tells the
50
+ * page which store it rendered. Without this the browser had no store id,
51
+ * booted mock fixtures and replaced the server's real products with
52
+ * "Example product · $99" on hydration.
53
+ */
54
+ export declare function runtimeStore(): RuntimeStore | null;
55
+ /**
56
+ * True when this page renders live data for a store — the same check
57
+ * `bootData()` makes. Anything else is an offline/mock page.
58
+ */
59
+ export declare function isConfiguredForLiveData(): boolean;
60
+ /**
61
+ * True when mock fixtures are an acceptable data source for this render.
62
+ *
63
+ * Deliberately NOT "the live fetch failed" — a configured storefront that
64
+ * cannot reach its backend must surface an error, not quietly serve example
65
+ * products at example prices. Mock data is for the offline dev server and for
66
+ * the editor previewing a theme that has no store attached.
67
+ */
68
+ export declare function isMockDataAllowed(): boolean;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Which plane is this render on?
3
+ *
4
+ * Three states the theme must keep apart — they used to be re-derived inline in
5
+ * the entry, the old layout and a product section with three
6
+ * slightly different expressions, which is how "editor convenience" behaviour
7
+ * (a section-setting product override, mock fixtures) leaked onto the published
8
+ * storefront.
9
+ *
10
+ * storefront — a real shopper on a published store. Live data, URL is
11
+ * canonical, no fixtures, no placeholders.
12
+ * editor — the Studio preview iframe. Overrides and placeholders are
13
+ * correct here; SPA routing and analytics are not.
14
+ * offline — `pnpm dev` with no backend configured. Mock fixtures, clearly
15
+ * marked, never reachable from a configured build.
16
+ *
17
+ * `isEditorPreview()` reads the URL, so call it inside render/effects, not at
18
+ * module scope (the value differs between SSG and the browser).
19
+ */
20
+ /** The rule itself, for a given location: the `preview-` host, or `?preview` on a dev build. */
21
+ export function isEditorPreviewAt(location, isDev) {
22
+ if (/^preview-/.test(location.hostname))
23
+ return true;
24
+ return isDev && new URLSearchParams(location.search).has('preview');
25
+ }
26
+ /**
27
+ * True inside the Studio editor's preview iframe: the dedicated `preview-`
28
+ * host, or `?preview` on a dev build (the laptop loop). The same rule
29
+ * the editor runtime applies before accepting live settings, so a
30
+ * published store never enters editor mode because a visitor's URL carries
31
+ * `?preview` — that flag used to switch a live store to fixtures, silence its
32
+ * analytics and disable its navigation.
33
+ */
34
+ export function isEditorPreview() {
35
+ if (typeof window === 'undefined')
36
+ return false;
37
+ return isEditorPreviewAt(window.location, Boolean(import.meta.env.DEV));
38
+ }
39
+ /**
40
+ * Which store this page renders live data for, or null for an offline/mock page.
41
+ *
42
+ * Two sources, in order:
43
+ * 1. Build-time variables (`VITE_TANQORY_BACKEND` + `VITE_TANQORY_STORE_ID`) —
44
+ * a bundle built for ONE store.
45
+ * 2. The server's handoff (`window.__TQ_STATE__.store`) — a v2 theme is built
46
+ * once and served for any store, so the SSR entry (`server-entry.ts`) tells the
47
+ * page which store it rendered. Without this the browser had no store id,
48
+ * booted mock fixtures and replaced the server's real products with
49
+ * "Example product · $99" on hydration.
50
+ */
51
+ export function runtimeStore() {
52
+ const env = import.meta.env;
53
+ if (env.VITE_TANQORY_BACKEND && env.VITE_TANQORY_STORE_ID) {
54
+ return { backend: env.VITE_TANQORY_BACKEND, id: env.VITE_TANQORY_STORE_ID, token: env.VITE_TANQORY_STOREFRONT_TOKEN || undefined };
55
+ }
56
+ if (typeof window === 'undefined')
57
+ return null;
58
+ const handoff = window.__TQ_STATE__?.store;
59
+ const id = typeof handoff?.id === 'string' ? handoff.id : '';
60
+ if (!id)
61
+ return null;
62
+ return {
63
+ backend: window.location.origin,
64
+ id,
65
+ token: typeof handoff?.token === 'string' && handoff.token ? handoff.token : undefined,
66
+ };
67
+ }
68
+ /**
69
+ * True when this page renders live data for a store — the same check
70
+ * `bootData()` makes. Anything else is an offline/mock page.
71
+ */
72
+ export function isConfiguredForLiveData() {
73
+ return runtimeStore() !== null;
74
+ }
75
+ /**
76
+ * True when mock fixtures are an acceptable data source for this render.
77
+ *
78
+ * Deliberately NOT "the live fetch failed" — a configured storefront that
79
+ * cannot reach its backend must surface an error, not quietly serve example
80
+ * products at example prices. Mock data is for the offline dev server and for
81
+ * the editor previewing a theme that has no store attached.
82
+ */
83
+ export function isMockDataAllowed() {
84
+ return !isConfiguredForLiveData() || isEditorPreview();
85
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The theme's own language — which of `locales/*.json` its fixed interface
3
+ * words are drawn from — and the rule for copy that ships with an English
4
+ * default a merchant may have kept or replaced.
5
+ *
6
+ * Why. A theme built for a Thai shop (production build 7270019a, 2026-09-15:
7
+ * "ผ้าเก่าเล่าเรื่อง") showed "Sign in for faster checkout." in the account
8
+ * menu and "We read every note." over the contact form on every page, with a
9
+ * Thai site around them. nova already had a Thai string map; nothing chose it
10
+ * except a visitor's own `?locale=`. `config/settings.json` `locale` is now the
11
+ * theme's language: the default map, before any visitor choice.
12
+ *
13
+ * Pure (no DOM, no React) so it is unit-tested directly (app/platform/locale.node.test.ts).
14
+ */
15
+ /** The map every other one is laid over, and the language of a theme that names none. */
16
+ export declare const FALLBACK_LOCALE = "en";
17
+ /**
18
+ * The locale a theme's `locale` setting names, when a string map for it is
19
+ * bundled (`th`, or `th` for `th-TH`); the fallback otherwise — blank, malformed
20
+ * or a language this theme has no strings for.
21
+ */
22
+ export declare function themeLocaleOf(setting: unknown, available: Iterable<string>): string;
23
+ /**
24
+ * The strings for `code`: the fallback map with that locale's own map laid over
25
+ * it, so a partly translated locale shows English rather than raw keys.
26
+ */
27
+ export declare function localeStrings(code: string, maps: Record<string, Record<string, string>>): Record<string, string>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The theme's own language — which of `locales/*.json` its fixed interface
3
+ * words are drawn from — and the rule for copy that ships with an English
4
+ * default a merchant may have kept or replaced.
5
+ *
6
+ * Why. A theme built for a Thai shop (production build 7270019a, 2026-09-15:
7
+ * "ผ้าเก่าเล่าเรื่อง") showed "Sign in for faster checkout." in the account
8
+ * menu and "We read every note." over the contact form on every page, with a
9
+ * Thai site around them. nova already had a Thai string map; nothing chose it
10
+ * except a visitor's own `?locale=`. `config/settings.json` `locale` is now the
11
+ * theme's language: the default map, before any visitor choice.
12
+ *
13
+ * Pure (no DOM, no React) so it is unit-tested directly (app/platform/locale.node.test.ts).
14
+ */
15
+ /** The map every other one is laid over, and the language of a theme that names none. */
16
+ export const FALLBACK_LOCALE = 'en';
17
+ const LOCALE_CODE = /^[a-z]{2}(?:-[a-z]{2})?$/i;
18
+ /**
19
+ * The locale a theme's `locale` setting names, when a string map for it is
20
+ * bundled (`th`, or `th` for `th-TH`); the fallback otherwise — blank, malformed
21
+ * or a language this theme has no strings for.
22
+ */
23
+ export function themeLocaleOf(setting, available) {
24
+ if (typeof setting !== 'string')
25
+ return FALLBACK_LOCALE;
26
+ const code = setting.trim().toLowerCase();
27
+ if (!LOCALE_CODE.test(code))
28
+ return FALLBACK_LOCALE;
29
+ const have = new Set(available);
30
+ if (have.has(code))
31
+ return code;
32
+ const base = code.split('-')[0];
33
+ return have.has(base) ? base : FALLBACK_LOCALE;
34
+ }
35
+ /**
36
+ * The strings for `code`: the fallback map with that locale's own map laid over
37
+ * it, so a partly translated locale shows English rather than raw keys.
38
+ */
39
+ export function localeStrings(code, maps) {
40
+ const base = maps[FALLBACK_LOCALE] ?? {};
41
+ return code === FALLBACK_LOCALE ? base : { ...base, ...(maps[code] ?? {}) };
42
+ }
@@ -0,0 +1,15 @@
1
+ import type { DataApi } from '../kit/data.js';
2
+ /** Forget the last emitted route. Tests only. */
3
+ export declare function resetRouteAnalytics(): void;
4
+ /**
5
+ * Emit `pageViewed` + the matching VIEW event for `url`, unless this exact URL
6
+ * was the previous emission.
7
+ *
8
+ * `getAnalytics()` is the kit's singleton: it is a no-op until `createAnalytics`
9
+ * has armed it, so calling this in the editor preview or on a mock build sends
10
+ * nothing rather than needing its own guard.
11
+ */
12
+ export declare function emitRoute(url: {
13
+ pathname: string;
14
+ search: string;
15
+ }, data: DataApi): boolean;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Route-level storefront analytics.
3
+ *
4
+ * `pageViewed` plus the VIEW customer event that matches the URL
5
+ * (product/collection/search/cart). Action events — add-to-cart, remove,
6
+ * checkout — fire from their own section handlers, not here.
7
+ *
8
+ * Extracted from `browser-entry.tsx` because it has to run on SPA navigation too. It
9
+ * only ran at boot, so with SPA routing on (the default) a shopper who browsed
10
+ * five products produced exactly one PRODUCT_VIEWED — for whichever page they
11
+ * happened to land on first.
12
+ *
13
+ * `emitRoute` is idempotent per route: it remembers the last pathname+search it
14
+ * emitted for and does nothing if asked again. React effects can and do run
15
+ * twice (StrictMode, a re-render mid-navigation), and a double PRODUCT_VIEWED
16
+ * is a silently wrong number in the merchant's reports.
17
+ */
18
+ import { getAnalytics } from '../kit/analytics.js';
19
+ import { matchRoute } from '../data/routes.js';
20
+ let lastEmitted = null;
21
+ /** Forget the last emitted route. Tests only. */
22
+ export function resetRouteAnalytics() {
23
+ lastEmitted = null;
24
+ }
25
+ /**
26
+ * Emit `pageViewed` + the matching VIEW event for `url`, unless this exact URL
27
+ * was the previous emission.
28
+ *
29
+ * `getAnalytics()` is the kit's singleton: it is a no-op until `createAnalytics`
30
+ * has armed it, so calling this in the editor preview or on a mock build sends
31
+ * nothing rather than needing its own guard.
32
+ */
33
+ export function emitRoute(url, data) {
34
+ const key = url.pathname + url.search;
35
+ if (key === lastEmitted)
36
+ return false;
37
+ lastEmitted = key;
38
+ const analytics = getAnalytics();
39
+ try {
40
+ analytics.pageViewed();
41
+ const route = matchRoute(url.pathname);
42
+ if (route.resource === 'product' && route.handle) {
43
+ const p = data.productByHandle?.(route.handle);
44
+ analytics.track('PRODUCT_VIEWED', p
45
+ ? { productId: p.id, title: p.title, handle: p.handle, price: p.price }
46
+ : { handle: route.handle });
47
+ }
48
+ else if (route.resource === 'collection' && route.handle) {
49
+ const c = data.collectionByHandle?.(route.handle);
50
+ analytics.track('COLLECTION_VIEWED', c
51
+ ? {
52
+ collectionId: c.id,
53
+ title: c.title,
54
+ handle: route.handle,
55
+ productCount: c.products?.length,
56
+ }
57
+ : { handle: route.handle });
58
+ }
59
+ else if (route.template === 'search') {
60
+ const q = new URLSearchParams(url.search).get('q')?.trim();
61
+ if (q)
62
+ analytics.track('SEARCH_SUBMITTED', { query: q });
63
+ }
64
+ else if (route.template === 'cart') {
65
+ analytics.track('CART_VIEWED', {});
66
+ }
67
+ }
68
+ catch {
69
+ /* telemetry must never break the page */
70
+ }
71
+ return true;
72
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Links that come from settings (theme settings, merchant-edited copy) are
3
+ * rendered as `href`s on the store's own origin. React 18 still renders a
4
+ * `javascript:` href, so every such value is checked here at render — on the
5
+ * live storefront, not only in the editor.
6
+ *
7
+ * Pure; unit-tested in app/platform/safe-href.node.test.ts.
8
+ */
9
+ /**
10
+ * The value when it is safe to use as an `href`: a relative URL (`/path`,
11
+ * `?q`, `#frag`, `page`), protocol-relative, or http(s) / mailto / tel.
12
+ * Anything else — `javascript:`, `data:`, `vbscript:`, non-strings, empty — is
13
+ * null so the caller falls back to its default link.
14
+ */
15
+ export declare function safeHref(value: unknown): string | null;
16
+ export interface AccountLink {
17
+ label: string;
18
+ href: string;
19
+ }
20
+ /**
21
+ * The account menu's extra links (theme setting `accountExtraLinks`), in either
22
+ * form — JSON `[{"label","href"}]` or one `Label|/path` per line / comma. Links
23
+ * whose href is not {@link safeHref} are dropped.
24
+ */
25
+ export declare function parseAccountLinks(raw: unknown): AccountLink[];