@numueg/theme-sdk 0.5.1 → 0.6.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.5.1" ;
12
+ var SDK_VERSION = "0.6.0" ;
13
13
  var REQUIRED_TEMPLATES = [
14
14
  "home",
15
15
  "product",
@@ -1470,16 +1470,17 @@ function availableValues(product, selection) {
1470
1470
  const variants = product.variants || [];
1471
1471
  const out = {};
1472
1472
  for (const axis of axes) {
1473
- out[axis.name] = /* @__PURE__ */ new Set();
1473
+ const set = /* @__PURE__ */ new Set();
1474
1474
  for (const v of variants) {
1475
1475
  const opts = v.option_values || v.options || {};
1476
1476
  const compatible = Object.entries(selection).every(
1477
1477
  ([k, val]) => k === axis.name || opts[k] === val
1478
1478
  );
1479
1479
  if (compatible && opts[axis.name]) {
1480
- out[axis.name].add(opts[axis.name]);
1480
+ set.add(opts[axis.name]);
1481
1481
  }
1482
1482
  }
1483
+ out[axis.name] = set.size > 0 ? set : new Set(axis.values || []);
1483
1484
  }
1484
1485
  return out;
1485
1486
  }
@@ -2741,6 +2742,7 @@ function Image({
2741
2742
  sizes = "(min-width: 1024px) 25vw, (min-width: 640px) 50vw, 100vw",
2742
2743
  responsive = true,
2743
2744
  loading = "lazy",
2745
+ priority = false,
2744
2746
  aspectRatio,
2745
2747
  objectFit,
2746
2748
  objectPosition,
@@ -2777,6 +2779,7 @@ function Image({
2777
2779
  );
2778
2780
  }
2779
2781
  const srcSet = responsive ? buildSrcSet(src) : void 0;
2782
+ const effLoading = priority ? "eager" : loading;
2780
2783
  const effFit = objectFit ?? (framed ? "cover" : void 0);
2781
2784
  const fitStyle = transform ? applyImageTransform(transform, effFit === "contain" ? "contain" : "cover") : {
2782
2785
  ...effFit ? { objectFit: effFit } : {},
@@ -2789,7 +2792,8 @@ function Image({
2789
2792
  alt,
2790
2793
  srcSet: srcSet || void 0,
2791
2794
  sizes: srcSet ? sizes : void 0,
2792
- loading,
2795
+ loading: effLoading,
2796
+ fetchPriority: priority ? "high" : void 0,
2793
2797
  decoding: "async",
2794
2798
  className: framed ? void 0 : className,
2795
2799
  style: framed ? { width: "100%", height: "100%", display: "block", ...fitStyle } : { ...fitStyle, ...style },
@@ -2813,6 +2817,111 @@ function Image({
2813
2817
  }
2814
2818
  );
2815
2819
  }
2820
+ var HERO_WIDTHS = [640, 768, 1024, 1280, 1920];
2821
+ var DEFAULT_BREAKPOINT = 768;
2822
+ var DESKTOP_BASE_WIDTH = 1920;
2823
+ var MOBILE_BASE_WIDTH = 1280;
2824
+ function heroSrcSet(url, opts) {
2825
+ return HERO_WIDTHS.map((w) => `${focalSrc(url, { width: w, ...opts })} ${w}w`).join(", ");
2826
+ }
2827
+ function HeroMedia({
2828
+ src,
2829
+ alt,
2830
+ transform,
2831
+ mobileSrc,
2832
+ mobileTransform,
2833
+ desktopAspect,
2834
+ mobileAspect,
2835
+ fit = "cover",
2836
+ priority = true,
2837
+ sizes = "100vw",
2838
+ breakpoint = DEFAULT_BREAKPOINT,
2839
+ preloadAlternate = true,
2840
+ className,
2841
+ style,
2842
+ ...rest
2843
+ }) {
2844
+ const hasMobile = !!mobileSrc;
2845
+ const mobileQuery = `(max-width: ${breakpoint - 1}px)`;
2846
+ const [isMobile, setIsMobile] = react.useState(
2847
+ () => hasMobile && typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(mobileQuery).matches
2848
+ );
2849
+ const [rawFallback, setRawFallback] = react.useState(false);
2850
+ const { onError: themeOnError, ...imgRest } = rest;
2851
+ const handleError = (e) => {
2852
+ if (!rawFallback) setRawFallback(true);
2853
+ else themeOnError?.(e);
2854
+ };
2855
+ react.useEffect(() => {
2856
+ if (!hasMobile || typeof window === "undefined" || typeof window.matchMedia !== "function") {
2857
+ return;
2858
+ }
2859
+ const mq = window.matchMedia(mobileQuery);
2860
+ const sync = () => setIsMobile(mq.matches);
2861
+ sync();
2862
+ mq.addEventListener?.("change", sync);
2863
+ return () => mq.removeEventListener?.("change", sync);
2864
+ }, [hasMobile, mobileQuery]);
2865
+ const desktopFocal = transform?.focal;
2866
+ const mobileFocal = mobileTransform?.focal ?? desktopFocal;
2867
+ const desktopCrop = desktopAspect ? { focal: desktopFocal, aspect: desktopAspect, fit } : {};
2868
+ const mobileCrop = {
2869
+ focal: mobileFocal,
2870
+ aspect: mobileAspect,
2871
+ fit
2872
+ };
2873
+ react.useEffect(() => {
2874
+ if (!preloadAlternate || !hasMobile || !src || !mobileSrc) return;
2875
+ if (typeof window === "undefined" || typeof window.Image !== "function") return;
2876
+ const altUrl = isMobile ? rawFallback ? src : focalSrc(src, { width: DESKTOP_BASE_WIDTH, ...desktopCrop }) : rawFallback ? mobileSrc : focalSrc(mobileSrc, { width: MOBILE_BASE_WIDTH, ...mobileCrop });
2877
+ if (!altUrl) return;
2878
+ const im = new window.Image();
2879
+ im.onerror = () => {
2880
+ };
2881
+ try {
2882
+ im.fetchPriority = "low";
2883
+ } catch {
2884
+ }
2885
+ im.decoding = "async";
2886
+ im.src = altUrl;
2887
+ if (typeof im.decode === "function") im.decode().catch(() => {
2888
+ });
2889
+ }, [preloadAlternate, hasMobile, src, mobileSrc, isMobile, rawFallback]);
2890
+ if (!src) {
2891
+ return /* @__PURE__ */ jsxRuntime.jsx(
2892
+ "div",
2893
+ {
2894
+ className,
2895
+ role: "img",
2896
+ "aria-label": alt,
2897
+ style: { width: "100%", height: "100%", backgroundColor: "rgba(0,0,0,0.05)", ...style }
2898
+ }
2899
+ );
2900
+ }
2901
+ const useMobile = hasMobile && isMobile;
2902
+ const activeUrl = useMobile ? mobileSrc : src;
2903
+ const activeCrop = useMobile ? mobileCrop : desktopCrop;
2904
+ const activeBase = useMobile ? MOBILE_BASE_WIDTH : DESKTOP_BASE_WIDTH;
2905
+ const activeSrc = rawFallback ? activeUrl : focalSrc(activeUrl, { width: activeBase, ...activeCrop });
2906
+ const activeSrcSet = rawFallback ? void 0 : heroSrcSet(activeUrl, activeCrop);
2907
+ const fitStyle = applyImageTransform(useMobile ? mobileTransform ?? transform : transform, fit);
2908
+ return /* @__PURE__ */ jsxRuntime.jsx(
2909
+ "img",
2910
+ {
2911
+ src: activeSrc,
2912
+ srcSet: activeSrcSet,
2913
+ sizes: activeSrcSet ? sizes : void 0,
2914
+ alt,
2915
+ loading: priority ? "eager" : "lazy",
2916
+ fetchPriority: priority ? "high" : void 0,
2917
+ decoding: "async",
2918
+ onError: handleError,
2919
+ className,
2920
+ style: { width: "100%", height: "100%", display: "block", ...fitStyle, ...style },
2921
+ ...imgRest
2922
+ }
2923
+ );
2924
+ }
2816
2925
  var str = (v) => typeof v === "string" ? v : "";
2817
2926
  var NONE_HEIGHT = { small: 28, medium: 36, large: 48 };
2818
2927
  function Logo({
@@ -4071,6 +4180,7 @@ exports.CustomerContext = CustomerContext;
4071
4180
  exports.EditableImage = EditableImage;
4072
4181
  exports.EditableText = EditableText;
4073
4182
  exports.Form = Form;
4183
+ exports.HeroMedia = HeroMedia;
4074
4184
  exports.ICON_NAMES = ICON_NAMES;
4075
4185
  exports.Icon = Icon;
4076
4186
  exports.IconMap = IconMap;