@numueg/theme-sdk 0.1.2 → 0.2.1
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.
- package/dist/{index-CGx6FNqb.d.ts → entities-iiuRSPpk.d.mts} +1 -3
- package/dist/{index-zSb0FIyh.d.mts → entities-iiuRSPpk.d.ts} +1 -3
- package/dist/index.cjs +775 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +493 -38
- package/dist/index.d.ts +493 -38
- package/dist/index.mjs +759 -47
- package/dist/index.mjs.map +1 -1
- package/dist/normalize.d.mts +1 -1
- package/dist/normalize.d.ts +1 -1
- package/dist/theme-D0QybTQS.d.mts +197 -0
- package/dist/theme-D0QybTQS.d.ts +197 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/v2-compat.cjs +248 -0
- package/dist/v2-compat.cjs.map +1 -0
- package/dist/v2-compat.d.mts +129 -0
- package/dist/v2-compat.d.ts +129 -0
- package/dist/v2-compat.mjs +242 -0
- package/dist/v2-compat.mjs.map +1 -0
- package/package.json +12 -1
- package/dist/theme-NWJAU9jd.d.mts +0 -128
- package/dist/theme-NWJAU9jd.d.ts +0 -128
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { createContext,
|
|
1
|
+
import { createContext, forwardRef, useState, useImperativeHandle, useEffect, useCallback, useMemo, useRef, useContext, StrictMode, createElement, Component } from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
2
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
4
|
|
|
4
|
-
// src/
|
|
5
|
+
// src/types/theme.ts
|
|
6
|
+
var MAX_BLOCK_DEPTH = 5;
|
|
5
7
|
var ShopContext = createContext(null);
|
|
6
8
|
var ProductContext = createContext(null);
|
|
7
9
|
var CollectionContext = createContext(null);
|
|
@@ -10,6 +12,10 @@ var CustomerContext = createContext(null);
|
|
|
10
12
|
var ThemeSettingsContext = createContext(null);
|
|
11
13
|
var LocalizationContext = createContext(null);
|
|
12
14
|
var PageContext = createContext(null);
|
|
15
|
+
var CurrentTemplateContext = createContext("home");
|
|
16
|
+
var NavigationContext = createContext(
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
13
19
|
function useLocalization() {
|
|
14
20
|
const ctx = useContext(LocalizationContext);
|
|
15
21
|
if (!ctx) throw new Error("useLocalization must be used within NuMuProvider");
|
|
@@ -118,6 +124,9 @@ function useThemeSettings() {
|
|
|
118
124
|
if (!ctx) throw new Error("useThemeSettings must be used within NuMuProvider");
|
|
119
125
|
return ctx;
|
|
120
126
|
}
|
|
127
|
+
function useCurrentTemplate() {
|
|
128
|
+
return useContext(CurrentTemplateContext);
|
|
129
|
+
}
|
|
121
130
|
function usePage() {
|
|
122
131
|
return useContext(PageContext);
|
|
123
132
|
}
|
|
@@ -487,15 +496,67 @@ function useCustomerAddresses() {
|
|
|
487
496
|
};
|
|
488
497
|
}
|
|
489
498
|
var cache = /* @__PURE__ */ new Map();
|
|
499
|
+
function localizeLabel(label, locale) {
|
|
500
|
+
if (!label) return "";
|
|
501
|
+
return label[locale] || label.en || label.ar || Object.values(label).find((v) => !!v) || "";
|
|
502
|
+
}
|
|
503
|
+
function mapResourceType(type) {
|
|
504
|
+
switch (type) {
|
|
505
|
+
case "product":
|
|
506
|
+
return "product";
|
|
507
|
+
case "collection":
|
|
508
|
+
return "collection";
|
|
509
|
+
case "page":
|
|
510
|
+
return "page";
|
|
511
|
+
case "blog":
|
|
512
|
+
return "blog";
|
|
513
|
+
case "article":
|
|
514
|
+
return "article";
|
|
515
|
+
case "http":
|
|
516
|
+
case "url":
|
|
517
|
+
return "url";
|
|
518
|
+
default:
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function toNavigationItem(raw, locale) {
|
|
523
|
+
return {
|
|
524
|
+
id: raw.id,
|
|
525
|
+
title: localizeLabel(raw.label, locale),
|
|
526
|
+
url: raw.url || "/",
|
|
527
|
+
resource_type: mapResourceType(raw.type),
|
|
528
|
+
resource_handle: raw.resource_id ?? null,
|
|
529
|
+
children: (raw.children ?? []).map(
|
|
530
|
+
(child) => toNavigationItem(child, locale)
|
|
531
|
+
)
|
|
532
|
+
};
|
|
533
|
+
}
|
|
490
534
|
function useNavigation(handle, options) {
|
|
535
|
+
const navMap = useContext(NavigationContext);
|
|
536
|
+
const localization = useContext(LocalizationContext);
|
|
537
|
+
const locale = localization?.locale ?? "en";
|
|
538
|
+
const hostProvidedAny = !!navMap && Object.keys(navMap).length > 0;
|
|
539
|
+
const rawItems = handle ? navMap?.[handle] : void 0;
|
|
540
|
+
const hostItems = useMemo(() => {
|
|
541
|
+
if (rawItems) return rawItems.map((it) => toNavigationItem(it, locale));
|
|
542
|
+
if (hostProvidedAny) return [];
|
|
543
|
+
return null;
|
|
544
|
+
}, [rawItems, hostProvidedAny, locale]);
|
|
491
545
|
const [items, setItems] = useState(
|
|
492
|
-
options?.initialItems ?? cache.get(handle) ?? []
|
|
546
|
+
hostItems ?? options?.initialItems ?? cache.get(handle) ?? []
|
|
493
547
|
);
|
|
494
548
|
const [loading, setLoading] = useState(
|
|
495
|
-
!options?.initialItems && !cache.has(handle)
|
|
549
|
+
hostItems === null && !options?.initialItems && !cache.has(handle)
|
|
496
550
|
);
|
|
497
551
|
const [error, setError] = useState(null);
|
|
498
552
|
useEffect(() => {
|
|
553
|
+
if (hostItems === null) return;
|
|
554
|
+
setItems(hostItems);
|
|
555
|
+
setLoading(false);
|
|
556
|
+
setError(null);
|
|
557
|
+
}, [hostItems]);
|
|
558
|
+
useEffect(() => {
|
|
559
|
+
if (hostItems !== null) return;
|
|
499
560
|
if (typeof window === "undefined") return;
|
|
500
561
|
if (!handle) {
|
|
501
562
|
setItems([]);
|
|
@@ -538,7 +599,7 @@ function useNavigation(handle, options) {
|
|
|
538
599
|
return () => {
|
|
539
600
|
cancelled = true;
|
|
540
601
|
};
|
|
541
|
-
}, [handle]);
|
|
602
|
+
}, [handle, hostItems === null]);
|
|
542
603
|
return { items, loading, error };
|
|
543
604
|
}
|
|
544
605
|
var EMPTY = {
|
|
@@ -612,34 +673,92 @@ function useSearch(query, options = {}) {
|
|
|
612
673
|
}, [query, mode, debounceMs, immediate, limit, types?.join(",")]);
|
|
613
674
|
return { query, results, loading, error };
|
|
614
675
|
}
|
|
676
|
+
var EVENT_TO_FUNNEL_STEP = {
|
|
677
|
+
page_view: "page_view",
|
|
678
|
+
view_item: "product_view",
|
|
679
|
+
view_collection: "page_view",
|
|
680
|
+
add_to_cart: "add_to_cart",
|
|
681
|
+
begin_checkout: "checkout_started",
|
|
682
|
+
purchase: "order_completed",
|
|
683
|
+
// Wave 2+ standard Meta events — backend's FUNNEL_STEP_TO_META_EVENT
|
|
684
|
+
// table accepts these as funnel steps directly.
|
|
685
|
+
search: "search",
|
|
686
|
+
lead: "lead",
|
|
687
|
+
sign_up: "complete_registration",
|
|
688
|
+
add_to_wishlist: "add_to_wishlist",
|
|
689
|
+
add_payment_info: "add_payment_info"
|
|
690
|
+
};
|
|
691
|
+
function readAttribution() {
|
|
692
|
+
if (typeof window === "undefined") return null;
|
|
693
|
+
try {
|
|
694
|
+
return window.__numu_attribution?.get?.() ?? null;
|
|
695
|
+
} catch {
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
function readCustomerId() {
|
|
700
|
+
if (typeof window === "undefined") return null;
|
|
701
|
+
try {
|
|
702
|
+
return window.__numu_customer?.getId?.() ?? null;
|
|
703
|
+
} catch {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
function getFingerprint() {
|
|
708
|
+
if (typeof window === "undefined") return "ssr";
|
|
709
|
+
const env = readAttribution();
|
|
710
|
+
if (env?.session_id) return env.session_id;
|
|
711
|
+
const w = window;
|
|
712
|
+
if (w.__numu_session_fp) return w.__numu_session_fp;
|
|
713
|
+
const fp = crypto.randomUUID();
|
|
714
|
+
w.__numu_session_fp = fp;
|
|
715
|
+
return fp;
|
|
716
|
+
}
|
|
717
|
+
function dispatchAnalyticsEvent(eventName, payload = {}) {
|
|
718
|
+
if (typeof window === "undefined") return;
|
|
719
|
+
try {
|
|
720
|
+
window.dispatchEvent(
|
|
721
|
+
new CustomEvent("numu:analytics:event", {
|
|
722
|
+
detail: { event: eventName, payload, ts: Date.now() }
|
|
723
|
+
})
|
|
724
|
+
);
|
|
725
|
+
} catch {
|
|
726
|
+
}
|
|
727
|
+
const step = EVENT_TO_FUNNEL_STEP[eventName] ?? null;
|
|
728
|
+
const customerId = readCustomerId();
|
|
729
|
+
const body = step ? {
|
|
730
|
+
event_id: crypto.randomUUID(),
|
|
731
|
+
path: window.location.pathname,
|
|
732
|
+
fingerprint: getFingerprint(),
|
|
733
|
+
step,
|
|
734
|
+
step_data: payload,
|
|
735
|
+
referrer: typeof document !== "undefined" && document.referrer ? document.referrer : void 0,
|
|
736
|
+
attribution: readAttribution() ?? void 0,
|
|
737
|
+
customer_id: customerId ?? void 0
|
|
738
|
+
} : {
|
|
739
|
+
event: eventName,
|
|
740
|
+
payload,
|
|
741
|
+
ts: Date.now(),
|
|
742
|
+
attribution: readAttribution() ?? void 0,
|
|
743
|
+
customer_id: customerId ?? void 0
|
|
744
|
+
};
|
|
745
|
+
void (async () => {
|
|
746
|
+
try {
|
|
747
|
+
await fetch("/api/storefront/track", {
|
|
748
|
+
method: "POST",
|
|
749
|
+
headers: { "Content-Type": "application/json" },
|
|
750
|
+
body: JSON.stringify(body),
|
|
751
|
+
keepalive: true
|
|
752
|
+
// survive page-unload (e.g. begin_checkout → redirect)
|
|
753
|
+
});
|
|
754
|
+
} catch {
|
|
755
|
+
}
|
|
756
|
+
})();
|
|
757
|
+
}
|
|
615
758
|
function useAnalytics() {
|
|
616
759
|
const track = useCallback(
|
|
617
760
|
(eventName, payload = {}) => {
|
|
618
|
-
|
|
619
|
-
try {
|
|
620
|
-
window.dispatchEvent(
|
|
621
|
-
new CustomEvent("numu:analytics:event", {
|
|
622
|
-
detail: { event: eventName, payload, ts: Date.now() }
|
|
623
|
-
})
|
|
624
|
-
);
|
|
625
|
-
} catch {
|
|
626
|
-
}
|
|
627
|
-
void (async () => {
|
|
628
|
-
try {
|
|
629
|
-
await fetch("/api/storefront/track", {
|
|
630
|
-
method: "POST",
|
|
631
|
-
headers: { "Content-Type": "application/json" },
|
|
632
|
-
body: JSON.stringify({
|
|
633
|
-
event: eventName,
|
|
634
|
-
payload,
|
|
635
|
-
ts: Date.now()
|
|
636
|
-
}),
|
|
637
|
-
keepalive: true
|
|
638
|
-
// survive page-unload (e.g. begin_checkout → redirect)
|
|
639
|
-
});
|
|
640
|
-
} catch {
|
|
641
|
-
}
|
|
642
|
-
})();
|
|
761
|
+
dispatchAnalyticsEvent(eventName, payload);
|
|
643
762
|
},
|
|
644
763
|
[]
|
|
645
764
|
);
|
|
@@ -1326,6 +1445,16 @@ var EMPTY_CART = {
|
|
|
1326
1445
|
total: 0,
|
|
1327
1446
|
currency: "EGP"
|
|
1328
1447
|
};
|
|
1448
|
+
function normalizeCartFromServer(cart) {
|
|
1449
|
+
const toMajor = (n) => typeof n === "number" ? n / 100 : 0;
|
|
1450
|
+
return {
|
|
1451
|
+
...cart,
|
|
1452
|
+
subtotal: toMajor(cart.subtotal),
|
|
1453
|
+
total: toMajor(cart.total),
|
|
1454
|
+
...cart.discount_amount != null ? { discount_amount: toMajor(cart.discount_amount) } : {},
|
|
1455
|
+
items: Array.isArray(cart.items) ? cart.items.map((it) => ({ ...it, price: toMajor(it.price) })) : []
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1329
1458
|
function readCsrfCookie() {
|
|
1330
1459
|
if (typeof document === "undefined") return null;
|
|
1331
1460
|
const match = document.cookie.match(/(?:^|;\s*)numu_csrf=([^;]+)/);
|
|
@@ -1355,8 +1484,23 @@ function NuMuProvider({
|
|
|
1355
1484
|
customer,
|
|
1356
1485
|
locale: initialLocale,
|
|
1357
1486
|
translations: initialTranslations,
|
|
1487
|
+
currentTemplate = "home",
|
|
1488
|
+
initialProducts,
|
|
1489
|
+
initialCollections,
|
|
1490
|
+
navigation,
|
|
1358
1491
|
children
|
|
1359
1492
|
}) {
|
|
1493
|
+
const pageValue = useMemo(
|
|
1494
|
+
() => ({
|
|
1495
|
+
type: currentTemplate,
|
|
1496
|
+
title: store?.name ?? "",
|
|
1497
|
+
data: {
|
|
1498
|
+
products: initialProducts ?? [],
|
|
1499
|
+
collections: initialCollections ?? []
|
|
1500
|
+
}
|
|
1501
|
+
}),
|
|
1502
|
+
[currentTemplate, store?.name, initialProducts, initialCollections]
|
|
1503
|
+
);
|
|
1360
1504
|
const [cart, setCart] = useState(
|
|
1361
1505
|
initialCart || { ...EMPTY_CART, currency: store.currency }
|
|
1362
1506
|
);
|
|
@@ -1513,7 +1657,7 @@ function NuMuProvider({
|
|
|
1513
1657
|
if (!res.ok || cancelled) return;
|
|
1514
1658
|
const data = await res.json();
|
|
1515
1659
|
if (data && typeof data === "object") {
|
|
1516
|
-
setCart(data);
|
|
1660
|
+
setCart(normalizeCartFromServer(data));
|
|
1517
1661
|
}
|
|
1518
1662
|
} catch {
|
|
1519
1663
|
}
|
|
@@ -1534,7 +1678,7 @@ function NuMuProvider({
|
|
|
1534
1678
|
return;
|
|
1535
1679
|
}
|
|
1536
1680
|
latestApplied.current = token;
|
|
1537
|
-
setCart(newCart);
|
|
1681
|
+
setCart(normalizeCartFromServer(newCart));
|
|
1538
1682
|
},
|
|
1539
1683
|
[]
|
|
1540
1684
|
);
|
|
@@ -1726,11 +1870,238 @@ function NuMuProvider({
|
|
|
1726
1870
|
defaultNumberFmt
|
|
1727
1871
|
]
|
|
1728
1872
|
);
|
|
1729
|
-
return /* @__PURE__ */ jsx(ShopContext.Provider, { value: store, children: /* @__PURE__ */ jsx(ThemeSettingsContext.Provider, { value: themeSettings, children: /* @__PURE__ */ jsx(LocalizationContext.Provider, { value: localization, children: /* @__PURE__ */ jsx(CartContext.Provider, { value: cartValue, children: /* @__PURE__ */ jsx(CustomerContext.Provider, { value: customerState, children: /* @__PURE__ */ jsx(CustomerActionsContext.Provider, { value: customerActions, children }) }) }) }) }) });
|
|
1873
|
+
return /* @__PURE__ */ jsx(ShopContext.Provider, { value: store, children: /* @__PURE__ */ jsx(ThemeSettingsContext.Provider, { value: themeSettings, children: /* @__PURE__ */ jsx(CurrentTemplateContext.Provider, { value: currentTemplate, children: /* @__PURE__ */ jsx(PageContext.Provider, { value: pageValue, children: /* @__PURE__ */ jsx(LocalizationContext.Provider, { value: localization, children: /* @__PURE__ */ jsx(CartContext.Provider, { value: cartValue, children: /* @__PURE__ */ jsx(CustomerContext.Provider, { value: customerState, children: /* @__PURE__ */ jsx(CustomerActionsContext.Provider, { value: customerActions, children: /* @__PURE__ */ jsx(NavigationContext.Provider, { value: navigation ?? {}, children }) }) }) }) }) }) }) }) });
|
|
1730
1874
|
}
|
|
1731
1875
|
function ProductProvider({ product, children }) {
|
|
1732
1876
|
return /* @__PURE__ */ jsx(ProductContext.Provider, { value: product, children });
|
|
1733
1877
|
}
|
|
1878
|
+
|
|
1879
|
+
// src/utils/styleTokens.ts
|
|
1880
|
+
var COLOR_ROLE_ALIASES = {
|
|
1881
|
+
background_color: "background",
|
|
1882
|
+
color_background: "background",
|
|
1883
|
+
bg_color: "background",
|
|
1884
|
+
text_color: "text",
|
|
1885
|
+
color_text: "text",
|
|
1886
|
+
primary_color: "primary",
|
|
1887
|
+
color_primary: "primary",
|
|
1888
|
+
secondary_color: "secondary",
|
|
1889
|
+
color_secondary: "secondary",
|
|
1890
|
+
accent_color: "accent",
|
|
1891
|
+
color_accent: "accent",
|
|
1892
|
+
border_color: "border",
|
|
1893
|
+
color_border: "border",
|
|
1894
|
+
button_color: "button",
|
|
1895
|
+
color_button: "button",
|
|
1896
|
+
button_text_color: "button-text",
|
|
1897
|
+
color_button_text: "button-text"
|
|
1898
|
+
};
|
|
1899
|
+
var FONT_ROLE_ALIASES = {
|
|
1900
|
+
heading_font: "heading",
|
|
1901
|
+
font_heading: "heading",
|
|
1902
|
+
headings_font: "heading",
|
|
1903
|
+
body_font: "body",
|
|
1904
|
+
font_body: "body",
|
|
1905
|
+
text_font: "body"
|
|
1906
|
+
};
|
|
1907
|
+
var FONT_REGISTRY = {
|
|
1908
|
+
cormorant: {
|
|
1909
|
+
stack: '"Cormorant Garamond", Georgia, "Times New Roman", serif',
|
|
1910
|
+
href: "https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap"
|
|
1911
|
+
},
|
|
1912
|
+
"dm-sans": {
|
|
1913
|
+
stack: '"DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif',
|
|
1914
|
+
href: "https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,700&display=swap"
|
|
1915
|
+
},
|
|
1916
|
+
playfair: {
|
|
1917
|
+
stack: '"Playfair Display", Georgia, serif',
|
|
1918
|
+
href: "https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700&display=swap"
|
|
1919
|
+
},
|
|
1920
|
+
inter: {
|
|
1921
|
+
stack: '"Inter", system-ui, -apple-system, sans-serif',
|
|
1922
|
+
href: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
|
|
1923
|
+
},
|
|
1924
|
+
poppins: {
|
|
1925
|
+
stack: '"Poppins", system-ui, sans-serif',
|
|
1926
|
+
href: "https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap"
|
|
1927
|
+
},
|
|
1928
|
+
montserrat: {
|
|
1929
|
+
stack: '"Montserrat", system-ui, sans-serif',
|
|
1930
|
+
href: "https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap"
|
|
1931
|
+
},
|
|
1932
|
+
lora: {
|
|
1933
|
+
stack: '"Lora", Georgia, serif',
|
|
1934
|
+
href: "https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;1,400&display=swap"
|
|
1935
|
+
},
|
|
1936
|
+
cairo: {
|
|
1937
|
+
stack: '"Cairo", system-ui, sans-serif',
|
|
1938
|
+
href: "https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap"
|
|
1939
|
+
},
|
|
1940
|
+
tajawal: {
|
|
1941
|
+
stack: '"Tajawal", system-ui, sans-serif',
|
|
1942
|
+
href: "https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap"
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
var COLOR_RE = /^(#([0-9a-f]{3,8})|rgba?\(|hsla?\(|color\(|var\()/i;
|
|
1946
|
+
function isColorValue(v) {
|
|
1947
|
+
return typeof v === "string" && COLOR_RE.test(v.trim());
|
|
1948
|
+
}
|
|
1949
|
+
function isFontToken(v) {
|
|
1950
|
+
return typeof v === "string" && Object.prototype.hasOwnProperty.call(FONT_REGISTRY, v);
|
|
1951
|
+
}
|
|
1952
|
+
function injectFontLink(href) {
|
|
1953
|
+
if (typeof document === "undefined" || !href) return;
|
|
1954
|
+
const existing = document.querySelector(
|
|
1955
|
+
`link[data-numu-font][href="${href}"]`
|
|
1956
|
+
);
|
|
1957
|
+
if (existing) return;
|
|
1958
|
+
const link = document.createElement("link");
|
|
1959
|
+
link.rel = "stylesheet";
|
|
1960
|
+
link.href = href;
|
|
1961
|
+
link.setAttribute("data-numu-font", "");
|
|
1962
|
+
document.head.appendChild(link);
|
|
1963
|
+
}
|
|
1964
|
+
function resolveFontStack(value) {
|
|
1965
|
+
const entry = FONT_REGISTRY[value];
|
|
1966
|
+
if (entry) {
|
|
1967
|
+
if (entry.href) injectFontLink(entry.href);
|
|
1968
|
+
return entry.stack;
|
|
1969
|
+
}
|
|
1970
|
+
return value;
|
|
1971
|
+
}
|
|
1972
|
+
function applyGlobalStyleTokens(globalSettings, el) {
|
|
1973
|
+
if (!el || !globalSettings || typeof globalSettings !== "object") return;
|
|
1974
|
+
const style = el.style;
|
|
1975
|
+
for (const [key, value] of Object.entries(globalSettings)) {
|
|
1976
|
+
if (!key || key.startsWith("__")) continue;
|
|
1977
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1978
|
+
for (const [role, c] of Object.entries(value)) {
|
|
1979
|
+
if (isColorValue(c)) style.setProperty(`--scheme-${key}-${role}`, c);
|
|
1980
|
+
}
|
|
1981
|
+
continue;
|
|
1982
|
+
}
|
|
1983
|
+
if (isColorValue(value)) {
|
|
1984
|
+
style.setProperty(`--theme-${key}`, value.trim());
|
|
1985
|
+
const role = COLOR_ROLE_ALIASES[key];
|
|
1986
|
+
if (role) style.setProperty(`--theme-color-${role}`, value.trim());
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
if (isFontToken(value)) {
|
|
1990
|
+
const stack = resolveFontStack(value);
|
|
1991
|
+
style.setProperty(`--theme-${key}`, stack);
|
|
1992
|
+
const role = FONT_ROLE_ALIASES[key];
|
|
1993
|
+
if (role) style.setProperty(`--theme-font-${role}`, stack);
|
|
1994
|
+
continue;
|
|
1995
|
+
}
|
|
1996
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
1997
|
+
const v = String(value).trim();
|
|
1998
|
+
if (v) style.setProperty(`--theme-${key}`, v);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
function pickStore(ctx) {
|
|
2003
|
+
const s = ctx.storeData ?? ctx.store;
|
|
2004
|
+
if (s) return s;
|
|
2005
|
+
return {
|
|
2006
|
+
id: "unknown",
|
|
2007
|
+
name: "Store",
|
|
2008
|
+
slug: "store",
|
|
2009
|
+
currency: "EGP",
|
|
2010
|
+
default_language: "en",
|
|
2011
|
+
use_nextjs_storefront: true
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
function pickTemplate(ctx) {
|
|
2015
|
+
if (typeof ctx.currentTemplate === "string" && ctx.currentTemplate) {
|
|
2016
|
+
return ctx.currentTemplate;
|
|
2017
|
+
}
|
|
2018
|
+
const pageType = ctx.page?.type;
|
|
2019
|
+
if (typeof pageType === "string" && pageType) return pageType;
|
|
2020
|
+
return "home";
|
|
2021
|
+
}
|
|
2022
|
+
function pickDemo(ctx, themeSettings) {
|
|
2023
|
+
if (typeof ctx.demo === "boolean") return ctx.demo;
|
|
2024
|
+
const t = themeSettings.templates;
|
|
2025
|
+
return !t || Object.keys(t).length === 0;
|
|
2026
|
+
}
|
|
2027
|
+
var ThemeMountBridge = forwardRef(function ThemeMountBridge2({ ctx, mountEl, renderApp }, ref) {
|
|
2028
|
+
const [themeSettings, setThemeSettings] = useState(
|
|
2029
|
+
ctx.themeSettings
|
|
2030
|
+
);
|
|
2031
|
+
useImperativeHandle(
|
|
2032
|
+
ref,
|
|
2033
|
+
() => ({
|
|
2034
|
+
applyDraft: (next) => setThemeSettings((prev) => prev === next ? prev : next)
|
|
2035
|
+
}),
|
|
2036
|
+
[]
|
|
2037
|
+
);
|
|
2038
|
+
useEffect(() => {
|
|
2039
|
+
const gs = themeSettings.global_settings ?? {};
|
|
2040
|
+
applyGlobalStyleTokens(gs, mountEl);
|
|
2041
|
+
const headingFont = gs.heading_font;
|
|
2042
|
+
if (typeof headingFont === "string" && headingFont.trim()) {
|
|
2043
|
+
mountEl.style.setProperty(
|
|
2044
|
+
"--theme-heading_font",
|
|
2045
|
+
resolveFontStack(headingFont)
|
|
2046
|
+
);
|
|
2047
|
+
}
|
|
2048
|
+
const bodyFont = gs.body_font;
|
|
2049
|
+
if (typeof bodyFont === "string" && bodyFont.trim()) {
|
|
2050
|
+
mountEl.style.setProperty("--theme-body_font", resolveFontStack(bodyFont));
|
|
2051
|
+
}
|
|
2052
|
+
}, [themeSettings, mountEl]);
|
|
2053
|
+
const store = pickStore(ctx);
|
|
2054
|
+
const template = pickTemplate(ctx);
|
|
2055
|
+
const demo = pickDemo(ctx, themeSettings);
|
|
2056
|
+
const pageData = ctx.page?.data ?? {};
|
|
2057
|
+
const app = renderApp({
|
|
2058
|
+
currentTemplate: template,
|
|
2059
|
+
demo,
|
|
2060
|
+
page: ctx.page ?? null,
|
|
2061
|
+
store,
|
|
2062
|
+
themeSettings
|
|
2063
|
+
});
|
|
2064
|
+
return /* @__PURE__ */ jsx(
|
|
2065
|
+
NuMuProvider,
|
|
2066
|
+
{
|
|
2067
|
+
store,
|
|
2068
|
+
themeSettings,
|
|
2069
|
+
initialCart: ctx.initialCart,
|
|
2070
|
+
customer: ctx.customer,
|
|
2071
|
+
locale: ctx.locale,
|
|
2072
|
+
translations: ctx.translations,
|
|
2073
|
+
navigation: ctx.navigation,
|
|
2074
|
+
initialProducts: pageData.products,
|
|
2075
|
+
initialCollections: pageData.collections,
|
|
2076
|
+
currentTemplate: template,
|
|
2077
|
+
children: pageData.product ? /* @__PURE__ */ jsx(ProductProvider, { product: pageData.product, children: app }) : app
|
|
2078
|
+
}
|
|
2079
|
+
);
|
|
2080
|
+
});
|
|
2081
|
+
function mountTheme(el, ctx, renderApp) {
|
|
2082
|
+
const root = createRoot(el);
|
|
2083
|
+
const handleRef = { current: null };
|
|
2084
|
+
root.render(
|
|
2085
|
+
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(
|
|
2086
|
+
ThemeMountBridge,
|
|
2087
|
+
{
|
|
2088
|
+
ctx,
|
|
2089
|
+
mountEl: el,
|
|
2090
|
+
renderApp,
|
|
2091
|
+
ref: (h) => {
|
|
2092
|
+
handleRef.current = h;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
) })
|
|
2096
|
+
);
|
|
2097
|
+
return {
|
|
2098
|
+
applyDraft: (next) => handleRef.current?.applyDraft(next),
|
|
2099
|
+
cleanup: () => {
|
|
2100
|
+
root.unmount();
|
|
2101
|
+
handleRef.current = null;
|
|
2102
|
+
}
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
1734
2105
|
function CollectionProvider({ collection, children }) {
|
|
1735
2106
|
return /* @__PURE__ */ jsx(CollectionContext.Provider, { value: collection, children });
|
|
1736
2107
|
}
|
|
@@ -2373,6 +2744,239 @@ function LocaleSwitcher({
|
|
|
2373
2744
|
}
|
|
2374
2745
|
);
|
|
2375
2746
|
}
|
|
2747
|
+
function useIsEditor() {
|
|
2748
|
+
const [isEditor, setIsEditor] = useState(false);
|
|
2749
|
+
useEffect(() => {
|
|
2750
|
+
if (typeof window === "undefined") return;
|
|
2751
|
+
try {
|
|
2752
|
+
const params = new URLSearchParams(window.location.search);
|
|
2753
|
+
const flag = params.get("editor") === "v3" || params.get("preview") === "true";
|
|
2754
|
+
const inFrame = window.parent !== window;
|
|
2755
|
+
setIsEditor(flag && inFrame);
|
|
2756
|
+
} catch {
|
|
2757
|
+
}
|
|
2758
|
+
}, []);
|
|
2759
|
+
return isEditor;
|
|
2760
|
+
}
|
|
2761
|
+
function postFieldSelected(sectionId, settingId, blockId) {
|
|
2762
|
+
if (typeof window === "undefined") return;
|
|
2763
|
+
if (window.parent === window) return;
|
|
2764
|
+
try {
|
|
2765
|
+
window.parent.postMessage(
|
|
2766
|
+
{
|
|
2767
|
+
type: "numu:editor:select-field",
|
|
2768
|
+
payload: {
|
|
2769
|
+
sectionId,
|
|
2770
|
+
blockId: blockId ?? null,
|
|
2771
|
+
settingId
|
|
2772
|
+
}
|
|
2773
|
+
},
|
|
2774
|
+
"*"
|
|
2775
|
+
);
|
|
2776
|
+
} catch {
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
var EditableText = forwardRef(
|
|
2780
|
+
function EditableText2({
|
|
2781
|
+
sectionId,
|
|
2782
|
+
blockId,
|
|
2783
|
+
settingId,
|
|
2784
|
+
value,
|
|
2785
|
+
as: Component2 = "span",
|
|
2786
|
+
html = false,
|
|
2787
|
+
placeholder,
|
|
2788
|
+
className,
|
|
2789
|
+
onClick,
|
|
2790
|
+
style,
|
|
2791
|
+
...rest
|
|
2792
|
+
}, ref) {
|
|
2793
|
+
const isEditor = useIsEditor();
|
|
2794
|
+
const handleClick = useCallback(
|
|
2795
|
+
(e) => {
|
|
2796
|
+
onClick?.(e);
|
|
2797
|
+
if (!isEditor) return;
|
|
2798
|
+
e.stopPropagation();
|
|
2799
|
+
postFieldSelected(sectionId, settingId, blockId);
|
|
2800
|
+
},
|
|
2801
|
+
[isEditor, onClick, sectionId, settingId, blockId]
|
|
2802
|
+
);
|
|
2803
|
+
const editorAttrs = useMemo(
|
|
2804
|
+
() => isEditor ? {
|
|
2805
|
+
"data-numu-editable": "text",
|
|
2806
|
+
"data-numu-section-id": sectionId,
|
|
2807
|
+
"data-numu-setting-id": settingId,
|
|
2808
|
+
"data-numu-block-id": blockId ?? void 0,
|
|
2809
|
+
role: "button",
|
|
2810
|
+
tabIndex: 0
|
|
2811
|
+
} : {},
|
|
2812
|
+
[isEditor, sectionId, settingId, blockId]
|
|
2813
|
+
);
|
|
2814
|
+
const effectiveStyle = isEditor ? {
|
|
2815
|
+
...style,
|
|
2816
|
+
cursor: "text",
|
|
2817
|
+
// Subtle dotted underline so the merchant discovers what's
|
|
2818
|
+
// editable. The dashed style + inherited color keeps the
|
|
2819
|
+
// affordance from clashing with the theme's typography.
|
|
2820
|
+
textDecoration: "underline dotted rgba(99, 102, 241, 0.7)",
|
|
2821
|
+
textUnderlineOffset: "4px"
|
|
2822
|
+
} : style;
|
|
2823
|
+
const isEmpty = value == null || value === "";
|
|
2824
|
+
const display = isEmpty && placeholder !== void 0 ? placeholder : value ?? "";
|
|
2825
|
+
if (html && typeof display === "string") {
|
|
2826
|
+
return /* @__PURE__ */ jsx(
|
|
2827
|
+
Component2,
|
|
2828
|
+
{
|
|
2829
|
+
ref,
|
|
2830
|
+
className,
|
|
2831
|
+
style: effectiveStyle,
|
|
2832
|
+
onClick: handleClick,
|
|
2833
|
+
dangerouslySetInnerHTML: { __html: display },
|
|
2834
|
+
...editorAttrs,
|
|
2835
|
+
...rest
|
|
2836
|
+
}
|
|
2837
|
+
);
|
|
2838
|
+
}
|
|
2839
|
+
return /* @__PURE__ */ jsx(
|
|
2840
|
+
Component2,
|
|
2841
|
+
{
|
|
2842
|
+
ref,
|
|
2843
|
+
className,
|
|
2844
|
+
style: effectiveStyle,
|
|
2845
|
+
onClick: handleClick,
|
|
2846
|
+
...editorAttrs,
|
|
2847
|
+
...rest,
|
|
2848
|
+
children: display
|
|
2849
|
+
}
|
|
2850
|
+
);
|
|
2851
|
+
}
|
|
2852
|
+
);
|
|
2853
|
+
var EMPTY_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
|
|
2854
|
+
var EditableImage = forwardRef(
|
|
2855
|
+
function EditableImage2({
|
|
2856
|
+
sectionId,
|
|
2857
|
+
blockId,
|
|
2858
|
+
settingId,
|
|
2859
|
+
src,
|
|
2860
|
+
alt,
|
|
2861
|
+
emptyPlaceholderSrc,
|
|
2862
|
+
className,
|
|
2863
|
+
onClick,
|
|
2864
|
+
style,
|
|
2865
|
+
...rest
|
|
2866
|
+
}, ref) {
|
|
2867
|
+
const isEditor = useIsEditor();
|
|
2868
|
+
const isEmpty = !src;
|
|
2869
|
+
const handleClick = useCallback(
|
|
2870
|
+
(e) => {
|
|
2871
|
+
onClick?.(e);
|
|
2872
|
+
if (!isEditor) return;
|
|
2873
|
+
e.stopPropagation();
|
|
2874
|
+
postFieldSelected(sectionId, settingId, blockId);
|
|
2875
|
+
},
|
|
2876
|
+
[isEditor, onClick, sectionId, settingId, blockId]
|
|
2877
|
+
);
|
|
2878
|
+
const editorAttrs = useMemo(
|
|
2879
|
+
() => isEditor ? {
|
|
2880
|
+
"data-numu-editable": "image",
|
|
2881
|
+
"data-numu-section-id": sectionId,
|
|
2882
|
+
"data-numu-setting-id": settingId,
|
|
2883
|
+
"data-numu-block-id": blockId ?? void 0,
|
|
2884
|
+
role: "button",
|
|
2885
|
+
tabIndex: 0
|
|
2886
|
+
} : {},
|
|
2887
|
+
[isEditor, sectionId, settingId, blockId]
|
|
2888
|
+
);
|
|
2889
|
+
const effectiveStyle = isEditor ? {
|
|
2890
|
+
...style,
|
|
2891
|
+
cursor: "pointer",
|
|
2892
|
+
outline: isEmpty ? "2px dashed rgba(99, 102, 241, 0.6)" : "2px dashed transparent",
|
|
2893
|
+
outlineOffset: "-2px"
|
|
2894
|
+
} : style;
|
|
2895
|
+
const effectiveSrc = src || emptyPlaceholderSrc || EMPTY_GIF;
|
|
2896
|
+
const effectiveAlt = alt ?? "";
|
|
2897
|
+
return /* @__PURE__ */ jsx(
|
|
2898
|
+
"img",
|
|
2899
|
+
{
|
|
2900
|
+
ref,
|
|
2901
|
+
src: effectiveSrc,
|
|
2902
|
+
alt: effectiveAlt,
|
|
2903
|
+
className,
|
|
2904
|
+
style: effectiveStyle,
|
|
2905
|
+
onClick: handleClick,
|
|
2906
|
+
...editorAttrs,
|
|
2907
|
+
...rest
|
|
2908
|
+
}
|
|
2909
|
+
);
|
|
2910
|
+
}
|
|
2911
|
+
);
|
|
2912
|
+
var ICON_DEFS = {
|
|
2913
|
+
star: '<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>',
|
|
2914
|
+
heart: '<path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.29 1.51 4.04 3 5.5l7 7Z"/>',
|
|
2915
|
+
check: '<path d="M20 6 9 17l-5-5"/>',
|
|
2916
|
+
"check-circle": '<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>',
|
|
2917
|
+
shield: '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"/>',
|
|
2918
|
+
"shield-check": '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"/><path d="m9 12 2 2 4-4"/>',
|
|
2919
|
+
truck: '<path d="M10 17h4V5H2v12h3"/><path d="M20 17h2v-3.34a4 4 0 0 0-1.17-2.83L19 9h-5v8h1"/><circle cx="7.5" cy="17.5" r="2.5"/><circle cx="17.5" cy="17.5" r="2.5"/>',
|
|
2920
|
+
"shopping-bag": '<path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z"/><path d="M3 6h18"/><path d="M16 10a4 4 0 0 1-8 0"/>',
|
|
2921
|
+
"shopping-cart": '<circle cx="8" cy="21" r="1"/><circle cx="19" cy="21" r="1"/><path d="M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"/>',
|
|
2922
|
+
gift: '<rect x="3" y="8" width="18" height="4" rx="1"/><path d="M12 8v13"/><path d="M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"/><path d="M7.5 8a2.5 2.5 0 0 1 0-5C9 3 10.5 4.5 12 8c1.5-3.5 3-5 4.5-5a2.5 2.5 0 0 1 0 5"/>',
|
|
2923
|
+
tag: '<path d="M20.59 13.41 13.42 20.6a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82Z"/><circle cx="7" cy="7" r="1"/>',
|
|
2924
|
+
zap: '<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>',
|
|
2925
|
+
sparkles: '<path d="M12 3 13.9 9.2 20 11l-6.1 1.8L12 19l-1.9-6.2L4 11l6.1-1.8L12 3Z"/><path d="M5 3v4"/><path d="M3 5h4"/><path d="M19 17v4"/><path d="M17 19h4"/>',
|
|
2926
|
+
flame: '<path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.07-2.14-.22-4.05 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.15.43-2.29 1-3a2.5 2.5 0 0 0 2.5 2.5Z"/>',
|
|
2927
|
+
leaf: '<path d="M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 4.48 19 2c1 2 2 4.18 2 8 0 5.5-4.78 10-10 10Z"/><path d="M2 21c0-3 1.85-5.36 5.08-6"/>',
|
|
2928
|
+
globe: '<circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10Z"/>',
|
|
2929
|
+
"map-pin": '<path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/>',
|
|
2930
|
+
phone: '<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92Z"/>',
|
|
2931
|
+
mail: '<rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>',
|
|
2932
|
+
clock: '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
|
|
2933
|
+
lock: '<rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/>',
|
|
2934
|
+
headphones: '<path d="M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3"/>',
|
|
2935
|
+
percent: '<line x1="19" x2="5" y1="5" y2="19"/><circle cx="6.5" cy="6.5" r="2.5"/><circle cx="17.5" cy="17.5" r="2.5"/>',
|
|
2936
|
+
users: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
|
|
2937
|
+
home: '<path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/>',
|
|
2938
|
+
store: '<path d="M2 7l2-4h16l2 4"/><path d="M4 7v13a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1V7"/><path d="M2 7h20"/><path d="M9 21v-6h6v6"/>',
|
|
2939
|
+
bell: '<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/>',
|
|
2940
|
+
camera: '<path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/>',
|
|
2941
|
+
image: '<rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.09-3.09a2 2 0 0 0-2.82 0L6 21"/>',
|
|
2942
|
+
smile: '<circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" x2="9.01" y1="9" y2="9"/><line x1="15" x2="15.01" y1="9" y2="9"/>',
|
|
2943
|
+
send: '<path d="m22 2-7 20-4-9-9-4Z"/><path d="M22 2 11 13"/>',
|
|
2944
|
+
"message-circle": '<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5Z"/>',
|
|
2945
|
+
search: '<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',
|
|
2946
|
+
package: '<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/>',
|
|
2947
|
+
award: '<circle cx="12" cy="8" r="6"/><path d="M15.477 12.89 17 22l-5-3-5 3 1.523-9.11"/>',
|
|
2948
|
+
coffee: '<path d="M10 2v2"/><path d="M14 2v2"/><path d="M6 2v2"/><path d="M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"/>'
|
|
2949
|
+
};
|
|
2950
|
+
var ICON_NAMES = Object.keys(ICON_DEFS);
|
|
2951
|
+
var IconMap = ICON_DEFS;
|
|
2952
|
+
var FALLBACK = ICON_DEFS["check-circle"];
|
|
2953
|
+
function Icon({
|
|
2954
|
+
name,
|
|
2955
|
+
size = 24,
|
|
2956
|
+
strokeWidth = 2,
|
|
2957
|
+
className,
|
|
2958
|
+
title
|
|
2959
|
+
}) {
|
|
2960
|
+
const inner = ICON_DEFS[name] ?? FALLBACK;
|
|
2961
|
+
return /* @__PURE__ */ jsx(
|
|
2962
|
+
"svg",
|
|
2963
|
+
{
|
|
2964
|
+
width: size,
|
|
2965
|
+
height: size,
|
|
2966
|
+
viewBox: "0 0 24 24",
|
|
2967
|
+
fill: "none",
|
|
2968
|
+
stroke: "currentColor",
|
|
2969
|
+
strokeWidth,
|
|
2970
|
+
strokeLinecap: "round",
|
|
2971
|
+
strokeLinejoin: "round",
|
|
2972
|
+
className,
|
|
2973
|
+
role: title ? "img" : void 0,
|
|
2974
|
+
"aria-hidden": title ? void 0 : true,
|
|
2975
|
+
"aria-label": title,
|
|
2976
|
+
dangerouslySetInnerHTML: { __html: inner }
|
|
2977
|
+
}
|
|
2978
|
+
);
|
|
2979
|
+
}
|
|
2376
2980
|
|
|
2377
2981
|
// src/utils/normalize.ts
|
|
2378
2982
|
var DEFAULT_THEME_ID = typeof process !== "undefined" && process.env?.NUMU_DEFAULT_THEME_ID || "modern";
|
|
@@ -2466,22 +3070,11 @@ function resolveThemeSettings(raw) {
|
|
|
2466
3070
|
}
|
|
2467
3071
|
|
|
2468
3072
|
// src/utils/federation.ts
|
|
2469
|
-
var SDK_SYMBOL_KEY = "__NUMU_SDK_SLOT__";
|
|
2470
|
-
var REACT_SYMBOL_KEY = "__NUMU_REACT_SLOT__";
|
|
2471
|
-
function globalSlot(name, slotKey) {
|
|
2472
|
-
const g = globalThis;
|
|
2473
|
-
let sym = g[slotKey];
|
|
2474
|
-
if (!sym) {
|
|
2475
|
-
sym = Symbol.for(name);
|
|
2476
|
-
g[slotKey] = sym;
|
|
2477
|
-
}
|
|
2478
|
-
return sym;
|
|
2479
|
-
}
|
|
2480
3073
|
function sdkSlot() {
|
|
2481
|
-
return
|
|
3074
|
+
return /* @__PURE__ */ Symbol.for("@numueg/theme-sdk:singleton");
|
|
2482
3075
|
}
|
|
2483
3076
|
function reactSlot() {
|
|
2484
|
-
return
|
|
3077
|
+
return /* @__PURE__ */ Symbol.for("@numueg/theme-sdk:react");
|
|
2485
3078
|
}
|
|
2486
3079
|
function registerSdkSingleton(sdk) {
|
|
2487
3080
|
if (typeof globalThis === "undefined") return;
|
|
@@ -2491,6 +3084,10 @@ function getSdkSingleton() {
|
|
|
2491
3084
|
if (typeof globalThis === "undefined") return null;
|
|
2492
3085
|
return globalThis[sdkSlot()] ?? null;
|
|
2493
3086
|
}
|
|
3087
|
+
function clearSdkSingleton() {
|
|
3088
|
+
if (typeof globalThis === "undefined") return;
|
|
3089
|
+
delete globalThis[sdkSlot()];
|
|
3090
|
+
}
|
|
2494
3091
|
function registerReactSingleton(react, reactDom) {
|
|
2495
3092
|
if (typeof globalThis === "undefined") return;
|
|
2496
3093
|
globalThis[reactSlot()] = {
|
|
@@ -2506,6 +3103,121 @@ function isSdkAvailable() {
|
|
|
2506
3103
|
return getSdkSingleton() !== null;
|
|
2507
3104
|
}
|
|
2508
3105
|
|
|
3106
|
+
// src/utils/dynamicSources.ts
|
|
3107
|
+
function isDynamicSource(value) {
|
|
3108
|
+
return typeof value === "object" && value !== null && typeof value.__numu_source === "string";
|
|
3109
|
+
}
|
|
3110
|
+
function dynamicSource(path) {
|
|
3111
|
+
return { __numu_source: path };
|
|
3112
|
+
}
|
|
3113
|
+
function resolveSourcePath(path, ctx) {
|
|
3114
|
+
const [root, ...rest] = path.split(".");
|
|
3115
|
+
switch (root) {
|
|
3116
|
+
case "product": {
|
|
3117
|
+
const p = ctx.product;
|
|
3118
|
+
if (!p) return null;
|
|
3119
|
+
return resolveProductField(p, rest.join("."));
|
|
3120
|
+
}
|
|
3121
|
+
case "collection": {
|
|
3122
|
+
const c = ctx.collection;
|
|
3123
|
+
if (!c) return null;
|
|
3124
|
+
return resolveCollectionField(c, rest.join("."));
|
|
3125
|
+
}
|
|
3126
|
+
case "store": {
|
|
3127
|
+
const s = ctx.store;
|
|
3128
|
+
if (!s) return null;
|
|
3129
|
+
return resolveStoreField(s, rest.join("."));
|
|
3130
|
+
}
|
|
3131
|
+
default:
|
|
3132
|
+
return null;
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
function resolveProductField(p, field) {
|
|
3136
|
+
switch (field) {
|
|
3137
|
+
case "title":
|
|
3138
|
+
case "name":
|
|
3139
|
+
return p.name;
|
|
3140
|
+
case "description":
|
|
3141
|
+
return p.description ?? "";
|
|
3142
|
+
case "description_snippet":
|
|
3143
|
+
return (p.description ?? "").replace(/<[^>]+>/g, " ").trim().slice(0, 200);
|
|
3144
|
+
case "price":
|
|
3145
|
+
return p.price;
|
|
3146
|
+
case "sku":
|
|
3147
|
+
return p.variants?.[0]?.sku ?? null;
|
|
3148
|
+
case "image":
|
|
3149
|
+
case "first_image_url":
|
|
3150
|
+
return p.images?.[0]?.url ?? null;
|
|
3151
|
+
case "slug":
|
|
3152
|
+
return p.slug;
|
|
3153
|
+
default:
|
|
3154
|
+
return null;
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
function resolveCollectionField(c, field) {
|
|
3158
|
+
switch (field) {
|
|
3159
|
+
case "title":
|
|
3160
|
+
case "name":
|
|
3161
|
+
return c.name;
|
|
3162
|
+
case "description":
|
|
3163
|
+
return c.description ?? "";
|
|
3164
|
+
case "description_snippet":
|
|
3165
|
+
return (c.description ?? "").replace(/<[^>]+>/g, " ").trim().slice(0, 200);
|
|
3166
|
+
case "image":
|
|
3167
|
+
return c.image_url ?? null;
|
|
3168
|
+
case "slug":
|
|
3169
|
+
return c.slug;
|
|
3170
|
+
case "product_count":
|
|
3171
|
+
return c.product_count ?? null;
|
|
3172
|
+
default:
|
|
3173
|
+
return null;
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
function resolveStoreField(s, field) {
|
|
3177
|
+
switch (field) {
|
|
3178
|
+
case "name":
|
|
3179
|
+
return s.name ?? "";
|
|
3180
|
+
case "description":
|
|
3181
|
+
return s.description ?? "";
|
|
3182
|
+
case "logo":
|
|
3183
|
+
return s.logo_url ?? null;
|
|
3184
|
+
default:
|
|
3185
|
+
return null;
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
function resolveDynamicValue(value, ctx) {
|
|
3189
|
+
if (!isDynamicSource(value)) return value;
|
|
3190
|
+
return resolveSourcePath(value.__numu_source, ctx);
|
|
3191
|
+
}
|
|
3192
|
+
function resolveSettingsMap(settings, ctx) {
|
|
3193
|
+
if (!settings || typeof settings !== "object") return settings;
|
|
3194
|
+
const input = settings;
|
|
3195
|
+
const out = {};
|
|
3196
|
+
for (const key of Object.keys(input)) {
|
|
3197
|
+
const v = input[key];
|
|
3198
|
+
if (isDynamicSource(v)) {
|
|
3199
|
+
const resolved = resolveSourcePath(v.__numu_source, ctx);
|
|
3200
|
+
out[key] = resolved;
|
|
3201
|
+
} else {
|
|
3202
|
+
out[key] = v;
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
return out;
|
|
3206
|
+
}
|
|
3207
|
+
function useResolvedSettings(instance) {
|
|
3208
|
+
const product = useContext(ProductContext);
|
|
3209
|
+
const collection = useContext(CollectionContext);
|
|
3210
|
+
const store = useContext(ShopContext);
|
|
3211
|
+
const ctx = useMemo(
|
|
3212
|
+
() => ({ product, collection, store }),
|
|
3213
|
+
[product, collection, store]
|
|
3214
|
+
);
|
|
3215
|
+
return useMemo(() => {
|
|
3216
|
+
const settings = instance?.settings ?? {};
|
|
3217
|
+
return resolveSettingsMap(settings, ctx);
|
|
3218
|
+
}, [instance, ctx]);
|
|
3219
|
+
}
|
|
3220
|
+
|
|
2509
3221
|
// src/utils/defineSection.ts
|
|
2510
3222
|
var SECTION_MARKER = /* @__PURE__ */ Symbol.for("numu.theme.section");
|
|
2511
3223
|
var BLOCK_MARKER = /* @__PURE__ */ Symbol.for("numu.theme.block");
|
|
@@ -2664,6 +3376,6 @@ function buildLocaleBundle(modules) {
|
|
|
2664
3376
|
return bundle;
|
|
2665
3377
|
}
|
|
2666
3378
|
|
|
2667
|
-
export { AddToCartButton, Block, CartContext, CollectionCard, CollectionContext, CollectionProvider, CurrencySwitcher, CustomerContext, Form, Image, Link, LocaleSwitcher, LocalizationContext, Money, NuMuProvider, PageContext, ProductCard, ProductContext, ProductProvider, RichText, Section, SectionContext, ShopContext, ThemeSettingsContext, assetUrl, availableValues, buildLocaleBundle, collectBlocks, collectSections, defaultVariant, defineBlock, defineSection, findVariantByOptions, flattenMessages, getReactSingleton, getSdkSingleton, isDefinedBlock, isDefinedSection, isSdkAvailable, pickTranslations, registerReactSingleton, registerSdkSingleton, resolveThemeSettings, sanitizeHtml, useAnalytics, useApp, useCart, useCheckout, useCollection, useCollectionOptional, useCollections, useCurrency, useCustomer, useCustomerActions, useCustomerAddresses, useDirection, useFieldTranslation, useGiftCardBalance, useImage, useLocale, useLocalization, useMoney, useNavigation, useNumberFormat, useOrder, useOrders, usePage, useProduct, useProductOptional, useProducts, useRelatedProducts, useReorder, useSearch, useSection, useSectionOptional, useShippingRates, useShop, useThemeSettings, useTranslation, useVariantSelection, useWishlist };
|
|
3379
|
+
export { AddToCartButton, Block, CartContext, CollectionCard, CollectionContext, CollectionProvider, CurrencySwitcher, CustomerContext, EditableImage, EditableText, Form, ICON_NAMES, Icon, IconMap, Image, Link, LocaleSwitcher, LocalizationContext, MAX_BLOCK_DEPTH, Money, NavigationContext, NuMuProvider, PageContext, ProductCard, ProductContext, ProductProvider, RichText, Section, SectionContext, ShopContext, ThemeSettingsContext, applyGlobalStyleTokens, assetUrl, availableValues, buildLocaleBundle, clearSdkSingleton, collectBlocks, collectSections, defaultVariant, defineBlock, defineSection, dynamicSource, findVariantByOptions, flattenMessages, getReactSingleton, getSdkSingleton, isDefinedBlock, isDefinedSection, isDynamicSource, isSdkAvailable, mountTheme, pickTranslations, registerReactSingleton, registerSdkSingleton, resolveDynamicValue, resolveFontStack, resolveSettingsMap, resolveSourcePath, resolveThemeSettings, sanitizeHtml, useAnalytics, useApp, useCart, useCheckout, useCollection, useCollectionOptional, useCollections, useCurrency, useCurrentTemplate, useCustomer, useCustomerActions, useCustomerAddresses, useDirection, useFieldTranslation, useGiftCardBalance, useImage, useLocale, useLocalization, useMoney, useNavigation, useNumberFormat, useOrder, useOrders, usePage, useProduct, useProductOptional, useProducts, useRelatedProducts, useReorder, useResolvedSettings, useSearch, useSection, useSectionOptional, useShippingRates, useShop, useThemeSettings, useTranslation, useVariantSelection, useWishlist };
|
|
2668
3380
|
//# sourceMappingURL=index.mjs.map
|
|
2669
3381
|
//# sourceMappingURL=index.mjs.map
|