@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.mjs CHANGED
@@ -1,13 +1,14 @@
1
1
  "use client";
2
- import { DURATION_UNIT, getVariantDisplayName, INPUT_FIELD_TYPE, PRODUCT_TYPE, resolveGallery, RENDER_HINT } from './chunk-E6T5VJMG.mjs';
2
+ import { DURATION_UNIT, getVariantDisplayName, INPUT_FIELD_TYPE, PRODUCT_TYPE, resolveGallery, RENDER_HINT, DEFAULT_CDN_BASE_URL } from './chunk-E6T5VJMG.mjs';
3
3
  export { getVariantDisplayName } from './chunk-E6T5VJMG.mjs';
4
- import { createCimplifyClient } from './chunk-LBFTEXGD.mjs';
5
- import { ELEMENT_TYPES, EVENT_TYPES, startSignIn } from './chunk-3BKMNVTR.mjs';
4
+ import { createCimplifyClient } from './chunk-NWUEWUX2.mjs';
5
+ import { ELEMENT_TYPES, EVENT_TYPES, startSignIn } from './chunk-7BM56JET.mjs';
6
6
  import { parsePrice, formatMoney, formatPrice, getProductCurrency, getUnitPriceAtQuantity, isOnSale, getDiscountPercentage, getBasePrice, getPriceRange, formatPriceRange } from './chunk-TD3AY34U.mjs';
7
7
  import { isSupportedCurrency } from './chunk-AMZXALF6.mjs';
8
8
  import './chunk-3G6RQLXK.mjs';
9
9
  import React14, { createContext, useRef, useState, useCallback, useEffect, useContext, useMemo, useId, useSyncExternalStore } from 'react';
10
10
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
11
+ import * as ReactDOM from 'react-dom';
11
12
  import { clsx } from 'clsx';
12
13
  import { twMerge } from 'tailwind-merge';
13
14
  import { format, parseISO, isValid } from 'date-fns';
@@ -1076,6 +1077,28 @@ function useCart(options = {}) {
1076
1077
  ]
1077
1078
  );
1078
1079
  }
1080
+ var reactPreconnect = typeof ReactDOM.preconnect === "function" ? ReactDOM.preconnect : void 0;
1081
+ var connected = /* @__PURE__ */ new Set();
1082
+ function preconnectOrigin(url, crossOrigin) {
1083
+ let origin;
1084
+ try {
1085
+ origin = new URL(url).origin;
1086
+ } catch {
1087
+ return;
1088
+ }
1089
+ if (reactPreconnect) {
1090
+ reactPreconnect(origin, crossOrigin ? { crossOrigin } : void 0);
1091
+ return;
1092
+ }
1093
+ if (typeof document === "undefined") return;
1094
+ if (origin === window.location.origin || connected.has(origin)) return;
1095
+ connected.add(origin);
1096
+ const link = document.createElement("link");
1097
+ link.rel = "preconnect";
1098
+ link.href = origin;
1099
+ if (crossOrigin) link.crossOrigin = crossOrigin;
1100
+ document.head.appendChild(link);
1101
+ }
1079
1102
  var LOCATION_STORAGE_KEY = "cimplify_location_id";
1080
1103
  var DISPLAY_CURRENCY_STORAGE_KEY = "cimplify_display_currency";
1081
1104
  var FX_REFRESH_INTERVAL = 12e4;
@@ -1141,6 +1164,11 @@ function resolveInitialLocation(locations) {
1141
1164
  }
1142
1165
  return locations[0];
1143
1166
  }
1167
+ var DEFAULT_PREFETCH_OPTIONS = {
1168
+ mode: "aggressive",
1169
+ rootMargin: "300px",
1170
+ images: true
1171
+ };
1144
1172
  var CimplifyClientContext = createContext(null);
1145
1173
  var CimplifyStateContext = createContext(null);
