@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,69 @@
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
+ const ALLOWED_SCHEMES = new Set(['http', 'https', 'mailto', 'tel']);
10
+ /**
11
+ * The value when it is safe to use as an `href`: a relative URL (`/path`,
12
+ * `?q`, `#frag`, `page`), protocol-relative, or http(s) / mailto / tel.
13
+ * Anything else — `javascript:`, `data:`, `vbscript:`, non-strings, empty — is
14
+ * null so the caller falls back to its default link.
15
+ */
16
+ export function safeHref(value) {
17
+ if (typeof value !== 'string')
18
+ return null;
19
+ const v = value.trim();
20
+ if (!v)
21
+ return null;
22
+ // Browsers strip leading C0 controls/spaces and drop tabs and newlines
23
+ // anywhere in a URL, so "java\tscript:" navigates as javascript:. Read the
24
+ // scheme the way the browser will.
25
+ const probe = v.replace(/[\u0000-\u0020]/g, '');
26
+ const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(probe);
27
+ if (scheme)
28
+ return ALLOWED_SCHEMES.has(scheme[1].toLowerCase()) ? v : null;
29
+ return v;
30
+ }
31
+ /**
32
+ * The account menu's extra links (theme setting `accountExtraLinks`), in either
33
+ * form — JSON `[{"label","href"}]` or one `Label|/path` per line / comma. Links
34
+ * whose href is not {@link safeHref} are dropped.
35
+ */
36
+ export function parseAccountLinks(raw) {
37
+ if (typeof raw !== 'string')
38
+ return [];
39
+ const trimmed = raw.trim();
40
+ if (!trimmed)
41
+ return [];
42
+ let links;
43
+ if (trimmed.startsWith('[')) {
44
+ try {
45
+ const parsed = JSON.parse(trimmed);
46
+ links = Array.isArray(parsed) ? parsed : [];
47
+ }
48
+ catch {
49
+ return [];
50
+ }
51
+ }
52
+ else {
53
+ links = trimmed
54
+ .split(/[,\n]/)
55
+ .map((entry) => entry.trim())
56
+ .filter(Boolean)
57
+ .map((entry) => {
58
+ const [label, href] = entry.split('|').map((s) => s.trim());
59
+ return { label, href };
60
+ });
61
+ }
62
+ const out = [];
63
+ for (const l of links) {
64
+ const href = safeHref(l?.href);
65
+ if (typeof l?.label === 'string' && l.label && href)
66
+ out.push({ label: l.label, href });
67
+ }
68
+ return out;
69
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Global theme-setting helpers the runtime still needs: validating a colour or
3
+ * an image URL before it reaches a stylesheet or an <img>, and the header logo
4
+ * precedence. The theme settings themselves are resolved by Nova's provider
5
+ * (`ui/styles/theme.ts`), which turns each semantic choice into a token.
6
+ *
7
+ * Pure: no React, no DOM, so node's test runner loads it directly.
8
+ */
9
+ export type ThemeSettings = Record<string, unknown>;
10
+ /** The slice of `shop.brand` (Settings → Brand) the logo falls back to. */
11
+ export interface BrandFallback {
12
+ logo?: {
13
+ url?: string | null;
14
+ altText?: string | null;
15
+ } | null;
16
+ }
17
+ type Rgb = [number, number, number];
18
+ /** Parse an accepted colour to RGB, or null. Accepts hex and rgb()/hsl(); opaque only. */
19
+ export declare function parseColor(value: unknown): Rgb | null;
20
+ /**
21
+ * A colour safe to write into a stylesheet, as canonical `#rrggbb`, or null.
22
+ * Hex, rgb() and hsl() are accepted when they are valid CSS and opaque; every
23
+ * other value — invalid numbers, translucent colours, keywords, anything that
24
+ * could close a declaration — is refused, so the theme default applies.
25
+ */
26
+ export declare function normalizeColor(value: unknown): string | null;
27
+ /** An image URL the header may render: absolute http(s), protocol-relative, or root-relative. */
28
+ export declare function normalizeImageUrl(value: unknown): string | null;
29
+ /**
30
+ * The header logo image: the theme's own logo, else the Settings → Brand logo,
31
+ * else null (the header then shows the shop name as text).
32
+ */
33
+ export declare function resolveLogo(settings: ThemeSettings, brand?: BrandFallback | null): {
34
+ url: string;
35
+ altText: string | null;
36
+ } | null;
37
+ export {};
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Global theme-setting helpers the runtime still needs: validating a colour or
3
+ * an image URL before it reaches a stylesheet or an <img>, and the header logo
4
+ * precedence. The theme settings themselves are resolved by Nova's provider
5
+ * (`ui/styles/theme.ts`), which turns each semantic choice into a token.
6
+ *
7
+ * Pure: no React, no DOM, so node's test runner loads it directly.
8
+ */
9
+ const NUM = /^(?:\d+(?:\.\d+)?|\.\d+)$/;
10
+ const PCT = /^(?:\d+(?:\.\d+)?|\.\d+)%$/;
11
+ /** An opaque alpha component: `1`, `1.0`, `100%`. Anything translucent is refused. */
12
+ function isOpaqueAlpha(token) {
13
+ if (NUM.test(token))
14
+ return Number(token) === 1;
15
+ if (PCT.test(token))
16
+ return Number(token.slice(0, -1)) === 100;
17
+ return false;
18
+ }
19
+ /**
20
+ * The arguments of `fn(…)` in either CSS syntax: legacy `a, b, c[, alpha]` or
21
+ * modern `a b c[ / alpha]`. Null when the list is neither (mixed separators,
22
+ * empty tokens, wrong arity).
23
+ */
24
+ function colorArgs(inner) {
25
+ const body = inner.trim();
26
+ if (!body)
27
+ return null;
28
+ if (body.includes(',')) {
29
+ if (body.includes('/'))
30
+ return null;
31
+ const parts = body.split(',').map((t) => t.trim());
32
+ if (parts.some((t) => !t || /\s/.test(t)))
33
+ return null;
34
+ if (parts.length === 3)
35
+ return { channels: parts, alpha: null };
36
+ if (parts.length === 4)
37
+ return { channels: parts.slice(0, 3), alpha: parts[3] };
38
+ return null;
39
+ }
40
+ const [main, alpha, extra] = body.split('/').map((t) => t.trim());
41
+ if (extra !== undefined || alpha === '')
42
+ return null;
43
+ const channels = main.split(/\s+/);
44
+ if (channels.length !== 3 || (alpha !== undefined && /\s/.test(alpha)))
45
+ return null;
46
+ return { channels, alpha: alpha ?? null };
47
+ }
48
+ function parseRgbFunction(inner) {
49
+ const args = colorArgs(inner);
50
+ if (!args || (args.alpha !== null && !isOpaqueAlpha(args.alpha)))
51
+ return null;
52
+ const { channels } = args;
53
+ // CSS requires the three channels to be all numbers or all percentages.
54
+ if (channels.every((t) => NUM.test(t))) {
55
+ const v = channels.map(Number);
56
+ return v.every((n) => n <= 255) ? v.map(Math.round) : null;
57
+ }
58
+ if (channels.every((t) => PCT.test(t))) {
59
+ const v = channels.map((t) => Number(t.slice(0, -1)));
60
+ return v.every((n) => n <= 100) ? v.map((n) => Math.round((n / 100) * 255)) : null;
61
+ }
62
+ return null;
63
+ }
64
+ function parseHslFunction(inner) {
65
+ const args = colorArgs(inner);
66
+ if (!args || (args.alpha !== null && !isOpaqueAlpha(args.alpha)))
67
+ return null;
68
+ const [hueToken, sToken, lToken] = args.channels;
69
+ const hue = /^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg)?$/.test(hueToken) ? Number(hueToken.replace(/deg$/, '')) : NaN;
70
+ if (!Number.isFinite(hue) || !PCT.test(sToken) || !PCT.test(lToken))
71
+ return null;
72
+ const sat = Number(sToken.slice(0, -1)) / 100;
73
+ const light = Number(lToken.slice(0, -1)) / 100;
74
+ if (sat > 1 || light > 1)
75
+ return null;
76
+ const h = ((hue % 360) + 360) % 360;
77
+ const a = sat * Math.min(light, 1 - light);
78
+ const f = (n) => {
79
+ const k = (n + h / 30) % 12;
80
+ return Math.round((light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))) * 255);
81
+ };
82
+ return [f(0), f(8), f(4)];
83
+ }
84
+ /** Parse an accepted colour to RGB, or null. Accepts hex and rgb()/hsl(); opaque only. */
85
+ export function parseColor(value) {
86
+ if (typeof value !== 'string')
87
+ return null;
88
+ const v = value.trim().toLowerCase();
89
+ const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(v);
90
+ if (hex) {
91
+ let h = hex[1];
92
+ if (h.length <= 4)
93
+ h = h.split('').map((c) => c + c).join('');
94
+ if (h.length === 8 && h.slice(6) !== 'ff')
95
+ return null;
96
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
97
+ }
98
+ const fn = /^(rgba?|hsla?)\((.*)\)$/.exec(v);
99
+ if (!fn)
100
+ return null;
101
+ return fn[1].startsWith('rgb') ? parseRgbFunction(fn[2]) : parseHslFunction(fn[2]);
102
+ }
103
+ const toHex = (rgb) => '#' + rgb.map((c) => c.toString(16).padStart(2, '0')).join('');
104
+ /**
105
+ * A colour safe to write into a stylesheet, as canonical `#rrggbb`, or null.
106
+ * Hex, rgb() and hsl() are accepted when they are valid CSS and opaque; every
107
+ * other value — invalid numbers, translucent colours, keywords, anything that
108
+ * could close a declaration — is refused, so the theme default applies.
109
+ */
110
+ export function normalizeColor(value) {
111
+ const rgb = parseColor(value);
112
+ return rgb ? toHex(rgb) : null;
113
+ }
114
+ /** An image URL the header may render: absolute http(s), protocol-relative, or root-relative. */
115
+ export function normalizeImageUrl(value) {
116
+ const raw = typeof value === 'string'
117
+ ? value
118
+ : value && typeof value === 'object' && typeof value.url === 'string'
119
+ ? value.url
120
+ : null;
121
+ if (raw === null)
122
+ return null;
123
+ const v = raw.trim();
124
+ if (!v || /[\s"'<>]/.test(v))
125
+ return null;
126
+ return /^https?:\/\//i.test(v) || /^\/\/[^/]/.test(v) || /^\/[^/]/.test(v) ? v : null;
127
+ }
128
+ /**
129
+ * The header logo image: the theme's own logo, else the Settings → Brand logo,
130
+ * else null (the header then shows the shop name as text).
131
+ */
132
+ export function resolveLogo(settings, brand) {
133
+ const themeLogo = normalizeImageUrl(settings.logo);
134
+ if (themeLogo)
135
+ return { url: themeLogo, altText: null };
136
+ const brandLogo = normalizeImageUrl(brand?.logo?.url);
137
+ if (brandLogo)
138
+ return { url: brandLogo, altText: brand?.logo?.altText ?? null };
139
+ return null;
140
+ }
@@ -0,0 +1,4 @@
1
+ import type { SectionProps } from '../kit/types.js';
2
+ export declare function SectionRenderer({ node }: SectionProps): JSX.Element | null;
3
+ /** Blocks render inside their section; standalone they render nothing. */
4
+ export declare function BlockPlaceholder(): null;
@@ -0,0 +1,111 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * One saved section node → the theme's component for it.
4
+ *
5
+ * node ─► section.data(node, store, { actions, context, page }) ─► props ─► component
6
+ *
7
+ * Registered as the component of every theme section (`raw`, so SectionTree
8
+ * hands over the node instead of pre-rendered blocks). Knows nothing about any
9
+ * particular section: what a section needs is the theme's `data` binding.
10
+ */
11
+ import { useContext, useEffect, useMemo } from 'react';
12
+ import { resolveSettings, useThemeActions, useThemeContext } from '../../sdk/index.js';
13
+ import { usePageTree } from '../kit/SectionTree.js';
14
+ import { getSection } from '../kit/registry.js';
15
+ import { getThemeBundle } from '../slots.js';
16
+ import { useStore } from '../data/StoreProvider.js';
17
+ import { useListing } from './product-listing.js';
18
+ import { ShowStarterContext, starterSet, withoutStarter } from './starter.js';
19
+ import { copyPlanOf, localizeShippedCopy, shippedCopyOf } from './localized-copy.js';
20
+ import { useLocaleStrings } from '../kit/theme-context.js';
21
+ const toSaved = (node) => ({
22
+ type: node.type,
23
+ settings: node.settings,
24
+ blocks: (node.blocks ?? []).map((b) => ({ type: b.type, settings: b.settings })),
25
+ });
26
+ /** A context for a section rendered with no page shell (the editor's single-section preview). */
27
+ const BARE = { shop: { name: '' }, menus: {} };
28
+ const isBody = (n) => {
29
+ const area = n.area ?? getSection(n.type)?.area;
30
+ return area !== 'header' && area !== 'footer';
31
+ };
32
+ export function SectionRenderer({ node }) {
33
+ const store = useStore();
34
+ const actions = useThemeActions();
35
+ const context = useThemeContext();
36
+ const tree = usePageTree();
37
+ const showStarter = useContext(ShowStarterContext);
38
+ // A load this render asked for starts after it commits, even when only this section re-rendered.
39
+ useEffect(() => store?.resources.flush(store.bump));
40
+ const theme = getThemeBundle().theme;
41
+ // On the live storefront, starter instructions never reach a shopper (the editor shows them).
42
+ const unpruned = node && context.mode !== 'editor' && !showStarter ? withoutStarter(node, starterSet(theme.starterText), defaultsFor(theme), copyFieldsFor(theme)) : node;
43
+ // Then the theme's own shipped words in the page's language (after the starter check, which matches the English).
44
+ const strings = useLocaleStrings();
45
+ const shown = useMemo(() => (unpruned ? localizeShippedCopy(unpruned, shippedCopyOf(theme.shippedCopy?.english, theme.shippedCopy?.prefix ?? ''), strings, copyPlanOf(theme)) : unpruned), [unpruned, theme, strings]);
46
+ const section = shown ? theme.sections.find((s) => s.id === shown.type) : undefined;
47
+ const firstBody = tree?.find(isBody) ?? null;
48
+ let props = null;
49
+ if (section && shown) {
50
+ const saved = toSaved(shown);
51
+ props = section.data
52
+ ? section.data(saved, store?.ctx ?? BARE, {
53
+ actions,
54
+ context,
55
+ page: {
56
+ firstBodySection: firstBody ? toSaved(firstBody) : null,
57
+ isFirstBodySection: Boolean(firstBody && firstBody.id === shown.id && firstBody.type === shown.type),
58
+ },
59
+ })
60
+ : resolveSettings(section.schema, saved.settings).settings;
61
+ }
62
+ const listing = useListing(section?.listing && props ? props : null);
63
+ if (!section || !props)
64
+ return null;
65
+ const C = section.component;
66
+ return _jsx(C, { ...props, ...(section.listing ? listing : {}) });
67
+ }
68
+ /** Setting defaults per section / block type, built once per theme (starter text can be a default). */
69
+ const defaultsCache = new WeakMap();
70
+ function defaultsFor(theme) {
71
+ let map = defaultsCache.get(theme);
72
+ if (!map) {
73
+ map = new Map();
74
+ for (const s of theme.sections) {
75
+ map.set(s.id, resolveSettings(s.schema, {}).settings);
76
+ for (const b of s.blocks ?? []) {
77
+ const name = b.name;
78
+ if (name && !map.has(name))
79
+ map.set(name, resolveSettings(b, {}).settings);
80
+ }
81
+ }
82
+ defaultsCache.set(theme, map);
83
+ }
84
+ const m = map;
85
+ return (type) => m.get(type);
86
+ }
87
+ /** Copy fields (text / textarea / richtext) per section / block type, built once per theme. */
88
+ const COPY_CONTROLS = new Set(['text', 'textarea', 'richtext']);
89
+ const copyCache = new WeakMap();
90
+ function copyFieldsFor(theme) {
91
+ let map = copyCache.get(theme);
92
+ if (!map) {
93
+ map = new Map();
94
+ const copyOf = (s) => new Set(Object.entries(s?.fields ?? {}).filter(([, f]) => COPY_CONTROLS.has(f?.control ?? '')).map(([k]) => k));
95
+ for (const s of theme.sections) {
96
+ map.set(s.id, copyOf(s.schema));
97
+ for (const b of s.blocks ?? []) {
98
+ const name = b.name;
99
+ if (name && !map.has(name))
100
+ map.set(name, copyOf(b));
101
+ }
102
+ }
103
+ copyCache.set(theme, map);
104
+ }
105
+ const m = map;
106
+ return (type) => m.get(type);
107
+ }
108
+ /** Blocks render inside their section; standalone they render nothing. */
109
+ export function BlockPlaceholder() {
110
+ return null;
111
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A product listing's state in the URL, so a sorted / filtered collection page can be shared,
3
+ * bookmarked and reloaded — and the server renders it the same way (no React here: the server's
4
+ * data plan and the browser's listing hook both use it).
5
+ *
6
+ * ?sort=price-asc the sort id (`featured` is the bare URL)
7
+ * ?filter.available=true a list facet value (its id, minus the facet id prefix)
8
+ * ?filter.productType=Mugs&filter.productType=Plates several values of one facet = any of them
9
+ * ?filter.price.gte=10&filter.price.lte=50 a price range (either end may be absent)
10
+ *
11
+ * The parameter name is the facet's own id, so it means the same thing on every store that has
12
+ * that facet. A value or facet this store does not have is ignored, never an error.
13
+ */
14
+ /** The sorts the listing offers (product-listing.ts). */
15
+ export declare const LISTING_SORTS: readonly ["featured", "price-asc", "price-desc", "title-asc"];
16
+ /** A facet as the listing reads it: `input` is the JSON filter object for one value. */
17
+ export interface ListingFacet {
18
+ id: string;
19
+ type: string;
20
+ values: ReadonlyArray<{
21
+ id: string;
22
+ input: string;
23
+ }>;
24
+ }
25
+ export type FilterInput = Record<string, unknown>;
26
+ export interface ListingState {
27
+ /** Facet id → the selected value ids. */
28
+ values: Record<string, string[]>;
29
+ price?: {
30
+ from?: number;
31
+ to?: number;
32
+ };
33
+ sort: string;
34
+ }
35
+ /** The listing part of a query string (`sort` and `filter.*`), in its original order; '' when none. */
36
+ export declare function listingQueryOf(search: string | URLSearchParams): string;
37
+ /** The selection a listing query names, resolved against this collection's facets. */
38
+ export declare function stateFromQuery(query: string, facets: readonly ListingFacet[]): ListingState;
39
+ /** The listing query for a selection (stable: facet order, then value order); '' for the default. */
40
+ export declare function queryOfState(state: ListingState, facets: readonly ListingFacet[]): string;
41
+ /** `href` with its listing params replaced by `query` (other params and the hash kept). */
42
+ export declare function withListingQuery(href: string, query: string): string;
43
+ /**
44
+ * The requests a filtered selection needs. The storefront ANDs every filter it is given, so two
45
+ * values of one facet are asked for one request each and unioned by the caller.
46
+ */
47
+ export declare function filterRequests(state: Pick<ListingState, 'values' | 'price'>, facets: readonly ListingFacet[], maxRequests: number): FilterInput[][];
@@ -0,0 +1,114 @@
1
+ /**
2
+ * A product listing's state in the URL, so a sorted / filtered collection page can be shared,
3
+ * bookmarked and reloaded — and the server renders it the same way (no React here: the server's
4
+ * data plan and the browser's listing hook both use it).
5
+ *
6
+ * ?sort=price-asc the sort id (`featured` is the bare URL)
7
+ * ?filter.available=true a list facet value (its id, minus the facet id prefix)
8
+ * ?filter.productType=Mugs&filter.productType=Plates several values of one facet = any of them
9
+ * ?filter.price.gte=10&filter.price.lte=50 a price range (either end may be absent)
10
+ *
11
+ * The parameter name is the facet's own id, so it means the same thing on every store that has
12
+ * that facet. A value or facet this store does not have is ignored, never an error.
13
+ */
14
+ /** The sorts the listing offers (product-listing.ts). */
15
+ export const LISTING_SORTS = ['featured', 'price-asc', 'price-desc', 'title-asc'];
16
+ const isFilterKey = (k) => k === 'sort' || k.startsWith('filter.');
17
+ /** The listing part of a query string (`sort` and `filter.*`), in its original order; '' when none. */
18
+ export function listingQueryOf(search) {
19
+ const params = typeof search === 'string' ? new URLSearchParams(search.startsWith('?') ? search.slice(1) : search) : search;
20
+ const out = new URLSearchParams();
21
+ for (const [k, v] of params)
22
+ if (isFilterKey(k) && v !== '' && k.length <= 128 && v.length <= 256)
23
+ out.append(k, v);
24
+ return out.toString();
25
+ }
26
+ const token = (facetId, valueId) => (valueId.startsWith(`${facetId}.`) ? valueId.slice(facetId.length + 1) : valueId);
27
+ const num = (v) => {
28
+ if (v === null || v.trim() === '')
29
+ return undefined;
30
+ const n = Number(v);
31
+ return Number.isFinite(n) && n >= 0 ? n : undefined;
32
+ };
33
+ /** The selection a listing query names, resolved against this collection's facets. */
34
+ export function stateFromQuery(query, facets) {
35
+ const params = new URLSearchParams(query);
36
+ const sortParam = params.get('sort') ?? '';
37
+ const sort = LISTING_SORTS.includes(sortParam) ? sortParam : 'featured';
38
+ const values = {};
39
+ let price;
40
+ for (const f of facets) {
41
+ if (f.type === 'PRICE_RANGE') {
42
+ const from = num(params.get(`${f.id}.gte`));
43
+ const to = num(params.get(`${f.id}.lte`));
44
+ if (from !== undefined || to !== undefined)
45
+ price = { ...(from !== undefined ? { from } : {}), ...(to !== undefined ? { to } : {}) };
46
+ continue;
47
+ }
48
+ const picked = params.getAll(f.id).flatMap((t) => f.values.filter((v) => v.id === t || token(f.id, v.id) === t).map((v) => v.id));
49
+ if (picked.length)
50
+ values[f.id] = [...new Set(picked)];
51
+ }
52
+ return { values, ...(price ? { price } : {}), sort };
53
+ }
54
+ /** The listing query for a selection (stable: facet order, then value order); '' for the default. */
55
+ export function queryOfState(state, facets) {
56
+ const out = new URLSearchParams();
57
+ if (state.sort && state.sort !== 'featured')
58
+ out.set('sort', state.sort);
59
+ for (const f of facets) {
60
+ if (f.type === 'PRICE_RANGE') {
61
+ if (state.price?.from != null)
62
+ out.set(`${f.id}.gte`, String(state.price.from));
63
+ if (state.price?.to != null)
64
+ out.set(`${f.id}.lte`, String(state.price.to));
65
+ continue;
66
+ }
67
+ for (const v of f.values)
68
+ if (state.values[f.id]?.includes(v.id))
69
+ out.append(f.id, token(f.id, v.id));
70
+ }
71
+ return out.toString();
72
+ }
73
+ /** `href` with its listing params replaced by `query` (other params and the hash kept). */
74
+ export function withListingQuery(href, query) {
75
+ const url = new URL(href);
76
+ for (const k of [...url.searchParams.keys()])
77
+ if (isFilterKey(k))
78
+ url.searchParams.delete(k);
79
+ // A new selection is a new list: the page number belonged to the old one.
80
+ url.searchParams.delete('page');
81
+ for (const [k, v] of new URLSearchParams(query))
82
+ url.searchParams.append(k, v);
83
+ return url.toString();
84
+ }
85
+ const parse = (input) => {
86
+ try {
87
+ return JSON.parse(input);
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ };
93
+ /** Every pick of one value per group — the requests that together mean "any of these". */
94
+ function combinations(groups) {
95
+ return groups.reduce((acc, g) => acc.flatMap((c) => g.map((v) => [...c, v])), [[]]);
96
+ }
97
+ /**
98
+ * The requests a filtered selection needs. The storefront ANDs every filter it is given, so two
99
+ * values of one facet are asked for one request each and unioned by the caller.
100
+ */
101
+ export function filterRequests(state, facets, maxRequests) {
102
+ const inputs = new Map(facets.flatMap((f) => f.values.map((v) => [v.id, parse(v.input)])));
103
+ const priceFacet = facets.find((f) => f.type === 'PRICE_RANGE');
104
+ const bounds = priceFacet ? (parse(priceFacet.values[0]?.input ?? '')?.price ?? null) : null;
105
+ const groups = Object.values(state.values)
106
+ .filter((ids) => ids.length > 0)
107
+ .map((ids) => ids.map((v) => inputs.get(v)).filter((v) => Boolean(v)))
108
+ .filter((g) => g.length > 0);
109
+ if (state.price)
110
+ groups.push([{ price: { min: state.price.from ?? bounds?.min ?? 0, max: state.price.to ?? bounds?.max ?? Number.MAX_SAFE_INTEGER } }]);
111
+ if (!groups.length)
112
+ return [];
113
+ return combinations(groups).slice(0, maxRequests);
114
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Shipped copy in the page's language (theme `shippedCopy`).
3
+ *
4
+ * A theme ships words a merchant may keep or replace: setting defaults
5
+ * ("Send message"), and the starter templates and presets that are copied into
6
+ * a store's content when the theme is installed ("Get in touch"). They are
7
+ * written once, in English. A Thai store that never touched them showed
8
+ * English to a Thai shopper — after a contact form was sent, "Thanks — we'll
9
+ * reply soon." (production store 3b866d32, 2026-10-17).
10
+ *
11
+ * The rule, per copy field (text / textarea / richtext) of a section or block:
12
+ *
13
+ * - unset → its default; saved → the saved value (as before);
14
+ * - if that value is, exactly (trimmed), an English string the theme shipped,
15
+ * it is the theme's word, not the merchant's: it renders as that string's
16
+ * entry in the active locale file (`copy.*` in locales/<code>.json);
17
+ * - anything else is the merchant's and renders verbatim.
18
+ *
19
+ * Why match the English text rather than mark the default. Installed stores
20
+ * already hold the shipped English literally — the starter template was copied
21
+ * into their content, so "untouched" and "typed" cannot be told apart by
22
+ * presence. A marker (a `t:` token) would only reach stores installed after
23
+ * this change, and the editor's settings panel would show the raw token. The
24
+ * English text is the one thing every existing store's untouched copy has in
25
+ * common. The cost is narrow: a merchant who types exactly a shipped English
26
+ * string on a store whose shopper reads Thai gets the Thai string — the same
27
+ * words, in the shopper's language.
28
+ *
29
+ * Pure (no React): SectionRenderer applies it to the node before `data()`.
30
+ */
31
+ import type { ContentNode } from '../kit/types.js';
32
+ /** English shipped text (trimmed) → its locale key. */
33
+ export type ShippedCopy = ReadonlyMap<string, string>;
34
+ /** One node type's copy fields and what each renders when unset (absent: no single default). */
35
+ export interface CopyFields {
36
+ readonly fields: ReadonlySet<string>;
37
+ readonly defaults: Readonly<Record<string, string>>;
38
+ }
39
+ /** Copy fields per node type; a section and a block may share a name, so they are looked up apart. */
40
+ export interface CopyPlan {
41
+ section(type: string): CopyFields | undefined;
42
+ block(type: string): CopyFields | undefined;
43
+ }
44
+ type ThemeLike = {
45
+ sections: readonly {
46
+ id: string;
47
+ schema: unknown;
48
+ blocks?: readonly unknown[];
49
+ }[];
50
+ shippedCopy?: {
51
+ keep?: readonly string[];
52
+ derivedWhenUnset?: readonly string[];
53
+ };
54
+ };
55
+ /**
56
+ * A field reference in a theme's `shippedCopy` lists: `section:<type>.<key>` or `block:<type>.<key>`.
57
+ *
58
+ * - `keep`: the renderer compares the value with the shipped English (a sentinel: "the default title is
59
+ * not an override", "this tagline is the editor placeholder"). Localizing it would break that test,
60
+ * so the field is never touched.
61
+ * - `derivedWhenUnset`: an unset value means "derive it from data" (a footer column's heading → its
62
+ * menu's name). The default is never filled in; a saved value is still localized.
63
+ */
64
+ export type CopyFieldRef = `${'section' | 'block'}:${string}.${string}`;
65
+ /**
66
+ * The copy plan of a theme, built once. A block name several schemas share
67
+ * (`newsletter`, `image` …) gets the union of their copy fields, and a default
68
+ * only where every one of those schemas agrees on it — an unset field is never
69
+ * filled with another schema's default.
70
+ */
71
+ /** The `shippedCopy` references that name no copy field of the theme (a test asserts there are none). */
72
+ export declare function unknownCopyRefs(theme: ThemeLike): string[];
73
+ export declare function copyPlanOf(theme: ThemeLike): CopyPlan;
74
+ /**
75
+ * The lookup for a theme: every `<prefix>*` key of its English locale map,
76
+ * inverted. The English file is the list, so a new shipped string is one new
77
+ * locale key and nothing else.
78
+ */
79
+ export declare function shippedCopyOf(english: Readonly<Record<string, string>> | undefined, prefix: string): ShippedCopy;
80
+ /**
81
+ * The section node with every shipped-English copy field (its own and its
82
+ * blocks') in the active language — the same object when nothing changes
83
+ * (an English page, or copy that is all the merchant's), so renders stay put.
84
+ */
85
+ export declare function localizeShippedCopy(node: ContentNode, copy: ShippedCopy, strings: Readonly<Record<string, string>>, plan: CopyPlan): ContentNode;
86
+ export {};