@orunelle/theme-sdk 0.0.0-stage → 2.0.0-alpha.14

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.
@@ -0,0 +1,49 @@
1
+ import type { ImgHTMLAttributes } from "react";
2
+ /**
3
+ * Widths the platform serves for store images (`?w=`). Any other width is
4
+ * refused by the server, so srcset entries only ever use these.
5
+ */
6
+ export declare const STORE_IMAGE_WIDTHS: readonly [160, 320, 480, 640, 960, 1280, 1920];
7
+ export type StoreImageWidth = (typeof STORE_IMAGE_WIDTHS)[number];
8
+ /** Whether a URL is a store image the platform can resize. */
9
+ export declare function isStoreImage(url: string | null | undefined): url is string;
10
+ /**
11
+ * Attributes for an `<img>` showing a store image at the size it's displayed.
12
+ * `sizes` says how wide the image is on the page (e.g. "(max-width: 700px)
13
+ * 50vw, 25vw"); the browser then downloads the smallest copy that is sharp,
14
+ * as WebP when it supports it. Other URLs (theme assets, external images) are
15
+ * returned unchanged.
16
+ *
17
+ * ```tsx
18
+ * <img {...storeImage(product.image.url, "(max-width: 700px) 50vw, 25vw")} alt="" />
19
+ * ```
20
+ */
21
+ export declare function storeImage(url: string, sizes: string): {
22
+ src: string;
23
+ srcSet?: string;
24
+ sizes?: string;
25
+ };
26
+ /** A store image URL at one fixed width (for CSS backgrounds, previews, etc.). */
27
+ export declare function storeImageUrl(url: string, width: StoreImageWidth): string;
28
+ /**
29
+ * `<img>` for store images, sized for how it's displayed. Lazy-loads and
30
+ * decodes off the main thread unless `priority` is set (use it for the
31
+ * largest image above the fold).
32
+ */
33
+ export declare function StoreImage({ src, sizes, priority, alt, ...rest }: Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "srcSet" | "sizes"> & {
34
+ src: string;
35
+ sizes: string;
36
+ alt: string;
37
+ priority?: boolean;
38
+ }): import("react").JSX.Element;
39
+ /**
40
+ * The address of a file the theme ships in its `public/` folder.
41
+ *
42
+ * `path` may be written as `public/assets/x.webp`, `/assets/x.webp` or
43
+ * `assets/x.webp`. Full URLs (`https:`, `data:`, `blob:`, `//host/...`) are
44
+ * returned unchanged. `base` is where the theme's public files are served:
45
+ * `/` on the storefront, a per-session address in the editor preview. Inside
46
+ * components, prefer `useAssetUrl()`, which fills `base` in for you.
47
+ */
48
+ export declare function themeAssetUrl(path: string, base?: string): string;
49
+ //# sourceMappingURL=image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../src/image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,gDAAiD,CAAC;AACjF,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAIlE,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,IAAI,MAAM,CAE1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAOlD;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EACzB,GAAG,EACH,KAAK,EACL,QAAgB,EAChB,GAAG,EACH,GAAG,IAAI,EACR,EAAE,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,GAAG;IACzE,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,+BAWA;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,CAI9D"}
package/dist/image.js ADDED
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Widths the platform serves for store images (`?w=`). Any other width is
4
+ * refused by the server, so srcset entries only ever use these.
5
+ */
6
+ export const STORE_IMAGE_WIDTHS = [160, 320, 480, 640, 960, 1280, 1920];
7
+ const STORE_MEDIA = /\/api\/media\/serve\/[0-9a-f-]{36}\/[0-9a-f-]{36}$/i;
8
+ /** Whether a URL is a store image the platform can resize. */
9
+ export function isStoreImage(url) {
10
+ return !!url && STORE_MEDIA.test(url);
11
+ }
12
+ /**
13
+ * Attributes for an `<img>` showing a store image at the size it's displayed.
14
+ * `sizes` says how wide the image is on the page (e.g. "(max-width: 700px)
15
+ * 50vw, 25vw"); the browser then downloads the smallest copy that is sharp,
16
+ * as WebP when it supports it. Other URLs (theme assets, external images) are
17
+ * returned unchanged.
18
+ *
19
+ * ```tsx
20
+ * <img {...storeImage(product.image.url, "(max-width: 700px) 50vw, 25vw")} alt="" />
21
+ * ```
22
+ */
23
+ export function storeImage(url, sizes) {
24
+ if (!isStoreImage(url))
25
+ return { src: url };
26
+ return {
27
+ src: `${url}?w=960`,
28
+ srcSet: STORE_IMAGE_WIDTHS.map((w) => `${url}?w=${w} ${w}w`).join(", "),
29
+ sizes,
30
+ };
31
+ }
32
+ /** A store image URL at one fixed width (for CSS backgrounds, previews, etc.). */
33
+ export function storeImageUrl(url, width) {
34
+ return isStoreImage(url) ? `${url}?w=${width}` : url;
35
+ }
36
+ /**
37
+ * `<img>` for store images, sized for how it's displayed. Lazy-loads and
38
+ * decodes off the main thread unless `priority` is set (use it for the
39
+ * largest image above the fold).
40
+ */
41
+ export function StoreImage({ src, sizes, priority = false, alt, ...rest }) {
42
+ return (_jsx("img", { ...rest, ...storeImage(src, sizes), alt: alt, loading: priority ? "eager" : (rest.loading ?? "lazy"), decoding: rest.decoding ?? "async", fetchPriority: priority ? "high" : rest.fetchPriority }));
43
+ }
44
+ /**
45
+ * The address of a file the theme ships in its `public/` folder.
46
+ *
47
+ * `path` may be written as `public/assets/x.webp`, `/assets/x.webp` or
48
+ * `assets/x.webp`. Full URLs (`https:`, `data:`, `blob:`, `//host/...`) are
49
+ * returned unchanged. `base` is where the theme's public files are served:
50
+ * `/` on the storefront, a per-session address in the editor preview. Inside
51
+ * components, prefer `useAssetUrl()`, which fills `base` in for you.
52
+ */
53
+ export function themeAssetUrl(path, base = "/") {
54
+ if (/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(path))
55
+ return path;
56
+ const relative = path.replace(/^public\//, "").replace(/^\/+/, "");
57
+ return (base.endsWith("/") ? base : base + "/") + relative;
58
+ }
@@ -0,0 +1,237 @@
1
+ import { type ComponentType, type ReactNode } from "react";
2
+ import { type ProductFieldValue, type PublicProduct, type StorefrontContext, type ThemeManifest } from "@orunelle/theme-contract";
3
+ import type { Collection, Pagination, Variant } from "./commerce.js";
4
+ import { type ConfigurationTemplate, type ThemeConfiguration, type SettingValues } from "@orunelle/theme-contract";
5
+ export { ThemeComposition, ThemeSlot, EditableField, resolvePublicSettings, themeSettingVariables, ThemeSettingsStyle, useThemeSettings, localizedHref, } from "./composition.js";
6
+ export { referenceEditor, referenceDefaults } from "./reference.js";
7
+ export { useCommerce, useCustomerQuery, customerCacheKey } from "./session.js";
8
+ export * from "./product.js";
9
+ export { storeImage, storeImageUrl, isStoreImage, StoreImage, STORE_IMAGE_WIDTHS, themeAssetUrl, type StoreImageWidth, } from "./image.js";
10
+ import type { OptionVisuals } from "./product.js";
11
+ export type { MenuItem, MenuLink } from "@orunelle/theme-contract";
12
+ export type { Locale, LocalizedText, PublicProduct, StorefrontContext, ThemeManifest, } from "@orunelle/theme-contract";
13
+ export { catalogQueryKey, RUNTIME_ABI } from "@orunelle/theme-contract";
14
+ /** A collection prepared for theme sections. */
15
+ export interface ThemeCollection {
16
+ readonly id: string;
17
+ readonly slug: string;
18
+ readonly name: string;
19
+ readonly description: string;
20
+ /** Present only for collections a section asked to show products for. */
21
+ readonly products?: readonly PublicProduct[];
22
+ }
23
+ /** Hand-picked public records referenced by the page's theme settings. */
24
+ export interface ThemeResources {
25
+ readonly products: Readonly<Record<string, PublicProduct>>;
26
+ readonly collections: Readonly<Record<string, ThemeCollection>>;
27
+ }
28
+ export interface ThemeComponents {
29
+ Layout: ComponentType<{
30
+ children: ReactNode;
31
+ }>;
32
+ HomePage: ComponentType<{
33
+ products: readonly PublicProduct[];
34
+ resources?: ThemeResources;
35
+ }>;
36
+ ProductCard: ComponentType<{
37
+ product: PublicProduct;
38
+ }>;
39
+ ProductPage: ComponentType<{
40
+ product: PublicProduct;
41
+ variants?: readonly Variant[];
42
+ related?: readonly PublicProduct[];
43
+ optionVisuals?: OptionVisuals;
44
+ }>;
45
+ ProductActions: ComponentType<{
46
+ variants: readonly Variant[];
47
+ }>;
48
+ CatalogPage: ComponentType<{
49
+ data: Extract<RoutePageData, {
50
+ kind: "catalog";
51
+ }>;
52
+ }>;
53
+ CollectionsPage: ComponentType<{
54
+ data: Extract<RoutePageData, {
55
+ kind: "collections";
56
+ }>;
57
+ }>;
58
+ ContentPage: ComponentType<{
59
+ data: Extract<RoutePageData, {
60
+ kind: "content";
61
+ }>;
62
+ }>;
63
+ AccountPage: ComponentType<{
64
+ path: string;
65
+ }>;
66
+ CartPage: ComponentType<Record<string, never>>;
67
+ }
68
+ export type RoutePageData = {
69
+ kind: "catalog";
70
+ title: string;
71
+ products: readonly PublicProduct[];
72
+ pagination: Pagination;
73
+ resources?: ThemeResources;
74
+ } | {
75
+ kind: "collections";
76
+ title: string;
77
+ collections: readonly Collection[];
78
+ pagination: Pagination;
79
+ basePath?: "categories" | "collections";
80
+ } | {
81
+ kind: "product";
82
+ title: string;
83
+ product: PublicProduct;
84
+ variants: readonly Variant[];
85
+ /** Other published products from the same category. */
86
+ related?: readonly PublicProduct[];
87
+ optionVisuals?: OptionVisuals;
88
+ } | {
89
+ kind: "content";
90
+ title: string;
91
+ paragraphs: readonly string[];
92
+ };
93
+ export interface ThemeDefinition {
94
+ readonly manifest: ThemeManifest;
95
+ readonly components: Readonly<Partial<ThemeComponents>>;
96
+ readonly sections: Readonly<Record<string, ComponentType<ThemeNodeProps>>>;
97
+ readonly blocks: Readonly<Record<string, ComponentType<ThemeNodeProps>>>;
98
+ readonly slots: Readonly<Partial<Record<ThemeSlotName, ComponentType>>>;
99
+ readonly defaults?: ConfigurationTemplate;
100
+ }
101
+ export interface ThemeNodeProps {
102
+ id: string;
103
+ settings: SettingValues;
104
+ children: ReactNode;
105
+ }
106
+ export type ThemeSlotName = "header.after" | "footer.before" | "product.after";
107
+ export interface ResolvedTheme {
108
+ readonly manifest: ThemeManifest;
109
+ readonly components: Readonly<ThemeComponents>;
110
+ readonly sections: ThemeDefinition["sections"];
111
+ readonly blocks: ThemeDefinition["blocks"];
112
+ readonly slots: ThemeDefinition["slots"];
113
+ readonly defaults?: ConfigurationTemplate;
114
+ }
115
+ export declare function defineTheme(input: {
116
+ manifest: ThemeManifest;
117
+ components?: Partial<ThemeComponents>;
118
+ sections?: ThemeDefinition["sections"];
119
+ blocks?: ThemeDefinition["blocks"];
120
+ slots?: ThemeDefinition["slots"];
121
+ defaults?: ConfigurationTemplate;
122
+ }): ThemeDefinition;
123
+ /** Public loader data for a composition; preserves the existing commerce session. */
124
+ export declare function ThemePageData({ products, variants, resources, related, optionVisuals, children, }: {
125
+ products: readonly PublicProduct[];
126
+ variants?: readonly Variant[];
127
+ resources?: ThemeResources | undefined;
128
+ related?: readonly PublicProduct[] | undefined;
129
+ optionVisuals?: OptionVisuals | undefined;
130
+ children: ReactNode;
131
+ }): import("react").JSX.Element;
132
+ export declare function StorefrontProvider({ theme, storefront, children, configuration, products, media, resources, assetBase, }: {
133
+ theme: ResolvedTheme;
134
+ storefront: StorefrontContext;
135
+ children: ReactNode;
136
+ configuration?: ThemeConfiguration;
137
+ products?: readonly PublicProduct[];
138
+ media?: readonly {
139
+ id: string;
140
+ url: string;
141
+ alt: string;
142
+ }[];
143
+ resources?: ThemeResources | undefined;
144
+ /**
145
+ * Where the theme's `public/` files are served. `/` on the storefront; the
146
+ * editor preview passes its per-session asset address.
147
+ */
148
+ assetBase?: string;
149
+ }): import("react").JSX.Element;
150
+ export declare function useStorefront(): StorefrontContext;
151
+ export declare function useThemeComponents(): Readonly<ThemeComponents>;
152
+ export declare function useThemeManifest(): ThemeManifest;
153
+ export declare function useThemeRuntime(): {
154
+ theme: ResolvedTheme;
155
+ storefront: StorefrontContext;
156
+ configuration: ThemeConfiguration | undefined;
157
+ products: readonly PublicProduct[];
158
+ variants?: readonly Variant[];
159
+ resources?: ThemeResources | undefined;
160
+ related?: readonly PublicProduct[] | undefined;
161
+ optionVisuals?: OptionVisuals | undefined;
162
+ media: readonly {
163
+ id: string;
164
+ url: string;
165
+ alt: string;
166
+ }[];
167
+ assetBase: string;
168
+ };
169
+ /**
170
+ * Returns `assetUrl(path)` for files the theme ships in `public/`. It gives
171
+ * the right address on the live storefront and in the editor preview, where
172
+ * a root path like `/assets/x.webp` does not exist.
173
+ *
174
+ * ```tsx
175
+ * const assetUrl = useAssetUrl();
176
+ * <img src={assetUrl("public/assets/hero.webp")} alt="" />
177
+ * ```
178
+ */
179
+ export declare function useAssetUrl(): (path: string) => string;
180
+ /**
181
+ * Returns `t(key)` for merchant-editable storefront texts. Merchant overrides
182
+ * win, then the theme's declared default, then the platform default.
183
+ */
184
+ export declare function useStoreText(): (key: string) => string;
185
+ /**
186
+ * Products for a `resource` or `resourceList` setting, in the merchant's order.
187
+ * Unavailable picks (unpublished, deleted) are skipped. In the editor preview,
188
+ * picks are looked up in the preview catalog.
189
+ */
190
+ export declare function usePickedProducts(value: unknown): readonly PublicProduct[];
191
+ /** Collections for a `resource` or `resourceList` setting, in order. */
192
+ export declare function usePickedCollections(value: unknown): readonly ThemeCollection[];
193
+ export declare const MAX_PICKED_PRODUCTS = 50;
194
+ export declare const MAX_PICKED_COLLECTIONS = 20;
195
+ /**
196
+ * Lists the products and collections a page's configuration references, so a
197
+ * loader can fetch them in one pass. Single collection picks ask for products
198
+ * (a featured collection); collection lists need only names.
199
+ */
200
+ export declare function referencedResources(configuration: ThemeConfiguration | undefined, template: string): {
201
+ products: string[];
202
+ collections: string[];
203
+ collectionProducts: string[];
204
+ };
205
+ /** Identity is explicit; the future editor must never derive it from DOM position. */
206
+ export declare function Editable({ id, type, children, }: {
207
+ id: string;
208
+ type: string;
209
+ children: ReactNode;
210
+ }): import("react").JSX.Element;
211
+ /** Storefront events forwarded to sandboxed apps (page views are automatic). */
212
+ export type StorefrontEventName = "product_viewed" | "product_added_to_cart" | "cart_viewed";
213
+ /** The public product shape apps receive; nothing identifies the customer. */
214
+ export declare function eventProduct(product: PublicProduct, locale: "en" | "ar"): {
215
+ id: string;
216
+ handle: string;
217
+ name: string;
218
+ price: Readonly<{
219
+ amountMinor: number;
220
+ currency: string;
221
+ }>;
222
+ };
223
+ /**
224
+ * Announces a storefront event to installed apps. The platform's app sandbox
225
+ * forwards only allow-listed fields; without apps this is a no-op.
226
+ */
227
+ export declare function emitStorefrontEvent(name: StorefrontEventName, payload?: Record<string, unknown>): void;
228
+ /** Finds a public custom field on a product by its key. */
229
+ export declare function productField(product: PublicProduct, key: string): ProductFieldValue | undefined;
230
+ /**
231
+ * Formats a custom field value as text for the visitor's language. Links and
232
+ * colors return their raw value; themes usually render those specially.
233
+ */
234
+ export declare function formatFieldValue(field: ProductFieldValue, locale: "en" | "ar"): string;
235
+ export declare function formatPrice(product: PublicProduct, locale: "en" | "ar"): string;
236
+ export declare function formatMoney(amountMinor: number, currency: string, locale: "en" | "ar"): string;
237
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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,MAAM,mBAAmB,GAC3B,gBAAgB,GAChB,uBAAuB,GACvB,aAAa,CAAC;AAClB,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI;;;;;;;;EAOvE;AACD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACpC,IAAI,CAKN;AACD,2DAA2D;AAC3D,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,GAAG,EAAE,MAAM,GACV,iBAAiB,GAAG,SAAS,CAE/B;AACD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,IAAI,GAAG,IAAI,GAClB,MAAM,CAiCR;AACD,wBAAgB,WAAW,CACzB,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,IAAI,GAAG,IAAI,GAClB,MAAM,CAER;AACD,wBAAgB,WAAW,CACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,IAAI,GAAG,IAAI,GAClB,MAAM,CAUR"}
package/dist/index.js ADDED
@@ -0,0 +1,271 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, } from "react";
3
+ import { themeManifestSchema, } from "@orunelle/theme-contract";
4
+ import { resolveStoreText, validateConfiguration, validateConfigurationTemplate, } from "@orunelle/theme-contract";
5
+ export { ThemeComposition, ThemeSlot, EditableField, resolvePublicSettings, themeSettingVariables, ThemeSettingsStyle, useThemeSettings, localizedHref, } from "./composition.js";
6
+ import { ThemeSettingsStyle as SettingsStyle } from "./composition.js";
7
+ export { referenceEditor, referenceDefaults } from "./reference.js";
8
+ import { CommerceProvider } from "./session.js";
9
+ export { useCommerce, useCustomerQuery, customerCacheKey } from "./session.js";
10
+ export * from "./product.js";
11
+ export { storeImage, storeImageUrl, isStoreImage, StoreImage, STORE_IMAGE_WIDTHS, themeAssetUrl, } from "./image.js";
12
+ import { themeAssetUrl as assetUrlFor } from "./image.js";
13
+ export { catalogQueryKey, RUNTIME_ABI } from "@orunelle/theme-contract";
14
+ export function defineTheme(input) {
15
+ const parsed = themeManifestSchema.parse(input.manifest);
16
+ const freeze = (value) => {
17
+ if (typeof value !== "object" || value === null)
18
+ return;
19
+ for (const child of Object.values(value))
20
+ freeze(child);
21
+ Object.freeze(value);
22
+ };
23
+ freeze(parsed);
24
+ for (const kind of ["sections", "blocks"])
25
+ for (const key of Object.keys(input[kind] ?? {}))
26
+ if (parsed.editor?.nodeTypes[key]?.kind !==
27
+ (kind === "sections" ? "section" : "block"))
28
+ throw new Error(`Undeclared ${kind} registration: ${key}`);
29
+ if (Object.keys(input.slots ?? {}).some((name) => !["header.after", "footer.before", "product.after"].includes(name)))
30
+ throw new Error("Unknown theme slot");
31
+ const defaults = input.defaults ? structuredClone(input.defaults) : undefined;
32
+ if (defaults && validateConfigurationTemplate(parsed, defaults))
33
+ throw new Error("Invalid default theme configuration");
34
+ freeze(defaults);
35
+ return Object.freeze({
36
+ manifest: parsed,
37
+ components: Object.freeze({ ...input.components }),
38
+ sections: Object.freeze({ ...input.sections }),
39
+ blocks: Object.freeze({ ...input.blocks }),
40
+ slots: Object.freeze({ ...input.slots }),
41
+ ...(defaults ? { defaults } : {}),
42
+ });
43
+ }
44
+ const Context = createContext(null);
45
+ /** Public loader data for a composition; preserves the existing commerce session. */
46
+ export function ThemePageData({ products, variants = [], resources, related, optionVisuals, children, }) {
47
+ const runtime = useThemeRuntime();
48
+ return (_jsx(Context.Provider, { value: {
49
+ ...runtime,
50
+ products,
51
+ variants,
52
+ resources: resources ?? runtime.resources,
53
+ related: related ?? runtime.related,
54
+ optionVisuals: optionVisuals ?? runtime.optionVisuals,
55
+ }, children: children }));
56
+ }
57
+ // Configurations are immutable once loaded, so validate each object once
58
+ // instead of on every render of the provider.
59
+ const validated = new WeakMap();
60
+ function configurationProblem(manifest, configuration) {
61
+ let byConfiguration = validated.get(manifest);
62
+ if (!byConfiguration)
63
+ validated.set(manifest, (byConfiguration = new WeakMap()));
64
+ if (!byConfiguration.has(configuration))
65
+ byConfiguration.set(configuration, validateConfiguration(manifest, configuration));
66
+ return byConfiguration.get(configuration);
67
+ }
68
+ export function StorefrontProvider({ theme, storefront, children, configuration, products = [], media = [], resources, assetBase = "/", }) {
69
+ if (configuration && configurationProblem(theme.manifest, configuration))
70
+ throw new Error("Invalid merchant configuration");
71
+ return (_jsxs(Context.Provider, { value: {
72
+ theme,
73
+ storefront,
74
+ configuration,
75
+ products,
76
+ media,
77
+ resources,
78
+ assetBase,
79
+ }, children: [_jsx(SettingsStyle, {}), _jsx(CommerceProvider, { context: storefront, children: children }, storefront.store.id + storefront.origin)] }));
80
+ }
81
+ function useThemeContext() {
82
+ const value = useContext(Context);
83
+ if (!value)
84
+ throw new Error("Render theme components inside StorefrontProvider.");
85
+ return value;
86
+ }
87
+ export function useStorefront() {
88
+ return useThemeContext().storefront;
89
+ }
90
+ export function useThemeComponents() {
91
+ return useThemeContext().theme.components;
92
+ }
93
+ export function useThemeManifest() {
94
+ return useThemeContext().theme.manifest;
95
+ }
96
+ export function useThemeRuntime() {
97
+ return useThemeContext();
98
+ }
99
+ /**
100
+ * Returns `assetUrl(path)` for files the theme ships in `public/`. It gives
101
+ * the right address on the live storefront and in the editor preview, where
102
+ * a root path like `/assets/x.webp` does not exist.
103
+ *
104
+ * ```tsx
105
+ * const assetUrl = useAssetUrl();
106
+ * <img src={assetUrl("public/assets/hero.webp")} alt="" />
107
+ * ```
108
+ */
109
+ export function useAssetUrl() {
110
+ const { assetBase } = useThemeContext();
111
+ return (path) => assetUrlFor(path, assetBase);
112
+ }
113
+ /**
114
+ * Returns `t(key)` for merchant-editable storefront texts. Merchant overrides
115
+ * win, then the theme's declared default, then the platform default.
116
+ */
117
+ export function useStoreText() {
118
+ const { theme, configuration, storefront } = useThemeContext();
119
+ const source = configuration ?? theme.defaults;
120
+ return (key) => resolveStoreText(theme.manifest, source, key, storefront.locale);
121
+ }
122
+ const resourceRefs = (value, kind) => (Array.isArray(value) ? value : [value]).flatMap((item) => item &&
123
+ typeof item === "object" &&
124
+ "kind" in item &&
125
+ item.kind === kind &&
126
+ "id" in item &&
127
+ typeof item.id === "string"
128
+ ? [item.id]
129
+ : []);
130
+ /**
131
+ * Products for a `resource` or `resourceList` setting, in the merchant's order.
132
+ * Unavailable picks (unpublished, deleted) are skipped. In the editor preview,
133
+ * picks are looked up in the preview catalog.
134
+ */
135
+ export function usePickedProducts(value) {
136
+ const { resources, products } = useThemeContext();
137
+ return resourceRefs(value, "product").flatMap((id) => {
138
+ const product = resources?.products[id] ?? products.find((item) => item.id === id);
139
+ return product ? [product] : [];
140
+ });
141
+ }
142
+ /** Collections for a `resource` or `resourceList` setting, in order. */
143
+ export function usePickedCollections(value) {
144
+ const { resources } = useThemeContext();
145
+ return resourceRefs(value, "collection").flatMap((id) => {
146
+ const collection = resources?.collections[id];
147
+ return collection ? [collection] : [];
148
+ });
149
+ }
150
+ export const MAX_PICKED_PRODUCTS = 50;
151
+ export const MAX_PICKED_COLLECTIONS = 20;
152
+ /**
153
+ * Lists the products and collections a page's configuration references, so a
154
+ * loader can fetch them in one pass. Single collection picks ask for products
155
+ * (a featured collection); collection lists need only names.
156
+ */
157
+ export function referencedResources(configuration, template) {
158
+ const products = new Set(), collections = new Set(), collectionProducts = new Set();
159
+ if (!configuration)
160
+ return { products: [], collections: [], collectionProducts: [] };
161
+ const visit = (values) => {
162
+ for (const value of Object.values(values)) {
163
+ for (const id of resourceRefs(value, "product"))
164
+ products.add(id);
165
+ for (const id of resourceRefs(value, "collection")) {
166
+ collections.add(id);
167
+ if (!Array.isArray(value))
168
+ collectionProducts.add(id);
169
+ }
170
+ }
171
+ };
172
+ visit(configuration.settings);
173
+ const nodes = new Map(configuration.nodes.map((node) => [node.id, node]));
174
+ const walk = (id, depth) => {
175
+ const node = nodes.get(id);
176
+ if (!node || node.hidden || depth > 8)
177
+ return;
178
+ visit(node.settings);
179
+ for (const child of node.children)
180
+ walk(child, depth + 1);
181
+ };
182
+ const roots = [
183
+ ...(configuration.templates[template]?.roots ?? []),
184
+ ...Object.values(configuration.groups).flatMap((group) => group.roots),
185
+ ];
186
+ for (const root of roots)
187
+ walk(root, 1);
188
+ return {
189
+ products: [...products].slice(0, MAX_PICKED_PRODUCTS),
190
+ collections: [...collections].slice(0, MAX_PICKED_COLLECTIONS),
191
+ collectionProducts: [...collectionProducts].slice(0, 4),
192
+ };
193
+ }
194
+ /** Identity is explicit; the future editor must never derive it from DOM position. */
195
+ export function Editable({ id, type, children, }) {
196
+ return (_jsx("div", { "data-orunelle-node-id": id, "data-orunelle-node-type": type, children: children }));
197
+ }
198
+ /** The public product shape apps receive; nothing identifies the customer. */
199
+ export function eventProduct(product, locale) {
200
+ return {
201
+ id: product.id,
202
+ handle: product.handle,
203
+ name: product.name[locale],
204
+ price: product.price,
205
+ };
206
+ }
207
+ /**
208
+ * Announces a storefront event to installed apps. The platform's app sandbox
209
+ * forwards only allow-listed fields; without apps this is a no-op.
210
+ */
211
+ export function emitStorefrontEvent(name, payload = {}) {
212
+ if (typeof window === "undefined")
213
+ return;
214
+ window.dispatchEvent(new CustomEvent("orunelle:event", { detail: { name, payload } }));
215
+ }
216
+ /** Finds a public custom field on a product by its key. */
217
+ export function productField(product, key) {
218
+ return product.fields?.find((field) => field.key === key);
219
+ }
220
+ /**
221
+ * Formats a custom field value as text for the visitor's language. Links and
222
+ * colors return their raw value; themes usually render those specially.
223
+ */
224
+ export function formatFieldValue(field, locale) {
225
+ const { value } = field;
226
+ switch (field.kind) {
227
+ case "text":
228
+ case "multiline":
229
+ return value && typeof value === "object" && locale in value
230
+ ? String(value[locale] ?? "")
231
+ : "";
232
+ case "number":
233
+ return typeof value === "number"
234
+ ? new Intl.NumberFormat(locale).format(value)
235
+ : "";
236
+ case "boolean":
237
+ return value === true
238
+ ? locale === "ar"
239
+ ? "نعم"
240
+ : "Yes"
241
+ : locale === "ar"
242
+ ? "لا"
243
+ : "No";
244
+ case "date": {
245
+ if (typeof value !== "string")
246
+ return "";
247
+ const date = new Date(`${value}T00:00:00Z`);
248
+ return Number.isNaN(date.getTime())
249
+ ? ""
250
+ : new Intl.DateTimeFormat(locale, {
251
+ dateStyle: "medium",
252
+ timeZone: "UTC",
253
+ }).format(date);
254
+ }
255
+ default:
256
+ return typeof value === "string" ? value : "";
257
+ }
258
+ }
259
+ export function formatPrice(product, locale) {
260
+ return formatMoney(product.price.amountMinor, product.price.currency, locale);
261
+ }
262
+ export function formatMoney(amountMinor, currency, locale) {
263
+ const digits = new Intl.NumberFormat(locale, {
264
+ style: "currency",
265
+ currency,
266
+ }).resolvedOptions().maximumFractionDigits ?? 2;
267
+ return new Intl.NumberFormat(locale, {
268
+ style: "currency",
269
+ currency,
270
+ }).format(amountMinor / 10 ** digits);
271
+ }
@@ -0,0 +1,40 @@
1
+ import type { PublicProduct } from "@orunelle/theme-contract";
2
+ import type { Variant } from "./commerce.js";
3
+ /** How one option value looks: a color swatch or an image swatch. */
4
+ export interface OptionVisual {
5
+ color?: string;
6
+ image?: string;
7
+ }
8
+ /** Visuals by option name, then by value, from the store's option library. */
9
+ export type OptionVisuals = Readonly<Record<string, Readonly<Record<string, OptionVisual>>>>;
10
+ export interface OptionValue {
11
+ value: string;
12
+ /** Some active variant with this value is in stock. */
13
+ available: boolean;
14
+ visual?: OptionVisual;
15
+ }
16
+ export interface OptionGroup {
17
+ name: string;
18
+ kind: "color" | "image" | "text";
19
+ values: OptionValue[];
20
+ }
21
+ /** A variant's options, including legacy size/color columns. */
22
+ export declare function variantOptions(variant: Variant): Record<string, string>;
23
+ /** Groups the active variants' option values in first-seen order. */
24
+ export declare function optionGroups(variants: readonly Variant[], visuals?: OptionVisuals): OptionGroup[];
25
+ /** The active variant matching every selected option, if any. */
26
+ export declare function matchVariant(variants: readonly Variant[], selection: Readonly<Record<string, string>>): Variant | undefined;
27
+ /**
28
+ * The starting selection: the first in-stock variant, otherwise the first
29
+ * active one. Products without options select their only variant.
30
+ */
31
+ export declare function initialSelection(variants: readonly Variant[]): Record<string, string>;
32
+ /** Whether choosing `value` for `name` keeps a purchasable variant reachable. */
33
+ export declare function optionAvailable(variants: readonly Variant[], selection: Readonly<Record<string, string>>, name: string, value: string): boolean;
34
+ /** The price a variant sells for. */
35
+ export declare function variantPrice(product: PublicProduct, variant: Variant | undefined): PublicProduct["price"];
36
+ /** Images for the chosen variant first, then the rest. */
37
+ export declare function imagesForVariant(product: PublicProduct, variant: Variant | undefined): NonNullable<PublicProduct["images"]>;
38
+ /** Turns the store's option library into visuals; malformed entries are ignored. */
39
+ export declare function visualsFromOptionLibrary(value: unknown): OptionVisuals;
40
+ //# sourceMappingURL=product.d.ts.map