@numueg/theme-sdk 0.4.0 → 0.5.0

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.cjs CHANGED
@@ -9,7 +9,7 @@ var MAX_BLOCK_DEPTH = 5;
9
9
 
10
10
  // src/validation/index.ts
11
11
  var THEME_CONTRACT_VERSION = 1;
12
- var SDK_VERSION = "0.4.0" ;
12
+ var SDK_VERSION = "0.5.0" ;
13
13
  var REQUIRED_TEMPLATES = [
14
14
  "home",
15
15
  "product",
@@ -2330,6 +2330,64 @@ function NuMuProvider({
2330
2330
  function ProductProvider({ product, children }) {
2331
2331
  return /* @__PURE__ */ jsxRuntime.jsx(ProductContext.Provider, { value: product, children });
2332
2332
  }
2333
+ function CollectionProvider({ collection, children }) {
2334
+ return /* @__PURE__ */ jsxRuntime.jsx(CollectionContext.Provider, { value: collection, children });
2335
+ }
2336
+
2337
+ // src/utils/logoStyle.ts
2338
+ var LOGO_SHAPE_OPTIONS = [
2339
+ { value: "none", label: "Original", label_ar: "\u0627\u0644\u0623\u0635\u0644\u064A" },
2340
+ { value: "square", label: "Square", label_ar: "\u0645\u0631\u0628\u0639" },
2341
+ { value: "rounded", label: "Rounded square", label_ar: "\u0645\u0631\u0628\u0639 \u0628\u0632\u0648\u0627\u064A\u0627 \u062F\u0627\u0626\u0631\u064A\u0629" },
2342
+ { value: "circle", label: "Circle", label_ar: "\u062F\u0627\u0626\u0631\u0629" },
2343
+ { value: "triangle", label: "Triangle", label_ar: "\u0645\u062B\u0644\u062B" }
2344
+ ];
2345
+ var LOGO_SIZE_OPTIONS = [
2346
+ { value: "small", label: "Small", label_ar: "\u0635\u063A\u064A\u0631" },
2347
+ { value: "medium", label: "Medium", label_ar: "\u0645\u062A\u0648\u0633\u0637" },
2348
+ { value: "large", label: "Large", label_ar: "\u0643\u0628\u064A\u0631" }
2349
+ ];
2350
+ var SHAPED_PX = {
2351
+ small: { plain: 32, rounded: 48 },
2352
+ medium: { plain: 40, rounded: 64 },
2353
+ large: { plain: 56, rounded: 80 }
2354
+ };
2355
+ function normalizeSize(size) {
2356
+ return size === "large" || size === "medium" ? size : "small";
2357
+ }
2358
+ function logoImgStyle(shape, size) {
2359
+ if (!shape || shape === "none") return void 0;
2360
+ const s = normalizeSize(size);
2361
+ const isRound = shape === "circle" || shape === "rounded";
2362
+ const px = isRound ? SHAPED_PX[s].rounded : SHAPED_PX[s].plain;
2363
+ const base = {
2364
+ height: px,
2365
+ width: px,
2366
+ objectFit: "cover",
2367
+ flex: "0 0 auto"
2368
+ };
2369
+ switch (shape) {
2370
+ case "circle":
2371
+ return { ...base, borderRadius: "9999px" };
2372
+ case "rounded":
2373
+ return { ...base, borderRadius: "0.5rem" };
2374
+ case "triangle":
2375
+ return { ...base, clipPath: "polygon(50% 0%, 100% 100%, 0% 100%)" };
2376
+ case "square":
2377
+ default:
2378
+ return base;
2379
+ }
2380
+ }
2381
+ function logoStyleTokens(shape, size) {
2382
+ const style = logoImgStyle(shape, size);
2383
+ if (!style) return {};
2384
+ const box = `${style.height}px`;
2385
+ return {
2386
+ "--theme-logo-box": box,
2387
+ "--theme-logo-radius": typeof style.borderRadius === "string" ? style.borderRadius : "0",
2388
+ "--theme-logo-clip": typeof style.clipPath === "string" ? style.clipPath : "none"
2389
+ };
2390
+ }
2333
2391
 
2334
2392
  // src/utils/styleTokens.ts
2335
2393
  var COLOR_ROLE_ALIASES = {
@@ -2470,6 +2528,12 @@ function computeGlobalStyleTokens(globalSettings) {
2470
2528
  pushHref(FONT_REGISTRY[value]?.href);
2471
2529
  }
2472
2530
  }
2531
+ const gs = globalSettings;
2532
+ const logoTokens = logoStyleTokens(
2533
+ typeof gs.logo_shape === "string" ? gs.logo_shape : void 0,
2534
+ typeof gs.logo_size === "string" ? gs.logo_size : void 0
2535
+ );
2536
+ for (const [k, v] of Object.entries(logoTokens)) cssVars[k] = v;
2473
2537
  return { cssVars, fontHrefs };
2474
2538
  }
2475
2539
  function applyGlobalStyleTokens(globalSettings, el) {
@@ -2512,6 +2576,16 @@ function pickDemo(ctx, themeSettings) {
2512
2576
  const t = themeSettings.templates;
2513
2577
  return !t || Object.keys(t).length === 0;
2514
2578
  }
2579
+ function wrapEntityProviders(app, pageData) {
2580
+ let inner = app;
2581
+ if (pageData.collection) {
2582
+ inner = /* @__PURE__ */ jsxRuntime.jsx(CollectionProvider, { collection: pageData.collection, children: inner });
2583
+ }
2584
+ if (pageData.product) {
2585
+ inner = /* @__PURE__ */ jsxRuntime.jsx(ProductProvider, { product: pageData.product, children: inner });
2586
+ }
2587
+ return inner;
2588
+ }
2515
2589
  var ThemeMountBridge = react.forwardRef(function ThemeMountBridge2({ ctx, mountEl, renderApp }, ref) {
2516
2590
  const [themeSettings, setThemeSettings] = react.useState(
2517
2591
  ctx.themeSettings
@@ -2552,7 +2626,7 @@ var ThemeMountBridge = react.forwardRef(function ThemeMountBridge2({ ctx, mountE
2552
2626
  initialProducts: pageData.products,
2553
2627
  initialCollections: pageData.collections,
2554
2628
  currentTemplate: template,
2555
- children: pageData.product ? /* @__PURE__ */ jsxRuntime.jsx(ProductProvider, { product: pageData.product, children: app }) : app
2629
+ children: wrapEntityProviders(app, pageData)
2556
2630
  }
2557
2631
  );
2558
2632
  });
@@ -2588,9 +2662,6 @@ function defineThemeEntry(renderApp) {
2588
2662
  createApp: (ctx) => buildThemeElement(ctx, null, renderApp)
2589
2663
  };
2590
2664
  }
2591
- function CollectionProvider({ collection, children }) {
2592
- return /* @__PURE__ */ jsxRuntime.jsx(CollectionContext.Provider, { value: collection, children });
2593
- }
2594
2665
  function Money({
2595
2666
  amount,
2596
2667
  currency,
@@ -2741,6 +2812,43 @@ function Image({
2741
2812
  }
2742
2813
  );
2743
2814
  }
2815
+ var str = (v) => typeof v === "string" ? v : "";
2816
+ var NONE_HEIGHT = { small: 28, medium: 36, large: 48 };
2817
+ function Logo({
2818
+ src,
2819
+ alt,
2820
+ shape,
2821
+ size,
2822
+ className,
2823
+ style,
2824
+ fallback
2825
+ }) {
2826
+ const settings = useThemeSettings();
2827
+ const shop = useShop();
2828
+ const g = settings?.global_settings ?? {};
2829
+ const url = str(src) || str(g.logo_url) || shop?.logo_url || "";
2830
+ const resolvedShape = shape || str(g.logo_shape) || "none";
2831
+ const resolvedSize = size || str(g.logo_size) || "small";
2832
+ const altText = alt || str(g.brand_name) || shop?.name || "";
2833
+ if (!url) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback ?? null });
2834
+ const shaped = resolvedShape !== "none";
2835
+ const imgStyle = shaped ? { ...logoImgStyle(resolvedShape, resolvedSize), ...style } : {
2836
+ height: NONE_HEIGHT[resolvedSize] ?? NONE_HEIGHT.small,
2837
+ width: "auto",
2838
+ objectFit: "contain",
2839
+ ...style
2840
+ };
2841
+ return /* @__PURE__ */ jsxRuntime.jsx(
2842
+ "img",
2843
+ {
2844
+ src: url,
2845
+ alt: altText,
2846
+ className,
2847
+ style: imgStyle,
2848
+ loading: "eager"
2849
+ }
2850
+ );
2851
+ }
2744
2852
  var ABSOLUTE_URL = /^[a-z]+:|^\/\//i;
2745
2853
  function Link({ to, children, ...rest }) {
2746
2854
  const shop = useShop();
@@ -3968,9 +4076,12 @@ exports.IconMap = IconMap;
3968
4076
  exports.Image = Image;
3969
4077
  exports.KNOWN_SETTING_TYPES = KNOWN_SETTING_TYPES;
3970
4078
  exports.KNOWN_TEMPLATES = KNOWN_TEMPLATES;
4079
+ exports.LOGO_SHAPE_OPTIONS = LOGO_SHAPE_OPTIONS;
4080
+ exports.LOGO_SIZE_OPTIONS = LOGO_SIZE_OPTIONS;
3971
4081
  exports.Link = Link;
3972
4082
  exports.LocaleSwitcher = LocaleSwitcher;
3973
4083
  exports.LocalizationContext = LocalizationContext;
4084
+ exports.Logo = Logo;
3974
4085
  exports.MAX_BLOCK_DEPTH = MAX_BLOCK_DEPTH;
3975
4086
  exports.Money = Money;
3976
4087
  exports.NavigationContext = NavigationContext;
@@ -4012,6 +4123,8 @@ exports.isDefinedBlock = isDefinedBlock;
4012
4123
  exports.isDefinedSection = isDefinedSection;
4013
4124
  exports.isDynamicSource = isDynamicSource;
4014
4125
  exports.isSdkAvailable = isSdkAvailable;
4126
+ exports.logoImgStyle = logoImgStyle;
4127
+ exports.logoStyleTokens = logoStyleTokens;
4015
4128
  exports.mergeResults = mergeResults;
4016
4129
  exports.mountTheme = mountTheme;
4017
4130
  exports.pickTranslations = pickTranslations;