@cimplify/sdk 0.79.0 → 0.81.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.
Files changed (58) hide show
  1. package/dist/advanced.d.mts +1 -1
  2. package/dist/advanced.d.ts +1 -1
  3. package/dist/advanced.js +20 -20
  4. package/dist/advanced.mjs +1 -1
  5. package/dist/{chunk-3BKMNVTR.mjs → chunk-7BM56JET.mjs} +1 -0
  6. package/dist/{chunk-FURKCWVG.mjs → chunk-7PAQR3VC.mjs} +2 -2
  7. package/dist/{chunk-BNA4GW4D.mjs → chunk-BRVIXGUW.mjs} +60 -0
  8. package/dist/{chunk-5BPBDWAA.js → chunk-GFM5JW45.js} +57 -36
  9. package/dist/{chunk-CV5QMDQS.js → chunk-HPN5R3K2.js} +1 -0
  10. package/dist/{chunk-T7ALPOK7.js → chunk-IZDJEDR4.js} +4 -4
  11. package/dist/{chunk-LBFTEXGD.mjs → chunk-NWUEWUX2.mjs} +22 -1
  12. package/dist/{chunk-OSTOGR4F.js → chunk-SRJEMEVZ.js} +60 -0
  13. package/dist/{client-Cn5trGYV.d.ts → client-BmDNlUMx.d.ts} +44 -2
  14. package/dist/{client-Byysg2IX.d.mts → client-C51FFhDz.d.mts} +2 -2
  15. package/dist/{client-D16qfHAB.d.mts → client-Cx3WLhMj.d.mts} +44 -2
  16. package/dist/{client-BAzvXSLJ.d.ts → client-Q_m-GkTl.d.ts} +2 -2
  17. package/dist/index.d.mts +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +69 -69
  20. package/dist/index.mjs +3 -3
  21. package/dist/mock/cli.mjs +60 -0
  22. package/dist/mock/library.js +60 -0
  23. package/dist/mock/library.mjs +60 -0
  24. package/dist/mock/msw.js +60 -0
  25. package/dist/mock/msw.mjs +60 -0
  26. package/dist/react.d.mts +51 -4
  27. package/dist/react.d.ts +51 -4
  28. package/dist/react.js +371 -65
  29. package/dist/react.mjs +337 -53
  30. package/dist/{server-Daq42vK7.d.ts → server-N4Q24CnO.d.ts} +21 -0
  31. package/dist/{server-CGO4zneR.d.mts → server-hP9NLtTh.d.mts} +21 -0
  32. package/dist/server.d.mts +2 -2
  33. package/dist/server.d.ts +2 -2
  34. package/dist/server.js +7 -7
  35. package/dist/server.mjs +2 -2
  36. package/dist/testing/msw.d.mts +1 -1
  37. package/dist/testing/msw.d.ts +1 -1
  38. package/dist/testing/msw.js +2 -2
  39. package/dist/testing/msw.mjs +1 -1
  40. package/dist/testing/suite.d.mts +4 -4
  41. package/dist/testing/suite.d.ts +4 -4
  42. package/dist/testing/suite.js +23 -23
  43. package/dist/testing/suite.mjs +4 -4
  44. package/dist/testing.d.mts +18 -18
  45. package/dist/testing.d.ts +18 -18
  46. package/dist/testing.js +79 -79
  47. package/dist/testing.mjs +5 -5
  48. package/package.json +7 -2
  49. package/registry/catalogue-page.json +1 -1
  50. package/registry/product-card.json +1 -1
  51. package/registry/product-grid.json +1 -1
  52. package/registry/product-image-gallery.json +1 -1
  53. package/registry/product-page.json +1 -1
  54. package/registry/recently-viewed.json +1 -1
  55. package/registry/recommendation-carousel.json +1 -1
  56. package/registry/search-input.json +1 -1
  57. package/dist/server-BXT62nBC.d.mts +0 -1186
  58. package/dist/server-BXT62nBC.d.ts +0 -1186
package/dist/react.js CHANGED
@@ -2,13 +2,14 @@
2
2
  'use strict';
3
3
 
4
4
  var chunkIQLJJW2H_js = require('./chunk-IQLJJW2H.js');
5
- var chunk5BPBDWAA_js = require('./chunk-5BPBDWAA.js');
6
- var chunkCV5QMDQS_js = require('./chunk-CV5QMDQS.js');
5
+ var chunkGFM5JW45_js = require('./chunk-GFM5JW45.js');
6
+ var chunkHPN5R3K2_js = require('./chunk-HPN5R3K2.js');
7
7
  var chunk7Y2O3E4D_js = require('./chunk-7Y2O3E4D.js');
8
8
  var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
9
9
  require('./chunk-OWW5GUSB.js');
10
10
  var React14 = require('react');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
+ var ReactDOM = require('react-dom');
12
13
  var clsx = require('clsx');
13
14
  var tailwindMerge = require('tailwind-merge');
14
15
  var dateFns = require('date-fns');
@@ -27,7 +28,26 @@ var input = require('@base-ui/react/input');
27
28
 
28
29
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
29
30
 
