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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -10
  3. package/dist/abi/canvas-live.d.ts +49 -0
  4. package/dist/abi/canvas-live.js +88 -0
  5. package/dist/abi/cart.d.ts +48 -0
  6. package/dist/abi/cart.js +321 -0
  7. package/dist/abi/convert.d.ts +192 -0
  8. package/dist/abi/convert.js +670 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +198 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/page-data.d.ts +209 -0
  14. package/dist/abi/page-data.js +583 -0
  15. package/dist/abi/page.d.ts +23 -0
  16. package/dist/abi/page.js +46 -0
  17. package/dist/abi/referrals.d.ts +23 -0
  18. package/dist/abi/referrals.js +89 -0
  19. package/dist/abi/rewards.d.ts +27 -0
  20. package/dist/abi/rewards.js +82 -0
  21. package/dist/abi/seo.d.ts +47 -0
  22. package/dist/abi/seo.js +68 -0
  23. package/dist/abi/shell.d.ts +22 -0
  24. package/dist/abi/shell.js +10 -0
  25. package/dist/abi/wire.d.ts +38 -0
  26. package/dist/abi/wire.js +84 -0
  27. package/dist/build.d.ts +113 -0
  28. package/dist/build.js +294 -0
  29. package/dist/client.d.ts +19 -0
  30. package/dist/client.js +76 -0
  31. package/dist/contract.d.ts +6 -0
  32. package/dist/contract.js +6 -0
  33. package/dist/headless/ai.d.ts +132 -0
  34. package/dist/headless/ai.js +99 -0
  35. package/dist/headless/hooks.d.ts +273 -0
  36. package/dist/headless/hooks.js +533 -0
  37. package/dist/headless/i18n.d.ts +13 -0
  38. package/dist/headless/i18n.js +45 -0
  39. package/dist/headless/index.d.ts +36 -0
  40. package/dist/headless/index.js +38 -0
  41. package/dist/headless/money.d.ts +25 -0
  42. package/dist/headless/money.js +61 -0
  43. package/dist/headless/page.d.ts +43 -0
  44. package/dist/headless/page.js +53 -0
  45. package/dist/headless/platform.d.ts +55 -0
  46. package/dist/headless/platform.js +77 -0
  47. package/dist/headless/primitives/cart.d.ts +90 -0
  48. package/dist/headless/primitives/cart.js +153 -0
  49. package/dist/headless/primitives/collection.d.ts +68 -0
  50. package/dist/headless/primitives/collection.js +80 -0
  51. package/dist/headless/primitives/product.d.ts +101 -0
  52. package/dist/headless/primitives/product.js +117 -0
  53. package/dist/headless/primitives/storefront.d.ts +106 -0
  54. package/dist/headless/primitives/storefront.js +186 -0
  55. package/dist/headless/primitives/util.d.ts +19 -0
  56. package/dist/headless/primitives/util.js +42 -0
  57. package/dist/headless/strings.d.ts +9 -0
  58. package/dist/headless/strings.js +186 -0
  59. package/dist/headless/structured-data.d.ts +31 -0
  60. package/dist/headless/structured-data.js +57 -0
  61. package/dist/headless/theme.d.ts +99 -0
  62. package/dist/headless/theme.js +54 -0
  63. package/dist/index.d.ts +20 -0
  64. package/dist/index.js +18 -553
  65. package/dist/runtime/data/StoreProvider.d.ts +56 -0
  66. package/dist/runtime/data/StoreProvider.js +308 -0
  67. package/dist/runtime/data/handle.d.ts +14 -0
  68. package/dist/runtime/data/handle.js +16 -0
  69. package/dist/runtime/data/routes.d.ts +87 -0
  70. package/dist/runtime/data/routes.js +154 -0
  71. package/dist/runtime/data/to-ui.d.ts +258 -0
  72. package/dist/runtime/data/to-ui.js +820 -0
  73. package/dist/runtime/entries/register.d.ts +9 -0
  74. package/dist/runtime/entries/register.js +9 -0
  75. package/dist/runtime/entries/sections.d.ts +16 -0
  76. package/dist/runtime/entries/sections.js +19 -0
  77. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  78. package/dist/runtime/kit/SectionTree.js +100 -0
  79. package/dist/runtime/kit/analytics.d.ts +63 -0
  80. package/dist/runtime/kit/analytics.js +233 -0
  81. package/dist/runtime/kit/cart.d.ts +186 -0
  82. package/dist/runtime/kit/cart.js +545 -0
  83. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  84. package/dist/runtime/kit/composition.js +3 -0
  85. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  86. package/dist/runtime/kit/config.js +6 -0
  87. package/dist/runtime/kit/consent.d.ts +29 -0
  88. package/dist/runtime/kit/consent.js +159 -0
  89. package/dist/runtime/kit/contract/content.d.ts +164 -0
  90. package/dist/runtime/kit/contract/content.js +83 -0
  91. package/dist/runtime/kit/contract/field-types.d.ts +290 -0
  92. package/dist/runtime/kit/contract/field-types.js +129 -0
  93. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  94. package/dist/runtime/kit/contract/groups.js +402 -0
  95. package/dist/runtime/kit/contract/index.d.ts +33 -0
  96. package/dist/runtime/kit/contract/index.js +33 -0
  97. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  98. package/dist/runtime/kit/contract/transform.js +133 -0
  99. package/dist/runtime/kit/contract/validate.d.ts +67 -0
  100. package/dist/runtime/kit/contract/validate.js +388 -0
  101. package/dist/runtime/kit/data.d.ts +636 -0
  102. package/dist/runtime/kit/data.js +1117 -0
  103. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  104. package/dist/runtime/kit/defineSection.js +10 -0
  105. package/dist/{types → runtime/kit}/dynamic-source.d.ts +4 -4
  106. package/dist/runtime/kit/dynamic-source.js +143 -0
  107. package/dist/runtime/kit/index.d.ts +24 -0
  108. package/dist/runtime/kit/index.js +24 -0
  109. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  110. package/dist/runtime/kit/jsx-to-json.js +28 -0
  111. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  112. package/dist/runtime/kit/mount.js +124 -0
  113. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  114. package/dist/runtime/kit/registry.js +12 -0
  115. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  116. package/dist/runtime/kit/ssg.js +56 -0
  117. package/dist/runtime/kit/storefront.d.ts +566 -0
  118. package/dist/runtime/kit/storefront.js +723 -0
  119. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  120. package/dist/runtime/kit/theme-context.js +25 -0
  121. package/dist/runtime/kit/types.d.ts +142 -0
  122. package/dist/runtime/kit/types.js +1 -0
  123. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  124. package/dist/runtime/platform/TrackingPixels.js +63 -0
  125. package/dist/runtime/platform/environment.d.ts +68 -0
  126. package/dist/runtime/platform/environment.js +85 -0
  127. package/dist/runtime/platform/locale.d.ts +27 -0
  128. package/dist/runtime/platform/locale.js +42 -0
  129. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  130. package/dist/runtime/platform/route-analytics.js +72 -0
  131. package/dist/runtime/platform/safe-href.d.ts +25 -0
  132. package/dist/runtime/platform/safe-href.js +69 -0
  133. package/dist/runtime/platform/safe-values.d.ts +37 -0
  134. package/dist/runtime/platform/safe-values.js +140 -0
  135. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  136. package/dist/runtime/render/SectionRenderer.js +111 -0
  137. package/dist/runtime/render/listing-query.d.ts +47 -0
  138. package/dist/runtime/render/listing-query.js +114 -0
  139. package/dist/runtime/render/localized-copy.d.ts +86 -0
  140. package/dist/runtime/render/localized-copy.js +129 -0
  141. package/dist/runtime/render/product-listing.d.ts +11 -0
  142. package/dist/runtime/render/product-listing.js +240 -0
  143. package/dist/runtime/render/section-actions.d.ts +48 -0
  144. package/dist/runtime/render/section-actions.js +170 -0
  145. package/dist/runtime/render/starter.d.ts +11 -0
  146. package/dist/runtime/render/starter.js +81 -0
  147. package/dist/runtime/seo/head.d.ts +87 -0
  148. package/dist/runtime/seo/head.js +224 -0
  149. package/dist/runtime/seo/structured-data.d.ts +22 -0
  150. package/dist/runtime/seo/structured-data.js +115 -0
  151. package/dist/runtime/shell/PageShell.d.ts +18 -0
  152. package/dist/runtime/shell/PageShell.js +113 -0
  153. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  154. package/dist/runtime/shell/RuntimeBridge.js +85 -0
  155. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  156. package/dist/runtime/shell/overlay-state.js +59 -0
  157. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  158. package/dist/runtime/shell/preview-mode.js +11 -0
  159. package/dist/runtime/shell/spa-router.d.ts +14 -0
  160. package/dist/runtime/shell/spa-router.js +76 -0
  161. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  162. package/dist/runtime/shell/url-redirects.js +37 -0
  163. package/dist/runtime/slots.d.ts +74 -0
  164. package/dist/runtime/slots.js +16 -0
  165. package/dist/runtime.d.ts +34 -0
  166. package/dist/runtime.js +40 -0
  167. package/dist/sdk/index.d.ts +24 -0
  168. package/dist/sdk/index.js +24 -0
  169. package/dist/sdk/referrals.d.ts +62 -0
  170. package/dist/sdk/referrals.js +20 -0
  171. package/dist/sdk/rewards.d.ts +85 -0
  172. package/dist/sdk/rewards.js +29 -0
  173. package/dist/sdk/runtime-context.d.ts +135 -0
  174. package/dist/sdk/runtime-context.js +73 -0
  175. package/dist/sdk/schema.d.ts +197 -0
  176. package/dist/sdk/schema.js +121 -0
  177. package/dist/sdk/server-render.d.ts +8 -0
  178. package/dist/sdk/server-render.js +12 -0
  179. package/dist/sdk/store-lookup.d.ts +27 -0
  180. package/dist/sdk/store-lookup.js +29 -0
  181. package/dist/sdk/store.d.ts +115 -0
  182. package/dist/sdk/store.js +1 -0
  183. package/dist/sdk/sx.d.ts +40 -0
  184. package/dist/sdk/sx.js +112 -0
  185. package/dist/sdk/theme.d.ts +152 -0
  186. package/dist/sdk/theme.js +10 -0
  187. package/dist/sdk/types.d.ts +470 -0
  188. package/dist/sdk/types.js +7 -0
  189. package/dist/server.d.ts +65 -0
  190. package/dist/server.js +370 -0
  191. package/docs/headless-api.md +220 -0
  192. package/package.json +77 -23
  193. package/dist/index.js.map +0 -1
  194. package/dist/ssg-BZ5FYTw7.js +0 -1802
  195. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  196. package/dist/ssg.js +0 -8
  197. package/dist/ssg.js.map +0 -1
  198. package/dist/types/cart.d.ts +0 -86
  199. package/dist/types/data.d.ts +0 -357
  200. package/dist/types/editor.d.ts +0 -5
  201. package/dist/types/index.d.ts +0 -20
  202. package/dist/types/preview-bridge.d.ts +0 -9
  203. package/dist/types/storefront.d.ts +0 -333
  204. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Reading the store context: a saved handle → the object the runtime already
