@numueg/theme-sdk 0.2.0 → 0.2.2

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
@@ -1447,6 +1447,16 @@ var EMPTY_CART = {
1447
1447
  total: 0,
1448
1448
  currency: "EGP"
1449
1449
  };
1450
+ function normalizeCartFromServer(cart) {
1451
+ const toMajor = (n) => typeof n === "number" ? n / 100 : 0;
1452
+ return {
1453
+ ...cart,
1454
+ subtotal: toMajor(cart.subtotal),
1455
+ total: toMajor(cart.total),
1456
+ ...cart.discount_amount != null ? { discount_amount: toMajor(cart.discount_amount) } : {},
1457
+ items: Array.isArray(cart.items) ? cart.items.map((it) => ({ ...it, price: toMajor(it.price) })) : []
1458
+ };
1459
+ }
1450
1460
  function readCsrfCookie() {
1451
1461
  if (typeof document === "undefined") return null;
1452
1462
  const match = document.cookie.match(/(?:^|;\s*)numu_csrf=([^;]+)/);
@@ -1649,7 +1659,7 @@ function NuMuProvider({
1649
1659
  if (!res.ok || cancelled) return;
1650
1660
  const data = await res.json();
1651
1661
  if (data && typeof data === "object") {
1652
- setCart(data);
1662
+ setCart(normalizeCartFromServer(data));
1653
1663
  }
1654
1664
  } catch {
1655
1665
  }
@@ -1670,7 +1680,7 @@ function NuMuProvider({
1670
1680
  return;
1671
1681
  }
1672
1682
  latestApplied.current = token;
1673
- setCart(newCart);
1683
+ setCart(normalizeCartFromServer(newCart));
1674
1684
  },
1675
1685
  []
1676
1686
  );
@@ -3324,6 +3334,23 @@ function assetUrl(name) {
3324
3334
  return `${cleanBase}${filename}`;
3325
3335
  }
3326
3336
 
3337
+ // src/utils/imageTransform.ts
3338
+ var clamp01 = (n) => Math.min(1, Math.max(0, n));
3339
+ function focalSrc(url, options = {}) {
3340
+ if (!url) return "";
3341
+ if (url.startsWith("data:") || /[?&](fp-x|fp-y)=/.test(url)) return url;
3342
+ const p = new URLSearchParams();
3343
+ p.set("url", url);
3344
+ if (options.width) p.set("w", String(Math.round(options.width)));
3345
+ if (options.focal?.x != null) p.set("fp-x", String(clamp01(options.focal.x)));
3346
+ if (options.focal?.y != null) p.set("fp-y", String(clamp01(options.focal.y)));
3347
+ if (options.aspect) p.set("ar", options.aspect);
3348
+ if (options.fit) p.set("fit", options.fit);
3349
+ if (options.quality) p.set("q", String(Math.min(100, Math.max(1, Math.round(options.quality)))));
3350
+ if (options.format) p.set("f", options.format.toLowerCase());
3351
+ return `/api/image-transform?${p.toString()}`;
3352
+ }
3353
+
3327
3354
  // src/utils/locales.ts
3328
3355
  function flattenMessages(source, prefix = "") {
3329
3356
  const out = {};
@@ -3412,6 +3439,7 @@ exports.defineSection = defineSection;
3412
3439
  exports.dynamicSource = dynamicSource;
3413
3440
  exports.findVariantByOptions = findVariantByOptions;
3414
3441
  exports.flattenMessages = flattenMessages;
3442
+ exports.focalSrc = focalSrc;
3415
3443
  exports.getReactSingleton = getReactSingleton;
3416
3444
  exports.getSdkSingleton = getSdkSingleton;
3417
3445
  exports.isDefinedBlock = isDefinedBlock;