31
+ function _interopNamespace(e) {
32
+ if (e && e.__esModule) return e;
33
+ var n = Object.create(null);
34
+ if (e) {
35
+ Object.keys(e).forEach(function (k) {
36
+ if (k !== 'default') {
37
+ var d = Object.getOwnPropertyDescriptor(e, k);
38
+ Object.defineProperty(n, k, d.get ? d : {
39
+ enumerable: true,
40
+ get: function () { return e[k]; }
41
+ });
42
+ }
43
+ });
44
+ }
45
+ n.default = e;
46
+ return Object.freeze(n);
47
+ }
48
+
30
49
  var React14__default = /*#__PURE__*/_interopDefault(React14);
50
+ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
31
51
 
32
52
  // src/ads/identity.ts
33
53
  var COOKIE_NAME = "_cimplify_uid";
@@ -1081,6 +1101,28 @@ function useCart(options = {}) {
1081
1101
  ]
1082
1102
  );
1083
1103
  }
1104
+ var reactPreconnect = typeof ReactDOM__namespace.preconnect === "function" ? ReactDOM__namespace.preconnect : void 0;
1105
+ var connected = /* @__PURE__ */ new Set();
1106
+ function preconnectOrigin(url, crossOrigin) {
1107
+ let origin;
1108
+ try {
1109
+ origin = new URL(url).origin;
1110
+ } catch {
1111
+ return;
1112
+ }
1113
+ if (reactPreconnect) {
1114
+ reactPreconnect(origin, crossOrigin ? { crossOrigin } : void 0);
1115
+ return;
1116
+ }
1117
+ if (typeof document === "undefined") return;
1118
+ if (origin === window.location.origin || connected.has(origin)) return;
1119
+ connected.add(origin);
1120
+ const link = document.createElement("link");
1121
+ link.rel = "preconnect";
1122
+ link.href = origin;
1123
+ if (crossOrigin) link.crossOrigin = crossOrigin;
1124
+ document.head.appendChild(link);
1125
+ }
1084
1126
  var LOCATION_STORAGE_KEY = "cimplify_location_id";
1085
1127
  var DISPLAY_CURRENCY_STORAGE_KEY = "cimplify_display_currency";
1086
1128
  var FX_REFRESH_INTERVAL = 12e4;
@@ -1089,7 +1131,7 @@ var DEFAULT_COUNTRY = "US";
1089
1131
  function createDefaultClient() {
1090
1132
  const processRef = globalThis.process;
1091
1133
  const envPublicKey = processRef?.env?.NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY || "";
1092
- return chunk5BPBDWAA_js.createCimplifyClient({ publicKey: envPublicKey });
1134
+ return chunkGFM5JW45_js.createCimplifyClient({ publicKey: envPublicKey });
1093
1135
  }