3
+ * put in the context (an image, a menu, a collection …). WHERE the data comes
4
+ * from is the runtime's job; these only look it up, the same way for every
5
+ * theme, including the platform rule that an unpublished or deleted handle is
6
+ * "unavailable", not missing. Nothing here fetches.
7
+ */
8
+ import type { StoreContext } from './store.js';
9
+ import type { Collection, Image, Link, Menu, Video, Product } from './types.js';
10
+ /** An image handle → the image, or null. */
11
+ export declare const imageFor: (store: StoreContext, handle: string | undefined) => Image | null;
12
+ /** A video handle → the video, or null. */
13
+ export declare const videoFor: (store: StoreContext, handle: string | undefined) => Video | null;
14
+ /** A menu handle → the menu, or null. */
15
+ export declare const menuFor: (store: StoreContext, handle: string | undefined) => Menu | null;
16
+ /** A collection handle → the collection; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
17
+ export declare function collectionFor(store: StoreContext, handle: string | undefined, fallback?: Collection): {
18
+ collection: Collection | null;
19
+ unavailable: boolean;
20
+ };
21
+ /** A product handle → the product; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
22
+ export declare function productFor(store: StoreContext, handle: string | undefined, fallback?: Product): {
23
+ product: Product | null;
24
+ unavailable: boolean;
25
+ };
26
+ /** Comma-separated collection handles (a multi-picker fallback) → links; typos and unavailable handles drop out. */
27
+ export declare function collectionLinksFor(store: StoreContext, handles: string): Link[];
@@ -0,0 +1,29 @@
1
+ /** An image handle → the image, or null. */
2
+ export const imageFor = (store, handle) => (handle ? (store.images?.[handle] ?? null) : null);
3
+ /** A video handle → the video, or null. */
4
+ export const videoFor = (store, handle) => (handle ? (store.videos?.[handle] ?? null) : null);
5
+ /** A menu handle → the menu, or null. */
6
+ export const menuFor = (store, handle) => (handle ? (store.menus[handle] ?? null) : null);
7
+ /** A collection handle → the collection; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
8
+ export function collectionFor(store, handle, fallback) {
9
+ if (handle && store.unavailableCollections?.includes(handle))
10
+ return { collection: null, unavailable: true };
11
+ return { collection: (handle ? store.collections?.[handle] : undefined) ?? fallback ?? null, unavailable: false };
12
+ }
13
+ /** A product handle → the product; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
14
+ export function productFor(store, handle, fallback) {
15
+ if (handle && store.unavailableProducts?.includes(handle))
16
+ return { product: null, unavailable: true };
17
+ return { product: (handle ? store.products?.[handle] : undefined) ?? fallback ?? null, unavailable: false };
18
+ }
19
+ /** Comma-separated collection handles (a multi-picker fallback) → links; typos and unavailable handles drop out. */
20
+ export function collectionLinksFor(store, handles) {
21
+ return handles
22
+ .split(',')
23
+ .map((h) => h.trim())
24
+ .filter(Boolean)
25
+ .flatMap((h) => {
26
+ const c = store.collections?.[h];
27
+ return c && !store.unavailableCollections?.includes(h) ? [{ title: c.title, url: c.url }] : [];
28
+ });
29
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The store context a section's data binding reads: the store's data, already
3
+ * shaped as the types in ./types. The theme runtime builds it; a theme never
4
+ * fetches.
5
+ */
6
+ import type { Article, Blog, Cart, CustomerAccount, Policy, ReviewsData, SearchResults, SortOption, StoreLocation, UgcPost, BreadcrumbItem, Collection, Product, CartSummary, Customer, Image, Localization, Menu, Shop, Video } from './types.js';
7
+ export interface SavedBlock {
8
+ type: string;
9
+ settings?: Record<string, unknown>;
10
+ }
11
+ export interface SavedSection {
12
+ type: string;
13
+ settings?: Record<string, unknown>;
14
+ blocks?: SavedBlock[];
15
+ }
16
+ export interface StoreContext {
17
+ shop: Shop;
18
+ menus: Record<string, Menu>;
19
+ images?: Record<string, Image>;
20
+ videos?: Record<string, Video>;
21
+ cart?: CartSummary;
22
+ customer?: Customer;
23
+ localization?: Localization | null;
24
+ /** Route context. */
25
+ breadcrumbs?: BreadcrumbItem[];
26
+ /** The page's first section is a hero with media (transparentOnHero). */
27
+ firstSectionIsHeroWithMedia?: boolean;
28
+ consentEnabled?: boolean;
29
+ brandColor?: string;
30
+ /** Collections by handle (collection pickers). */
31
+ collections?: Record<string, Collection>;
32
+ /** The route's collection on collection templates (collection-banner default). */
33
+ currentCollection?: Collection;
34
+ /** Handles that exist but are unpublished or deleted. */
35
+ unavailableCollections?: readonly string[];
36
+ /** The store's IANA time zone (promo-banner endsAt). */
37
+ timeZone?: string;
38
+ /** The store / server clock. */
39
+ clock?: () => number;
40
+ /** The shopper has not answered the cookie banner yet (the phone sticky bar waits). */
41
+ consentAnswered?: boolean;
42
+ /** Products by handle (product pickers). */
43
+ products?: Record<string, Product>;
44
+ /** The route's product on product templates. */
45
+ currentProduct?: Product;
46
+ /** The variant the product URL names (`?variant=`), as given; the section checks it belongs to the product. */
47
+ currentVariantId?: string;
48
+ /** Handles that exist but are unpublished or deleted. */
49
+ unavailableProducts?: readonly string[];
50
+ /** Pages by handle (size guide page). */
51
+ pages?: Record<string, {
52
+ title: string;
53
+ html: string;
54
+ }>;
55
+ /** Recommendations for the current product, by intent (platform). */
56
+ recommendations?: Partial<Record<'related' | 'complementary', Product[]>>;
57
+ /** This shopper's viewed products — null until the platform supports history + consent. */
58
+ recentlyViewed?: Product[] | null;
59
+ /** The store's newest collections (collection-list without blocks). */
60
+ newestCollections?: Collection[];
61
+ /** The page being rendered (page-body). */
62
+ currentPage?: {
63
+ title: string;
64
+ html: string;
65
+ };
66
+ /** The article being rendered and its blog (article-body). */
67
+ currentArticle?: Article & {
68
+ contentHtml?: string;
69
+ };
70
+ currentBlog?: {
71
+ title: string;
72
+ url: string;
73
+ };
74
+ /** The tag a blog page is filtered to (`/blogs/<blog>/tagged/<tag>`). */
75
+ currentTag?: string;
76
+ /** Blogs by handle (blog-posts). */
77
+ blogs?: Record<string, Blog>;
78
+ /** The current product's reviews from a reviews source — null until the platform has one (12F DATA REQUIREMENT). */
79
+ reviews?: ReviewsData | null;
80
+ /** A connected social feed for ugc-gallery source = feed — null until the platform has one. */
81
+ ugcFeed?: UgcPost[] | null;
82
+ /** 12G · the full cart for the cart page (the header only needs the summary above). */
83
+ currentCart?: Cart | null;
84
+ /** The checkout app — the only place Checkout goes. */
85
+ checkoutUrl?: string;
86
+ /** Why a cart permalink the store could not open sent the shopper to the cart page (`unavailable`, `failed`), else null. */
87
+ cartLink?: string | null;
88
+ searchQuery?: string;
89
+ searchResults?: SearchResults | null;
90
+ searchSortOptions?: SortOption[];
91
+ /** The search page's current sort id (`?sort=`); 'relevance' when none. */
92
+ searchSort?: string;
93
+ /** The signed-in customer's account (accounts app); null when signed out. */
94
+ account?: CustomerAccount | null;
95
+ /**
96
+ * The Account BFF URL to frame on the customer route (`/account*`): render
97
+ * `<iframe data-tq-slot="account" src={accountUrl} sandbox="allow-scripts allow-forms allow-same-origin">`
98
+ * (Theme ABI v2 §4, the account slot). Sign-in, orders and addresses render inside that frame; customer data
99
+ * never reaches the theme. Absent on every other route and where the host has no account area.
100
+ */
101
+ accountUrl?: string;
102
+ /** Store policies by handle, and the route's policy on policy templates. */
103
+ policies?: Record<string, Policy>;
104
+ currentPolicy?: Policy | null;
105
+ locations?: StoreLocation[];
106
+ /** Platform form endpoints, when they exist (12G DATA REQUIREMENT). */
107
+ newsletterEndpoint?: string;
108
+ contactEndpoint?: string;
109
+ /** The outcome of the platform form POST this page answers (ABI native forms). */
110
+ formResult?: {
111
+ formId: string;
112
+ status: 'ok' | 'invalid' | 'rate_limited' | 'unavailable' | 'expired';
113
+ email?: string;
114
+ };
115
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Dynamic style values without `style=""` attributes.
3
+ *
4
+ * The platform's CSP carries `style-src-attr 'none'` and no 'unsafe-inline' (Theme ABI v2 §5), and
5
+ * conformance fails a page whose DOM holds a style attribute at all. So a value a component computes
6
+ * (a column count, a scrim, an aspect ratio, the theme settings' CSS variables) becomes a CLASS:
7
+ *
8
+ * <ul className={cx('nv-list', sx({ '--nv-cols': columns }))}>
9
+ *
10
+ * - The class name is a hash of the declarations: the server and the hydrating browser compute the
11
+ * same name from the same values, so hydration matches.
12
+ * - Server: the entry opens a sink for exactly one synchronous `renderToString` (`collectStyles`) and
13
+ * emits its rules as ONE hashed `<style>`. Nothing outlives the render — no module cache, so no
14
+ * value of one store can reach another store's page.
15
+ * - Browser: a rule the server block does not already hold is inserted through CSSOM (a constructed
16
+ * stylesheet), which CSP does not govern.
17
+ *
18
+ * A declaration whose value could leave its rule (`<`, `{`, `}`, `;`, `\`, a newline) is dropped,
19
+ * never escaped into place.
20
+ */
21
+ import type { CSSProperties } from 'react';
22
+ /** id of the server-emitted `<style>` that carries the page's rules. */
23
+ export declare const STYLE_RULES_ID = "tq-style-rules";
24
+ export interface StyleSink {
25
+ add(className: string, declarations: string): void;
26
+ }
27
+ /** Declarations text of a style object (`prop:value;…`), unsafe values dropped. */
28
+ export declare function declarations(style: CSSProperties | Record<string, unknown>): string;
29
+ /**
30
+ * Run `render` (a synchronous `renderToString`) with a fresh sink and return its output plus the
31
+ * rules it used. The sink exists only for that call.
32
+ */
33
+ export declare function collectStyles<T>(render: () => T): {
34
+ result: T;
35
+ css: string;
36
+ };
37
+ /** `sx(style)` → a class name carrying those declarations (undefined for an empty style). */
38
+ export declare function sx(style: CSSProperties | Record<string, unknown> | null | undefined | false): string | undefined;
39
+ /** Join class names, skipping empty ones. */
40
+ export declare function cx(...names: Array<string | false | null | undefined>): string | undefined;
package/dist/sdk/sx.js ADDED
@@ -0,0 +1,112 @@
1
+ /** id of the server-emitted `<style>` that carries the page's rules. */
2
+ export const STYLE_RULES_ID = 'tq-style-rules';
3
+ const UNITLESS = new Set([
4
+ 'aspectRatio', 'flex', 'flexGrow', 'flexShrink', 'fontWeight', 'lineHeight', 'opacity', 'order', 'zIndex', 'zoom',
5
+ 'animationIterationCount', 'columnCount', 'gridColumn', 'gridRow', 'scale',
6
+ ]);
7
+ const UNSAFE = /[<>{};\\\n\r]/;
8
+ const hyphenate = (prop) => prop.startsWith('--') ? prop : prop.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).replace(/^ms-/, '-ms-');
9
+ /** Declarations text of a style object (`prop:value;…`), unsafe values dropped. */
10
+ export function declarations(style) {
11
+ const out = [];
12
+ for (const [prop, raw] of Object.entries(style)) {
13
+ if (raw === undefined || raw === null || raw === '' || typeof raw === 'boolean')
14
+ continue;
15
+ const value = typeof raw === 'number' && raw !== 0 && !prop.startsWith('--') && !UNITLESS.has(prop) ? `${raw}px` : String(raw);
16
+ if (UNSAFE.test(value) && !/^url\("[^"<>\\\n]*"\)$/.test(value))
17
+ continue;
18
+ out.push(`${hyphenate(prop)}:${value}`);
19
+ }
20
+ return out.join(';');
21
+ }
22
+ /** FNV-1a 32-bit, base36 — the same on the server and in the browser. */
23
+ function hash(text) {
24
+ let h = 0x811c9dc5;
25
+ for (let i = 0; i < text.length; i++) {
26
+ h ^= text.charCodeAt(i);
27
+ h = Math.imul(h, 0x01000193);
28
+ }
29
+ return (h >>> 0).toString(36);
30
+ }
31
+ // ── server: one sink per synchronous render ─────────────────────────────────
32
+ let serverSink = null;
33
+ /**
34
+ * Run `render` (a synchronous `renderToString`) with a fresh sink and return its output plus the
35
+ * rules it used. The sink exists only for that call.
36
+ */
37
+ export function collectStyles(render) {
38
+ const rules = new Map();
39
+ const prev = serverSink;
40
+ serverSink = { add: (c, d) => { if (!rules.has(c))
41
+ rules.set(c, d); } };
42
+ try {
43
+ const result = render();
44
+ return { result, css: [...rules].map(([c, d]) => `.${c}{${d}}`).join('') };
45
+ }
46
+ finally {
47
+ serverSink = prev;
48
+ }
49
+ }
50
+ // ── browser: CSSOM ──────────────────────────────────────────────────────────
51
+ let browserSink = null;
52
+ function constructedSheet() {
53
+ if (typeof CSSStyleSheet === 'function' && 'adoptedStyleSheets' in document) {
54
+ try {
55
+ const sheet = new CSSStyleSheet();
56
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
57
+ return sheet;
58
+ }
59
+ catch {
60
+ /* fall through */
61
+ }
62
+ }
63
+ // Environments without constructable stylesheets (jsdom in unit tests).
64
+ const el = document.createElement('style');
65
+ el.setAttribute('data-tq-rules', 'live');
66
+ document.head.appendChild(el);
67
+ return el.sheet;
68
+ }
69
+ function getBrowserSink() {
70
+ if (typeof document === 'undefined')
71
+ return null;
72
+ if (browserSink)
73
+ return browserSink;
74
+ const known = new Set();
75
+ const el = document.getElementById(STYLE_RULES_ID);
76
+ for (const m of (el?.textContent ?? '').matchAll(/\.(tqs-[a-z0-9]+)\{/g))
77
+ known.add(m[1]);
78
+ let sheet = null;
79
+ browserSink = {
80
+ add(className, decl) {
81
+ if (known.has(className))
82
+ return;
83
+ known.add(className);
84
+ sheet ??= constructedSheet();
85
+ if (!sheet)
86
+ return;
87
+ try {
88
+ sheet.insertRule(`.${className}{${decl}}`, sheet.cssRules.length);
89
+ }
90
+ catch {
91
+ /* a declaration the browser rejects is simply not applied */
92
+ }
93
+ },
94
+ };
95
+ return browserSink;
96
+ }
97
+ /** `sx(style)` → a class name carrying those declarations (undefined for an empty style). */
98
+ export function sx(style) {
99
+ if (!style)
100
+ return undefined;
101
+ const decl = declarations(style);
102
+ if (!decl)
103
+ return undefined;
104
+ const className = `tqs-${hash(decl)}`;
105
+ (serverSink ?? getBrowserSink())?.add(className, decl);
106
+ return className;
107
+ }
108
+ /** Join class names, skipping empty ones. */
109
+ export function cx(...names) {
110
+ const s = names.filter(Boolean).join(' ');
111
+ return s || undefined;
112
+ }
@@ -0,0 +1,152 @@
1
+ /**
2
+ * How a theme describes itself to the platform: its sections and its shell.
3
+ *
4
+ * export default defineTheme({ name, sections, Provider, Layout, labels })
5
+ *
6
+ * The theme compiler reads this to build the editor's catalog; the theme
7
+ * runtime reads it to render pages. Neither needs anything else from the theme.
8
+ */
9
+ import type { ComponentType, ReactNode } from 'react';
10
+ import type { Field, Schema } from './schema.js';
11
+ import type { SavedSection, StoreContext } from './store.js';
12
+ import type { ThemeActions, ThemeContextValue, ThemeMode } from './runtime-context.js';
13
+ export type SectionZone = 'header' | 'main' | 'footer';
14
+ export interface SectionPreset {
15
+ name: string;
16
+ label?: string;
17
+ settings: Record<string, unknown>;
18
+ blocks?: {
19
+ type: string;
20
+ settings?: Record<string, unknown>;
21
+ }[];
22
+ }
23
+ /** What a section's data binding receives besides the saved node and the store. */
24
+ export interface SectionBindingContext {
25
+ /** The platform actions (for callback props: add to cart, search …). */
26
+ actions: ThemeActions;
27
+ /** Page state (cart line status, mode, locale). */
28
+ context: ThemeContextValue;
29
+ /** The page this section is on. */
30
+ page: {
31
+ /** The first section of the page body (a header over a hero goes transparent). */
32
+ firstBodySection: SavedSection | null;
33
+ /** This section is that first body section. */
34
+ isFirstBodySection: boolean;
35
+ };
36
+ }
37
+ export interface ThemeSection<P = any> {
38
+ /** The persisted section type — never changes once stores have saved it. */
39
+ id: string;
40
+ /** Settings (persisted ids, controls, defaults, legacy values). */
41
+ schema: Schema;
42
+ /**
43
+ * The block schemas this section accepts — one per name in `schema.blocks`
44
+ * and `schema.legacyBlocks`. The section owns its block contracts: the
45
+ * compiler reads blocks from here, never from a separate registry.
46
+ */
47
+ blocks?: readonly Schema[];
48
+ component: ComponentType<P>;
49
+ /** Picker group. */
50
+ category: string;
51
+ /** Where the page places it: header zone, page body, footer zone. */
52
+ zone: SectionZone;
53
+ /** How the editor names it in "Add section". */
54
+ title?: string;
55
+ /** One line for the editor's picker: what it shows and when to use it. */
56
+ description?: string;
57
+ icon?: string;
58
+ /** Route context it needs (`product`, `collection`, `cart` …): offered only on templates that have it. */
59
+ requiresContext?: readonly string[];
60
+ /** Starting points "Add section" offers. */
61
+ presets?: readonly SectionPreset[];
62
+ /** Pages through a collection: the runtime adds paging (load more) to its props. */
63
+ listing?: boolean;
64
+ /**
65
+ * Saved node + store data → the component's props. Absent: the resolved
66
+ * settings are the props.
67
+ */
68
+ data?: (node: SavedSection, store: StoreContext, binding: SectionBindingContext) => P | null;
69
+ }
70
+ export interface ThemeProviderProps {
71
+ mode: ThemeMode;
72
+ locale: string;
73
+ /** The language the page's content is in (the request's), when the host knows it; `lang` follows it. */
74
+ contentLanguage?: string;
75
+ settings: Readonly<Record<string, unknown>>;
76
+ children: ReactNode;
77
+ }
78
+ export interface ThemeDefinition {
79
+ name: string;
80
+ /** Every section, in the editor picker's order. */
81
+ sections: readonly ThemeSection[];
82
+ /** Wraps every page and the editor's single-section preview: tokens, theme settings, strings. */
83
+ Provider: ComponentType<ThemeProviderProps>;
84
+ /** The page layout around the page's sections — and where page-level overlays render. */
85
+ Layout: ComponentType<{
86
+ children: ReactNode;
87
+ }>;
88
+ /** Interface words the runtime needs for the breadcrumb trail, in a locale. */
89
+ labels(locale: string): {
90
+ home: string;
91
+ collections?: string;
92
+ search?: string;
93
+ cart?: string;
94
+ account?: string;
95
+ };
96
+ /** External stylesheets every page loads in <head> (web fonts). */
97
+ stylesheets?: readonly string[];
98
+ /**
99
+ * Starter text: words that only tell the merchant what to write ("Describe
100
+ * your returns window.", "Customer name"). The editor shows them as they are;
101
+ * on the live storefront a section whose own settings still hold one is not
102
+ * rendered, and a block that holds one is left out — a shopper never reads an
103
+ * instruction, or a review nobody wrote. Exact strings, compared trimmed.
104
+ */
105
+ starterText?: readonly string[];
106
+ /**
107
+ * Shipped copy: the English words this theme ships in setting defaults,
108
+ * starter templates and presets, as `<prefix>*` keys of its English locale
109
+ * map. A copy field whose value is exactly one of them (unset → its default)
110
+ * renders as that key in the page's locale; any other value is the
111
+ * merchant's and renders verbatim (runtime/render/localized-copy.ts).
112
+ */
113
+ shippedCopy?: {
114
+ english: Readonly<Record<string, string>>;
115
+ prefix: string;
116
+ /** Fields whose renderer tests the value against the shipped English: never localized (`block:footer-brand.title`). */
117
+ keep?: readonly string[];
118
+ /** Fields whose unset value is derived from data: their default is never filled in (`block:footer-menu.heading`). */
119
+ derivedWhenUnset?: readonly string[];
120
+ };
121
+ /**
122
+ * The settings every section shares (width, spacing, background …), with the
123
+ * editor group of each — published so a custom section can fold them in.
124
+ */
125
+ sharedSettings?: {
126
+ fields: Readonly<Record<string, Field>>;
127
+ groups?: Readonly<Record<string, string>>;
128
+ contentSlots?: readonly string[];
129
+ };
130
+ }
131
+ /** One theme setting (config/settings.schema.ts): the control the editor's Theme panel shows. */
132
+ export interface SettingSpec {
133
+ type: 'text' | 'textarea' | 'richtext' | 'url' | 'color' | 'image' | 'select' | 'radio' | 'boolean' | 'range' | 'number' | 'menu';
134
+ label?: string;
135
+ /** Theme panel group. */
136
+ group?: string;
137
+ info?: string;
138
+ default?: unknown;
139
+ options?: {
140
+ value: string;
141
+ label: string;
142
+ }[];
143
+ min?: number;
144
+ max?: number;
145
+ step?: number;
146
+ unit?: string;
147
+ placeholder?: string;
148
+ }
149
+ /** Declare the theme's settings (the Theme panel). */
150
+ export declare function defineSettings<T extends Record<string, SettingSpec>>(settings: T): T;
151
+ export declare function defineTheme(theme: ThemeDefinition): ThemeDefinition;
152
+ export declare function defineSection<P>(section: ThemeSection<P>): ThemeSection<P>;
@@ -0,0 +1,10 @@
1
+ /** Declare the theme's settings (the Theme panel). */
2
+ export function defineSettings(settings) {
3
+ return settings;
4
+ }
5
+ export function defineTheme(theme) {
6
+ return theme;
7
+ }
8
+ export function defineSection(section) {
9
+ return section;
10
+ }