@appfunnel-dev/sdk 2.0.0-canary.10 → 2.0.0-canary.12

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.js CHANGED
@@ -1,10 +1,11 @@
1
- import { isRtl, formatOffering, bucketingSeed, resolveExperiments, entryGuard, evaluateGate, expectedPathLength, nextPage, outgoingKeys, buildCatalog, resolveLocale } from './chunk-VW2HVPR4.js';
2
- export { assignVariant, bucketingSeed, buildCatalog, compileManifest, currencyExponent, defineFunnel, definePage, entryGuard, evaluateCondition, evaluateGate, expectedPathLength, fnv1a, formatMoney, formatOffering, hashToUnit, isRtl, isVariantKey, nextPage, outgoingKeys, pageMeta, parseSlotKey, pickByWeight, resolveExperiments, resolveLocale, resolveOffering, resolveRoute } from './chunk-VW2HVPR4.js';
1
+ import { isRtl, formatOffering, bucketingSeed, resolveExperiments, entryGuard, evaluateGate, expectedPathLength, groupProgress, nextPage, outgoingKeys, buildCatalog, resolveLocale } from './chunk-UAQV22UK.js';
2
+ export { assignVariant, bucketingSeed, buildCatalog, compileManifest, currencyExponent, defineFunnel, definePage, entryGuard, evaluateCondition, evaluateGate, expectedPathLength, fnv1a, formatMoney, formatOffering, groupProgress, hashToUnit, isRtl, isVariantKey, nextPage, outgoingKeys, pageMeta, parseSlotKey, pickByWeight, resolveExperiments, resolveLocale, resolveOffering, resolveRoute } from './chunk-UAQV22UK.js';
3
3
  import { AF_PROTOCOL } from './chunk-ZZJG4EYL.js';
4
4
  import { checkoutError, resolveSurface, isInlineSurface, PROVIDER_PROFILES } from './chunk-OXQBEKZ5.js';
5
5
  export { INLINE_SURFACES, PROVIDER_PROFILES, checkoutError, isInlineSurface, isMerchantOfRecord, isOrchestrator, isRenderableSurface, renderableSurfaces, resolveSurface, surfacesFor, validateCheckout, validateUpsell } from './chunk-OXQBEKZ5.js';
6
6
  import './chunk-G3PMV62Z.js';
7
- import React, { createContext, createElement, useCallback, useContext, useMemo, lazy, useRef, useState, useEffect, useTransition, Suspense, Fragment, isValidElement, cloneElement, useReducer, useSyncExternalStore } from 'react';
7
+ import * as React2 from 'react';
8
+ import React2__default, { createContext, createElement, useCallback, useContext, useMemo, lazy, useRef, useState, useEffect, useTransition, Suspense, Fragment, isValidElement, cloneElement, useReducer, useSyncExternalStore } from 'react';
8
9
  import ReactDOM, { createPortal } from 'react-dom';
9
10
  import { jsx } from 'react/jsx-runtime';
10
11
 
@@ -703,16 +704,20 @@ async function captureScreenshot(params = {}) {
703
704
  }
704
705
 
705
706
  // src/flow/flow.tsx
707
+ var Activity2 = React2.Activity ?? React2.unstable_Activity;
708
+ var HIDDEN_CANDIDATE_CAP = 2;
706
709
  var NavContext = createContext(null);
710
+ var GroupProgressContext = createContext(null);
707
711
  var ExperimentContext = createContext({});
708
712
  function useExperiment(id) {
709
713
  return useContext(ExperimentContext)[id];
710
714
  }
