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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -10
  3. package/dist/abi/canvas-live.d.ts +72 -0
  4. package/dist/abi/canvas-live.js +159 -0
  5. package/dist/abi/cart.d.ts +60 -0
  6. package/dist/abi/cart.js +396 -0
  7. package/dist/abi/convert.d.ts +360 -0
  8. package/dist/abi/convert.js +1330 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +213 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/labels.d.ts +3 -0
  14. package/dist/abi/labels.js +34 -0
  15. package/dist/abi/page-data.d.ts +264 -0
  16. package/dist/abi/page-data.js +746 -0
  17. package/dist/abi/page.d.ts +28 -0
  18. package/dist/abi/page.js +57 -0
  19. package/dist/abi/referrals.d.ts +23 -0
  20. package/dist/abi/referrals.js +89 -0
  21. package/dist/abi/rewards.d.ts +27 -0
  22. package/dist/abi/rewards.js +82 -0
  23. package/dist/abi/seo.d.ts +47 -0
  24. package/dist/abi/seo.js +68 -0
  25. package/dist/abi/shell.d.ts +23 -0
  26. package/dist/abi/shell.js +10 -0
  27. package/dist/abi/state-pack.d.ts +17 -0
  28. package/dist/abi/state-pack.js +43 -0
  29. package/dist/abi/wire.d.ts +46 -0
  30. package/dist/abi/wire.js +114 -0
  31. package/dist/build.d.ts +121 -0
  32. package/dist/build.js +401 -0
  33. package/dist/chunks.d.ts +23 -0
  34. package/dist/chunks.js +41 -0
  35. package/dist/client.d.ts +26 -0
  36. package/dist/client.js +101 -0
  37. package/dist/contract.d.ts +6 -0
  38. package/dist/contract.js +6 -0
  39. package/dist/headless/ai.d.ts +132 -0
  40. package/dist/headless/ai.js +99 -0
  41. package/dist/headless/hooks.d.ts +276 -0
  42. package/dist/headless/hooks.js +544 -0
  43. package/dist/headless/i18n.d.ts +13 -0
  44. package/dist/headless/i18n.js +45 -0
  45. package/dist/headless/index.d.ts +44 -0
  46. package/dist/headless/index.js +48 -0
  47. package/dist/headless/lazy-component.d.ts +72 -0
  48. package/dist/headless/lazy-component.js +225 -0
  49. package/dist/headless/lazy-section.d.ts +38 -0
  50. package/dist/headless/lazy-section.js +97 -0
  51. package/dist/headless/model.d.ts +73 -0
  52. package/dist/headless/model.js +115 -0
  53. package/dist/headless/money.d.ts +17 -0
  54. package/dist/headless/money.js +63 -0
  55. package/dist/headless/page.d.ts +45 -0
  56. package/dist/headless/page.js +53 -0
  57. package/dist/headless/platform.d.ts +55 -0
  58. package/dist/headless/platform.js +77 -0
  59. package/dist/headless/primitives/cart.d.ts +90 -0
  60. package/dist/headless/primitives/cart.js +153 -0
  61. package/dist/headless/primitives/collection.d.ts +68 -0
  62. package/dist/headless/primitives/collection.js +80 -0
  63. package/dist/headless/primitives/product.d.ts +101 -0
  64. package/dist/headless/primitives/product.js +117 -0
  65. package/dist/headless/primitives/storefront.d.ts +106 -0
  66. package/dist/headless/primitives/storefront.js +187 -0
  67. package/dist/headless/primitives/util.d.ts +19 -0
  68. package/dist/headless/primitives/util.js +42 -0
  69. package/dist/headless/strings.d.ts +9 -0
  70. package/dist/headless/strings.js +198 -0
  71. package/dist/headless/structured-data.d.ts +31 -0
  72. package/dist/headless/structured-data.js +57 -0
  73. package/dist/headless/tanqory-money.generated.d.ts +493 -0
  74. package/dist/headless/tanqory-money.generated.js +507 -0
  75. package/dist/headless/theme.d.ts +109 -0
  76. package/dist/headless/theme.js +62 -0
  77. package/dist/index.d.ts +21 -0
  78. package/dist/index.js +21 -553
  79. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  80. package/dist/runtime/data/StoreProvider.js +380 -0
  81. package/dist/runtime/data/handle.d.ts +14 -0
  82. package/dist/runtime/data/handle.js +16 -0
  83. package/dist/runtime/data/routes.d.ts +87 -0
  84. package/dist/runtime/data/routes.js +158 -0
  85. package/dist/runtime/data/to-ui.d.ts +286 -0
  86. package/dist/runtime/data/to-ui.js +1009 -0
  87. package/dist/runtime/entries/register.d.ts +9 -0
  88. package/dist/runtime/entries/register.js +9 -0
  89. package/dist/runtime/entries/sections.d.ts +16 -0
  90. package/dist/runtime/entries/sections.js +19 -0
  91. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  92. package/dist/runtime/kit/SectionTree.js +100 -0
  93. package/dist/runtime/kit/analytics.d.ts +63 -0
  94. package/dist/runtime/kit/analytics.js +250 -0
  95. package/dist/runtime/kit/cart.d.ts +222 -0
  96. package/dist/runtime/kit/cart.js +545 -0
  97. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  98. package/dist/runtime/kit/composition.js +3 -0
  99. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  100. package/dist/runtime/kit/config.js +6 -0
  101. package/dist/runtime/kit/consent.d.ts +29 -0
  102. package/dist/runtime/kit/consent.js +159 -0
  103. package/dist/runtime/kit/contract/content.d.ts +213 -0
  104. package/dist/runtime/kit/contract/content.js +119 -0
  105. package/dist/runtime/kit/contract/field-types.d.ts +360 -0
  106. package/dist/runtime/kit/contract/field-types.js +216 -0
  107. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  108. package/dist/runtime/kit/contract/groups.js +402 -0
  109. package/dist/runtime/kit/contract/index.d.ts +33 -0
  110. package/dist/runtime/kit/contract/index.js +33 -0
  111. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  112. package/dist/runtime/kit/contract/transform.js +133 -0
  113. package/dist/runtime/kit/contract/validate.d.ts +77 -0
  114. package/dist/runtime/kit/contract/validate.js +520 -0
  115. package/dist/runtime/kit/data.d.ts +732 -0
  116. package/dist/runtime/kit/data.js +1131 -0
  117. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  118. package/dist/runtime/kit/defineSection.js +10 -0
  119. package/dist/runtime/kit/dynamic-source.d.ts +118 -0
  120. package/dist/runtime/kit/dynamic-source.js +311 -0
  121. package/dist/runtime/kit/index.d.ts +24 -0
  122. package/dist/runtime/kit/index.js +24 -0
  123. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  124. package/dist/runtime/kit/jsx-to-json.js +28 -0
  125. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  126. package/dist/runtime/kit/mount.js +124 -0
  127. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  128. package/dist/runtime/kit/registry.js +12 -0
  129. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  130. package/dist/runtime/kit/ssg.js +56 -0
  131. package/dist/runtime/kit/storefront.d.ts +652 -0
  132. package/dist/runtime/kit/storefront.js +723 -0
  133. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  134. package/dist/runtime/kit/theme-context.js +25 -0
  135. package/dist/runtime/kit/types.d.ts +155 -0
  136. package/dist/runtime/kit/types.js +1 -0
  137. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  138. package/dist/runtime/platform/TrackingPixels.js +63 -0
  139. package/dist/runtime/platform/environment.d.ts +68 -0
  140. package/dist/runtime/platform/environment.js +85 -0
  141. package/dist/runtime/platform/locale.d.ts +27 -0
  142. package/dist/runtime/platform/locale.js +42 -0
  143. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  144. package/dist/runtime/platform/route-analytics.js +72 -0
  145. package/dist/runtime/platform/safe-href.d.ts +25 -0
  146. package/dist/runtime/platform/safe-href.js +69 -0
  147. package/dist/runtime/platform/safe-values.d.ts +37 -0
  148. package/dist/runtime/platform/safe-values.js +140 -0
  149. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  150. package/dist/runtime/render/SectionRenderer.js +199 -0
  151. package/dist/runtime/render/listing-query.d.ts +52 -0
  152. package/dist/runtime/render/listing-query.js +122 -0
  153. package/dist/runtime/render/localized-copy.d.ts +86 -0
  154. package/dist/runtime/render/localized-copy.js +129 -0
  155. package/dist/runtime/render/product-listing.d.ts +11 -0
  156. package/dist/runtime/render/product-listing.js +243 -0
  157. package/dist/runtime/render/resolved.d.ts +47 -0
  158. package/dist/runtime/render/resolved.js +80 -0
  159. package/dist/runtime/render/section-actions.d.ts +67 -0
  160. package/dist/runtime/render/section-actions.js +205 -0
  161. package/dist/runtime/render/starter.d.ts +11 -0
  162. package/dist/runtime/render/starter.js +96 -0
  163. package/dist/runtime/seo/head.d.ts +115 -0
  164. package/dist/runtime/seo/head.js +281 -0
  165. package/dist/runtime/seo/structured-data.d.ts +83 -0
  166. package/dist/runtime/seo/structured-data.js +252 -0
  167. package/dist/runtime/shell/PageShell.d.ts +18 -0
  168. package/dist/runtime/shell/PageShell.js +118 -0
  169. package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
  170. package/dist/runtime/shell/RuntimeBridge.js +124 -0
  171. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  172. package/dist/runtime/shell/overlay-state.js +59 -0
  173. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  174. package/dist/runtime/shell/preview-mode.js +11 -0
  175. package/dist/runtime/shell/spa-router.d.ts +14 -0
  176. package/dist/runtime/shell/spa-router.js +76 -0
  177. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  178. package/dist/runtime/shell/url-redirects.js +37 -0
  179. package/dist/runtime/slots.d.ts +74 -0
  180. package/dist/runtime/slots.js +16 -0
  181. package/dist/runtime.d.ts +34 -0
  182. package/dist/runtime.js +40 -0
  183. package/dist/sdk/app-block.d.ts +29 -0
  184. package/dist/sdk/app-block.js +22 -0
  185. package/dist/sdk/font-hooks.d.ts +7 -0
  186. package/dist/sdk/font-hooks.js +21 -0
  187. package/dist/sdk/fonts.d.ts +144 -0
  188. package/dist/sdk/fonts.js +241 -0
  189. package/dist/sdk/index.d.ts +32 -0
  190. package/dist/sdk/index.js +36 -0
  191. package/dist/sdk/motion-hooks.d.ts +23 -0
  192. package/dist/sdk/motion-hooks.js +46 -0
  193. package/dist/sdk/motion.d.ts +78 -0
  194. package/dist/sdk/motion.js +292 -0
  195. package/dist/sdk/referrals.d.ts +62 -0
  196. package/dist/sdk/referrals.js +20 -0
  197. package/dist/sdk/rewards.d.ts +85 -0
  198. package/dist/sdk/rewards.js +29 -0
  199. package/dist/sdk/runtime-context.d.ts +230 -0
  200. package/dist/sdk/runtime-context.js +73 -0
  201. package/dist/sdk/schema.d.ts +249 -0
  202. package/dist/sdk/schema.js +168 -0
  203. package/dist/sdk/server-render.d.ts +8 -0
  204. package/dist/sdk/server-render.js +12 -0
  205. package/dist/sdk/store-lookup.d.ts +32 -0
  206. package/dist/sdk/store-lookup.js +48 -0
  207. package/dist/sdk/store.d.ts +164 -0
  208. package/dist/sdk/store.js +5 -0
  209. package/dist/sdk/sx.d.ts +45 -0
  210. package/dist/sdk/sx.js +117 -0
  211. package/dist/sdk/theme.d.ts +212 -0
  212. package/dist/sdk/theme.js +27 -0
  213. package/dist/sdk/types.d.ts +789 -0
  214. package/dist/sdk/types.js +7 -0
  215. package/dist/server.d.ts +112 -0
  216. package/dist/server.js +589 -0
  217. package/dist/vite-chunks.d.ts +10 -0
  218. package/dist/vite-chunks.js +44 -0
  219. package/docs/headless-api.md +250 -0
  220. package/package.json +72 -26
  221. package/dist/index.js.map +0 -1
  222. package/dist/ssg-BZ5FYTw7.js +0 -1802
  223. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  224. package/dist/ssg.js +0 -8
  225. package/dist/ssg.js.map +0 -1
  226. package/dist/types/cart.d.ts +0 -86
  227. package/dist/types/data.d.ts +0 -357
  228. package/dist/types/dynamic-source.d.ts +0 -84
  229. package/dist/types/editor.d.ts +0 -5
  230. package/dist/types/index.d.ts +0 -20
  231. package/dist/types/preview-bridge.d.ts +0 -9
  232. package/dist/types/storefront.d.ts +0 -333
  233. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,281 @@