1094
1136
  function getStoredLocationId() {
1095
1137
  if (typeof window === "undefined" || !window.localStorage) {
@@ -1146,6 +1188,11 @@ function resolveInitialLocation(locations) {
1146
1188
  }
1147
1189
  return locations[0];
1148
1190
  }
1191
+ var DEFAULT_PREFETCH_OPTIONS = {
1192
+ mode: "aggressive",
1193
+ rootMargin: "300px",
1194
+ images: true
1195
+ };
1149
1196
  var CimplifyClientContext = React14.createContext(null);
1150
1197
  var CimplifyStateContext = React14.createContext(null);
1151
1198
  function CimplifyProvider({
@@ -1154,9 +1201,19 @@ function CimplifyProvider({
1154
1201
  onLocationChange,
1155
1202
  initialBusiness,
1156
1203
  initialLocations,
1157
- optimistic = true
1204
+ optimistic = true,
1205
+ prefetch,
1206
+ linkComponent
1158
1207
  }) {
1159
1208
  const resolvedClient = React14.useMemo(() => client ?? createDefaultClient(), [client]);
1209
+ const resolvedPrefetch = React14.useMemo(
1210
+ () => ({
1211
+ mode: prefetch?.mode ?? DEFAULT_PREFETCH_OPTIONS.mode,
1212
+ rootMargin: prefetch?.rootMargin ?? DEFAULT_PREFETCH_OPTIONS.rootMargin,
1213
+ images: prefetch?.images ?? DEFAULT_PREFETCH_OPTIONS.images
1214
+ }),
1215
+ [prefetch?.mode, prefetch?.rootMargin, prefetch?.images]
1216
+ );
1160
1217
  const onLocationChangeRef = React14.useRef(onLocationChange);
1161
1218
  const seeded = initialBusiness !== void 0;
1162
1219
  const initialBootstrapDone = React14.useRef(seeded);
@@ -1223,6 +1280,12 @@ function CimplifyProvider({
1223
1280
  },
1224
1281
  [fxRate, displayCurrency, baseCurrency]
1225
1282
  );
1283
+ if (resolvedPrefetch.mode !== "off") {
1284
+ const apiCredentials = resolvedClient.getCredentialsMode() === "include" ? "use-credentials" : "anonymous";
1285
+ preconnectOrigin(resolvedClient.getBaseUrl(), apiCredentials);
1286
+ preconnectOrigin(resolvedClient.getLinkApiUrl(), apiCredentials);
1287
+ preconnectOrigin(chunkIQLJJW2H_js.DEFAULT_CDN_BASE_URL);
1288
+ }
1226
1289
  const setCurrentLocation = React14.useCallback(
1227
1290
  (location) => {
1228
1291
  const previousLocationId = resolvedClient.getLocationId();
@@ -1296,7 +1359,9 @@ function CimplifyProvider({
1296
1359
  locations,
1297
1360
  isReady,
1298
1361
  baseCurrency,
1299
- optimistic
1362
+ optimistic,
1363
+ prefetch: resolvedPrefetch,
1364
+ linkComponent: linkComponent ?? null
1300
1365
  }),
1301
1366
  [
1302
1367
  resolvedClient,
@@ -1304,7 +1369,9 @@ function CimplifyProvider({
1304
1369
  baseCurrency,
1305
1370
  locations,
1306
1371
  isReady,
1307
- optimistic
1372
+ optimistic,
1373
+ resolvedPrefetch,
1374
+ linkComponent
1308
1375
  ]
1309
1376
  );
1310
1377
  const stateContextValue = React14.useMemo(
@@ -3376,7 +3443,7 @@ function CimplifySignInButton({
3376
3443
  const onClick = async () => {
3377
3444
  if (busy || disabled) return;
3378
3445
  setBusy(true);
3379
- await chunkCV5QMDQS_js.startSignIn({
3446
+ await chunkHPN5R3K2_js.startSignIn({
3380
3447
  ...signInOpts,
3381
3448
  onSuccess: () => {
3382
3449
  setBusy(false);
@@ -4326,6 +4393,16 @@ function createCachedQuery(config) {
4326
4393
  }, [cacheKey2, load]);
4327
4394
  return { data, isLoading, error, refetch };
4328
4395
  }
4396
+ useCachedQuery.prefetch = (client, options) => {
4397
+ const key = config.key(client, options);
4398
+ if (cache.has(key) || inflight.has(key)) return void 0;
4399
+ const promise = config.fetch(client, options);
4400
+ inflight.set(key, promise);
4401
+ return promise.then((value) => {
4402
+ cache.set(key, { data: value, ts: Date.now() });
4403
+ }).catch(() => {
4404
+ }).finally(() => inflight.delete(key));
4405
+ };
4329
4406
  useCachedQuery.clear = () => {
4330
4407
  cache.clear();
4331
4408
  inflight.clear();
@@ -4382,6 +4459,9 @@ var productsQuery = createCachedQuery({
4382
4459
  };
4383
4460
  }
4384
4461
  });
4462
+ function prefetchProducts(client, options) {
4463
+ return productsQuery.prefetch(client, options);
4464
+ }
4385
4465
  function useProducts(options = {}) {
4386
4466
  const { data, isLoading, error, refetch } = productsQuery(options);
4387
4467
  return {
@@ -4406,14 +4486,27 @@ var productQuery = createCachedQuery({
4406
4486
  fetch: async (client, options) => {
4407
4487
  const result = isLikelySlug(options.slugOrId) ? await client.catalogue.getProductBySlug(options.slugOrId) : await client.catalogue.getProduct(options.slugOrId);
4408
4488
  if (!result.ok) throw result.error;
4409
- client.activity.trackProductView(result.value.id, {
4410
- productName: result.value.name,
4411
- categoryId: result.value.category_id,
4412
- price: String(result.value.default_price)
4413
- });
4414
4489
  return result.value;
4415
4490
  }
4416
4491
  });
4492
+ function prefetchProduct(client, slugOrId) {
4493
+ const normalized = (slugOrId || "").trim();
4494
+ if (!normalized) return void 0;
4495
+ return productQuery.prefetch(client, { slugOrId: normalized });
4496
+ }
4497
+ var VIEW_DEDUPE_WINDOW_MS = 3e5;
4498
+ var recentlyTracked = /* @__PURE__ */ new Map();
4499
+ function trackProductView(client, product) {
4500
+ const now = Date.now();
4501
+ const last = recentlyTracked.get(product.id);
4502
+ if (last !== void 0 && now - last < VIEW_DEDUPE_WINDOW_MS) return;
4503
+ recentlyTracked.set(product.id, now);
4504
+ client.activity.trackProductView(product.id, {
4505
+ productName: product.name,
4506
+ categoryId: product.category_id,
4507
+ price: String(product.default_price)
4508
+ });
4509
+ }
4417
4510
  function useProduct(slugOrId, options = {}) {
4418
4511
  const normalized = (slugOrId || "").trim();
4419
4512
  const { data, isLoading, error, refetch } = productQuery({
@@ -5712,6 +5805,30 @@ function useDeliveryFee(options) {
5712
5805
  return { fee: data, isLoading, error, refetch };
5713
5806
  }
5714
5807
 
5808
+ // src/react/hooks/use-delivery-options.ts
5809
+ var deliveryOptionsQuery = createCachedQuery({
5810
+ name: "useDeliveryOptions",
5811
+ key: (client, options) => cacheKey(
5812
+ client.getPublicKey(),
5813
+ options.latitude,
5814
+ options.longitude,
5815
+ options.country,
5816
+ options.orderValue
5817
+ ),
5818
+ fetch: async (client, options) => {
5819
+ const result = await client.delivery.getOptions(options.latitude, options.longitude, {
5820
+ country: options.country,
5821
+ orderValue: options.orderValue
5822
+ });
5823
+ if (!result.ok) throw result.error;
5824
+ return result.value;
5825
+ }
5826
+ });
5827
+ function useDeliveryOptions(options) {
5828
+ const { data, isLoading, error, refetch } = deliveryOptionsQuery(options);
5829
+ return { options: data, isLoading, error, refetch };
5830
+ }
5831
+
5715
5832
  // src/react/hooks/use-fx-rate.ts
5716
5833
  var fxRateQuery = createCachedQuery({
5717
5834
  name: "useFxRate",
@@ -6004,15 +6121,15 @@ function AuthElement({
6004
6121
  }, [onReady, onAuthenticated, onError]);
6005
6122
  React14.useEffect(() => {
6006
6123
  if (!elements || !containerRef.current) return;
6007
- const element = elements.create(chunkCV5QMDQS_js.ELEMENT_TYPES.AUTH, { prefillEmail });
6124
+ const element = elements.create(chunkHPN5R3K2_js.ELEMENT_TYPES.AUTH, { prefillEmail });
6008
6125
  elementRef.current = element;
6009
- element.on(chunkCV5QMDQS_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
6126
+ element.on(chunkHPN5R3K2_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
6010
6127
  element.on(
6011
- chunkCV5QMDQS_js.EVENT_TYPES.AUTHENTICATED,
6128
+ chunkHPN5R3K2_js.EVENT_TYPES.AUTHENTICATED,
6012
6129
  (data) => onAuthenticatedRef.current?.(data)
6013
6130
  );
6014
6131
  element.on(
6015
- chunkCV5QMDQS_js.EVENT_TYPES.ERROR,
6132
+ chunkHPN5R3K2_js.EVENT_TYPES.ERROR,
6016
6133
  (data) => onErrorRef.current?.(data)
6017
6134
  );
6018
6135
  element.mount(containerRef.current);
@@ -6041,15 +6158,15 @@ function AddressElement({
6041
6158
  }, [onReady, onChange, onError]);
6042
6159
  React14.useEffect(() => {
6043
6160
  if (!elements || !containerRef.current) return;
6044
- const element = elements.create(chunkCV5QMDQS_js.ELEMENT_TYPES.ADDRESS, { mode });
6161
+ const element = elements.create(chunkHPN5R3K2_js.ELEMENT_TYPES.ADDRESS, { mode });
6045
6162
  elementRef.current = element;
6046
- element.on(chunkCV5QMDQS_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
6163
+ element.on(chunkHPN5R3K2_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
6047
6164
  element.on(
6048
- chunkCV5QMDQS_js.EVENT_TYPES.CHANGE,
6165
+ chunkHPN5R3K2_js.EVENT_TYPES.CHANGE,
6049
6166
  (data) => onChangeRef.current?.(data)
6050
6167
  );
6051
6168
  element.on(
6052
- chunkCV5QMDQS_js.EVENT_TYPES.ERROR,
6169
+ chunkHPN5R3K2_js.EVENT_TYPES.ERROR,
6053
6170
  (data) => onErrorRef.current?.(data)
6054
6171
  );
6055
6172
  element.mount(containerRef.current);
@@ -6079,15 +6196,15 @@ function PaymentElement({
6079
6196
  }, [onReady, onChange, onError]);
6080
6197
  React14.useEffect(() => {
6081
6198
  if (!elements || !containerRef.current) return;
6082
- const element = elements.create(chunkCV5QMDQS_js.ELEMENT_TYPES.PAYMENT, { amount, currency });
6199
+ const element = elements.create(chunkHPN5R3K2_js.ELEMENT_TYPES.PAYMENT, { amount, currency });
6083
6200
  elementRef.current = element;
6084
- element.on(chunkCV5QMDQS_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
6201
+ element.on(chunkHPN5R3K2_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
6085
6202
  element.on(
6086
- chunkCV5QMDQS_js.EVENT_TYPES.CHANGE,
6203
+ chunkHPN5R3K2_js.EVENT_TYPES.CHANGE,
6087
6204
  (data) => onChangeRef.current?.(data)
6088
6205
  );
6089
6206
  element.on(
6090
- chunkCV5QMDQS_js.EVENT_TYPES.ERROR,
6207
+ chunkHPN5R3K2_js.EVENT_TYPES.ERROR,
6091
6208
  (data) => onErrorRef.current?.(data)
6092
6209
  );
6093
6210
  element.mount(containerRef.current);
@@ -9626,6 +9743,39 @@ function ProductCustomizer({
9626
9743
  )
9627
9744
  ] });
9628
9745
  }
9746
+
9747
+ // src/react/utils/prefetch-policy.ts
9748
+ var SLOW_EFFECTIVE_TYPES = /* @__PURE__ */ new Set(["slow-2g", "2g"]);
9749
+ var MAX_CONCURRENT_SPECULATIVE = 4;
9750
+ var inFlight = 0;
9751
+ function connectionAllowsPrefetch() {
9752
+ if (typeof navigator === "undefined") return false;
9753
+ const connection = navigator.connection;
9754
+ if (!connection) return true;
9755
+ if (connection.saveData) return false;
9756
+ return !SLOW_EFFECTIVE_TYPES.has(connection.effectiveType ?? "");
9757
+ }
9758
+ function speculate(task) {
9759
+ if (!connectionAllowsPrefetch() || inFlight >= MAX_CONCURRENT_SPECULATIVE) return;
9760
+ const pending = task();
9761
+ if (!pending) return;
9762
+ inFlight++;
9763
+ pending.catch(() => {
9764
+ }).finally(() => {
9765
+ inFlight--;
9766
+ });
9767
+ }
9768
+
9769
+ // src/react/utils/preload-image.ts
9770
+ var preloaded = /* @__PURE__ */ new Set();
9771
+ function preloadImage(src) {
9772
+ if (!src || typeof window === "undefined") return;
9773
+ if (!connectionAllowsPrefetch() || preloaded.has(src)) return;
9774
+ preloaded.add(src);
9775
+ const image = new Image();
9776
+ image.decoding = "async";
9777
+ image.src = src;
9778
+ }
9629
9779
  var ASPECT_STYLES = {
9630
9780
  square: { aspectRatio: "1/1" },
9631
9781
  "4/3": { aspectRatio: "4/3" },
@@ -9658,6 +9808,8 @@ function ProductImageGallery({
9658
9808
  return null;
9659
9809
  }
9660
9810
  const activeImage = normalizedImages[selectedImage] || normalizedImages[0];
9811
+ preloadImage(normalizedImages[selectedImage + 1]);
9812
+ preloadImage(normalizedImages[selectedImage - 1]);
9661
9813
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-cimplify-image-gallery": true, className, children: [
9662
9814
  /* @__PURE__ */ jsxRuntime.jsx(
9663
9815
  "div",
@@ -9669,6 +9821,7 @@ function ProductImageGallery({
9669
9821
  {
9670
9822
  src: activeImage,
9671
9823
  alt: productName,
9824
+ fetchPriority: "high",
9672
9825
  style: {
9673
9826
  width: "100%",
9674
9827
  height: "100%",
@@ -9710,6 +9863,8 @@ function ProductImageGallery({
9710
9863
  {
9711
9864
  src: image,
9712
9865
  alt: "",
9866
+ loading: "lazy",
9867
+ decoding: "async",
9713
9868
  style: { width: "100%", height: "100%", objectFit: "cover" }
9714
9869
  }
9715
9870
  )
@@ -10698,6 +10853,63 @@ function ProductSheet({
10698
10853
  }
10699
10854
  );
10700
10855
  }
10856
+ var observers = /* @__PURE__ */ new Map();
10857
+ function observe(node, rootMargin, onEnter) {
10858
+ let shared = observers.get(rootMargin);
10859
+ if (!shared) {
10860
+ const targets = /* @__PURE__ */ new Map();
10861
+ const observer = new IntersectionObserver(
10862
+ (entries) => {
10863
+ for (const entry of entries) {
10864
+ if (!entry.isIntersecting) continue;
10865
+ const callback = targets.get(entry.target);
10866
+ if (callback) {
10867
+ unobserve(entry.target, rootMargin);
10868
+ callback();
10869
+ }
10870
+ }
10871
+ },
10872
+ { rootMargin }
10873
+ );
10874
+ shared = { observer, targets };
10875
+ observers.set(rootMargin, shared);
10876
+ }
10877
+ shared.targets.set(node, onEnter);
10878
+ shared.observer.observe(node);
10879
+ }
10880
+ function unobserve(node, rootMargin) {
10881
+ const shared = observers.get(rootMargin);
10882
+ if (!shared || !shared.targets.delete(node)) return;
10883
+ shared.observer.unobserve(node);
10884
+ if (shared.targets.size === 0) {
10885
+ shared.observer.disconnect();
10886
+ observers.delete(rootMargin);
10887
+ }
10888
+ }
10889
+ function useInViewport(onEnter, { rootMargin = "300px", disabled = false } = {}) {
10890
+ const onEnterRef = React14.useRef(onEnter);
10891
+ onEnterRef.current = onEnter;
10892
+ const attachedRef = React14.useRef(null);
10893
+ const firedRef = React14.useRef(false);
10894
+ return React14.useCallback(
10895
+ (node) => {
10896
+ if (attachedRef.current) {
10897
+ unobserve(attachedRef.current.node, attachedRef.current.rootMargin);
10898
+ attachedRef.current = null;
10899
+ }
10900
+ if (!node || disabled || firedRef.current) return;
10901
+ if (typeof IntersectionObserver === "undefined") return;
10902
+ attachedRef.current = { node, rootMargin };
10903
+ observe(node, rootMargin, () => {
10904
+ firedRef.current = true;
10905
+ attachedRef.current = null;
10906
+ onEnterRef.current();
10907
+ });
10908
+ },
10909
+ [rootMargin, disabled]
10910
+ );
10911
+ }
10912
+ var ImagePriorityContext = React14__default.default.createContext(false);
10701
10913
  function CardImage({
10702
10914
  src,
10703
10915
  alt,
@@ -10706,6 +10918,7 @@ function CardImage({
10706
10918
  className,
10707
10919
  children
10708
10920
  }) {
10921
+ const priority = React14__default.default.useContext(ImagePriorityContext);
10709
10922
  const aspectClass = {
10710
10923
  square: "aspect-square",
10711
10924
  "3/4": "aspect-[3/4]",
@@ -10713,11 +10926,14 @@ function CardImage({
10713
10926
  "16/9": "aspect-[16/9]"
10714
10927
  }[aspectRatio];
10715
10928
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-cimplify-card-image": true, className: cn("relative overflow-hidden bg-muted", aspectClass, className), children: [
10716
- renderImage ? renderImage({ src, alt, className: "w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-[1.04]" }) : src ? /* @__PURE__ */ jsxRuntime.jsx(
10929
+ renderImage ? renderImage({ src, alt, className: "w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-[1.04]", priority }) : src ? /* @__PURE__ */ jsxRuntime.jsx(
10717
10930
  "img",
10718
10931
  {
10719
10932
  src,
10720
10933
  alt,
10934
+ loading: priority ? "eager" : "lazy",
10935
+ decoding: priority ? "auto" : "async",
10936
+ fetchPriority: priority ? "high" : void 0,
10721
10937
  className: "w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-[1.04]"
10722
10938
  }
10723
10939
  ) : null,
@@ -11657,25 +11873,41 @@ function ProductCard({
11657
11873
  onQuickAdd,
11658
11874
  children,
11659
11875
  aspectRatio = "4/3",
11876
+ prefetch: prefetchProp,
11660
11877
  className,
11661
11878
  classNames
11662
11879
  }) {
11663
11880
  const mode = displayMode ?? product.display_mode ?? "card";
11664
11881
  const [isOpen, setIsOpen] = React14.useState(false);
11665
- const [shouldFetch, setShouldFetch] = React14.useState(false);
11666
- const { product: productDetails } = useProduct(
11667
- product.slug ?? product.id,
11668
- { enabled: shouldFetch || isOpen }
11669
- );
11670
- const handlePrefetch = React14.useCallback(() => {
11671
- setShouldFetch(true);
11672
- }, []);
11673
- const handleOpenChange = React14.useCallback((open) => {
11674
- setIsOpen(open);
11675
- if (open) {
11676
- setShouldFetch(true);
11882
+ const context = useOptionalCimplifyClient();
11883
+ const client = context?.client ?? null;
11884
+ const prefetchConfig = context?.prefetch ?? DEFAULT_PREFETCH_OPTIONS;
11885
+ const LinkComponent = context?.linkComponent ?? null;
11886
+ const prefetchMode = prefetchProp ?? prefetchConfig.mode;
11887
+ const imagePriority = React14.useContext(ImagePriorityContext);
11888
+ const { product: productDetails } = useProduct(product.slug ?? product.id, {
11889
+ enabled: isOpen
11890
+ });
11891
+ const warm = React14.useCallback(() => {
11892
+ if (!client || prefetchMode === "off") return;
11893
+ speculate(() => prefetchProduct(client, product.slug ?? product.id));
11894
+ if (prefetchConfig.images) {
11895
+ preloadImage(product.images?.[0] || product.image_url);
11677
11896
  }
11678
- }, []);
11897
+ }, [client, prefetchMode, prefetchConfig.images, product]);
11898
+ const viewportRef = useInViewport(warm, {
11899
+ rootMargin: prefetchConfig.rootMargin,
11900
+ disabled: prefetchMode !== "aggressive"
11901
+ });
11902
+ const handleOpenChange = React14.useCallback(
11903
+ (open) => {
11904
+ setIsOpen(open);
11905
+ if (open && client) {
11906
+ trackProductView(client, product);
11907
+ }
11908
+ },
11909
+ [client, product]
11910
+ );
11679
11911
  const handleClose = React14.useCallback(() => {
11680
11912
  setIsOpen(false);
11681
11913
  }, []);
@@ -11704,6 +11936,9 @@ function ProductCard({
11704
11936
  {
11705
11937
  src: imageUrl,
11706
11938
  alt: product.name,
11939
+ loading: imagePriority ? "eager" : "lazy",
11940
+ decoding: imagePriority ? "auto" : "async",
11941
+ fetchPriority: imagePriority ? "high" : void 0,
11707
11942
  className: cn("w-full h-full object-cover transition-transform duration-300 group-hover:scale-105", classNames?.image),
11708
11943
  "data-cimplify-product-card-image": true
11709
11944
  }
@@ -11721,12 +11956,33 @@ function ProductCard({
11721
11956
  const linkHref = href ?? `/menu/${product.slug}`;
11722
11957
  const linkClassName = cn("group block no-underline text-[inherit] rounded-xl border border-border bg-background transition-shadow duration-200 hover:shadow-md", className, classNames?.root);
11723
11958
  if (renderLink) {
11724
- return renderLink({ href: linkHref, className: linkClassName, children: cardBody });
11959
+ return renderLink({
11960
+ href: linkHref,
11961
+ className: linkClassName,
11962
+ children: cardBody,
11963
+ onPointerEnter: warm,
11964
+ onFocus: warm
11965
+ });
11966
+ }
11967
+ if (LinkComponent) {
11968
+ return /* @__PURE__ */ jsxRuntime.jsx(
11969
+ LinkComponent,
11970
+ {
11971
+ href: linkHref,
11972
+ className: linkClassName,
11973
+ onPointerEnter: warm,
11974
+ onFocus: warm,
11975
+ children: cardBody
11976
+ }
11977
+ );
11725
11978
  }
11726
11979
  return /* @__PURE__ */ jsxRuntime.jsx(
11727
11980
  "a",
11728
11981
  {
11729
11982
  href: linkHref,
11983
+ ref: viewportRef,
11984
+ onPointerEnter: warm,
11985
+ onFocus: warm,
11730
11986
  "data-cimplify-product-card": true,
11731
11987
  "data-display-mode": "page",
11732
11988
  className: linkClassName,
@@ -11738,7 +11994,9 @@ function ProductCard({
11738
11994
  /* @__PURE__ */ jsxRuntime.jsx(
11739
11995
  dialog.Dialog.Trigger,
11740
11996
  {
11741
- onPointerEnter: handlePrefetch,
11997
+ ref: viewportRef,
11998
+ onPointerEnter: warm,
11999
+ onFocus: warm,
11742
12000
  "data-cimplify-product-card": true,
11743
12001
  "data-display-mode": "card",
11744
12002
  className: cn(
@@ -11840,21 +12098,18 @@ function ProductGrid({
11840
12098
  id: gridId,
11841
12099
  "data-cimplify-product-grid": true,
11842
12100
  className: cn(className, classNames?.root),
11843
- children: products.map((product) => /* @__PURE__ */ jsxRuntime.jsx(
11844
- "div",
11845
- {
11846
- "data-cimplify-product-grid-item": true,
11847
- className: classNames?.item,
11848
- children: renderCard ? renderCard(product) : /* @__PURE__ */ jsxRuntime.jsx(
11849
- ProductCard,
11850
- {
11851
- product,
11852
- renderImage
11853
- }
11854
- )
11855
- },
11856
- product.id
11857
- ))
12101
+ children: products.map((product, index) => {
12102
+ const card = renderCard ? renderCard(product) : /* @__PURE__ */ jsxRuntime.jsx(ProductCard, { product, renderImage });
12103
+ return /* @__PURE__ */ jsxRuntime.jsx(
12104
+ "div",
12105
+ {
12106
+ "data-cimplify-product-grid-item": true,
12107
+ className: classNames?.item,
12108
+ children: index < xl ? /* @__PURE__ */ jsxRuntime.jsx(ImagePriorityContext.Provider, { value: true, children: card }) : card
12109
+ },
12110
+ product.id
12111
+ );
12112
+ })
11858
12113
  }
11859
12114
  )
11860
12115
  ] });
@@ -11895,6 +12150,15 @@ function SearchInput({
11895
12150
  [searchOptions, categoryId]
11896
12151
  );
11897
12152
  const { results, isLoading, query, setQuery, clear } = useSearch(mergedOptions);
12153
+ const context = useOptionalCimplifyClient();
12154
+ const warmResult = React14.useCallback(
12155
+ (product) => {
12156
+ const client = mergedOptions.client ?? context?.client;
12157
+ if (!client || context?.prefetch.mode === "off") return;
12158
+ speculate(() => prefetchProduct(client, product.slug ?? product.id));
12159
+ },
12160
+ [mergedOptions.client, context]
12161
+ );
11898
12162
  const handleValueChange = React14.useCallback(
11899
12163
  (value) => {
11900
12164
  setQuery(value);
@@ -11959,6 +12223,8 @@ function SearchInput({
11959
12223
  {
11960
12224
  type: "button",
11961
12225
  onClick: () => onResultClick?.(product),
12226
+ onPointerEnter: () => warmResult(product),
12227
+ onFocus: () => warmResult(product),
11962
12228
  "data-cimplify-search-result": true,
11963
12229
  className: classNames?.resultItem,
11964
12230
  style: !renderResult ? { display: "flex", alignItems: "center", gap: "0.5rem", width: "100%" } : void 0,
@@ -13668,18 +13934,24 @@ function CataloguePage({
13668
13934
  const [maxPrice, setMaxPrice] = React14.useState("");
13669
13935
  const [page, setPage] = React14.useState(1);
13670
13936
  const debouncedSearch = useDebounce(searchQuery, 300);
13937
+ const filterOptions = React14.useMemo(
13938
+ () => ({
13939
+ category: selectedCategory ?? void 0,
13940
+ search: debouncedSearch.length >= 2 ? debouncedSearch : void 0,
13941
+ sort_by: sortBy,
13942
+ sort_order: sortOrder,
13943
+ in_stock: inStockOnly || void 0,
13944
+ tags: selectedTags.length > 0 ? selectedTags : void 0,
13945
+ min_price: minPrice ? parseFloat(minPrice) : void 0,
13946
+ max_price: maxPrice ? parseFloat(maxPrice) : void 0,
13947
+ limit: pageSize
13948
+ }),
13949
+ [selectedCategory, debouncedSearch, sortBy, sortOrder, inStockOnly, selectedTags, minPrice, maxPrice, pageSize]
13950
+ );
13671
13951
  const { products: fetchedProducts, isLoading, pagination } = useProducts({
13952
+ ...filterOptions,
13672
13953
  enabled: productsProp === void 0,
13673
- category: selectedCategory ?? void 0,
13674
- search: debouncedSearch.length >= 2 ? debouncedSearch : void 0,
13675
- sort_by: sortBy,
13676
- sort_order: sortOrder,
13677
- in_stock: inStockOnly || void 0,
13678
- tags: selectedTags.length > 0 ? selectedTags : void 0,
13679
- min_price: minPrice ? parseFloat(minPrice) : void 0,
13680
- max_price: maxPrice ? parseFloat(maxPrice) : void 0,
13681
- page,
13682
- limit: pageSize
13954
+ page
13683
13955
  });
13684
13956
  const { categories: fetchedCategories } = useCategories({
13685
13957
  enabled: categoriesProp === void 0
@@ -13687,6 +13959,10 @@ function CataloguePage({
13687
13959
  const products = productsProp ?? fetchedProducts;
13688
13960
  const categories = categoriesProp ?? fetchedCategories;
13689
13961
  const totalPages = pagination?.total_pages ?? 1;
13962
+ const context = useOptionalCimplifyClient();
13963
+ if (context && context.prefetch.mode !== "off" && productsProp === void 0 && !isLoading && page < totalPages) {
13964
+ speculate(() => prefetchProducts(context.client, { ...filterOptions, page: page + 1 }));
13965
+ }
13690
13966
  const handleCategoryChange = React14.useCallback((id) => {
13691
13967
  setSelectedCategory(id);
13692
13968
  setPage(1);
@@ -14588,6 +14864,12 @@ function ProductPage({
14588
14864
  enabled: !productProp && resolvedId.length > 0
14589
14865
  });
14590
14866
  const product = productProp ?? fetched;
14867
+ const context = useOptionalCimplifyClient();
14868
+ React14.useEffect(() => {
14869
+ if (product && context) {
14870
+ trackProductView(context.client, product);
14871
+ }
14872
+ }, [context, product]);
14591
14873
  if (isLoading && !product) {
14592
14874
  return /* @__PURE__ */ jsxRuntime.jsx(
14593
14875
  "div",
@@ -16012,6 +16294,15 @@ function RecommendationCarousel({
16012
16294
  enabled: recommendationsProp === void 0
16013
16295
  });
16014
16296
  const recommendations = recommendationsProp ?? fetched;
16297
+ const context = useOptionalCimplifyClient();
16298
+ const warmRecommendation = React14.useCallback(
16299
+ (rec) => {
16300
+ const productId = rec.product?.id;
16301
+ if (!productId || !context || context.prefetch.mode === "off") return;
16302
+ speculate(() => prefetchProduct(context.client, productId));
16303
+ },
16304
+ [context]
16305
+ );
16015
16306
  if (isLoading && recommendations.length === 0) {
16016
16307
  return /* @__PURE__ */ jsxRuntime.jsx(
16017
16308
  "div",
@@ -16038,6 +16329,8 @@ function RecommendationCarousel({
16038
16329
  {
16039
16330
  type: "button",
16040
16331
  onClick: () => onProductClick?.(rec),
16332
+ onPointerEnter: () => warmRecommendation(rec),
16333
+ onFocus: () => warmRecommendation(rec),
16041
16334
  "data-cimplify-recommendation-item": true,
16042
16335
  className: classNames?.item,
16043
16336
  style: { flexShrink: 0 },
@@ -16116,6 +16409,14 @@ function RecentlyViewed({
16116
16409
  classNames
16117
16410
  }) {
16118
16411
  const { state, isLoading } = useActivityState();
16412
+ const context = useOptionalCimplifyClient();
16413
+ const warmViewed = React14.useCallback(
16414
+ (productId) => {
16415
+ if (!context || context.prefetch.mode === "off") return;
16416
+ speculate(() => prefetchProduct(context.client, productId));
16417
+ },
16418
+ [context]
16419
+ );
16119
16420
  const rawViewed = state?.activity?.viewed_products ?? [];
16120
16421
  const viewed = limit ? rawViewed.slice(0, limit) : rawViewed;
16121
16422
  if (isLoading && viewed.length === 0) {
@@ -16136,6 +16437,8 @@ function RecentlyViewed({
16136
16437
  {
16137
16438
  type: "button",
16138
16439
  onClick: () => onProductClick?.(product),
16440
+ onPointerEnter: () => warmViewed(product.product_id),
16441
+ onFocus: () => warmViewed(product.product_id),
16139
16442
  "data-cimplify-recently-viewed-item": true,
16140
16443
  className: classNames?.item,
16141
16444
  children: renderProduct ? renderProduct(product) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: product.product_name ?? product.product_id })
@@ -16956,6 +17259,8 @@ exports.WholesaleProductCard = WholesaleProductCard;
16956
17259
  exports.WholesaleProductLayout = WholesaleProductLayout;
16957
17260
  exports.WishlistButton = WishlistButton;
16958
17261
  exports.cn = cn;
17262
+ exports.prefetchProduct = prefetchProduct;
17263
+ exports.prefetchProducts = prefetchProducts;
16959
17264
  exports.roomToResource = roomToResource;
16960
17265
  exports.sanitizeRichTextHtml = sanitizeRichTextHtml;
16961
17266
  exports.stripHtmlToText = stripHtmlToText;
@@ -16982,6 +17287,7 @@ exports.useCollection = useCollection;
16982
17287
  exports.useCollections = useCollections;
16983
17288
  exports.useDeals = useDeals;
16984
17289
  exports.useDeliveryFee = useDeliveryFee;
17290
+ exports.useDeliveryOptions = useDeliveryOptions;
16985
17291
  exports.useElements = useElements;
16986
17292
  exports.useElementsReady = useElementsReady;
16987
17293
  exports.useFxRate = useFxRate;