@sazito/checkout 0.1.2 → 0.2.1

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var labels = require('../chunks/labels-DJ_RnkCQ.cjs');
3
+ var labels = require('../chunks/labels-BlZiVd3n.cjs');
4
4
  require('@sazito/client-sdk');
5
5
 
6
6
 
@@ -70,6 +70,14 @@ interface CheckoutTheme {
70
70
  danger?: string;
71
71
  /** Success and completed-state color. */
72
72
  success?: string;
73
+ /** Foreground used on top of solid success surfaces. */
74
+ successForeground?: string;
75
+ /** Background plate behind carrier and shipping-method logos. */
76
+ logoBackground?: string;
77
+ /** Neutral surface used when a shipping color is white or near-white. */
78
+ shippingNeutral?: string;
79
+ /** Foreground used on the neutral shipping surface. */
80
+ shippingNeutralForeground?: string;
73
81
  /** Base corner radius in px. */
74
82
  radius?: number;
75
83
  /** Font family. Defaults to `inherit` so the host font flows through. */
@@ -250,6 +258,7 @@ interface Store<T> {
250
258
  getState(): T;
251
259
  setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;
252
260
  subscribe(listener: () => void): () => void;
261
+ batch<R>(callback: () => R): R;
253
262
  }
254
263
  declare function createStore<T extends object>(initialState: T): Store<T>;
255
264
 
@@ -70,6 +70,14 @@ interface CheckoutTheme {
70
70
  danger?: string;
71
71
  /** Success and completed-state color. */
72
72
  success?: string;
73
+ /** Foreground used on top of solid success surfaces. */
74
+ successForeground?: string;
75
+ /** Background plate behind carrier and shipping-method logos. */
76
+ logoBackground?: string;
77
+ /** Neutral surface used when a shipping color is white or near-white. */
78
+ shippingNeutral?: string;
79
+ /** Foreground used on the neutral shipping surface. */
80
+ shippingNeutralForeground?: string;
73
81
  /** Base corner radius in px. */
74
82
  radius?: number;
75
83
  /** Font family. Defaults to `inherit` so the host font flows through. */
@@ -250,6 +258,7 @@ interface Store<T> {
250
258
  getState(): T;
251
259
  setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;
252
260
  subscribe(listener: () => void): () => void;
261
+ batch<R>(callback: () => R): R;
253
262
  }
254
263
  declare function createStore<T extends object>(initialState: T): Store<T>;
255
264
 
@@ -1,3 +1,3 @@
1
- export { a as addressFormFromInvoice, b as buildShippingAssignments, c as classifyAppliedDiscount, d as createBrowserEffectExecutor, e as createCheckoutEngine, f as createSdkBinding, g as createStore, h as defaultCurrencyLabel, i as deriveShippingGroups, j as emptyAddressForm, k as formatMoney, l as formatNumber, m as formatPercent, n as formatPrice, o as fromSdkError, p as isAddressComplete, q as isAddressDirty, r as isDigitalServiceGroup, s as isShippingComplete, t as isValidIranianMobile, u as isValidIranianPhone, v as makeError, w as makeEvent, x as messageForCode, y as noopEffectExecutor, z as normalizeIranianPhone, A as paymentMethodInfo, B as paymentMethodLabel, C as selectDigitalItems, D as selectSummary, E as sortCartItemsNewestFirst, F as strings, G as toEnglishDigits, H as toPersianDigits } from '../chunks/labels-ByA_yGKl.js';
1
+ export { a as addressFormFromInvoice, b as buildShippingAssignments, c as classifyAppliedDiscount, d as createBrowserEffectExecutor, e as createCheckoutEngine, f as createSdkBinding, g as createStore, h as defaultCurrencyLabel, i as deriveShippingGroups, j as emptyAddressForm, k as formatMoney, l as formatNumber, m as formatPercent, n as formatPrice, o as fromSdkError, p as isAddressComplete, q as isAddressDirty, r as isDigitalServiceGroup, s as isShippingComplete, t as isValidIranianMobile, u as isValidIranianPhone, v as makeError, w as makeEvent, x as messageForCode, y as noopEffectExecutor, z as normalizeIranianPhone, A as paymentMethodInfo, B as paymentMethodLabel, C as selectDigitalItems, D as selectSummary, E as sortCartItemsNewestFirst, F as strings, G as toEnglishDigits, H as toPersianDigits } from '../chunks/labels-CTR6b-KZ.js';
2
2
  import '@sazito/client-sdk';
3
3
  //# sourceMappingURL=index.js.map
@@ -3,8 +3,8 @@
3
3
 
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('react');
6
- var useCheckout = require('../chunks/use-checkout-CQBSONj1.cjs');
7
- var labels = require('../chunks/labels-DJ_RnkCQ.cjs');
6
+ var useCheckout = require('../chunks/use-checkout-BEaLKgNa.cjs');
7
+ var labels = require('../chunks/labels-BlZiVd3n.cjs');
8
8
  require('@sazito/client-sdk');
9
9
 
10
10
  /**
@@ -575,8 +575,8 @@ function shippingRateIconStyle(color) {
575
575
  // the card. Render a neutral chip with a slate glyph instead.
576
576
  if (luminance > 0.9) {
577
577
  return {
578
- '--szc-rate-color': '#eef0f5',
579
- '--szc-rate-foreground': '#475569'
578
+ '--szc-rate-color': 'var(--szc-shipping-neutral)',
579
+ '--szc-rate-foreground': 'var(--szc-shipping-neutral-foreground)'
580
580
  };
581
581
  }
582
582
  const foreground = luminance > 0.62
@@ -742,14 +742,22 @@ function themeVars(theme) {
742
742
  vars['--szc-danger'] = theme.danger;
743
743
  if (theme?.success)
744
744
  vars['--szc-success'] = theme.success;
745
+ if (theme?.successForeground)
746
+ vars['--szc-success-foreground'] = theme.successForeground;
747
+ if (theme?.logoBackground)
748
+ vars['--szc-logo-bg'] = theme.logoBackground;
749
+ if (theme?.shippingNeutral)
750
+ vars['--szc-shipping-neutral'] = theme.shippingNeutral;
751
+ if (theme?.shippingNeutralForeground)
752
+ vars['--szc-shipping-neutral-foreground'] = theme.shippingNeutralForeground;
745
753
  if (theme?.radius != null)
746
754
  vars['--szc-radius'] = `${theme.radius}px`;
747
755
  if (theme?.fontFamily)
748
756
  vars['--szc-font'] = theme.fontFamily;
749
757
  return vars;
750
758
  }
751
- function CheckoutSkeleton({ label }) {
752
- return (jsxRuntime.jsxs("div", { className: "szc-layout szc-skeleton-layout", role: "status", "aria-label": label, children: [jsxRuntime.jsxs("main", { className: "szc-main", "aria-hidden": "true", children: [jsxRuntime.jsxs("div", { className: "szc-skeleton-cart-row", children: [jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--thumb" }), jsxRuntime.jsxs("div", { className: "szc-skeleton-copy", children: [jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--title" }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--text" }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--price" })] }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--counter" })] }), jsxRuntime.jsxs("div", { className: "szc-skeleton-cart-row", children: [jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--thumb" }), jsxRuntime.jsxs("div", { className: "szc-skeleton-copy", children: [jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--title" }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--text" }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--price" })] }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--counter" })] })] }), jsxRuntime.jsxs("div", { className: "szc-side", "aria-hidden": "true", children: [jsxRuntime.jsxs("aside", { className: "szc-summary szc-summary--skeleton", children: [jsxRuntime.jsxs("div", { className: "szc-summary__total-head", children: [jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--summary-label" }), jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--summary-total" })] }), jsxRuntime.jsxs("div", { className: "szc-skeleton-summary-lines", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("span", { className: "szc-skeleton" }), jsxRuntime.jsx("span", { className: "szc-skeleton" })] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("span", { className: "szc-skeleton" }), jsxRuntime.jsx("span", { className: "szc-skeleton" })] })] }), jsxRuntime.jsxs("div", { className: "szc-skeleton-summary-grand", children: [jsxRuntime.jsx("span", { className: "szc-skeleton" }), jsxRuntime.jsx("span", { className: "szc-skeleton" })] })] }), jsxRuntime.jsx("div", { className: "szc-side__cta", children: jsxRuntime.jsx("span", { className: "szc-skeleton szc-skeleton--button" }) })] })] }));
759
+ function CheckoutLoading({ label }) {
760
+ return (jsxRuntime.jsxs("div", { className: "szc-checkout-loading", role: "status", "aria-live": "polite", children: [jsxRuntime.jsx(Spinner, { className: "szc-checkout-loading__spinner" }), jsxRuntime.jsx("span", { children: label })] }));
753
761
  }
754
762
  function SazitoCheckout({ theme, continueShoppingUrl, className, renderNextButton, renderBackButton, renderEmptyCart, }) {
755
763
  const { state, actions, t, summary, money } = useCheckout.useCheckout();
@@ -824,7 +832,7 @@ function SazitoCheckout({ theme, continueShoppingUrl, className, renderNextButto
824
832
  ? CardIcon
825
833
  : ClipboardIcon;
826
834
  const mobileHead = (jsxRuntime.jsxs("div", { className: "szc-mobile-head", children: [footerVisible && backVisible ? (jsxRuntime.jsx("button", { type: "button", className: "szc-mobile-head__back", "aria-label": t.back, onClick: backOnClick, children: jsxRuntime.jsx("svg", { className: "szc-back-arrow", viewBox: "0 0 16 16", width: "18", height: "18", fill: "none", "aria-hidden": "true", children: jsxRuntime.jsx("path", { d: "M9.5 3.5 5 8l4.5 4.5", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }) })) : (jsxRuntime.jsx("span", {})), jsxRuntime.jsxs("span", { className: "szc-mobile-head__title", children: [jsxRuntime.jsx("span", { className: "szc-mobile-head__dot", children: jsxRuntime.jsx(HeadIcon, {}) }), headTitle] }), flowIndex >= 0 ? (jsxRuntime.jsx("span", { className: "szc-mobile-head__count", children: t.stepOf(labels.formatNumber(flowIndex + 1, state.locale), labels.formatNumber(flowSteps.length, state.locale)) })) : (jsxRuntime.jsx("span", {}))] }));
827
- return (jsxRuntime.jsxs("div", { className: `szc-root${className ? ` ${className}` : ''}`, dir: direction, style: themeVars(theme), children: [mobileHead, jsxRuntime.jsx(Stepper, {}), bootstrapping ? (jsxRuntime.jsx(CheckoutSkeleton, { label: t.loading })) : fatal ? (jsxRuntime.jsx(ErrorBanner, { message: error.message })) : isResult ? (jsxRuntime.jsx("div", { className: "szc-result-wrap", children: jsxRuntime.jsx(ResultStep, { continueShoppingUrl: continueShoppingUrl }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { className: `szc-layout${cartEmpty ? ' szc-layout--full' : ''}`, children: [jsxRuntime.jsxs("main", { className: "szc-main", children: [error ? jsxRuntime.jsx(ErrorBanner, { message: error.message }) : null, step === 'cart' ? jsxRuntime.jsx(CartStep, { continueShoppingUrl: continueShoppingUrl, renderEmpty: renderEmptyCart }) : null, step === 'shipping' ? jsxRuntime.jsx(ShippingStep, {}) : null, step === 'payment' ? jsxRuntime.jsx(PaymentStep, {}) : null, actionsVisible && backButtonNode ? (jsxRuntime.jsx("div", { className: "szc-back-row", children: backButtonNode })) : null] }), !cartEmpty ? (jsxRuntime.jsxs("div", { className: "szc-side", children: [jsxRuntime.jsx(OrderSummary, {}), actionsVisible ? jsxRuntime.jsx("div", { className: "szc-side__cta", children: nextButtonNode }) : null] })) : null] }) })), actionsVisible ? (jsxRuntime.jsx("div", { className: "szc-footer-bar", children: jsxRuntime.jsxs("div", { className: "szc-footer", children: [jsxRuntime.jsxs("div", { className: "szc-footer__total", children: [jsxRuntime.jsx("span", { className: "szc-footer__total-label", children: t.total }), jsxRuntime.jsx("span", { className: "szc-footer__total-value", children: money(summary.total) })] }), jsxRuntime.jsx("div", { className: "szc-footer__actions", children: nextButtonNode })] }) })) : null] }));
835
+ return (jsxRuntime.jsxs("div", { className: `szc-root${className ? ` ${className}` : ''}`, dir: direction, style: themeVars(theme), children: [mobileHead, jsxRuntime.jsx(Stepper, {}), bootstrapping ? (jsxRuntime.jsx(CheckoutLoading, { label: t.loading })) : fatal ? (jsxRuntime.jsx(ErrorBanner, { message: error.message })) : isResult ? (jsxRuntime.jsx("div", { className: "szc-result-wrap", children: jsxRuntime.jsx(ResultStep, { continueShoppingUrl: continueShoppingUrl }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { className: `szc-layout${cartEmpty ? ' szc-layout--full' : ''}`, children: [jsxRuntime.jsxs("main", { className: "szc-main", children: [error ? jsxRuntime.jsx(ErrorBanner, { message: error.message }) : null, step === 'cart' ? jsxRuntime.jsx(CartStep, { continueShoppingUrl: continueShoppingUrl, renderEmpty: renderEmptyCart }) : null, step === 'shipping' ? jsxRuntime.jsx(ShippingStep, {}) : null, step === 'payment' ? jsxRuntime.jsx(PaymentStep, {}) : null, actionsVisible && backButtonNode ? (jsxRuntime.jsx("div", { className: "szc-back-row", children: backButtonNode })) : null] }), !cartEmpty ? (jsxRuntime.jsxs("div", { className: "szc-side", children: [jsxRuntime.jsx(OrderSummary, {}), actionsVisible ? jsxRuntime.jsx("div", { className: "szc-side__cta", children: nextButtonNode }) : null] })) : null] }) })), actionsVisible ? (jsxRuntime.jsx("div", { className: "szc-footer-bar", children: jsxRuntime.jsxs("div", { className: "szc-footer", children: [jsxRuntime.jsxs("div", { className: "szc-footer__total", children: [jsxRuntime.jsx("span", { className: "szc-footer__total-label", children: t.total }), jsxRuntime.jsx("span", { className: "szc-footer__total-value", children: money(summary.total) })] }), jsxRuntime.jsx("div", { className: "szc-footer__actions", children: nextButtonNode })] }) })) : null] }));
828
836
  }
829
837
 
830
838
  function SazitoCheckoutPage({ credentials, config, paymentReturnParams, className, renderNextButton, renderBackButton, renderEmptyCart, }) {