711
- function pageContextFor(currentKey, slug, index, total, startedAt) {
715
+ function pageContextFor(currentKey, slug, group, index, total, startedAt) {
712
716
  const denom = Math.max(total, index + 1);
713
717
  return {
714
718
  key: currentKey,
715
719
  slug,
720
+ group,
716
721
  index,
717
722
  total: denom,
718
723
  progressPercentage: denom > 0 ? Math.min(100, Math.round((index + 1) / denom * 100)) : 0,
@@ -822,9 +827,15 @@ function FunnelView({
822
827
  [flow, startKey, currentKey, funnel]
823
828
  );
824
829
  const slug = pageByKey.get(currentKey)?.meta?.slug ?? currentKey;
830
+ const group = pageByKey.get(currentKey)?.meta?.group;
825
831
  const page = useMemo(
826
- () => pageContextFor(currentKey, slug, index, total, funnel.context.system.now),
827
- [currentKey, slug, index, total, funnel.context.system.now]
832
+ () => pageContextFor(currentKey, slug, group, index, total, funnel.context.system.now),
833
+ [currentKey, slug, group, index, total, funnel.context.system.now]
834
+ );
835
+ const groups = useMemo(
836
+ () => groupProgress(flow, startKey, currentKey, funnel.snapshot()),
837
+ // currentKey in deps: re-trace as each step's answers settle the branch.
838
+ [flow, startKey, currentKey, funnel]
828
839
  );
829
840
  useEffect(() => {
830
841
  funnel.context.page = page;
@@ -864,6 +875,7 @@ function FunnelView({
864
875
  (key) => startNav(() => setHistory((h) => [...h, toSlot(key)])),
865
876
  [toSlot]
866
877
  );
878
+ const [loadedComps, setLoadedComps] = useState(() => /* @__PURE__ */ new Map());
867
879
  const prefetched = useRef(/* @__PURE__ */ new Set());
868
880
  const prefetch = useCallback(
869
881
  (key) => {
@@ -871,7 +883,10 @@ function FunnelView({
871
883
  const load = loaders.get(target);
872
884
  if (!load || prefetched.current.has(target)) return;
873
885
  prefetched.current.add(target);
874
- load().catch(() => prefetched.current.delete(target));
886
+ load().then((m) => {
887
+ const Comp = typeof m === "function" ? m : m.default;
888
+ setLoadedComps((prev) => prev.has(target) ? prev : new Map(prev).set(target, Comp));
889
+ }).catch(() => prefetched.current.delete(target));
875
890
  },
876
891
  [loaders, toRenderKey]
877
892
  );
@@ -883,6 +898,15 @@ function FunnelView({
883
898
  if (prefetchMode !== "auto") return;
884
899
  for (const key of nextCandidates) prefetch(key);
885
900
  }, [prefetchMode, nextCandidates, prefetch]);
901
+ useEffect(() => {
902
+ if (prefetchMode !== "off") return;
903
+ for (const key of nextCandidates) prefetch(key);
904
+ }, [prefetchMode, nextCandidates, prefetch]);
905
+ const [preMountReady, setPreMountReady] = useState(false);
906
+ useEffect(() => {
907
+ const saveData = typeof navigator !== "undefined" && navigator.connection?.saveData === true;
908
+ if (!saveData) setPreMountReady(true);
909
+ }, []);
886
910
  const value = {
887
911
  page,
888
912
  next,
@@ -934,11 +958,21 @@ function FunnelView({
934
958
  const renderKey = toRenderKey(currentKey);
935
959
  const Current = components.get(renderKey);
936
960
  const pageEl = createElement(Suspense, { fallback: fallback ?? null }, Current ? createElement(Current) : null);
937
- const content = layout ? createElement(layout, null, pageEl) : pageEl;
961
+ const visible = layout ? createElement(layout, null, pageEl) : pageEl;
962
+ const hiddenKeys = preMountReady && Activity2 ? nextCandidates.filter((k) => k !== renderKey && (pageByKey.get(k)?.Component !== void 0 || loadedComps.has(k))).slice(0, HIDDEN_CANDIDATE_CAP) : [];
963
+ const hiddenEls = hiddenKeys.map((k) => {
964
+ const C = pageByKey.get(k)?.Component ?? loadedComps.get(k);
965
+ return C ? createElement(Activity2, { key: k, mode: "hidden" }, createElement(C)) : null;
966
+ });
967
+ const content = hiddenEls.length > 0 ? createElement(Fragment, null, visible, ...hiddenEls) : visible;
938
968
  return createElement(
939
969
  ExperimentContext.Provider,
940
970
  { value: experiments.assignments },
941
- createElement(NavContext.Provider, { value }, content)
971
+ createElement(
972
+ NavContext.Provider,
973
+ { value },
974
+ createElement(GroupProgressContext.Provider, { value: groups }, content)
975
+ )
942
976
  );
943
977
  }
944
978
  function useNavigation() {
@@ -1024,6 +1058,11 @@ function EmbedBridge() {
1024
1058
  function usePage() {
1025
1059
  return useNavigation().page;
1026
1060
  }
1061
+ function useGroupProgress() {
1062
+ const ctx = useContext(GroupProgressContext);
1063
+ if (!ctx) throw new Error("useGroupProgress must be used inside <FunnelView>");
1064
+ return ctx;
1065
+ }
1027
1066
  var symModalId = /* @__PURE__ */ Symbol("AppfunnelModalId");
1028
1067
  var initialState = {};
1029
1068
  var ModalStateContext = createContext(initialState);
@@ -1867,64 +1906,64 @@ var getAsset = (type) => {
1867
1906
  };
1868
1907
  var bars = Array(12).fill(0);
1869
1908
  var Loader = ({ visible, className }) => {
1870
- return /* @__PURE__ */ React.createElement("div", {
1909
+ return /* @__PURE__ */ React2__default.createElement("div", {
1871
1910
  className: [
1872
1911
  "sonner-loading-wrapper",
1873
1912
  className
1874
1913
  ].filter(Boolean).join(" "),
1875
1914
  "data-visible": visible
1876
- }, /* @__PURE__ */ React.createElement("div", {
1915
+ }, /* @__PURE__ */ React2__default.createElement("div", {
1877
1916
  className: "sonner-spinner"
1878
- }, bars.map((_, i) => /* @__PURE__ */ React.createElement("div", {
1917
+ }, bars.map((_, i) => /* @__PURE__ */ React2__default.createElement("div", {
1879
1918
  className: "sonner-loading-bar",
1880
1919
  key: `spinner-bar-${i}`
1881
1920
  }))));
1882
1921
  };
1883
- var SuccessIcon = /* @__PURE__ */ React.createElement("svg", {
1922
+ var SuccessIcon = /* @__PURE__ */ React2__default.createElement("svg", {
1884
1923
  xmlns: "http://www.w3.org/2000/svg",
1885
1924
  viewBox: "0 0 20 20",
1886
1925
  fill: "currentColor",
1887
1926
  height: "20",
1888
1927
  width: "20"
1889
- }, /* @__PURE__ */ React.createElement("path", {
1928
+ }, /* @__PURE__ */ React2__default.createElement("path", {
1890
1929
  fillRule: "evenodd",
1891
1930
  d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",
1892
1931
  clipRule: "evenodd"
1893
1932
  }));
1894
- var WarningIcon = /* @__PURE__ */ React.createElement("svg", {
1933
+ var WarningIcon = /* @__PURE__ */ React2__default.createElement("svg", {
1895
1934
  xmlns: "http://www.w3.org/2000/svg",
1896
1935
  viewBox: "0 0 24 24",
1897
1936
  fill: "currentColor",
1898
1937
  height: "20",
1899
1938
  width: "20"
1900
- }, /* @__PURE__ */ React.createElement("path", {
1939
+ }, /* @__PURE__ */ React2__default.createElement("path", {
1901
1940
  fillRule: "evenodd",
1902
1941
  d: "M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",
1903
1942
  clipRule: "evenodd"
1904
1943
  }));
1905
- var InfoIcon = /* @__PURE__ */ React.createElement("svg", {
1944
+ var InfoIcon = /* @__PURE__ */ React2__default.createElement("svg", {
1906
1945
  xmlns: "http://www.w3.org/2000/svg",
1907
1946
  viewBox: "0 0 20 20",
1908
1947
  fill: "currentColor",
1909
1948
  height: "20",
1910
1949
  width: "20"
1911
- }, /* @__PURE__ */ React.createElement("path", {
1950
+ }, /* @__PURE__ */ React2__default.createElement("path", {
1912
1951
  fillRule: "evenodd",
1913
1952
  d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",
1914
1953
  clipRule: "evenodd"
1915
1954
  }));
1916
- var ErrorIcon = /* @__PURE__ */ React.createElement("svg", {
1955
+ var ErrorIcon = /* @__PURE__ */ React2__default.createElement("svg", {
1917
1956
  xmlns: "http://www.w3.org/2000/svg",
1918
1957
  viewBox: "0 0 20 20",
1919
1958
  fill: "currentColor",
1920
1959
  height: "20",
1921
1960
  width: "20"
1922
- }, /* @__PURE__ */ React.createElement("path", {
1961
+ }, /* @__PURE__ */ React2__default.createElement("path", {
1923
1962
  fillRule: "evenodd",
1924
1963
  d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",
1925
1964
  clipRule: "evenodd"
1926
1965
  }));
1927
- var CloseIcon = /* @__PURE__ */ React.createElement("svg", {
1966
+ var CloseIcon = /* @__PURE__ */ React2__default.createElement("svg", {
1928
1967
  xmlns: "http://www.w3.org/2000/svg",
1929
1968
  width: "12",
1930
1969
  height: "12",
@@ -1934,20 +1973,20 @@ var CloseIcon = /* @__PURE__ */ React.createElement("svg", {
1934
1973
  strokeWidth: "1.5",
1935
1974
  strokeLinecap: "round",
1936
1975
  strokeLinejoin: "round"
1937
- }, /* @__PURE__ */ React.createElement("line", {
1976
+ }, /* @__PURE__ */ React2__default.createElement("line", {
1938
1977
  x1: "18",
1939
1978
  y1: "6",
1940
1979
  x2: "6",
1941
1980
  y2: "18"
1942
- }), /* @__PURE__ */ React.createElement("line", {
1981
+ }), /* @__PURE__ */ React2__default.createElement("line", {
1943
1982
  x1: "6",
1944
1983
  y1: "6",
1945
1984
  x2: "18",
1946
1985
  y2: "18"
1947
1986
  }));
1948
1987
  var useIsDocumentHidden = () => {
1949
- const [isDocumentHidden, setIsDocumentHidden] = React.useState(document.hidden);
1950
- React.useEffect(() => {
1988
+ const [isDocumentHidden, setIsDocumentHidden] = React2__default.useState(document.hidden);
1989
+ React2__default.useEffect(() => {
1951
1990
  const callback = () => {
1952
1991
  setIsDocumentHidden(document.hidden);
1953
1992
  };
@@ -2096,7 +2135,7 @@ var Observer = class {
2096
2135
  "resolve",
2097
2136
  response
2098
2137
  ];
2099
- const isReactElementResponse = React.isValidElement(response);
2138
+ const isReactElementResponse = React2__default.isValidElement(response);
2100
2139
  if (isReactElementResponse) {
2101
2140
  shouldDismiss = false;
2102
2141
  this.create({
@@ -2108,7 +2147,7 @@ var Observer = class {
2108
2147
  shouldDismiss = false;
2109
2148
  const promiseData = typeof data.error === "function" ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
2110
2149
  const description = typeof data.description === "function" ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
2111
- const isExtendedResult = typeof promiseData === "object" && !React.isValidElement(promiseData);
2150
+ const isExtendedResult = typeof promiseData === "object" && !React2__default.isValidElement(promiseData);
2112
2151
  const toastSettings = isExtendedResult ? promiseData : {
2113
2152
  message: promiseData
2114
2153
  };
@@ -2122,7 +2161,7 @@ var Observer = class {
2122
2161
  shouldDismiss = false;
2123
2162
  const promiseData = typeof data.error === "function" ? await data.error(response) : data.error;
2124
2163
  const description = typeof data.description === "function" ? await data.description(response) : data.description;
2125
- const isExtendedResult = typeof promiseData === "object" && !React.isValidElement(promiseData);
2164
+ const isExtendedResult = typeof promiseData === "object" && !React2__default.isValidElement(promiseData);
2126
2165
  const toastSettings = isExtendedResult ? promiseData : {
2127
2166
  message: promiseData
2128
2167
  };
@@ -2136,7 +2175,7 @@ var Observer = class {
2136
2175
  shouldDismiss = false;
2137
2176
  const promiseData = typeof data.success === "function" ? await data.success(response) : data.success;
2138
2177
  const description = typeof data.description === "function" ? await data.description(response) : data.description;
2139
- const isExtendedResult = typeof promiseData === "object" && !React.isValidElement(promiseData);
2178
+ const isExtendedResult = typeof promiseData === "object" && !React2__default.isValidElement(promiseData);
2140
2179
  const toastSettings = isExtendedResult ? promiseData : {
2141
2180
  message: promiseData
2142
2181
  };
@@ -2156,7 +2195,7 @@ var Observer = class {
2156
2195
  shouldDismiss = false;
2157
2196
  const promiseData = typeof data.error === "function" ? await data.error(error) : data.error;
2158
2197
  const description = typeof data.description === "function" ? await data.description(error) : data.description;
2159
- const isExtendedResult = typeof promiseData === "object" && !React.isValidElement(promiseData);
2198
+ const isExtendedResult = typeof promiseData === "object" && !React2__default.isValidElement(promiseData);
2160
2199
  const toastSettings = isExtendedResult ? promiseData : {
2161
2200
  message: promiseData
2162
2201
  };
@@ -2261,45 +2300,45 @@ function getDefaultSwipeDirections(position) {
2261
2300
  var Toast = (props) => {
2262
2301
  var _toast_classNames, _toast_classNames1, _toast_classNames2, _toast_classNames3, _toast_classNames4, _toast_classNames5, _toast_classNames6, _toast_classNames7, _toast_classNames8;
2263
2302
  const { invert: ToasterInvert, toast: toast2, unstyled, interacting, setHeights, visibleToasts, heights, index, toasts, expanded, removeToast, defaultRichColors, closeButton: closeButtonFromToaster, style, cancelButtonStyle, actionButtonStyle, className = "", descriptionClassName = "", duration: durationFromToaster, position, gap, expandByDefault, classNames, icons, closeButtonAriaLabel = "Close toast" } = props;
2264
- const [swipeDirection, setSwipeDirection] = React.useState(null);
2265
- const [swipeOutDirection, setSwipeOutDirection] = React.useState(null);
2266
- const [mounted, setMounted] = React.useState(false);
2267
- const [removed, setRemoved] = React.useState(false);
2268
- const [swiping, setSwiping] = React.useState(false);
2269
- const [swipeOut, setSwipeOut] = React.useState(false);
2270
- const [isSwiped, setIsSwiped] = React.useState(false);
2271
- const [offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0);
2272
- const [initialHeight, setInitialHeight] = React.useState(0);
2273
- const remainingTime = React.useRef(toast2.duration || durationFromToaster || TOAST_LIFETIME);
2274
- const dragStartTime = React.useRef(null);
2275
- const toastRef = React.useRef(null);
2303
+ const [swipeDirection, setSwipeDirection] = React2__default.useState(null);
2304
+ const [swipeOutDirection, setSwipeOutDirection] = React2__default.useState(null);
2305
+ const [mounted, setMounted] = React2__default.useState(false);
2306
+ const [removed, setRemoved] = React2__default.useState(false);
2307
+ const [swiping, setSwiping] = React2__default.useState(false);
2308
+ const [swipeOut, setSwipeOut] = React2__default.useState(false);
2309
+ const [isSwiped, setIsSwiped] = React2__default.useState(false);
2310
+ const [offsetBeforeRemove, setOffsetBeforeRemove] = React2__default.useState(0);
2311
+ const [initialHeight, setInitialHeight] = React2__default.useState(0);
2312
+ const remainingTime = React2__default.useRef(toast2.duration || durationFromToaster || TOAST_LIFETIME);
2313
+ const dragStartTime = React2__default.useRef(null);
2314
+ const toastRef = React2__default.useRef(null);
2276
2315
  const isFront = index === 0;
2277
2316
  const isVisible = index + 1 <= visibleToasts;
2278
2317
  const toastType = toast2.type;
2279
2318
  const dismissible = toast2.dismissible !== false;
2280
2319
  const toastClassname = toast2.className || "";
2281
2320
  const toastDescriptionClassname = toast2.descriptionClassName || "";
2282
- const heightIndex = React.useMemo(() => heights.findIndex((height) => height.toastId === toast2.id) || 0, [
2321
+ const heightIndex = React2__default.useMemo(() => heights.findIndex((height) => height.toastId === toast2.id) || 0, [
2283
2322
  heights,
2284
2323
  toast2.id
2285
2324
  ]);
2286
- const closeButton = React.useMemo(() => {
2325
+ const closeButton = React2__default.useMemo(() => {
2287
2326
  var _toast_closeButton;
2288
2327
  return (_toast_closeButton = toast2.closeButton) != null ? _toast_closeButton : closeButtonFromToaster;
2289
2328
  }, [
2290
2329
  toast2.closeButton,
2291
2330
  closeButtonFromToaster
2292
2331
  ]);
2293
- const duration = React.useMemo(() => toast2.duration || durationFromToaster || TOAST_LIFETIME, [
2332
+ const duration = React2__default.useMemo(() => toast2.duration || durationFromToaster || TOAST_LIFETIME, [
2294
2333
  toast2.duration,
2295
2334
  durationFromToaster
2296
2335
  ]);
2297
- const closeTimerStartTimeRef = React.useRef(0);
2298
- const offset = React.useRef(0);
2299
- const lastCloseTimerStartTimeRef = React.useRef(0);
2300
- const pointerStartRef = React.useRef(null);
2336
+ const closeTimerStartTimeRef = React2__default.useRef(0);
2337
+ const offset = React2__default.useRef(0);
2338
+ const lastCloseTimerStartTimeRef = React2__default.useRef(0);
2339
+ const pointerStartRef = React2__default.useRef(null);
2301
2340
  const [y, x] = position.split("-");
2302
- const toastsHeightBefore = React.useMemo(() => {
2341
+ const toastsHeightBefore = React2__default.useMemo(() => {
2303
2342
  return heights.reduce((prev, curr, reducerIndex) => {
2304
2343
  if (reducerIndex >= heightIndex) {
2305
2344
  return prev;
@@ -2313,19 +2352,19 @@ var Toast = (props) => {
2313
2352
  const isDocumentHidden = useIsDocumentHidden();
2314
2353
  const invert = toast2.invert || ToasterInvert;
2315
2354
  const disabled = toastType === "loading";
2316
- offset.current = React.useMemo(() => heightIndex * gap + toastsHeightBefore, [
2355
+ offset.current = React2__default.useMemo(() => heightIndex * gap + toastsHeightBefore, [
2317
2356
  heightIndex,
2318
2357
  toastsHeightBefore
2319
2358
  ]);
2320
- React.useEffect(() => {
2359
+ React2__default.useEffect(() => {
2321
2360
  remainingTime.current = duration;
2322
2361
  }, [
2323
2362
  duration
2324
2363
  ]);
2325
- React.useEffect(() => {
2364
+ React2__default.useEffect(() => {
2326
2365
  setMounted(true);
2327
2366
  }, []);
2328
- React.useEffect(() => {
2367
+ React2__default.useEffect(() => {
2329
2368
  const toastNode = toastRef.current;
2330
2369
  if (toastNode) {
2331
2370
  const height = toastNode.getBoundingClientRect().height;
@@ -2344,7 +2383,7 @@ var Toast = (props) => {
2344
2383
  setHeights,
2345
2384
  toast2.id
2346
2385
  ]);
2347
- React.useLayoutEffect(() => {
2386
+ React2__default.useLayoutEffect(() => {
2348
2387
  if (!mounted) return;
2349
2388
  const toastNode = toastRef.current;
2350
2389
  const originalHeight = toastNode.style.height;
@@ -2380,7 +2419,7 @@ var Toast = (props) => {
2380
2419
  toast2.action,
2381
2420
  toast2.cancel
2382
2421
  ]);
2383
- const deleteToast = React.useCallback(() => {
2422
+ const deleteToast = React2__default.useCallback(() => {
2384
2423
  setRemoved(true);
2385
2424
  setOffsetBeforeRemove(offset.current);
2386
2425
  setHeights((h) => h.filter((height) => height.toastId !== toast2.id));
@@ -2393,7 +2432,7 @@ var Toast = (props) => {
2393
2432
  setHeights,
2394
2433
  offset
2395
2434
  ]);
2396
- React.useEffect(() => {
2435
+ React2__default.useEffect(() => {
2397
2436
  if (toast2.promise && toastType === "loading" || toast2.duration === Infinity || toast2.type === "loading") return;
2398
2437
  let timeoutId;
2399
2438
  const pauseTimer = () => {
@@ -2425,7 +2464,7 @@ var Toast = (props) => {
2425
2464
  isDocumentHidden,
2426
2465
  deleteToast
2427
2466
  ]);
2428
- React.useEffect(() => {
2467
+ React2__default.useEffect(() => {
2429
2468
  if (toast2.delete) {
2430
2469
  deleteToast();
2431
2470
  toast2.onDismiss == null ? void 0 : toast2.onDismiss.call(toast2, toast2);
@@ -2438,19 +2477,19 @@ var Toast = (props) => {
2438
2477
  var _toast_classNames9;
2439
2478
  if (icons == null ? void 0 : icons.loading) {
2440
2479
  var _toast_classNames12;
2441
- return /* @__PURE__ */ React.createElement("div", {
2480
+ return /* @__PURE__ */ React2__default.createElement("div", {
2442
2481
  className: cn(classNames == null ? void 0 : classNames.loader, toast2 == null ? void 0 : (_toast_classNames12 = toast2.classNames) == null ? void 0 : _toast_classNames12.loader, "sonner-loader"),
2443
2482
  "data-visible": toastType === "loading"
2444
2483
  }, icons.loading);
2445
2484
  }
2446
- return /* @__PURE__ */ React.createElement(Loader, {
2485
+ return /* @__PURE__ */ React2__default.createElement(Loader, {
2447
2486
  className: cn(classNames == null ? void 0 : classNames.loader, toast2 == null ? void 0 : (_toast_classNames9 = toast2.classNames) == null ? void 0 : _toast_classNames9.loader),
2448
2487
  visible: toastType === "loading"
2449
2488
  });
2450
2489
  }
2451
2490
  const icon = toast2.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType);
2452
2491
  var _toast_richColors, _icons_close;
2453
- return /* @__PURE__ */ React.createElement("li", {
2492
+ return /* @__PURE__ */ React2__default.createElement("li", {
2454
2493
  tabIndex: 0,
2455
2494
  ref: toastRef,
2456
2495
  className: cn(className, toastClassname, classNames == null ? void 0 : classNames.toast, toast2 == null ? void 0 : (_toast_classNames = toast2.classNames) == null ? void 0 : _toast_classNames.toast, classNames == null ? void 0 : classNames.default, classNames == null ? void 0 : classNames[toastType], toast2 == null ? void 0 : (_toast_classNames1 = toast2.classNames) == null ? void 0 : _toast_classNames1[toastType]),
@@ -2575,7 +2614,7 @@ var Toast = (props) => {
2575
2614
  (_toastRef_current = toastRef.current) == null ? void 0 : _toastRef_current.style.setProperty("--swipe-amount-x", `${swipeAmount.x}px`);
2576
2615
  (_toastRef_current1 = toastRef.current) == null ? void 0 : _toastRef_current1.style.setProperty("--swipe-amount-y", `${swipeAmount.y}px`);
2577
2616
  }
2578
- }, closeButton && !toast2.jsx && toastType !== "loading" ? /* @__PURE__ */ React.createElement("button", {
2617
+ }, closeButton && !toast2.jsx && toastType !== "loading" ? /* @__PURE__ */ React2__default.createElement("button", {
2579
2618
  "aria-label": closeButtonAriaLabel,
2580
2619
  "data-disabled": disabled,
2581
2620
  "data-close-button": true,
@@ -2585,19 +2624,19 @@ var Toast = (props) => {
2585
2624
  toast2.onDismiss == null ? void 0 : toast2.onDismiss.call(toast2, toast2);
2586
2625
  },
2587
2626
  className: cn(classNames == null ? void 0 : classNames.closeButton, toast2 == null ? void 0 : (_toast_classNames2 = toast2.classNames) == null ? void 0 : _toast_classNames2.closeButton)
2588
- }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, (toastType || toast2.icon || toast2.promise) && toast2.icon !== null && ((icons == null ? void 0 : icons[toastType]) !== null || toast2.icon) ? /* @__PURE__ */ React.createElement("div", {
2627
+ }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, (toastType || toast2.icon || toast2.promise) && toast2.icon !== null && ((icons == null ? void 0 : icons[toastType]) !== null || toast2.icon) ? /* @__PURE__ */ React2__default.createElement("div", {
2589
2628
  "data-icon": "",
2590
2629
  className: cn(classNames == null ? void 0 : classNames.icon, toast2 == null ? void 0 : (_toast_classNames3 = toast2.classNames) == null ? void 0 : _toast_classNames3.icon)
2591
- }, toast2.promise || toast2.type === "loading" && !toast2.icon ? toast2.icon || getLoadingIcon() : null, toast2.type !== "loading" ? icon : null) : null, /* @__PURE__ */ React.createElement("div", {
2630
+ }, toast2.promise || toast2.type === "loading" && !toast2.icon ? toast2.icon || getLoadingIcon() : null, toast2.type !== "loading" ? icon : null) : null, /* @__PURE__ */ React2__default.createElement("div", {
2592
2631
  "data-content": "",
2593
2632
  className: cn(classNames == null ? void 0 : classNames.content, toast2 == null ? void 0 : (_toast_classNames4 = toast2.classNames) == null ? void 0 : _toast_classNames4.content)
2594
- }, /* @__PURE__ */ React.createElement("div", {
2633
+ }, /* @__PURE__ */ React2__default.createElement("div", {
2595
2634
  "data-title": "",
2596
2635
  className: cn(classNames == null ? void 0 : classNames.title, toast2 == null ? void 0 : (_toast_classNames5 = toast2.classNames) == null ? void 0 : _toast_classNames5.title)
2597
- }, toast2.jsx ? toast2.jsx : typeof toast2.title === "function" ? toast2.title() : toast2.title), toast2.description ? /* @__PURE__ */ React.createElement("div", {
2636
+ }, toast2.jsx ? toast2.jsx : typeof toast2.title === "function" ? toast2.title() : toast2.title), toast2.description ? /* @__PURE__ */ React2__default.createElement("div", {
2598
2637
  "data-description": "",
2599
2638
  className: cn(descriptionClassName, toastDescriptionClassname, classNames == null ? void 0 : classNames.description, toast2 == null ? void 0 : (_toast_classNames6 = toast2.classNames) == null ? void 0 : _toast_classNames6.description)
2600
- }, typeof toast2.description === "function" ? toast2.description() : toast2.description) : null), /* @__PURE__ */ React.isValidElement(toast2.cancel) ? toast2.cancel : toast2.cancel && isAction(toast2.cancel) ? /* @__PURE__ */ React.createElement("button", {
2639
+ }, typeof toast2.description === "function" ? toast2.description() : toast2.description) : null), /* @__PURE__ */ React2__default.isValidElement(toast2.cancel) ? toast2.cancel : toast2.cancel && isAction(toast2.cancel) ? /* @__PURE__ */ React2__default.createElement("button", {
2601
2640
  "data-button": true,
2602
2641
  "data-cancel": true,
2603
2642
  style: toast2.cancelButtonStyle || cancelButtonStyle,
@@ -2608,7 +2647,7 @@ var Toast = (props) => {
2608
2647
  deleteToast();
2609
2648
  },
2610
2649
  className: cn(classNames == null ? void 0 : classNames.cancelButton, toast2 == null ? void 0 : (_toast_classNames7 = toast2.classNames) == null ? void 0 : _toast_classNames7.cancelButton)
2611
- }, toast2.cancel.label) : null, /* @__PURE__ */ React.isValidElement(toast2.action) ? toast2.action : toast2.action && isAction(toast2.action) ? /* @__PURE__ */ React.createElement("button", {
2650
+ }, toast2.cancel.label) : null, /* @__PURE__ */ React2__default.isValidElement(toast2.action) ? toast2.action : toast2.action && isAction(toast2.action) ? /* @__PURE__ */ React2__default.createElement("button", {
2612
2651
  "data-button": true,
2613
2652
  "data-action": true,
2614
2653
  style: toast2.actionButtonStyle || actionButtonStyle,
@@ -2670,13 +2709,13 @@ function assignOffset(defaultOffset, mobileOffset) {
2670
2709
  });
2671
2710
  return styles;
2672
2711
  }
2673
- var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2712
+ var Toaster = /* @__PURE__ */ React2__default.forwardRef(function Toaster2(props, ref) {
2674
2713
  const { id, invert, position = "bottom-right", hotkey = [
2675
2714
  "altKey",
2676
2715
  "KeyT"
2677
2716
  ], expand, closeButton, className, offset, mobileOffset, theme = "light", richColors, duration, style, visibleToasts = VISIBLE_TOASTS_AMOUNT, toastOptions, dir = getDocumentDirection(), gap = GAP, icons, containerAriaLabel = "Notifications" } = props;
2678
- const [toasts, setToasts] = React.useState([]);
2679
- const filteredToasts = React.useMemo(() => {
2717
+ const [toasts, setToasts] = React2__default.useState([]);
2718
+ const filteredToasts = React2__default.useMemo(() => {
2680
2719
  if (id) {
2681
2720
  return toasts.filter((toast2) => toast2.toasterId === id);
2682
2721
  }
@@ -2685,7 +2724,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2685
2724
  toasts,
2686
2725
  id
2687
2726
  ]);
2688
- const possiblePositions = React.useMemo(() => {
2727
+ const possiblePositions = React2__default.useMemo(() => {
2689
2728
  return Array.from(new Set([
2690
2729
  position
2691
2730
  ].concat(filteredToasts.filter((toast2) => toast2.position).map((toast2) => toast2.position))));
@@ -2693,15 +2732,15 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2693
2732
  filteredToasts,
2694
2733
  position
2695
2734
  ]);
2696
- const [heights, setHeights] = React.useState([]);
2697
- const [expanded, setExpanded] = React.useState(false);
2698
- const [interacting, setInteracting] = React.useState(false);
2699
- const [actualTheme, setActualTheme] = React.useState(theme !== "system" ? theme : typeof window !== "undefined" ? window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : "light");
2700
- const listRef = React.useRef(null);
2735
+ const [heights, setHeights] = React2__default.useState([]);
2736
+ const [expanded, setExpanded] = React2__default.useState(false);
2737
+ const [interacting, setInteracting] = React2__default.useState(false);
2738
+ const [actualTheme, setActualTheme] = React2__default.useState(theme !== "system" ? theme : typeof window !== "undefined" ? window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" : "light");
2739
+ const listRef = React2__default.useRef(null);
2701
2740
  const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
2702
- const lastFocusedElementRef = React.useRef(null);
2703
- const isFocusWithinRef = React.useRef(false);
2704
- const removeToast = React.useCallback((toastToRemove) => {
2741
+ const lastFocusedElementRef = React2__default.useRef(null);
2742
+ const isFocusWithinRef = React2__default.useRef(false);
2743
+ const removeToast = React2__default.useCallback((toastToRemove) => {
2705
2744
  setToasts((toasts2) => {
2706
2745
  var _toasts_find;
2707
2746
  if (!((_toasts_find = toasts2.find((toast2) => toast2.id === toastToRemove.id)) == null ? void 0 : _toasts_find.delete)) {
@@ -2710,7 +2749,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2710
2749
  return toasts2.filter(({ id: id2 }) => id2 !== toastToRemove.id);
2711
2750
  });
2712
2751
  }, []);
2713
- React.useEffect(() => {
2752
+ React2__default.useEffect(() => {
2714
2753
  return ToastState.subscribe((toast2) => {
2715
2754
  if (toast2.dismiss) {
2716
2755
  requestAnimationFrame(() => {
@@ -2746,7 +2785,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2746
2785
  }, [
2747
2786
  toasts
2748
2787
  ]);
2749
- React.useEffect(() => {
2788
+ React2__default.useEffect(() => {
2750
2789
  if (theme !== "system") {
2751
2790
  setActualTheme(theme);
2752
2791
  return;
@@ -2784,14 +2823,14 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2784
2823
  }, [
2785
2824
  theme
2786
2825
  ]);
2787
- React.useEffect(() => {
2826
+ React2__default.useEffect(() => {
2788
2827
  if (toasts.length <= 1) {
2789
2828
  setExpanded(false);
2790
2829
  }
2791
2830
  }, [
2792
2831
  toasts
2793
2832
  ]);
2794
- React.useEffect(() => {
2833
+ React2__default.useEffect(() => {
2795
2834
  const handleKeyDown = (event) => {
2796
2835
  var _listRef_current;
2797
2836
  const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
@@ -2809,7 +2848,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2809
2848
  }, [
2810
2849
  hotkey
2811
2850
  ]);
2812
- React.useEffect(() => {
2851
+ React2__default.useEffect(() => {
2813
2852
  if (listRef.current) {
2814
2853
  return () => {
2815
2854
  if (lastFocusedElementRef.current) {
@@ -2826,7 +2865,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2826
2865
  ]);
2827
2866
  return (
2828
2867
  // Remove item from normal navigation flow, only available via hotkey
2829
- /* @__PURE__ */ React.createElement("section", {
2868
+ /* @__PURE__ */ React2__default.createElement("section", {
2830
2869
  ref,
2831
2870
  "aria-label": `${containerAriaLabel} ${hotkeyLabel}`,
2832
2871
  tabIndex: -1,
@@ -2838,7 +2877,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2838
2877
  var _heights_;
2839
2878
  const [y, x] = position2.split("-");
2840
2879
  if (!filteredToasts.length) return null;
2841
- return /* @__PURE__ */ React.createElement("ol", {
2880
+ return /* @__PURE__ */ React2__default.createElement("ol", {
2842
2881
  key: position2,
2843
2882
  dir: dir === "auto" ? getDocumentDirection() : dir,
2844
2883
  tabIndex: -1,
@@ -2890,7 +2929,7 @@ var Toaster = /* @__PURE__ */ React.forwardRef(function Toaster2(props, ref) {
2890
2929
  onPointerUp: () => setInteracting(false)
2891
2930
  }, filteredToasts.filter((toast2) => !toast2.position && index === 0 || toast2.position === position2).map((toast2, index2) => {
2892
2931
  var _toastOptions_duration, _toastOptions_closeButton;
2893
- return /* @__PURE__ */ React.createElement(Toast, {
2932
+ return /* @__PURE__ */ React2__default.createElement(Toast, {
2894
2933
  key: toast2.id,
2895
2934
  icons,
2896
2935
  index: index2,
@@ -3701,6 +3740,6 @@ function Script({
3701
3740
  return null;
3702
3741
  }
3703
3742
 
3704
- export { AssetsContext, AssetsProvider, Back, Checkout, CheckoutResume, Choice, EVENT_CATALOG, FunnelProvider, FunnelToaster, FunnelView, Modal, Next, Script, Sheet, Upsell, VariableStore, attachBus, buildAcquisition, buildContext, createBus, createConsoleTracker, createFunnelStore, createFunnelTree, createMockDriver, createPlatformTracker, defineModal, driverWithEmail, hideModal, integrationEvents, isIntegrationEvent, isTrackableEvent, newEventId, registerModal, removeModal, showModal, toast, unregisterModal, useActiveLocale, useAsset, useAssets, useCheckout, useClickIds, useContextValue, useData, useDevice, useExperiment, useField, useFunnel, useLocale, useModal, useNavigation, useOffering, useOfferings, usePage, useResponse, useSystem, useTracker, useTranslation, useUserAttribute, useUtm, withBus };
3743
+ export { AssetsContext, AssetsProvider, Back, Checkout, CheckoutResume, Choice, EVENT_CATALOG, FunnelProvider, FunnelToaster, FunnelView, Modal, Next, Script, Sheet, Upsell, VariableStore, attachBus, buildAcquisition, buildContext, createBus, createConsoleTracker, createFunnelStore, createFunnelTree, createMockDriver, createPlatformTracker, defineModal, driverWithEmail, hideModal, integrationEvents, isIntegrationEvent, isTrackableEvent, newEventId, registerModal, removeModal, showModal, toast, unregisterModal, useActiveLocale, useAsset, useAssets, useCheckout, useClickIds, useContextValue, useData, useDevice, useExperiment, useField, useFunnel, useGroupProgress, useLocale, useModal, useNavigation, useOffering, useOfferings, usePage, useResponse, useSystem, useTracker, useTranslation, useUserAttribute, useUtm, withBus };
3705
3744
  //# sourceMappingURL=index.js.map
3706
3745
  //# sourceMappingURL=index.js.map