1
+ import { matchRoute } from '../data/routes.js';
2
+ import { productJsonLd, serializeJsonLd } from './structured-data.js';
3
+ /**
4
+ * A meta description from a resource's own text when the merchant wrote no SEO
5
+ * one: tags stripped, whitespace collapsed, cut at a word near 160 characters
6
+ * (what results pages show).
7
+ */
8
+ export function summary(text, max = 160) {
9
+ const plain = String(text ?? '').replace(/<[^>]*>/g, ' ').replace(/&nbsp;/g, ' ').replace(/\s+/g, ' ').trim();
10
+ if (plain.length <= max)
11
+ return plain;
12
+ const cut = plain.slice(0, max);
13
+ const space = cut.lastIndexOf(' ');
14
+ return `${(space > max * 0.6 ? cut.slice(0, space) : cut).replace(/[\s,.;:–—-]+$/, '')}…`;
15
+ }
16
+ /** Build a HeadMeta from a resource's SEO (shared by blog/article, which resolve
17
+ * their SEO asynchronously rather than from the sync bootstrap). */
18
+ export function headFrom(seo, resourceTitle, shopName, fallbackDesc, image) {
19
+ return {
20
+ title: documentTitle({ seoTitle: seo?.title, resourceTitle, shopName }),
21
+ description: (seo?.description || fallbackDesc || '').trim(),
22
+ keywords: (seo?.keywords ?? []).filter(Boolean),
23
+ image: absUrl(image),
24
+ type: 'article',
25
+ siteName: shopName,
26
+ favicon: '',
27
+ };
28
+ }
29
+ /** Resolve a possibly-relative asset URL to an absolute one, against the
30
+ * current origin — social scrapers require absolute og:image URLs. */
31
+ export function absUrl(url) {
32
+ if (!url)
33
+ return '';
34
+ if (/^https?:\/\//.test(url))
35
+ return url;
36
+ if (typeof window === 'undefined')
37
+ return url;
38
+ return new URL(url, window.location.origin).toString();
39
+ }
40
+ /**
41
+ * The metaobject page entry whose head this is: the route's own (`<definitionHandle>/<handle>` equal to the route
42
+ * handle), else null. Exported for tests.
43
+ */
44
+ export function metaobjectHeadSource(entry, routeHandle) {
45
+ return entry && `${entry.definitionHandle}/${entry.handle}` === routeHandle ? entry : null;
46
+ }
47
+ export function computeHead(pathname, data, settings,
48
+ /** The request origin on the server render; the browser origin when omitted. */
49
+ origin) {
50
+ const shop = data.shop;
51
+ // The theme's shop name first, like the header — never the store ACCOUNT's
52
+ // name when the theme names its brand (nova#14).
53
+ const shopName = shopNameOf(settings.shopName, shop?.name);
54
+ let seoTitle;
55
+ let rawTitle;
56
+ let description;
57
+ let keywords = [];
58
+ let image;
59
+ let type = 'website';
60
+ let jsonLd = null;
61
+ const pageOrigin = origin ?? (typeof window === 'undefined' ? '' : window.location.origin);
62
+ const route = matchRoute(pathname);
63
+ const isDetail = {
64
+ pg: route.resource === 'page' ? route.handle : undefined,
65
+ pr: route.resource === 'product' ? route.handle : undefined,
66
+ co: route.resource === 'collection' ? route.handle : undefined,
67
+ // a metaobject page (`/pages/<definition>/<entry>`): its handle is `<definition>/<entry>`
68
+ mo: route.resource === 'metaobject' ? route.handle : undefined,
69
+ };
70
+ if (isDetail.pr) {
71
+ const r = data.productByHandle(isDetail.pr);
72
+ seoTitle = r?.seo?.title;
73
+ rawTitle = r?.title;
74
+ description = r?.seo?.description || summary(r?.description);
75
+ keywords = r?.seo?.keywords ?? [];
76
+ image = r?.featuredImage?.url;
77
+ type = 'product';
78
+ jsonLd = productJsonLd(data.productByHandle(isDetail.pr) ?? null, {
79
+ url: pageOrigin ? `${pageOrigin}${pathname}` : pathname,
80
+ origin: pageOrigin,
81
+ shopName,
82
+ });
83
+ }
84
+ else if (isDetail.co) {
85
+ const r = data.collectionByHandle(isDetail.co);
86
+ seoTitle = r?.seo?.title;
87
+ rawTitle = r?.title;
88
+ description = r?.seo?.description || summary(r?.description);
89
+ keywords = r?.seo?.keywords ?? [];
90
+ image = r?.image?.url;
91
+ }
92
+ else if (isDetail.pg) {
93
+ const r = data.pageByHandle(isDetail.pg);
94
+ seoTitle = r?.seo?.title;
95
+ rawTitle = r?.title;
96
+ description = r?.seo?.description || r?.bodySummary;
97
+ keywords = r?.seo?.keywords ?? [];
98
+ type = 'article';
99
+ }
100
+ else if (isDetail.mo) {
101
+ // The route's own entry only (a soft navigation never shows the previous entry's head): its SEO title verbatim,
102
+ // else "<entry handle> — <shop>"; its meta description (storefront-query rev 2.62 `Metaobject.seo`).
103
+ const m = metaobjectHeadSource(data.routeMetaobject, isDetail.mo);
104
+ // before the entry's data (a soft navigation), the route's own entry handle still names the page
105
+ seoTitle = m?.seo?.title;
106
+ rawTitle = m?.handle ?? isDetail.mo.slice(isDetail.mo.indexOf('/') + 1);
107
+ description = m?.seo?.description;
108
+ type = 'article';
109
+ }
110
+ const isHome = !isDetail.pg && !isDetail.pr && !isDetail.co && !isDetail.mo;
111
+ const title = documentTitle({ seoTitle, resourceTitle: rawTitle, shopName });
112
+ return {
113
+ title,
114
+ description: (description || (isHome ? shop?.description : '') || '').trim(),
115
+ keywords: keywords.filter(Boolean),
116
+ // og:image fallback chain: the resource's own image → the brand cover image
117
+ // (Settings → Brand, a purpose-built share banner) → the brand logo. Both
118
+ // brand images were SAVED_ONLY — carried on the SDL, rendered nowhere.
119
+ image: absUrl(image || shop?.brand?.coverImage?.url || shop?.brand?.logo?.url),
120
+ type,
121
+ siteName: shopName,
122
+ // The square brand mark makes the best favicon / tab icon; fall back to the
123
+ // primary logo. Also previously SAVED_ONLY.
124
+ favicon: absUrl(shop?.brand?.squareLogo?.url || shop?.brand?.logo?.url),
125
+ jsonLd,
126
+ };
127
+ }
128
+ /**
129
+ * Write the computed head into the live document (client-side).
130
+ *
131
+ * Beyond title/description/keywords this now emits the canonical link + Open
132
+ * Graph + Twitter card tags that were missing entirely — which is why a shared
133
+ * product link previewed as the bare shop name on every page. The canonical and
134
+ * og:url use the page's own URL (the host the storefront is served on is the
135
+ * correct canonical for that page); forcing canonical to a configured primary
136
+ * domain when a shopper is on a different host is the store-api#558 follow-up.
137
+ */
138
+ export function applyHead({ title, description, keywords, image, type, siteName, favicon, jsonLd }) {
139
+ if (typeof document === 'undefined')
140
+ return;
141
+ const head = document.head;
142
+ if (title)
143
+ document.title = title;
144
+ /**
145
+ * Write a head tag, or REMOVE it when the new page has no value for it.
146
+ *
147
+ * Skipping empty values left the previous route's head in place on a soft
148
+ * navigation: opening a product set `og:description`, `og:image` and
149
+ * `keywords`, and clicking through to a page without them kept all three, so
150
+ * sharing that URL previewed the product you had just left — the exact stale
151
+ * -head bug this module exists to fix.
152
+ */
153
+ const upsert = (selector, make, content) => {
154
+ const existing = head.querySelector(selector);
155
+ if (!content) {
156
+ // Only ever remove a tag this function owns, never one the document
157
+ // shipped with that we have no replacement for.
158
+ if (existing && existing.getAttribute('data-tq-head') === 'true')
159
+ existing.remove();
160
+ return;
161
+ }
162
+ let el = existing;
163
+ if (!el) {
164
+ el = make();
165
+ el.setAttribute('data-tq-head', 'true');
166
+ head.appendChild(el);
167
+ }
168
+ if (el.tagName === 'LINK')
169
+ el.setAttribute('href', content);
170
+ else
171
+ el.setAttribute('content', content);
172
+ };
173
+ const meta = (name, content) => upsert(`meta[name="${name}"]`, () => {
174
+ const m = document.createElement('meta');
175
+ m.setAttribute('name', name);
176
+ return m;
177
+ }, content);
178
+ const prop = (property, content) => upsert(`meta[property="${property}"]`, () => {
179
+ const m = document.createElement('meta');
180
+ m.setAttribute('property', property);
181
+ return m;
182
+ }, content);
183
+ const url = window.location.origin + window.location.pathname;
184
+ meta('description', description);
185
+ meta('keywords', keywords.join(', '));
186
+ upsert('link[rel="canonical"]', () => {
187
+ const l = document.createElement('link');
188
+ l.setAttribute('rel', 'canonical');
189
+ return l;
190
+ }, url);
191
+ prop('og:type', type);
192
+ prop('og:url', url);
193
+ prop('og:title', title);
194
+ prop('og:description', description);
195
+ prop('og:site_name', siteName);
196
+ prop('og:image', image);
197
+ meta('twitter:card', image ? 'summary_large_image' : 'summary');
198
+ meta('twitter:title', title);
199
+ meta('twitter:description', description);
200
+ meta('twitter:image', image);
201
+ // JSON-LD: written for a product, removed on the next route that has none (soft navigation must not leave the
202
+ // previous product's structured data behind). Same ownership rule as the other tags.
203
+ const ld = head.querySelector('script[type="application/ld+json"][data-tq-head="true"]');
204
+ if (jsonLd) {
205
+ const el = ld ?? document.createElement('script');
206
+ el.setAttribute('type', 'application/ld+json');
207
+ el.setAttribute('data-tq-head', 'true');
208
+ el.textContent = serializeJsonLd(jsonLd);
209
+ if (!ld)
210
+ head.appendChild(el);
211
+ }
212
+ else if (ld) {
213
+ ld.remove();
214
+ }
215
+ if (favicon) {
216
+ upsert('link[rel="icon"]', () => {
217
+ const l = document.createElement('link');
218
+ l.setAttribute('rel', 'icon');
219
+ return l;
220
+ }, favicon);
221
+ }
222
+ }
223
+ // ── Title: the store's name, like the header ────────────────────────────
224
+ /**
225
+ * The shop's name as the storefront shows it: the store's own name
226
+ * (Settings › General), else the theme's `shopName` setting (an AI-built theme
227
+ * may still carry the name it was built under), else 'Store'. The store name
228
+ * wins so a rename in Settings reaches the header, footer and titles (D-13).
229
+ */
230
+ export function shopNameOf(themeShopName, storeName) {
231
+ const text = (v) => (typeof v === 'string' ? v.trim() : '');
232
+ return text(storeName) || text(themeShopName) || 'Store';
233
+ }
234
+ /**
235
+ * A route's title: the resource's SEO title verbatim (the merchant owns it),
236
+ * else "<resource title> — <shop>", else the shop name alone.
237
+ */
238
+ export function documentTitle(input) {
239
+ const seo = input.seoTitle?.trim();
240
+ if (seo)
241
+ return seo;
242
+ const title = input.resourceTitle?.trim();
243
+ return title ? `${title} — ${input.shopName}` : input.shopName;
244
+ }
245
+ /**
246
+ * The page name in the `<title>` of a route that has no resource of its own (board 35 #76): the cart, search, the
247
+ * collections list, a policy and the Not found page each name the page, as "<page> — <shop>" does on a product,
248
+ * instead of the bare shop name on every one of them. The reference storefront does the same: its `page_title` names
249
+ * the cart, the search with its terms, the collection list, the policy and the 404 page, and only the home page takes
250
+ * the shop's own title (Online Store > Preferences; that stays `homeHead`).
251
+ *
252
+ * The words are the theme's strings (`seo.title.*`, translated per language and by the merchant like any theme
253
+ * word), with these English fallbacks for a theme that ships none. `{query}` in `seo.title.searchResults` is the
254
+ * shopper's search; the caller escapes the whole title. Null for every other route (the head keeps its title).
255
+ */
256
+ export const ROUTE_TITLE_FALLBACK = {
257
+ 'seo.title.cart': 'Cart',
258
+ 'seo.title.search': 'Search',
259
+ 'seo.title.searchResults': 'Search: {query}',
260
+ 'seo.title.collections': 'Collections',
261
+ 'seo.title.notFound': 'Page not found',
262
+ };
263
+ export function routeTitleOf(input) {
264
+ const word = (key) => input.t(key)?.trim() || ROUTE_TITLE_FALLBACK[key];
265
+ if (input.kind === 'not_found' || input.missing)
266
+ return word('seo.title.notFound');
267
+ switch (input.kind) {
268
+ case 'cart':
269
+ return word('seo.title.cart');
270
+ case 'search': {
271
+ const q = input.searchQuery?.replace(/\s+/g, ' ').trim().slice(0, 100);
272
+ return q ? word('seo.title.searchResults').split('{query}').join(q) : word('seo.title.search');
273
+ }
274
+ case 'collections':
275
+ return word('seo.title.collections');
276
+ case 'policy':
277
+ return input.policyTitle?.trim() || null;
278
+ default:
279
+ return null;
280
+ }
281
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * schema.org Product / Offer JSON-LD for search engines and AI answer engines (ChatGPT search, Google, Bing).
3
+ *
4
+ * Built from the product exactly as the buyer sees it: price and currency are the storefront's own `Money`
5
+ * (the buyer's market currency, never a hardcoded THB/USD), availability is claimed only when the storefront knows
6
+ * it, and anything unknown is omitted rather than invented. Pure and free of `window`, so the same builder runs on
7
+ * the server render and on soft navigation.
8
+ */
9
+ import type { Product } from '../kit/data.js';
10
+ export type JsonLd = Record<string, unknown>;
11
+ /**
12
+ * The Product JSON-LD for a product page, or null when there is no product (or no title). `ctx.url` is the page's
13
+ * own absolute URL and `ctx.origin` resolves relative image URLs; both come from the request on the server.
14
+ */
15
+ export declare function productJsonLd(product: Product | null | undefined, ctx: {
16
+ url: string;
17
+ origin: string;
18
+ shopName?: string;
19
+ }): JsonLd | null;
20
+ /** The store's own facts the home page's JSON-LD is built from (kit `Shop`). */
21
+ export interface ShopFacts {
22
+ name?: string | null;
23
+ description?: string | null;
24
+ email?: string | null;
25
+ phone?: string | null;
26
+ brand?: {
27
+ logo?: {
28
+ url?: string | null;
29
+ } | null;
30
+ squareLogo?: {
31
+ url?: string | null;
32
+ } | null;
33
+ } | null;
34
+ address?: {
35
+ address1?: string;
36
+ address2?: string;
37
+ city?: string;
38
+ province?: string;
39
+ zip?: string;
40
+ country?: string;
41
+ countryCode?: string;
42
+ } | null;
43
+ socialLinks?: readonly {
44
+ platform: string;
45
+ url: string;
46
+ }[] | null;
47
+ }
48
+ /**
49
+ * SEO-01: the home page's Organization (Online Store) — name, URL, logo, social profiles (`sameAs`), contact and
50
+ * address — and the WebSite with its SearchAction (the site search box), as the reference platform's themes print on the index page.
51
+ * Answer engines read these to say who the store is and how to reach it. Only what the store published.
52
+ */
53
+ export declare function homeJsonLd(shop: ShopFacts | null | undefined, ctx: {
54
+ origin: string;
55
+ shopName: string;
56
+ language?: string;
57
+ }): JsonLd[];
58
+ /** The article facts an article page's JSON-LD is built from (kit `Article`). */
59
+ export interface ArticleFacts {
60
+ title?: string | null;
61
+ excerpt?: string | null;
62
+ contentHtml?: string | null;
63
+ image?: {
64
+ url?: string | null;
65
+ } | null;
66
+ author?: string | null;
67
+ publishedAt?: string | null;
68
+ tags?: readonly string[] | null;
69
+ seo?: {
70
+ description?: string | null;
71
+ } | null;
72
+ }
73
+ /** SEO-09: an article's BlogPosting — headline, dates, author, image, publisher — for search and answer engines. */
74
+ export declare function articleJsonLd(article: ArticleFacts | null | undefined, ctx: {
75
+ url: string;
76
+ origin: string;
77
+ shopName: string;
78
+ blogTitle?: string;
79
+ }): JsonLd | null;
80
+ /** Serialise for embedding in HTML: `<` and the JS line separators cannot end the script element or the string. */
81
+ export declare function serializeJsonLd(data: JsonLd): string;
82
+ /** The `<script type="application/ld+json">` tag, or '' when there is nothing to say. */
83
+ export declare function jsonLdTag(data: JsonLd | null | undefined): string;
@@ -0,0 +1,252 @@
1
+ const SCHEMA = 'https://schema.org';
2
+ const MONEY_AMOUNT = /^\d+(?:\.\d+)?$/;
3
+ const CURRENCY = /^[A-Z]{3}$/;
4
+ const GTIN = /^(?:\d{8}|\d{12,14})$/;
5
+ const MAX_IMAGES = 10;
6
+ const MAX_DESCRIPTION = 5000;
7
+ const text = (v) => (typeof v === 'string' ? v.trim() : '');
8
+ const absolute = (url, origin) => {
9
+ const u = text(url);
10
+ if (!u)
11
+ return '';
12
+ // Crawlers can only fetch http(s): a `data:` placeholder or a `javascript:` URL is never an image URL.
13
+ if (/^https?:\/\//.test(u))
14
+ return u;
15
+ if (/^[a-z][a-z0-9+.-]*:/i.test(u) || !origin)
16
+ return '';
17
+ try {
18
+ return new URL(u, origin).toString();
19
+ }
20
+ catch {
21
+ return '';
22
+ }
23
+ };
24
+ const plain = (html) => html
25
+ .replace(/<[^>]*>/g, ' ')
26
+ .replace(/\s+/g, ' ')
27
+ .trim();
28
+ /** A valid money value, or null: numeric, non-negative amount and an uppercase ISO-4217 code. */
29
+ function validMoney(m) {
30
+ const amount = text(m?.amount);
31
+ const currencyCode = text(m?.currencyCode);
32
+ if (!MONEY_AMOUNT.test(amount) || !CURRENCY.test(currencyCode))
33
+ return null;
34
+ return { amount, currencyCode };
35
+ }
36
+ const availabilityOf = (available) => available === true ? `${SCHEMA}/InStock` : available === false ? `${SCHEMA}/OutOfStock` : undefined;
37
+ /** At most this many per-variant offers are listed (a product with more keeps the price range alone). */
38
+ const MAX_OFFERS = 100;
39
+ /** The page URL with `?variant=<id>` (the theme's variant link), for a variant's own offer. */
40
+ const variantUrl = (url, id) => {
41
+ if (!id)
42
+ return url;
43
+ try {
44
+ const u = new URL(url);
45
+ u.searchParams.set('variant', id);
46
+ return u.toString();
47
+ }
48
+ catch {
49
+ return url;
50
+ }
51
+ };
52
+ function offersOf(product, url, seller) {
53
+ const variants = (product.variants ?? [])
54
+ .map((v) => ({ v, money: validMoney(v.price) }))
55
+ .filter((x) => x.money !== null);
56
+ const sellerOf = seller ? { seller: { '@type': 'Organization', name: seller } } : {};
57
+ const currency = variants[0]?.money.currencyCode;
58
+ // SEO-07: one Offer per variant, each with its own SKU, GTIN, price and availability (what the reference platform's themes print,
59
+ // and what Google Merchant listings and AI shopping read), when every variant prices in one currency.
60
+ if (variants.length > 1 && variants.length <= MAX_OFFERS && variants.every((x) => x.money.currencyCode === currency)) {
61
+ return variants.map(({ v, money }) => {
62
+ const sku = text(v.sku);
63
+ const barcode = text(v.barcode);
64
+ const availability = availabilityOf(v.availableForSale);
65
+ return {
66
+ '@type': 'Offer',
67
+ url: variantUrl(url, text(v.id)),
68
+ ...(text(v.title) ? { name: text(v.title) } : {}),
69
+ ...(sku ? { sku } : {}),
70
+ ...(GTIN.test(barcode) ? { gtin: barcode } : {}),
71
+ price: money.amount,
72
+ priceCurrency: money.currencyCode,
73
+ ...(availability ? { availability } : {}),
74
+ ...sellerOf,
75
+ };
76
+ });
77
+ }
78
+ if (variants.length > 1 && variants.every((x) => x.money.currencyCode === currency)) {
79
+ const amounts = variants.map((x) => Number(x.money.amount));
80
+ const lowIdx = amounts.indexOf(Math.min(...amounts));
81
+ const highIdx = amounts.indexOf(Math.max(...amounts));
82
+ if (amounts[lowIdx] !== amounts[highIdx]) {
83
+ return {
84
+ '@type': 'AggregateOffer',
85
+ url,
86
+ lowPrice: variants[lowIdx].money.amount,
87
+ highPrice: variants[highIdx].money.amount,
88
+ priceCurrency: currency,
89
+ offerCount: variants.length,
90
+ ...(variants.some((x) => x.v.availableForSale)
91
+ ? { availability: `${SCHEMA}/InStock` }
92
+ : { availability: `${SCHEMA}/OutOfStock` }),
93
+ };
94
+ }
95
+ }
96
+ const money = variants[0]?.money ?? validMoney(product.price);
97
+ if (!money)
98
+ return undefined;
99
+ const availability = availabilityOf(variants.length ? variants.some((x) => x.v.availableForSale) : product.availableForSale);
100
+ return {
101
+ '@type': 'Offer',
102
+ url,
103
+ price: money.amount,
104
+ priceCurrency: money.currencyCode,
105
+ ...(availability ? { availability } : {}),
106
+ ...sellerOf,
107
+ };
108
+ }
109
+ /** SEO-08: the published-review aggregate and the newest reviews, only when the store has them (never invented). */
110
+ function reviewsOf(product) {
111
+ const r = product.rating;
112
+ if (!r || !(typeof r.value === 'number' && r.value >= 1 && r.value <= 5) || !(Number.isInteger(r.count) && r.count >= 1))
113
+ return {};
114
+ const reviews = (product.reviews?.nodes ?? [])
115
+ .filter((x) => x && Number.isInteger(x.rating) && x.rating >= 1 && x.rating <= 5 && text(x.author) && text(x.body))
116
+ .slice(0, 10)
117
+ .map((x) => ({
118
+ '@type': 'Review',
119
+ reviewRating: { '@type': 'Rating', ratingValue: x.rating, bestRating: 5, worstRating: 1 },
120
+ author: { '@type': 'Person', name: text(x.author) },
121
+ ...(text(x.title) ? { name: text(x.title) } : {}),
122
+ reviewBody: plain(text(x.body)).slice(0, MAX_DESCRIPTION),
123
+ ...(text(x.createdAt) ? { datePublished: text(x.createdAt) } : {}),
124
+ }));
125
+ return {
126
+ aggregateRating: { '@type': 'AggregateRating', ratingValue: Math.round(r.value * 10) / 10, reviewCount: r.count, bestRating: 5, worstRating: 1 },
127
+ ...(reviews.length ? { review: reviews } : {}),
128
+ };
129
+ }
130
+ /**
131
+ * The Product JSON-LD for a product page, or null when there is no product (or no title). `ctx.url` is the page's
132
+ * own absolute URL and `ctx.origin` resolves relative image URLs; both come from the request on the server.
133
+ */
134
+ export function productJsonLd(product, ctx) {
135
+ if (!product)
136
+ return null;
137
+ const name = text(product.title);
138
+ if (!name)
139
+ return null;
140
+ const images = [
141
+ ...new Set([product.featuredImage?.url, ...(product.images ?? []).map((i) => i.url)]
142
+ .map((u) => absolute(u, ctx.origin))
143
+ .filter(Boolean)),
144
+ ].slice(0, MAX_IMAGES);
145
+ const description = (text(product.seo?.description) || plain(text(product.description))).slice(0, MAX_DESCRIPTION);
146
+ const vendor = text(product.vendor);
147
+ const offers = offersOf(product, ctx.url, text(ctx.shopName) || undefined);
148
+ const single = product.variants?.length === 1 ? product.variants[0] : undefined;
149
+ const sku = text(single?.sku);
150
+ const barcode = text(single?.barcode);
151
+ return {
152
+ '@context': SCHEMA,
153
+ '@type': 'Product',
154
+ name,
155
+ url: ctx.url,
156
+ ...(images.length ? { image: images } : {}),
157
+ ...(description ? { description } : {}),
158
+ ...(vendor ? { brand: { '@type': 'Brand', name: vendor } } : {}),
159
+ ...(sku ? { sku } : {}),
160
+ ...(GTIN.test(barcode) ? { gtin: barcode } : {}),
161
+ ...(product.productType && text(product.productType) ? { category: text(product.productType) } : {}),
162
+ ...(offers ? { offers } : {}),
163
+ ...reviewsOf(product),
164
+ };
165
+ }
166
+ /**
167
+ * SEO-01: the home page's Organization (Online Store) — name, URL, logo, social profiles (`sameAs`), contact and
168
+ * address — and the WebSite with its SearchAction (the site search box), as the reference platform's themes print on the index page.
169
+ * Answer engines read these to say who the store is and how to reach it. Only what the store published.
170
+ */
171
+ export function homeJsonLd(shop, ctx) {
172
+ const name = text(ctx.shopName) || text(shop?.name);
173
+ if (!name || !/^https?:\/\//.test(ctx.origin))
174
+ return [];
175
+ const url = `${ctx.origin}/`;
176
+ const logo = absolute(shop?.brand?.squareLogo?.url ?? shop?.brand?.logo?.url, ctx.origin);
177
+ const sameAs = [...new Set((shop?.socialLinks ?? []).map((l) => text(l?.url)).filter((u) => /^https:\/\//.test(u)))].slice(0, 16);
178
+ const email = text(shop?.email);
179
+ const phone = text(shop?.phone);
180
+ const a = shop?.address;
181
+ const address = a
182
+ ? Object.fromEntries(Object.entries({
183
+ streetAddress: [text(a.address1), text(a.address2)].filter(Boolean).join(', '),
184
+ addressLocality: text(a.city),
185
+ addressRegion: text(a.province),
186
+ postalCode: text(a.zip),
187
+ addressCountry: text(a.countryCode) || text(a.country),
188
+ }).filter(([, v]) => v))
189
+ : {};
190
+ const description = plain(text(shop?.description)).slice(0, MAX_DESCRIPTION);
191
+ const org = {
192
+ '@context': SCHEMA,
193
+ '@type': 'OnlineStore',
194
+ '@id': `${url}#organization`,
195
+ name,
196
+ url,
197
+ ...(description ? { description } : {}),
198
+ ...(logo ? { logo } : {}),
199
+ ...(sameAs.length ? { sameAs } : {}),
200
+ ...(email ? { email } : {}),
201
+ ...(phone ? { telephone: phone } : {}),
202
+ ...(Object.keys(address).length ? { address: { '@type': 'PostalAddress', ...address } } : {}),
203
+ ...(email || phone ? { contactPoint: { '@type': 'ContactPoint', contactType: 'customer service', ...(email ? { email } : {}), ...(phone ? { telephone: phone } : {}) } } : {}),
204
+ };
205
+ const site = {
206
+ '@context': SCHEMA,
207
+ '@type': 'WebSite',
208
+ '@id': `${url}#website`,
209
+ name,
210
+ url,
211
+ ...(text(ctx.language) ? { inLanguage: text(ctx.language) } : {}),
212
+ publisher: { '@id': `${url}#organization` },
213
+ potentialAction: { '@type': 'SearchAction', target: { '@type': 'EntryPoint', urlTemplate: `${ctx.origin}/search?q={search_term_string}` }, 'query-input': 'required name=search_term_string' },
214
+ };
215
+ return [org, site];
216
+ }
217
+ /** SEO-09: an article's BlogPosting — headline, dates, author, image, publisher — for search and answer engines. */
218
+ export function articleJsonLd(article, ctx) {
219
+ const headline = text(article?.title);
220
+ if (!article || !headline)
221
+ return null;
222
+ const image = absolute(article.image?.url, ctx.origin);
223
+ const description = (text(article.seo?.description) || plain(text(article.excerpt)) || plain(text(article.contentHtml))).slice(0, 300);
224
+ const published = text(article.publishedAt);
225
+ const author = text(article.author);
226
+ const tags = (article.tags ?? []).map(text).filter(Boolean).slice(0, 20);
227
+ const shopName = text(ctx.shopName);
228
+ return {
229
+ '@context': SCHEMA,
230
+ '@type': 'BlogPosting',
231
+ headline: headline.slice(0, 110),
232
+ url: ctx.url,
233
+ mainEntityOfPage: { '@type': 'WebPage', '@id': ctx.url },
234
+ ...(description ? { description } : {}),
235
+ ...(image ? { image: [image] } : {}),
236
+ ...(published && !Number.isNaN(Date.parse(published)) ? { datePublished: published } : {}),
237
+ ...(author ? { author: { '@type': 'Person', name: author } } : shopName ? { author: { '@type': 'Organization', name: shopName } } : {}),
238
+ ...(shopName ? { publisher: { '@type': 'Organization', name: shopName, url: `${ctx.origin}/` } } : {}),
239
+ ...(tags.length ? { keywords: tags.join(', ') } : {}),
240
+ ...(text(ctx.blogTitle) ? { isPartOf: { '@type': 'Blog', name: text(ctx.blogTitle) } } : {}),
241
+ };
242
+ }
243
+ const LINE_SEP = String.fromCharCode(0x2028);
244
+ const PARA_SEP = String.fromCharCode(0x2029);
245
+ /** Serialise for embedding in HTML: `<` and the JS line separators cannot end the script element or the string. */
246
+ export function serializeJsonLd(data) {
247
+ return JSON.stringify(data).replace(/</g, '\\u003c').split(LINE_SEP).join('\\u2028').split(PARA_SEP).join('\\u2029');
248
+ }
249
+ /** The `<script type="application/ld+json">` tag, or '' when there is nothing to say. */
250
+ export function jsonLdTag(data) {
251
+ return data ? `<script type="application/ld+json">${serializeJsonLd(data)}</script>` : '';
252
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The storefront shell: everything a page needs around the theme's sections.
3
+ *
4
+ * theme.Provider the theme's tokens, theme settings, strings (the theme's own component)
5
+ * StoreProvider route context + store data the sections' bindings read
6
+ * RuntimeBridge what the SDK hooks return (cart, overlays, actions, consent)
7
+ * theme.Layout the theme's page layout — sections and page-level overlays
8
+ *
9
+ * The section tree arrives as `children` (mount and the editor's preview bridge
10
+ * both render `<Shell><SectionTree/></Shell>`). With SPA navigation on, a soft
11
+ * navigation away from the landing URL renders the new template's tree instead.
12
+ */
13
+ import { type ReactNode } from 'react';
14
+ /** The locales the theme ships strings for (locales/<code>.json). */
15
+ export declare function themeLocales(): string[];
16
+ export default function PageShell({ children }: {
17
+ children: ReactNode;
18
+ }): JSX.Element;