1146
1174
  function CimplifyProvider({
@@ -1149,9 +1177,19 @@ function CimplifyProvider({
1149
1177
  onLocationChange,
1150
1178
  initialBusiness,
1151
1179
  initialLocations,
1152
- optimistic = true
1180
+ optimistic = true,
1181
+ prefetch,
1182
+ linkComponent
1153
1183
  }) {
1154
1184
  const resolvedClient = useMemo(() => client ?? createDefaultClient(), [client]);
1185
+ const resolvedPrefetch = useMemo(
1186
+ () => ({
1187
+ mode: prefetch?.mode ?? DEFAULT_PREFETCH_OPTIONS.mode,
1188
+ rootMargin: prefetch?.rootMargin ?? DEFAULT_PREFETCH_OPTIONS.rootMargin,
1189
+ images: prefetch?.images ?? DEFAULT_PREFETCH_OPTIONS.images
1190
+ }),
1191
+ [prefetch?.mode, prefetch?.rootMargin, prefetch?.images]
1192
+ );
1155
1193
  const onLocationChangeRef = useRef(onLocationChange);
1156
1194
  const seeded = initialBusiness !== void 0;
1157
1195
  const initialBootstrapDone = useRef(seeded);
@@ -1218,6 +1256,12 @@ function CimplifyProvider({
1218
1256
  },
1219
1257
  [fxRate, displayCurrency, baseCurrency]
1220
1258
  );
1259
+ if (resolvedPrefetch.mode !== "off") {
1260
+ const apiCredentials = resolvedClient.getCredentialsMode() === "include" ? "use-credentials" : "anonymous";
1261
+ preconnectOrigin(resolvedClient.getBaseUrl(), apiCredentials);
1262
+ preconnectOrigin(resolvedClient.getLinkApiUrl(), apiCredentials);
1263
+ preconnectOrigin(DEFAULT_CDN_BASE_URL);
1264
+ }
1221
1265
  const setCurrentLocation = useCallback(
1222
1266
  (location) => {
1223
1267
  const previousLocationId = resolvedClient.getLocationId();
@@ -1291,7 +1335,9 @@ function CimplifyProvider({
1291
1335
  locations,
1292
1336
  isReady,
1293
1337
  baseCurrency,
1294
- optimistic
1338
+ optimistic,
1339
+ prefetch: resolvedPrefetch,
1340
+ linkComponent: linkComponent ?? null
1295
1341
  }),
1296
1342
  [
1297
1343
  resolvedClient,
@@ -1299,7 +1345,9 @@ function CimplifyProvider({
1299
1345
  baseCurrency,
1300
1346
  locations,
1301
1347
  isReady,
1302
- optimistic
1348
+ optimistic,
1349
+ resolvedPrefetch,
1350
+ linkComponent
1303
1351
  ]
1304
1352
  );
1305
1353
  const stateContextValue = useMemo(
@@ -4321,6 +4369,16 @@ function createCachedQuery(config) {
4321
4369
  }, [cacheKey2, load]);
4322
4370
  return { data, isLoading, error, refetch };
4323
4371
  }
4372
+ useCachedQuery.prefetch = (client, options) => {
4373
+ const key = config.key(client, options);
4374
+ if (cache.has(key) || inflight.has(key)) return void 0;
4375
+ const promise = config.fetch(client, options);
4376
+ inflight.set(key, promise);
4377
+ return promise.then((value) => {
4378
+ cache.set(key, { data: value, ts: Date.now() });
4379
+ }).catch(() => {
4380
+ }).finally(() => inflight.delete(key));
4381
+ };
4324
4382
  useCachedQuery.clear = () => {
4325
4383
  cache.clear();
4326
4384
  inflight.clear();
@@ -4377,6 +4435,9 @@ var productsQuery = createCachedQuery({
4377
4435
  };
4378
4436
  }
4379
4437
  });
4438
+ function prefetchProducts(client, options) {
4439
+ return productsQuery.prefetch(client, options);
4440
+ }
4380
4441
  function useProducts(options = {}) {
4381
4442
  const { data, isLoading, error, refetch } = productsQuery(options);
4382
4443
  return {
@@ -4401,14 +4462,27 @@ var productQuery = createCachedQuery({
4401
4462
  fetch: async (client, options) => {
4402
4463
  const result = isLikelySlug(options.slugOrId) ? await client.catalogue.getProductBySlug(options.slugOrId) : await client.catalogue.getProduct(options.slugOrId);
4403
4464
  if (!result.ok) throw result.error;
4404
- client.activity.trackProductView(result.value.id, {
4405
- productName: result.value.name,
4406
- categoryId: result.value.category_id,
4407
- price: String(result.value.default_price)
4408
- });
4409
4465
  return result.value;
4410
4466
  }
4411
4467
  });
4468
+ function prefetchProduct(client, slugOrId) {
4469
+ const normalized = (slugOrId || "").trim();
4470
+ if (!normalized) return void 0;
4471
+ return productQuery.prefetch(client, { slugOrId: normalized });
4472
+ }
4473
+ var VIEW_DEDUPE_WINDOW_MS = 3e5;
4474
+ var recentlyTracked = /* @__PURE__ */ new Map();
4475
+ function trackProductView(client, product) {
4476
+ const now = Date.now();
4477
+ const last = recentlyTracked.get(product.id);
4478
+ if (last !== void 0 && now - last < VIEW_DEDUPE_WINDOW_MS) return;
4479
+ recentlyTracked.set(product.id, now);
4480
+ client.activity.trackProductView(product.id, {
4481
+ productName: product.name,
4482
+ categoryId: product.category_id,
4483
+ price: String(product.default_price)
4484
+ });
4485
+ }
4412
4486
  function useProduct(slugOrId, options = {}) {
4413
4487
  const normalized = (slugOrId || "").trim();
4414
4488
  const { data, isLoading, error, refetch } = productQuery({
@@ -5707,6 +5781,30 @@ function useDeliveryFee(options) {
5707
5781
  return { fee: data, isLoading, error, refetch };
5708
5782
  }
5709
5783
 
5784
+ // src/react/hooks/use-delivery-options.ts
5785
+ var deliveryOptionsQuery = createCachedQuery({
5786
+ name: "useDeliveryOptions",
5787
+ key: (client, options) => cacheKey(
5788
+ client.getPublicKey(),
5789
+ options.latitude,
5790
+ options.longitude,
5791
+ options.country,
5792
+ options.orderValue
5793
+ ),
5794
+ fetch: async (client, options) => {
5795
+ const result = await client.delivery.getOptions(options.latitude, options.longitude, {
5796
+ country: options.country,
5797
+ orderValue: options.orderValue
5798
+ });
5799
+ if (!result.ok) throw result.error;
5800
+ return result.value;
5801
+ }
5802
+ });
5803
+ function useDeliveryOptions(options) {
5804
+ const { data, isLoading, error, refetch } = deliveryOptionsQuery(options);
5805
+ return { options: data, isLoading, error, refetch };
5806
+ }
5807
+
5710
5808
  // src/react/hooks/use-fx-rate.ts
5711
5809
  var fxRateQuery = createCachedQuery({
5712
5810
  name: "useFxRate",
@@ -9621,6 +9719,39 @@ function ProductCustomizer({
9621
9719
  )
9622
9720
  ] });
9623
9721
  }
9722
+
9723
+ // src/react/utils/prefetch-policy.ts
9724
+ var SLOW_EFFECTIVE_TYPES = /* @__PURE__ */ new Set(["slow-2g", "2g"]);
9725
+ var MAX_CONCURRENT_SPECULATIVE = 4;
9726
+ var inFlight = 0;
9727
+ function connectionAllowsPrefetch() {
9728
+ if (typeof navigator === "undefined") return false;
9729
+ const connection = navigator.connection;
9730
+ if (!connection) return true;
9731
+ if (connection.saveData) return false;
9732
+ return !SLOW_EFFECTIVE_TYPES.has(connection.effectiveType ?? "");
9733
+ }
9734
+ function speculate(task) {
9735
+ if (!connectionAllowsPrefetch() || inFlight >= MAX_CONCURRENT_SPECULATIVE) return;
9736
+ const pending = task();
9737
+ if (!pending) return;
9738
+ inFlight++;
9739
+ pending.catch(() => {
9740
+ }).finally(() => {
9741
+ inFlight--;
9742
+ });
9743
+ }
9744
+
9745
+ // src/react/utils/preload-image.ts
9746
+ var preloaded = /* @__PURE__ */ new Set();
9747
+ function preloadImage(src) {
9748
+ if (!src || typeof window === "undefined") return;
9749
+ if (!connectionAllowsPrefetch() || preloaded.has(src)) return;
9750
+ preloaded.add(src);
9751
+ const image = new Image();
9752
+ image.decoding = "async";
9753
+ image.src = src;
9754
+ }
9624
9755
  var ASPECT_STYLES = {
9625
9756
  square: { aspectRatio: "1/1" },
9626
9757
  "4/3": { aspectRatio: "4/3" },
@@ -9653,6 +9784,8 @@ function ProductImageGallery({
9653
9784
  return null;
9654
9785
  }
9655
9786
  const activeImage = normalizedImages[selectedImage] || normalizedImages[0];
9787
+ preloadImage(normalizedImages[selectedImage + 1]);
9788
+ preloadImage(normalizedImages[selectedImage - 1]);
9656
9789
  return /* @__PURE__ */ jsxs("div", { "data-cimplify-image-gallery": true, className, children: [
9657
9790
  /* @__PURE__ */ jsx(
9658
9791
  "div",
@@ -9664,6 +9797,7 @@ function ProductImageGallery({
9664
9797
  {
9665
9798
  src: activeImage,
9666
9799
  alt: productName,
9800
+ fetchPriority: "high",
9667
9801
  style: {
9668
9802
  width: "100%",
9669
9803
  height: "100%",
@@ -9705,6 +9839,8 @@ function ProductImageGallery({
9705
9839
  {
9706
9840
  src: image,
9707
9841
  alt: "",
9842
+ loading: "lazy",
9843
+ decoding: "async",
9708
9844
  style: { width: "100%", height: "100%", objectFit: "cover" }
9709
9845
  }
9710
9846
  )
@@ -10693,6 +10829,63 @@ function ProductSheet({
10693
10829
  }
10694
10830
  );
10695
10831
  }
10832
+ var observers = /* @__PURE__ */ new Map();
10833
+ function observe(node, rootMargin, onEnter) {
10834
+ let shared = observers.get(rootMargin);
10835
+ if (!shared) {
10836
+ const targets = /* @__PURE__ */ new Map();
10837
+ const observer = new IntersectionObserver(
10838
+ (entries) => {
10839
+ for (const entry of entries) {
10840
+ if (!entry.isIntersecting) continue;
10841
+ const callback = targets.get(entry.target);
10842
+ if (callback) {
10843
+ unobserve(entry.target, rootMargin);
10844
+ callback();
10845
+ }
10846
+ }
10847
+ },
10848
+ { rootMargin }
10849
+ );
10850
+ shared = { observer, targets };
10851
+ observers.set(rootMargin, shared);
10852
+ }
10853
+ shared.targets.set(node, onEnter);
10854
+ shared.observer.observe(node);
10855
+ }
10856
+ function unobserve(node, rootMargin) {
10857
+ const shared = observers.get(rootMargin);
10858
+ if (!shared || !shared.targets.delete(node)) return;
10859
+ shared.observer.unobserve(node);
10860
+ if (shared.targets.size === 0) {
10861
+ shared.observer.disconnect();
10862
+ observers.delete(rootMargin);
10863
+ }
10864
+ }
10865
+ function useInViewport(onEnter, { rootMargin = "300px", disabled = false } = {}) {
10866
+ const onEnterRef = useRef(onEnter);
10867
+ onEnterRef.current = onEnter;
10868
+ const attachedRef = useRef(null);
10869
+ const firedRef = useRef(false);
10870
+ return useCallback(
10871
+ (node) => {
10872
+ if (attachedRef.current) {
10873
+ unobserve(attachedRef.current.node, attachedRef.current.rootMargin);
10874
+ attachedRef.current = null;
10875
+ }
10876
+ if (!node || disabled || firedRef.current) return;
10877
+ if (typeof IntersectionObserver === "undefined") return;
10878
+ attachedRef.current = { node, rootMargin };
10879
+ observe(node, rootMargin, () => {
10880
+ firedRef.current = true;
10881
+ attachedRef.current = null;
10882
+ onEnterRef.current();
10883
+ });
10884
+ },
10885
+ [rootMargin, disabled]
10886
+ );
10887
+ }
10888
+ var ImagePriorityContext = React14.createContext(false);
10696
10889
  function CardImage({
10697
10890
  src,
10698
10891
  alt,
@@ -10701,6 +10894,7 @@ function CardImage({
10701
10894
  className,
10702
10895
  children
10703
10896
  }) {
10897
+ const priority = React14.useContext(ImagePriorityContext);
10704
10898
  const aspectClass = {
10705
10899
  square: "aspect-square",
10706
10900
  "3/4": "aspect-[3/4]",
@@ -10708,11 +10902,14 @@ function CardImage({
10708
10902
  "16/9": "aspect-[16/9]"
10709
10903
  }[aspectRatio];
10710
10904
  return /* @__PURE__ */ jsxs("div", { "data-cimplify-card-image": true, className: cn("relative overflow-hidden bg-muted", aspectClass, className), children: [
10711
- renderImage ? renderImage({ src, alt, className: "w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-[1.04]" }) : src ? /* @__PURE__ */ jsx(
10905
+ 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__ */ jsx(
10712
10906
  "img",
10713
10907
  {
10714
10908
  src,
10715
10909
  alt,
10910
+ loading: priority ? "eager" : "lazy",
10911
+ decoding: priority ? "auto" : "async",
10912
+ fetchPriority: priority ? "high" : void 0,
10716
10913
  className: "w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-[1.04]"
10717
10914
  }
10718
10915
  ) : null,
@@ -11652,25 +11849,41 @@ function ProductCard({
11652
11849
  onQuickAdd,
11653
11850
  children,
11654
11851
  aspectRatio = "4/3",
11852
+ prefetch: prefetchProp,
11655
11853
  className,
11656
11854
  classNames
11657
11855
  }) {
11658
11856
  const mode = displayMode ?? product.display_mode ?? "card";
11659
11857
  const [isOpen, setIsOpen] = useState(false);
11660
- const [shouldFetch, setShouldFetch] = useState(false);
11661
- const { product: productDetails } = useProduct(
11662
- product.slug ?? product.id,
11663
- { enabled: shouldFetch || isOpen }
11664
- );
11665
- const handlePrefetch = useCallback(() => {
11666
- setShouldFetch(true);
11667
- }, []);
11668
- const handleOpenChange = useCallback((open) => {
11669
- setIsOpen(open);
11670
- if (open) {
11671
- setShouldFetch(true);
11858
+ const context = useOptionalCimplifyClient();
11859
+ const client = context?.client ?? null;
11860
+ const prefetchConfig = context?.prefetch ?? DEFAULT_PREFETCH_OPTIONS;
11861
+ const LinkComponent = context?.linkComponent ?? null;
11862
+ const prefetchMode = prefetchProp ?? prefetchConfig.mode;
11863
+ const imagePriority = useContext(ImagePriorityContext);
11864
+ const { product: productDetails } = useProduct(product.slug ?? product.id, {
11865
+ enabled: isOpen
11866
+ });
11867
+ const warm = useCallback(() => {
11868
+ if (!client || prefetchMode === "off") return;
11869
+ speculate(() => prefetchProduct(client, product.slug ?? product.id));
11870
+ if (prefetchConfig.images) {
11871
+ preloadImage(product.images?.[0] || product.image_url);
11672
11872
  }
11673
- }, []);
11873
+ }, [client, prefetchMode, prefetchConfig.images, product]);
11874
+ const viewportRef = useInViewport(warm, {
11875
+ rootMargin: prefetchConfig.rootMargin,
11876
+ disabled: prefetchMode !== "aggressive"
11877
+ });
11878
+ const handleOpenChange = useCallback(
11879
+ (open) => {
11880
+ setIsOpen(open);
11881
+ if (open && client) {
11882
+ trackProductView(client, product);
11883
+ }
11884
+ },
11885
+ [client, product]
11886
+ );
11674
11887
  const handleClose = useCallback(() => {
11675
11888
  setIsOpen(false);
11676
11889
  }, []);
@@ -11699,6 +11912,9 @@ function ProductCard({
11699
11912
  {
11700
11913
  src: imageUrl,
11701
11914
  alt: product.name,
11915
+ loading: imagePriority ? "eager" : "lazy",
11916
+ decoding: imagePriority ? "auto" : "async",
11917
+ fetchPriority: imagePriority ? "high" : void 0,
11702
11918
  className: cn("w-full h-full object-cover transition-transform duration-300 group-hover:scale-105", classNames?.image),
11703
11919
  "data-cimplify-product-card-image": true
11704
11920
  }
@@ -11716,12 +11932,33 @@ function ProductCard({
11716
11932
  const linkHref = href ?? `/menu/${product.slug}`;
11717
11933
  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);
11718
11934
  if (renderLink) {
11719
- return renderLink({ href: linkHref, className: linkClassName, children: cardBody });
11935
+ return renderLink({
11936
+ href: linkHref,
11937
+ className: linkClassName,
11938
+ children: cardBody,
11939
+ onPointerEnter: warm,
11940
+ onFocus: warm
11941
+ });
11942
+ }
11943
+ if (LinkComponent) {
11944
+ return /* @__PURE__ */ jsx(
11945
+ LinkComponent,
11946
+ {
11947
+ href: linkHref,
11948
+ className: linkClassName,
11949
+ onPointerEnter: warm,
11950
+ onFocus: warm,
11951
+ children: cardBody
11952
+ }
11953
+ );
11720
11954
  }
11721
11955
  return /* @__PURE__ */ jsx(
11722
11956
  "a",
11723
11957
  {
11724
11958
  href: linkHref,
11959
+ ref: viewportRef,
11960
+ onPointerEnter: warm,
11961
+ onFocus: warm,
11725
11962
  "data-cimplify-product-card": true,
11726
11963
  "data-display-mode": "page",
11727
11964
  className: linkClassName,
@@ -11733,7 +11970,9 @@ function ProductCard({
11733
11970
  /* @__PURE__ */ jsx(
11734
11971
  Dialog.Trigger,
11735
11972
  {
11736
- onPointerEnter: handlePrefetch,
11973
+ ref: viewportRef,
11974
+ onPointerEnter: warm,
11975
+ onFocus: warm,
11737
11976
  "data-cimplify-product-card": true,
11738
11977
  "data-display-mode": "card",
11739
11978
  className: cn(
@@ -11835,21 +12074,18 @@ function ProductGrid({
11835
12074
  id: gridId,
11836
12075
  "data-cimplify-product-grid": true,
11837
12076
  className: cn(className, classNames?.root),
11838
- children: products.map((product) => /* @__PURE__ */ jsx(
11839
- "div",
11840
- {
11841
- "data-cimplify-product-grid-item": true,
11842
- className: classNames?.item,
11843
- children: renderCard ? renderCard(product) : /* @__PURE__ */ jsx(
11844
- ProductCard,
11845
- {
11846
- product,
11847
- renderImage
11848
- }
11849
- )
11850
- },
11851
- product.id
11852
- ))
12077
+ children: products.map((product, index) => {
12078
+ const card = renderCard ? renderCard(product) : /* @__PURE__ */ jsx(ProductCard, { product, renderImage });
12079
+ return /* @__PURE__ */ jsx(
12080
+ "div",
12081
+ {
12082
+ "data-cimplify-product-grid-item": true,
12083
+ className: classNames?.item,
12084
+ children: index < xl ? /* @__PURE__ */ jsx(ImagePriorityContext.Provider, { value: true, children: card }) : card
12085
+ },
12086
+ product.id
12087
+ );
12088
+ })
11853
12089
  }
11854
12090
  )
11855
12091
  ] });
@@ -11890,6 +12126,15 @@ function SearchInput({
11890
12126
  [searchOptions, categoryId]
11891
12127
  );
11892
12128
  const { results, isLoading, query, setQuery, clear } = useSearch(mergedOptions);
12129
+ const context = useOptionalCimplifyClient();
12130
+ const warmResult = useCallback(
12131
+ (product) => {
12132
+ const client = mergedOptions.client ?? context?.client;
12133
+ if (!client || context?.prefetch.mode === "off") return;
12134
+ speculate(() => prefetchProduct(client, product.slug ?? product.id));
12135
+ },
12136
+ [mergedOptions.client, context]
12137
+ );
11893
12138
  const handleValueChange = useCallback(
11894
12139
  (value) => {
11895
12140
  setQuery(value);
@@ -11954,6 +12199,8 @@ function SearchInput({
11954
12199
  {
11955
12200
  type: "button",
11956
12201
  onClick: () => onResultClick?.(product),
12202
+ onPointerEnter: () => warmResult(product),
12203
+ onFocus: () => warmResult(product),
11957
12204
  "data-cimplify-search-result": true,
11958
12205
  className: classNames?.resultItem,
11959
12206
  style: !renderResult ? { display: "flex", alignItems: "center", gap: "0.5rem", width: "100%" } : void 0,
@@ -13663,18 +13910,24 @@ function CataloguePage({
13663
13910
  const [maxPrice, setMaxPrice] = useState("");
13664
13911
  const [page, setPage] = useState(1);
13665
13912
  const debouncedSearch = useDebounce(searchQuery, 300);
13913
+ const filterOptions = useMemo(
13914
+ () => ({
13915
+ category: selectedCategory ?? void 0,
13916
+ search: debouncedSearch.length >= 2 ? debouncedSearch : void 0,
13917
+ sort_by: sortBy,
13918
+ sort_order: sortOrder,
13919
+ in_stock: inStockOnly || void 0,
13920
+ tags: selectedTags.length > 0 ? selectedTags : void 0,
13921
+ min_price: minPrice ? parseFloat(minPrice) : void 0,
13922
+ max_price: maxPrice ? parseFloat(maxPrice) : void 0,
13923
+ limit: pageSize
13924
+ }),
13925
+ [selectedCategory, debouncedSearch, sortBy, sortOrder, inStockOnly, selectedTags, minPrice, maxPrice, pageSize]
13926
+ );
13666
13927
  const { products: fetchedProducts, isLoading, pagination } = useProducts({
13928
+ ...filterOptions,
13667
13929
  enabled: productsProp === void 0,
13668
- category: selectedCategory ?? void 0,
13669
- search: debouncedSearch.length >= 2 ? debouncedSearch : void 0,
13670
- sort_by: sortBy,
13671
- sort_order: sortOrder,
13672
- in_stock: inStockOnly || void 0,
13673
- tags: selectedTags.length > 0 ? selectedTags : void 0,
13674
- min_price: minPrice ? parseFloat(minPrice) : void 0,
13675
- max_price: maxPrice ? parseFloat(maxPrice) : void 0,
13676
- page,
13677
- limit: pageSize
13930
+ page
13678
13931
  });
13679
13932
  const { categories: fetchedCategories } = useCategories({
13680
13933
  enabled: categoriesProp === void 0
@@ -13682,6 +13935,10 @@ function CataloguePage({
13682
13935
  const products = productsProp ?? fetchedProducts;
13683
13936
  const categories = categoriesProp ?? fetchedCategories;
13684
13937
  const totalPages = pagination?.total_pages ?? 1;
13938
+ const context = useOptionalCimplifyClient();
13939
+ if (context && context.prefetch.mode !== "off" && productsProp === void 0 && !isLoading && page < totalPages) {
13940
+ speculate(() => prefetchProducts(context.client, { ...filterOptions, page: page + 1 }));
13941
+ }
13685
13942
  const handleCategoryChange = useCallback((id) => {
13686
13943
  setSelectedCategory(id);
13687
13944
  setPage(1);
@@ -14583,6 +14840,12 @@ function ProductPage({
14583
14840
  enabled: !productProp && resolvedId.length > 0
14584
14841
  });
14585
14842
  const product = productProp ?? fetched;
14843
+ const context = useOptionalCimplifyClient();
14844
+ useEffect(() => {
14845
+ if (product && context) {
14846
+ trackProductView(context.client, product);
14847
+ }
14848
+ }, [context, product]);
14586
14849
  if (isLoading && !product) {
14587
14850
  return /* @__PURE__ */ jsx(
14588
14851
  "div",
@@ -16007,6 +16270,15 @@ function RecommendationCarousel({
16007
16270
  enabled: recommendationsProp === void 0
16008
16271
  });
16009
16272
  const recommendations = recommendationsProp ?? fetched;
16273
+ const context = useOptionalCimplifyClient();
16274
+ const warmRecommendation = useCallback(
16275
+ (rec) => {
16276
+ const productId = rec.product?.id;
16277
+ if (!productId || !context || context.prefetch.mode === "off") return;
16278
+ speculate(() => prefetchProduct(context.client, productId));
16279
+ },
16280
+ [context]
16281
+ );
16010
16282
  if (isLoading && recommendations.length === 0) {
16011
16283
  return /* @__PURE__ */ jsx(
16012
16284
  "div",
@@ -16033,6 +16305,8 @@ function RecommendationCarousel({
16033
16305
  {
16034
16306
  type: "button",
16035
16307
  onClick: () => onProductClick?.(rec),
16308
+ onPointerEnter: () => warmRecommendation(rec),
16309
+ onFocus: () => warmRecommendation(rec),
16036
16310
  "data-cimplify-recommendation-item": true,
16037
16311
  className: classNames?.item,
16038
16312
  style: { flexShrink: 0 },
@@ -16111,6 +16385,14 @@ function RecentlyViewed({
16111
16385
  classNames
16112
16386
  }) {
16113
16387
  const { state, isLoading } = useActivityState();
16388
+ const context = useOptionalCimplifyClient();
16389
+ const warmViewed = useCallback(
16390
+ (productId) => {
16391
+ if (!context || context.prefetch.mode === "off") return;
16392
+ speculate(() => prefetchProduct(context.client, productId));
16393
+ },
16394
+ [context]
16395
+ );
16114
16396
  const rawViewed = state?.activity?.viewed_products ?? [];
16115
16397
  const viewed = limit ? rawViewed.slice(0, limit) : rawViewed;
16116
16398
  if (isLoading && viewed.length === 0) {
@@ -16131,6 +16413,8 @@ function RecentlyViewed({
16131
16413
  {
16132
16414
  type: "button",
16133
16415
  onClick: () => onProductClick?.(product),
16416
+ onPointerEnter: () => warmViewed(product.product_id),
16417
+ onFocus: () => warmViewed(product.product_id),
16134
16418
  "data-cimplify-recently-viewed-item": true,
16135
16419
  className: classNames?.item,
16136
16420
  children: renderProduct ? renderProduct(product) : /* @__PURE__ */ jsx("span", { children: product.product_name ?? product.product_id })
@@ -16771,4 +17055,4 @@ function SparkleIcon({ className }) {
16771
17055
  );
16772
17056
  }
16773
17057
 
16774
- export { AccommodationCard, AccountContent, AccountDashboardPage, AccountHero, AccountIdentityStrip, AccountLineItem, AccountLineItems, AccountNav, AccountOrderDetailPage, AccountOrderView, AccountOrdersPage, AccountShell, AccountSidebar, AccountSignedOutPrompt, AccountSubscriptionDetailPage, AccountSubscriptionsPage, Ad, AdProvider, AddOnSelector, AddressElement, AuthElement, AvailabilityBadge, BackLink, BillingPlanSelector, BookingCard, BookingList, BookingPage, BookingSummary, BookingsPage, BoxIcon24, BundleProductCard, BundleProductLayout, BundleSelector, Button, CardImage, CardShell, CardVariant, CartDrawer, CartDrawerProvider, CartPage, CartSummary, CartTemplate, CatalogueCollectionLayout, CataloguePage, CatalogueTemplate, CategoryFilter, CategoryGrid, ChatWidget, CheckIcon, CheckoutPage, CimplifyCheckout, CimplifyProvider, CimplifySignInButton, CimplifyUserButton, CollectionPage, CollectionTemplate, CompactCartLayout, CompactCatalogueLayout, CompactSearchLayout, CompactServiceCard, CompositeProductCard, CompositeProductLayout, CompositeSelector, ContextCard, ContinuityCard, CurrencySelector, CustomAttributesTable, CustomerInputFields, DashboardIcon, DashboardIcon20, DatePicker, DateSlotPicker, DealBanner, DealsPage, DefaultCartLayout, DefaultCatalogueLayout, DefaultCollectionLayout, DefaultProductLayout, DefaultSearchLayout, DeliveryEstimate, DeliveryTracker, DeliveryTruckIcon, DigitalProductCard, DigitalProductLayout, DiscountInput, ElementsProvider, EmptyState, ErrorState, FeaturedCollectionLayout, FilterTabs, FoodProductCard, FoodProductLayout, HappeningCard, IdentityIcon, IdentityOfframp, InventoryBadge, ItemsCard, LeaseServiceCard, LineItemDetails, LocationPicker, MediaGallery, MetadataStringList, MobileAccountShell, MobileBackButton, MobileMoreButton, MobileTabBar, NextDeliveryCard, OrderDetailHeader, OrderDetailMetaPipe, OrderDetailPage, OrderHistory, OrderHistoryPage, OrderList, OrderRow, OrderSummary, OrderTimeline, OrderTotals, OrdersIcon, OrdersIcon20, OvenIcon, PackageIcon, PaymentElement, Price, PriceRange, ProductCard, ProductCustomizer, ProductGrid, ProductImageGallery, ProductModel3D, ProductPage, ProductSheet, ProductTemplate, PropertiesTable, QuantitySelector, QuickAddButton, RecentlyViewed, RecommendationCarousel, RelatedProductsSection, RentalServiceCard, ResourcePicker, RetailProductCard, RichText, SaleBadge, ScheduleServiceCard, SearchInput, SearchPage, SearchTemplate, Section, SectionMore, ServiceProductLayout, SessionMessageBanner, SignOutIcon, Skeleton, SlotPicker, SoldOutOverlay, StaffPicker, StandardServiceCard, Status, StoreNav, StoreVideo, SubscriptionCard, SubscriptionList, SubscriptionRow, SubscriptionsIcon, SubscriptionsIcon20, TagPills, TimePicker, Toast, TwoColumnGrid, VariantSelector, VolumePricing, WelcomeCard, WholesaleProductCard, WholesaleProductLayout, WishlistButton, cn, roomToResource, sanitizeRichTextHtml, stripHtmlToText, toAccountLineItem, toAccountLineItems, toAccountOrderView, useActivityState, useAds, useAttributeDefinitions, useAvailableSlots, useBillingPlans, useBookings, useBootstrap, useBundles, useCart, useCartDrawer, useCategories, useChat, useCheckout, useCimplify, useCimplifyClient, useCimplifySession, useCollection, useCollections, useDeals, useDeliveryFee, useElements, useElementsReady, useFxRate, useLocations, useOptionalCimplify, useOrder, useOrders, useProduct, useProductAvailability, useProductDeals, useProductPrice, useProductSchedules, useProducts, useProductsOnSale, usePropertyFacets, useQuote, useRecommendations, useSearch, useServiceAvailability, useServices, useStoreCredit, useSubscription, useSubscriptions, useTaxonomies, useTaxonomy, useTaxonomyPath, useValidateDiscount, useVariantSelector };
17058
+ export { AccommodationCard, AccountContent, AccountDashboardPage, AccountHero, AccountIdentityStrip, AccountLineItem, AccountLineItems, AccountNav, AccountOrderDetailPage, AccountOrderView, AccountOrdersPage, AccountShell, AccountSidebar, AccountSignedOutPrompt, AccountSubscriptionDetailPage, AccountSubscriptionsPage, Ad, AdProvider, AddOnSelector, AddressElement, AuthElement, AvailabilityBadge, BackLink, BillingPlanSelector, BookingCard, BookingList, BookingPage, BookingSummary, BookingsPage, BoxIcon24, BundleProductCard, BundleProductLayout, BundleSelector, Button, CardImage, CardShell, CardVariant, CartDrawer, CartDrawerProvider, CartPage, CartSummary, CartTemplate, CatalogueCollectionLayout, CataloguePage, CatalogueTemplate, CategoryFilter, CategoryGrid, ChatWidget, CheckIcon, CheckoutPage, CimplifyCheckout, CimplifyProvider, CimplifySignInButton, CimplifyUserButton, CollectionPage, CollectionTemplate, CompactCartLayout, CompactCatalogueLayout, CompactSearchLayout, CompactServiceCard, CompositeProductCard, CompositeProductLayout, CompositeSelector, ContextCard, ContinuityCard, CurrencySelector, CustomAttributesTable, CustomerInputFields, DashboardIcon, DashboardIcon20, DatePicker, DateSlotPicker, DealBanner, DealsPage, DefaultCartLayout, DefaultCatalogueLayout, DefaultCollectionLayout, DefaultProductLayout, DefaultSearchLayout, DeliveryEstimate, DeliveryTracker, DeliveryTruckIcon, DigitalProductCard, DigitalProductLayout, DiscountInput, ElementsProvider, EmptyState, ErrorState, FeaturedCollectionLayout, FilterTabs, FoodProductCard, FoodProductLayout, HappeningCard, IdentityIcon, IdentityOfframp, InventoryBadge, ItemsCard, LeaseServiceCard, LineItemDetails, LocationPicker, MediaGallery, MetadataStringList, MobileAccountShell, MobileBackButton, MobileMoreButton, MobileTabBar, NextDeliveryCard, OrderDetailHeader, OrderDetailMetaPipe, OrderDetailPage, OrderHistory, OrderHistoryPage, OrderList, OrderRow, OrderSummary, OrderTimeline, OrderTotals, OrdersIcon, OrdersIcon20, OvenIcon, PackageIcon, PaymentElement, Price, PriceRange, ProductCard, ProductCustomizer, ProductGrid, ProductImageGallery, ProductModel3D, ProductPage, ProductSheet, ProductTemplate, PropertiesTable, QuantitySelector, QuickAddButton, RecentlyViewed, RecommendationCarousel, RelatedProductsSection, RentalServiceCard, ResourcePicker, RetailProductCard, RichText, SaleBadge, ScheduleServiceCard, SearchInput, SearchPage, SearchTemplate, Section, SectionMore, ServiceProductLayout, SessionMessageBanner, SignOutIcon, Skeleton, SlotPicker, SoldOutOverlay, StaffPicker, StandardServiceCard, Status, StoreNav, StoreVideo, SubscriptionCard, SubscriptionList, SubscriptionRow, SubscriptionsIcon, SubscriptionsIcon20, TagPills, TimePicker, Toast, TwoColumnGrid, VariantSelector, VolumePricing, WelcomeCard, WholesaleProductCard, WholesaleProductLayout, WishlistButton, cn, prefetchProduct, prefetchProducts, roomToResource, sanitizeRichTextHtml, stripHtmlToText, toAccountLineItem, toAccountLineItems, toAccountOrderView, useActivityState, useAds, useAttributeDefinitions, useAvailableSlots, useBillingPlans, useBookings, useBootstrap, useBundles, useCart, useCartDrawer, useCategories, useChat, useCheckout, useCimplify, useCimplifyClient, useCimplifySession, useCollection, useCollections, useDeals, useDeliveryFee, useDeliveryOptions, useElements, useElementsReady, useFxRate, useLocations, useOptionalCimplify, useOrder, useOrders, useProduct, useProductAvailability, useProductDeals, useProductPrice, useProductSchedules, useProducts, useProductsOnSale, usePropertyFacets, useQuote, useRecommendations, useSearch, useServiceAvailability, useServices, useStoreCredit, useSubscription, useSubscriptions, useTaxonomies, useTaxonomy, useTaxonomyPath, useValidateDiscount, useVariantSelector };
@@ -894,6 +894,19 @@ interface PlacesService {
894
894
  }): unknown;
895
895
  }
896
896
 
897
+ interface MockDeliveryOption {
898
+ rate_id: string | null;
899
+ name: string;
900
+ description?: string;
901
+ fee: string;
902
+ currency: string;
903
+ free_delivery_applied: boolean;
904
+ free_over_amount?: string;
905
+ eta_min_minutes?: number;
906
+ eta_max_minutes?: number;
907
+ is_default: boolean;
908
+ details: Record<string, unknown>;
909
+ }
897
910
  interface DeliveryService {
898
911
  getFee(opts: {
899
912
  lat?: number;
@@ -907,6 +920,14 @@ interface DeliveryService {
907
920
  provider: string;
908
921
  quotes: unknown[];
909
922
  };
923
+ getOptions(opts: {
924
+ lat?: number;
925
+ lng?: number;
926
+ order_value?: string;
927
+ }): {
928
+ serviceable: boolean;
929
+ options: MockDeliveryOption[];
930
+ };
910
931
  }
911
932
 
912
933
  interface ActivityService {