@betterstore/react 0.2.44 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bug fix
8
+
9
+ ## 0.2.45
10
+
11
+ ### Patch Changes
12
+
13
+ - new version
14
+
3
15
  ## 0.2.44
4
16
 
5
17
  ### Patch Changes
@@ -1,10 +1,10 @@
1
1
  import { LineItem } from "@betterstore/sdk";
2
2
  import React from "react";
3
- export default function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }: {
3
+ export default function CheckoutSummary({ lineItems, shipping, tax, currency, onCancel, exchangeRate, }: {
4
4
  lineItems: LineItem[];
5
5
  shipping?: number;
6
6
  tax?: number;
7
7
  currency: string;
8
8
  exchangeRate: number;
9
- cancelUrl: string;
9
+ onCancel: () => void;
10
10
  }): React.JSX.Element;
@@ -5,6 +5,8 @@ export interface FormStore {
5
5
  setFormData: (formData: Partial<CheckoutFormData>) => void;
6
6
  step: CheckoutStep;
7
7
  setStep: (step: CheckoutStep) => void;
8
+ checkoutId: string;
9
+ setCheckoutId: (checkoutId: string) => void;
8
10
  }
9
11
  export declare const useFormStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<FormStore>, "persist"> & {
10
12
  persist: {
package/dist/index.cjs.js CHANGED
@@ -5088,25 +5088,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
5088
5088
  attrs[keys.array] = `${pathLength} ${pathSpacing}`;
5089
5089
  }
5090
5090
 
5091
- function calcOrigin$1(origin, offset, size) {
5092
- return typeof origin === "string"
5093
- ? origin
5094
- : px.transform(offset + size * origin);
5095
- }
5096
- /**
5097
- * The SVG transform origin defaults are different to CSS and is less intuitive,
5098
- * so we use the measured dimensions of the SVG to reconcile these.
5099
- */
5100
- function calcSVGTransformOrigin(dimensions, originX, originY) {
5101
- const pxOriginX = calcOrigin$1(originX, dimensions.x, dimensions.width);
5102
- const pxOriginY = calcOrigin$1(originY, dimensions.y, dimensions.height);
5103
- return `${pxOriginX} ${pxOriginY}`;
5104
- }
5105
-
5106
5091
  /**
5107
5092
  * Build SVG visual attrbutes, like cx and style.transform
5108
5093
  */
5109
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
5094
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
5110
5095
  // This is object creation, which we try to avoid per-frame.
5111
5096
  ...latest }, isSVGTag, transformTemplate) {
5112
5097
  buildHTMLStyles(state, latest, transformTemplate);
@@ -5122,20 +5107,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
5122
5107
  }
5123
5108
  state.attrs = state.style;
5124
5109
  state.style = {};
5125
- const { attrs, style, dimensions } = state;
5110
+ const { attrs, style } = state;
5126
5111
  /**
5127
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
5128
- * and copy it into style.
5112
+ * However, we apply transforms as CSS transforms.
5113
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
5129
5114
  */
5130
5115
  if (attrs.transform) {
5131
- if (dimensions)
5132
- style.transform = attrs.transform;
5116
+ style.transform = attrs.transform;
5133
5117
  delete attrs.transform;
5134
5118
  }
5135
- // Parse transformOrigin
5136
- if (dimensions &&
5137
- (originX !== undefined || originY !== undefined || style.transform)) {
5138
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
5119
+ if (style.transform || attrs.transformOrigin) {
5120
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
5121
+ delete attrs.transformOrigin;
5122
+ }
5123
+ if (style.transform) {
5124
+ /**
5125
+ * SVG's element transform-origin uses its own median as a reference.
5126
+ * Therefore, transformBox becomes a fill-box
5127
+ */
5128
+ style.transformBox = "fill-box";
5129
+ delete attrs.transformBox;
5139
5130
  }
5140
5131
  // Render attrX/attrY/attrScale as attributes
5141
5132
  if (attrX !== undefined)
@@ -5243,20 +5234,11 @@ function resolveMotionValue(value) {
5243
5234
  return isMotionValue(value) ? value.get() : value;
5244
5235
  }
5245
5236
 
5246
- function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
5237
+ function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
5247
5238
  const state = {
5248
5239
  latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
5249
5240
  renderState: createRenderState(),
5250
5241
  };
5251
- if (onUpdate) {
5252
- /**
5253
- * onMount works without the VisualElement because it could be
5254
- * called before the VisualElement payload has been hydrated.
5255
- * (e.g. if someone is using m components <m.circle />)
5256
- */
5257
- state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
5258
- state.onUpdate = (visualElement) => onUpdate(visualElement);
5259
- }
5260
5242
  return state;
5261
5243
  }
5262
5244
  const makeUseVisualState = (config) => (props, isStatic) => {
@@ -5343,68 +5325,6 @@ const htmlMotionConfig = {
5343
5325
  }),
5344
5326
  };
5345
5327
 
5346
- function updateSVGDimensions(instance, renderState) {
5347
- try {
5348
- renderState.dimensions =
5349
- typeof instance.getBBox === "function"
5350
- ? instance.getBBox()
5351
- : instance.getBoundingClientRect();
5352
- }
5353
- catch (e) {
5354
- // Most likely trying to measure an unrendered element under Firefox
5355
- renderState.dimensions = {
5356
- x: 0,
5357
- y: 0,
5358
- width: 0,
5359
- height: 0,
5360
- };
5361
- }
5362
- }
5363
-
5364
- function renderHTML(element, { style, vars }, styleProp, projection) {
5365
- Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
5366
- // Loop over any CSS variables and assign those.
5367
- for (const key in vars) {
5368
- element.style.setProperty(key, vars[key]);
5369
- }
5370
- }
5371
-
5372
- /**
5373
- * A set of attribute names that are always read/written as camel case.
5374
- */
5375
- const camelCaseAttributes = new Set([
5376
- "baseFrequency",
5377
- "diffuseConstant",
5378
- "kernelMatrix",
5379
- "kernelUnitLength",
5380
- "keySplines",
5381
- "keyTimes",
5382
- "limitingConeAngle",
5383
- "markerHeight",
5384
- "markerWidth",
5385
- "numOctaves",
5386
- "targetX",
5387
- "targetY",
5388
- "surfaceScale",
5389
- "specularConstant",
5390
- "specularExponent",
5391
- "stdDeviation",
5392
- "tableValues",
5393
- "viewBox",
5394
- "gradientTransform",
5395
- "pathLength",
5396
- "startOffset",
5397
- "textLength",
5398
- "lengthAdjust",
5399
- ]);
5400
-
5401
- function renderSVG(element, renderState, _styleProp, projection) {
5402
- renderHTML(element, renderState, undefined, projection);
5403
- for (const key in renderState.attrs) {
5404
- element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
5405
- }
5406
- }
5407
-
5408
5328
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
5409
5329
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
5410
5330
  for (const key in props) {
@@ -5419,49 +5339,10 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
5419
5339
  return newValues;
5420
5340
  }
5421
5341
 
5422
- const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
5423
5342
  const svgMotionConfig = {
5424
5343
  useVisualState: makeUseVisualState({
5425
5344
  scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
5426
5345
  createRenderState: createSvgRenderState,
5427
- onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
5428
- if (!current)
5429
- return;
5430
- let hasTransform = !!props.drag;
5431
- if (!hasTransform) {
5432
- for (const key in latestValues) {
5433
- if (transformProps.has(key)) {
5434
- hasTransform = true;
5435
- break;
5436
- }
5437
- }
5438
- }
5439
- if (!hasTransform)
5440
- return;
5441
- let needsMeasure = !prevProps;
5442
- if (prevProps) {
5443
- /**
5444
- * Check the layout props for changes, if any are found we need to
5445
- * measure the element again.
5446
- */
5447
- for (let i = 0; i < layoutProps.length; i++) {
5448
- const key = layoutProps[i];
5449
- if (props[key] !==
5450
- prevProps[key]) {
5451
- needsMeasure = true;
5452
- }
5453
- }
5454
- }
5455
- if (!needsMeasure)
5456
- return;
5457
- frame.read(() => {
5458
- updateSVGDimensions(current, renderState);
5459
- frame.render(() => {
5460
- buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
5461
- renderSVG(current, renderState);
5462
- });
5463
- });
5464
- },
5465
5346
  }),
5466
5347
  };
5467
5348
 
@@ -5599,7 +5480,7 @@ class MotionValue {
5599
5480
  * This will be replaced by the build step with the latest version number.
5600
5481
  * When MotionValues are provided to motion components, warn if versions are mixed.
5601
5482
  */
5602
- this.version = "12.8.0";
5483
+ this.version = "12.9.0";
5603
5484
  /**
5604
5485
  * Tracks whether this value can output a velocity. Currently this is only true
5605
5486
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -5625,12 +5506,12 @@ class MotionValue {
5625
5506
  this.prev = this.current;
5626
5507
  this.setCurrent(v);
5627
5508
  // Update update subscribers
5628
- if (this.current !== this.prev && this.events.change) {
5629
- this.events.change.notify(this.current);
5509
+ if (this.current !== this.prev) {
5510
+ this.events.change?.notify(this.current);
5630
5511
  }
5631
5512
  // Update render subscribers
5632
- if (render && this.events.renderRequest) {
5633
- this.events.renderRequest.notify(this.current);
5513
+ if (render) {
5514
+ this.events.renderRequest?.notify(this.current);
5634
5515
  }
5635
5516
  };
5636
5517
  this.hasAnimated = false;
@@ -5743,8 +5624,6 @@ class MotionValue {
5743
5624
  * @public
5744
5625
  */
5745
5626
  set(v, render = true) {
5746
- if (v === "none")
5747
- console.trace();
5748
5627
  if (!render || !this.passiveEffect) {
5749
5628
  this.updateAndNotify(v, render);
5750
5629
  }
@@ -7451,7 +7330,6 @@ class JSAnimation extends WithPromise {
7451
7330
  this.holdTime = null;
7452
7331
  }
7453
7332
  finish() {
7454
- this.notifyFinished();
7455
7333
  this.teardown();
7456
7334
  this.state = "finished";
7457
7335
  const { onComplete } = this.options;
@@ -7464,6 +7342,7 @@ class JSAnimation extends WithPromise {
7464
7342
  this.teardown();
7465
7343
  }
7466
7344
  teardown() {
7345
+ this.notifyFinished();
7467
7346
  this.state = "idle";
7468
7347
  this.stopDriver();
7469
7348
  this.startTime = this.holdTime = null;
@@ -7886,7 +7765,7 @@ class NativeAnimation extends WithPromise {
7886
7765
  this.isStopped = false;
7887
7766
  if (!options)
7888
7767
  return;
7889
- const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, } = options;
7768
+ const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, onComplete, } = options;
7890
7769
  this.isPseudoElement = Boolean(pseudoElement);
7891
7770
  this.allowFlatten = allowFlatten;
7892
7771
  this.options = options;
@@ -7912,8 +7791,13 @@ class NativeAnimation extends WithPromise {
7912
7791
  }
7913
7792
  this.animation.cancel();
7914
7793
  }
7794
+ onComplete?.();
7915
7795
  this.notifyFinished();
7916
7796
  };
7797
+ /**
7798
+ * TODO: In a breaking change, we should replace this with `.notifyCancel()`
7799
+ */
7800
+ this.animation.oncancel = () => this.notifyFinished();
7917
7801
  }
7918
7802
  play() {
7919
7803
  if (this.isStopped)
@@ -8238,7 +8122,7 @@ class AsyncMotionValueAnimation extends WithPromise {
8238
8122
  }
8239
8123
  onKeyframesResolved(keyframes, finalKeyframe, options, sync) {
8240
8124
  this.keyframeResolver = undefined;
8241
- const { name, type, velocity, delay, isHandoff, onUpdate, onComplete } = options;
8125
+ const { name, type, velocity, delay, isHandoff, onUpdate } = options;
8242
8126
  this.resolvedAt = time.now();
8243
8127
  /**
8244
8128
  * If we can't animate this value with the resolved keyframes
@@ -8288,12 +8172,7 @@ class AsyncMotionValueAnimation extends WithPromise {
8288
8172
  element: resolvedOptions.motionValue.owner.current,
8289
8173
  })
8290
8174
  : new JSAnimation(resolvedOptions);
8291
- animation.finished
8292
- .then(() => {
8293
- onComplete?.();
8294
- this.notifyFinished();
8295
- })
8296
- .catch(noop);
8175
+ animation.finished.then(() => this.notifyFinished()).catch(noop);
8297
8176
  if (this.pendingTimeline) {
8298
8177
  this.stopTimeline = animation.attachTimeline(this.pendingTimeline);
8299
8178
  this.pendingTimeline = undefined;
@@ -8491,6 +8370,17 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
8491
8370
  delay,
8492
8371
  ...getValueTransition(transition || {}, key),
8493
8372
  };
8373
+ /**
8374
+ * If the value is already at the defined target, skip the animation.
8375
+ */
8376
+ const currentValue = value.get();
8377
+ if (currentValue !== undefined &&
8378
+ !value.isAnimating &&
8379
+ !Array.isArray(valueTarget) &&
8380
+ valueTarget === currentValue &&
8381
+ !valueTransition.velocity) {
8382
+ continue;
8383
+ }
8494
8384
  /**
8495
8385
  * If this is the first time a value is being animated, check
8496
8386
  * to see if we're handling off from an existing animation.
@@ -12822,7 +12712,7 @@ function updateMotionValuesFromProps(element, next, prev) {
12822
12712
  * and warn against mismatches.
12823
12713
  */
12824
12714
  if (process.env.NODE_ENV === "development") {
12825
- warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
12715
+ warnOnce(nextValue.version === "12.9.0", `Attempting to mix Motion versions ${nextValue.version} with 12.9.0 may not work as expected.`);
12826
12716
  }
12827
12717
  }
12828
12718
  else if (isMotionValue(prevValue)) {
@@ -13057,8 +12947,7 @@ class VisualElement {
13057
12947
  frame.render(this.render, false, true);
13058
12948
  }
13059
12949
  };
13060
- const { latestValues, renderState, onUpdate } = visualState;
13061
- this.onUpdate = onUpdate;
12950
+ const { latestValues, renderState } = visualState;
13062
12951
  this.latestValues = latestValues;
13063
12952
  this.baseTarget = { ...latestValues };
13064
12953
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -13260,7 +13149,6 @@ class VisualElement {
13260
13149
  if (this.handleChildMotionValue) {
13261
13150
  this.handleChildMotionValue();
13262
13151
  }
13263
- this.onUpdate && this.onUpdate(this);
13264
13152
  }
13265
13153
  getProps() {
13266
13154
  return this.props;
@@ -13654,6 +13542,14 @@ class DOMVisualElement extends VisualElement {
13654
13542
  }
13655
13543
  }
13656
13544
 
13545
+ function renderHTML(element, { style, vars }, styleProp, projection) {
13546
+ Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
13547
+ // Loop over any CSS variables and assign those.
13548
+ for (const key in vars) {
13549
+ element.style.setProperty(key, vars[key]);
13550
+ }
13551
+ }
13552
+
13657
13553
  function getComputedStyle$1(element) {
13658
13554
  return window.getComputedStyle(element);
13659
13555
  }
@@ -13686,17 +13582,48 @@ class HTMLVisualElement extends DOMVisualElement {
13686
13582
  }
13687
13583
  }
13688
13584
 
13585
+ /**
13586
+ * A set of attribute names that are always read/written as camel case.
13587
+ */
13588
+ const camelCaseAttributes = new Set([
13589
+ "baseFrequency",
13590
+ "diffuseConstant",
13591
+ "kernelMatrix",
13592
+ "kernelUnitLength",
13593
+ "keySplines",
13594
+ "keyTimes",
13595
+ "limitingConeAngle",
13596
+ "markerHeight",
13597
+ "markerWidth",
13598
+ "numOctaves",
13599
+ "targetX",
13600
+ "targetY",
13601
+ "surfaceScale",
13602
+ "specularConstant",
13603
+ "specularExponent",
13604
+ "stdDeviation",
13605
+ "tableValues",
13606
+ "viewBox",
13607
+ "gradientTransform",
13608
+ "pathLength",
13609
+ "startOffset",
13610
+ "textLength",
13611
+ "lengthAdjust",
13612
+ ]);
13613
+
13614
+ function renderSVG(element, renderState, _styleProp, projection) {
13615
+ renderHTML(element, renderState, undefined, projection);
13616
+ for (const key in renderState.attrs) {
13617
+ element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
13618
+ }
13619
+ }
13620
+
13689
13621
  class SVGVisualElement extends DOMVisualElement {
13690
13622
  constructor() {
13691
13623
  super(...arguments);
13692
13624
  this.type = "svg";
13693
13625
  this.isSVGTag = false;
13694
13626
  this.measureInstanceViewportBox = createBox;
13695
- this.updateDimensions = () => {
13696
- if (this.current && !this.renderState.dimensions) {
13697
- updateSVGDimensions(this.current, this.renderState);
13698
- }
13699
- };
13700
13627
  }
13701
13628
  getBaseTargetFromProps(props, key) {
13702
13629
  return props[key];
@@ -13712,11 +13639,6 @@ class SVGVisualElement extends DOMVisualElement {
13712
13639
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
13713
13640
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
13714
13641
  }
13715
- onBindTransform() {
13716
- if (this.current && !this.renderState.dimensions) {
13717
- frame.postRender(this.updateDimensions);
13718
- }
13719
- }
13720
13642
  build(renderState, latestValues, props) {
13721
13643
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
13722
13644
  }
@@ -34336,6 +34258,8 @@ const useFormStore = create()(persist((set) => ({
34336
34258
  setFormData: (formData) => set({ formData }),
34337
34259
  step: "customer",
34338
34260
  setStep: (step) => set({ step }),
34261
+ checkoutId: "",
34262
+ setCheckoutId: (checkoutId) => set({ checkoutId }),
34339
34263
  }), { name: `checkout` }));
34340
34264
 
34341
34265
  const motionSettings = {
@@ -34345,7 +34269,7 @@ const motionSettings = {
34345
34269
  transition: { duration: 0.2 },
34346
34270
  };
34347
34271
  function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }) {
34348
- const { formData, setFormData, step, setStep } = useFormStore();
34272
+ const { formData, setFormData, step, setStep, checkoutId: storedCheckoutId, setCheckoutId, } = useFormStore();
34349
34273
  const [paymentSecret, setPaymentSecret] = React.useState(null);
34350
34274
  const [publicKey, setPublicKey] = React.useState(null);
34351
34275
  const [shippingRates, setShippingRates] = React.useState([]);
@@ -34369,21 +34293,53 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
34369
34293
  validateStep();
34370
34294
  }, [step]);
34371
34295
  React.useEffect(() => {
34372
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
34373
- if (customer && !((_a = formData.customer) === null || _a === void 0 ? void 0 : _a.email)) {
34296
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
34297
+ if (checkoutId !== storedCheckoutId) {
34298
+ setStep("customer");
34299
+ setCheckoutId(checkoutId);
34300
+ if (customer) {
34301
+ setFormData({
34302
+ customerId: customer.id,
34303
+ customer: {
34304
+ firstName: (_c = (_b = (_a = customer.address) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split(" ")[0]) !== null && _c !== void 0 ? _c : "",
34305
+ lastName: (_f = (_e = (_d = customer.address) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.split(" ")[1]) !== null && _f !== void 0 ? _f : "",
34306
+ phone: (_h = (_g = customer.address) === null || _g === void 0 ? void 0 : _g.phone) !== null && _h !== void 0 ? _h : "",
34307
+ email: (_j = customer.email) !== null && _j !== void 0 ? _j : "",
34308
+ address: {
34309
+ line1: (_l = (_k = customer.address) === null || _k === void 0 ? void 0 : _k.line1) !== null && _l !== void 0 ? _l : "",
34310
+ line2: (_o = (_m = customer.address) === null || _m === void 0 ? void 0 : _m.line2) !== null && _o !== void 0 ? _o : "",
34311
+ city: (_q = (_p = customer.address) === null || _p === void 0 ? void 0 : _p.city) !== null && _q !== void 0 ? _q : "",
34312
+ zipCode: (_s = (_r = customer.address) === null || _r === void 0 ? void 0 : _r.zipCode) !== null && _s !== void 0 ? _s : "",
34313
+ country: (_u = (_t = customer.address) === null || _t === void 0 ? void 0 : _t.country) !== null && _u !== void 0 ? _u : "",
34314
+ countryCode: (_w = (_v = customer.address) === null || _v === void 0 ? void 0 : _v.countryCode) !== null && _w !== void 0 ? _w : "",
34315
+ },
34316
+ },
34317
+ });
34318
+ }
34319
+ else if ((_x = formData.customer) === null || _x === void 0 ? void 0 : _x.email) {
34320
+ setFormData({
34321
+ customer: formData.customer,
34322
+ });
34323
+ }
34324
+ else {
34325
+ setFormData({});
34326
+ }
34327
+ return;
34328
+ }
34329
+ if (customer && !((_y = formData.customer) === null || _y === void 0 ? void 0 : _y.email)) {
34374
34330
  const step = customer.id ? "shipping" : "customer";
34375
34331
  setFormData(Object.assign(Object.assign({}, formData), { customerId: customer.id, customer: {
34376
- firstName: (_d = (_c = (_b = customer.address) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split(" ")[0]) !== null && _d !== void 0 ? _d : "",
34377
- lastName: (_g = (_f = (_e = customer.address) === null || _e === void 0 ? void 0 : _e.name) === null || _f === void 0 ? void 0 : _f.split(" ")[1]) !== null && _g !== void 0 ? _g : "",
34378
- phone: (_j = (_h = customer.address) === null || _h === void 0 ? void 0 : _h.phone) !== null && _j !== void 0 ? _j : "",
34379
- email: (_k = customer.email) !== null && _k !== void 0 ? _k : "",
34332
+ firstName: (_1 = (_0 = (_z = customer.address) === null || _z === void 0 ? void 0 : _z.name) === null || _0 === void 0 ? void 0 : _0.split(" ")[0]) !== null && _1 !== void 0 ? _1 : "",
34333
+ lastName: (_4 = (_3 = (_2 = customer.address) === null || _2 === void 0 ? void 0 : _2.name) === null || _3 === void 0 ? void 0 : _3.split(" ")[1]) !== null && _4 !== void 0 ? _4 : "",
34334
+ phone: (_6 = (_5 = customer.address) === null || _5 === void 0 ? void 0 : _5.phone) !== null && _6 !== void 0 ? _6 : "",
34335
+ email: (_7 = customer.email) !== null && _7 !== void 0 ? _7 : "",
34380
34336
  address: {
34381
- line1: (_m = (_l = customer.address) === null || _l === void 0 ? void 0 : _l.line1) !== null && _m !== void 0 ? _m : "",
34382
- line2: (_p = (_o = customer.address) === null || _o === void 0 ? void 0 : _o.line2) !== null && _p !== void 0 ? _p : "",
34383
- city: (_r = (_q = customer.address) === null || _q === void 0 ? void 0 : _q.city) !== null && _r !== void 0 ? _r : "",
34384
- zipCode: (_t = (_s = customer.address) === null || _s === void 0 ? void 0 : _s.zipCode) !== null && _t !== void 0 ? _t : "",
34385
- country: (_v = (_u = customer.address) === null || _u === void 0 ? void 0 : _u.country) !== null && _v !== void 0 ? _v : "",
34386
- countryCode: (_x = (_w = customer.address) === null || _w === void 0 ? void 0 : _w.countryCode) !== null && _x !== void 0 ? _x : "",
34337
+ line1: (_9 = (_8 = customer.address) === null || _8 === void 0 ? void 0 : _8.line1) !== null && _9 !== void 0 ? _9 : "",
34338
+ line2: (_11 = (_10 = customer.address) === null || _10 === void 0 ? void 0 : _10.line2) !== null && _11 !== void 0 ? _11 : "",
34339
+ city: (_13 = (_12 = customer.address) === null || _12 === void 0 ? void 0 : _12.city) !== null && _13 !== void 0 ? _13 : "",
34340
+ zipCode: (_15 = (_14 = customer.address) === null || _14 === void 0 ? void 0 : _14.zipCode) !== null && _15 !== void 0 ? _15 : "",
34341
+ country: (_17 = (_16 = customer.address) === null || _16 === void 0 ? void 0 : _16.country) !== null && _17 !== void 0 ? _17 : "",
34342
+ countryCode: (_19 = (_18 = customer.address) === null || _18 === void 0 ? void 0 : _18.countryCode) !== null && _19 !== void 0 ? _19 : "",
34387
34343
  },
34388
34344
  } }));
34389
34345
  setStep(step);
@@ -34505,7 +34461,7 @@ function InputGroupLoading({ className }) {
34505
34461
  React.createElement(Skeleton, { className: "w-full h-9" })));
34506
34462
  }
34507
34463
 
34508
- function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }) {
34464
+ function CheckoutSummary({ lineItems, shipping, tax, currency, onCancel, exchangeRate, }) {
34509
34465
  var _a;
34510
34466
  const { formData } = useFormStore();
34511
34467
  const [isOpen, setIsOpen] = React.useState(false);
@@ -34532,8 +34488,7 @@ function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchan
34532
34488
  "rotate-180": isOpen,
34533
34489
  }) })),
34534
34490
  React.createElement("p", { className: "font-bold text-lg tracking-tight md:hidden" }, storeHelpers.formatPrice(total, currency, exchangeRate)),
34535
- React.createElement(Button, { className: "max-sm:hidden", variant: "link", size: "link", asChild: true },
34536
- React.createElement("a", { href: cancelUrl }, t("CheckoutEmbed.Summary.edit")))),
34491
+ React.createElement(Button, { className: "max-sm:hidden", variant: "link", size: "link", onClick: onCancel }, t("CheckoutEmbed.Summary.edit"))),
34537
34492
  React.createElement("hr", null),
34538
34493
  React.createElement("div", { className: clsx("gap-3 order-4 md:order-none", {
34539
34494
  "hidden md:grid": !isOpen,
@@ -34623,6 +34578,7 @@ function CheckoutEmbed({ checkoutId, config }) {
34623
34578
  const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
34624
34579
  const storeClient = sdk.createStoreClient({ proxy: clientProxy });
34625
34580
  React.useMemo(() => createI18nInstance(locale), []);
34581
+ const { formData, setFormData, step, setStep } = useFormStore();
34626
34582
  const [checkout, setCheckout] = React.useState(null);
34627
34583
  const [loading, setLoading] = React.useState(true);
34628
34584
  React.useEffect(() => {
@@ -34651,15 +34607,20 @@ function CheckoutEmbed({ checkoutId, config }) {
34651
34607
  };
34652
34608
  }, [checkoutId]); // Only re-run if checkoutId changes
34653
34609
  const onSuccess = () => {
34610
+ setStep("customer");
34611
+ setFormData({ customer: formData.customer });
34654
34612
  if (successUrl) {
34655
34613
  window.location.href = successUrl;
34656
34614
  }
34657
34615
  };
34658
- const onError = () => {
34616
+ const onCancel = () => {
34617
+ setStep("customer");
34618
+ setFormData({ customer: formData.customer });
34659
34619
  if (cancelUrl) {
34660
34620
  window.location.href = cancelUrl;
34661
34621
  }
34662
34622
  };
34623
+ const onError = () => { };
34663
34624
  if (!checkout && !loading) {
34664
34625
  throw new Error("Checkout not found");
34665
34626
  }
@@ -34671,7 +34632,7 @@ function CheckoutEmbed({ checkoutId, config }) {
34671
34632
  return (React.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
34672
34633
  React.createElement(Appearance, { appearance: appearance }),
34673
34634
  React.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1 }))),
34674
- React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
34635
+ React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, onCancel: onCancel, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
34675
34636
  }
34676
34637
  var index = React.memo(CheckoutEmbed);
34677
34638
 
package/dist/index.mjs CHANGED
@@ -5065,25 +5065,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
5065
5065
  attrs[keys.array] = `${pathLength} ${pathSpacing}`;
5066
5066
  }
5067
5067
 
5068
- function calcOrigin$1(origin, offset, size) {
5069
- return typeof origin === "string"
5070
- ? origin
5071
- : px.transform(offset + size * origin);
5072
- }
5073
- /**
5074
- * The SVG transform origin defaults are different to CSS and is less intuitive,
5075
- * so we use the measured dimensions of the SVG to reconcile these.
5076
- */
5077
- function calcSVGTransformOrigin(dimensions, originX, originY) {
5078
- const pxOriginX = calcOrigin$1(originX, dimensions.x, dimensions.width);
5079
- const pxOriginY = calcOrigin$1(originY, dimensions.y, dimensions.height);
5080
- return `${pxOriginX} ${pxOriginY}`;
5081
- }
5082
-
5083
5068
  /**
5084
5069
  * Build SVG visual attrbutes, like cx and style.transform
5085
5070
  */
5086
- function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
5071
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
5087
5072
  // This is object creation, which we try to avoid per-frame.
5088
5073
  ...latest }, isSVGTag, transformTemplate) {
5089
5074
  buildHTMLStyles(state, latest, transformTemplate);
@@ -5099,20 +5084,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
5099
5084
  }
5100
5085
  state.attrs = state.style;
5101
5086
  state.style = {};
5102
- const { attrs, style, dimensions } = state;
5087
+ const { attrs, style } = state;
5103
5088
  /**
5104
- * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
5105
- * and copy it into style.
5089
+ * However, we apply transforms as CSS transforms.
5090
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
5106
5091
  */
5107
5092
  if (attrs.transform) {
5108
- if (dimensions)
5109
- style.transform = attrs.transform;
5093
+ style.transform = attrs.transform;
5110
5094
  delete attrs.transform;
5111
5095
  }
5112
- // Parse transformOrigin
5113
- if (dimensions &&
5114
- (originX !== undefined || originY !== undefined || style.transform)) {
5115
- style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
5096
+ if (style.transform || attrs.transformOrigin) {
5097
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
5098
+ delete attrs.transformOrigin;
5099
+ }
5100
+ if (style.transform) {
5101
+ /**
5102
+ * SVG's element transform-origin uses its own median as a reference.
5103
+ * Therefore, transformBox becomes a fill-box
5104
+ */
5105
+ style.transformBox = "fill-box";
5106
+ delete attrs.transformBox;
5116
5107
  }
5117
5108
  // Render attrX/attrY/attrScale as attributes
5118
5109
  if (attrX !== undefined)
@@ -5220,20 +5211,11 @@ function resolveMotionValue(value) {
5220
5211
  return isMotionValue(value) ? value.get() : value;
5221
5212
  }
5222
5213
 
5223
- function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
5214
+ function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
5224
5215
  const state = {
5225
5216
  latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
5226
5217
  renderState: createRenderState(),
5227
5218
  };
5228
- if (onUpdate) {
5229
- /**
5230
- * onMount works without the VisualElement because it could be
5231
- * called before the VisualElement payload has been hydrated.
5232
- * (e.g. if someone is using m components <m.circle />)
5233
- */
5234
- state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
5235
- state.onUpdate = (visualElement) => onUpdate(visualElement);
5236
- }
5237
5219
  return state;
5238
5220
  }
5239
5221
  const makeUseVisualState = (config) => (props, isStatic) => {
@@ -5320,68 +5302,6 @@ const htmlMotionConfig = {
5320
5302
  }),
5321
5303
  };
5322
5304
 
5323
- function updateSVGDimensions(instance, renderState) {
5324
- try {
5325
- renderState.dimensions =
5326
- typeof instance.getBBox === "function"
5327
- ? instance.getBBox()
5328
- : instance.getBoundingClientRect();
5329
- }
5330
- catch (e) {
5331
- // Most likely trying to measure an unrendered element under Firefox
5332
- renderState.dimensions = {
5333
- x: 0,
5334
- y: 0,
5335
- width: 0,
5336
- height: 0,
5337
- };
5338
- }
5339
- }
5340
-
5341
- function renderHTML(element, { style, vars }, styleProp, projection) {
5342
- Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
5343
- // Loop over any CSS variables and assign those.
5344
- for (const key in vars) {
5345
- element.style.setProperty(key, vars[key]);
5346
- }
5347
- }
5348
-
5349
- /**
5350
- * A set of attribute names that are always read/written as camel case.
5351
- */
5352
- const camelCaseAttributes = new Set([
5353
- "baseFrequency",
5354
- "diffuseConstant",
5355
- "kernelMatrix",
5356
- "kernelUnitLength",
5357
- "keySplines",
5358
- "keyTimes",
5359
- "limitingConeAngle",
5360
- "markerHeight",
5361
- "markerWidth",
5362
- "numOctaves",
5363
- "targetX",
5364
- "targetY",
5365
- "surfaceScale",
5366
- "specularConstant",
5367
- "specularExponent",
5368
- "stdDeviation",
5369
- "tableValues",
5370
- "viewBox",
5371
- "gradientTransform",
5372
- "pathLength",
5373
- "startOffset",
5374
- "textLength",
5375
- "lengthAdjust",
5376
- ]);
5377
-
5378
- function renderSVG(element, renderState, _styleProp, projection) {
5379
- renderHTML(element, renderState, undefined, projection);
5380
- for (const key in renderState.attrs) {
5381
- element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
5382
- }
5383
- }
5384
-
5385
5305
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
5386
5306
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
5387
5307
  for (const key in props) {
@@ -5396,49 +5316,10 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
5396
5316
  return newValues;
5397
5317
  }
5398
5318
 
5399
- const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
5400
5319
  const svgMotionConfig = {
5401
5320
  useVisualState: makeUseVisualState({
5402
5321
  scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
5403
5322
  createRenderState: createSvgRenderState,
5404
- onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
5405
- if (!current)
5406
- return;
5407
- let hasTransform = !!props.drag;
5408
- if (!hasTransform) {
5409
- for (const key in latestValues) {
5410
- if (transformProps.has(key)) {
5411
- hasTransform = true;
5412
- break;
5413
- }
5414
- }
5415
- }
5416
- if (!hasTransform)
5417
- return;
5418
- let needsMeasure = !prevProps;
5419
- if (prevProps) {
5420
- /**
5421
- * Check the layout props for changes, if any are found we need to
5422
- * measure the element again.
5423
- */
5424
- for (let i = 0; i < layoutProps.length; i++) {
5425
- const key = layoutProps[i];
5426
- if (props[key] !==
5427
- prevProps[key]) {
5428
- needsMeasure = true;
5429
- }
5430
- }
5431
- }
5432
- if (!needsMeasure)
5433
- return;
5434
- frame.read(() => {
5435
- updateSVGDimensions(current, renderState);
5436
- frame.render(() => {
5437
- buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
5438
- renderSVG(current, renderState);
5439
- });
5440
- });
5441
- },
5442
5323
  }),
5443
5324
  };
5444
5325
 
@@ -5576,7 +5457,7 @@ class MotionValue {
5576
5457
  * This will be replaced by the build step with the latest version number.
5577
5458
  * When MotionValues are provided to motion components, warn if versions are mixed.
5578
5459
  */
5579
- this.version = "12.8.0";
5460
+ this.version = "12.9.0";
5580
5461
  /**
5581
5462
  * Tracks whether this value can output a velocity. Currently this is only true
5582
5463
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -5602,12 +5483,12 @@ class MotionValue {
5602
5483
  this.prev = this.current;
5603
5484
  this.setCurrent(v);
5604
5485
  // Update update subscribers
5605
- if (this.current !== this.prev && this.events.change) {
5606
- this.events.change.notify(this.current);
5486
+ if (this.current !== this.prev) {
5487
+ this.events.change?.notify(this.current);
5607
5488
  }
5608
5489
  // Update render subscribers
5609
- if (render && this.events.renderRequest) {
5610
- this.events.renderRequest.notify(this.current);
5490
+ if (render) {
5491
+ this.events.renderRequest?.notify(this.current);
5611
5492
  }
5612
5493
  };
5613
5494
  this.hasAnimated = false;
@@ -5720,8 +5601,6 @@ class MotionValue {
5720
5601
  * @public
5721
5602
  */
5722
5603
  set(v, render = true) {
5723
- if (v === "none")
5724
- console.trace();
5725
5604
  if (!render || !this.passiveEffect) {
5726
5605
  this.updateAndNotify(v, render);
5727
5606
  }
@@ -7428,7 +7307,6 @@ class JSAnimation extends WithPromise {
7428
7307
  this.holdTime = null;
7429
7308
  }
7430
7309
  finish() {
7431
- this.notifyFinished();
7432
7310
  this.teardown();
7433
7311
  this.state = "finished";
7434
7312
  const { onComplete } = this.options;
@@ -7441,6 +7319,7 @@ class JSAnimation extends WithPromise {
7441
7319
  this.teardown();
7442
7320
  }
7443
7321
  teardown() {
7322
+ this.notifyFinished();
7444
7323
  this.state = "idle";
7445
7324
  this.stopDriver();
7446
7325
  this.startTime = this.holdTime = null;
@@ -7863,7 +7742,7 @@ class NativeAnimation extends WithPromise {
7863
7742
  this.isStopped = false;
7864
7743
  if (!options)
7865
7744
  return;
7866
- const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, } = options;
7745
+ const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, onComplete, } = options;
7867
7746
  this.isPseudoElement = Boolean(pseudoElement);
7868
7747
  this.allowFlatten = allowFlatten;
7869
7748
  this.options = options;
@@ -7889,8 +7768,13 @@ class NativeAnimation extends WithPromise {
7889
7768
  }
7890
7769
  this.animation.cancel();
7891
7770
  }
7771
+ onComplete?.();
7892
7772
  this.notifyFinished();
7893
7773
  };
7774
+ /**
7775
+ * TODO: In a breaking change, we should replace this with `.notifyCancel()`
7776
+ */
7777
+ this.animation.oncancel = () => this.notifyFinished();
7894
7778
  }
7895
7779
  play() {
7896
7780
  if (this.isStopped)
@@ -8215,7 +8099,7 @@ class AsyncMotionValueAnimation extends WithPromise {
8215
8099
  }
8216
8100
  onKeyframesResolved(keyframes, finalKeyframe, options, sync) {
8217
8101
  this.keyframeResolver = undefined;
8218
- const { name, type, velocity, delay, isHandoff, onUpdate, onComplete } = options;
8102
+ const { name, type, velocity, delay, isHandoff, onUpdate } = options;
8219
8103
  this.resolvedAt = time.now();
8220
8104
  /**
8221
8105
  * If we can't animate this value with the resolved keyframes
@@ -8265,12 +8149,7 @@ class AsyncMotionValueAnimation extends WithPromise {
8265
8149
  element: resolvedOptions.motionValue.owner.current,
8266
8150
  })
8267
8151
  : new JSAnimation(resolvedOptions);
8268
- animation.finished
8269
- .then(() => {
8270
- onComplete?.();
8271
- this.notifyFinished();
8272
- })
8273
- .catch(noop);
8152
+ animation.finished.then(() => this.notifyFinished()).catch(noop);
8274
8153
  if (this.pendingTimeline) {
8275
8154
  this.stopTimeline = animation.attachTimeline(this.pendingTimeline);
8276
8155
  this.pendingTimeline = undefined;
@@ -8468,6 +8347,17 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
8468
8347
  delay,
8469
8348
  ...getValueTransition(transition || {}, key),
8470
8349
  };
8350
+ /**
8351
+ * If the value is already at the defined target, skip the animation.
8352
+ */
8353
+ const currentValue = value.get();
8354
+ if (currentValue !== undefined &&
8355
+ !value.isAnimating &&
8356
+ !Array.isArray(valueTarget) &&
8357
+ valueTarget === currentValue &&
8358
+ !valueTransition.velocity) {
8359
+ continue;
8360
+ }
8471
8361
  /**
8472
8362
  * If this is the first time a value is being animated, check
8473
8363
  * to see if we're handling off from an existing animation.
@@ -12799,7 +12689,7 @@ function updateMotionValuesFromProps(element, next, prev) {
12799
12689
  * and warn against mismatches.
12800
12690
  */
12801
12691
  if (process.env.NODE_ENV === "development") {
12802
- warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
12692
+ warnOnce(nextValue.version === "12.9.0", `Attempting to mix Motion versions ${nextValue.version} with 12.9.0 may not work as expected.`);
12803
12693
  }
12804
12694
  }
12805
12695
  else if (isMotionValue(prevValue)) {
@@ -13034,8 +12924,7 @@ class VisualElement {
13034
12924
  frame.render(this.render, false, true);
13035
12925
  }
13036
12926
  };
13037
- const { latestValues, renderState, onUpdate } = visualState;
13038
- this.onUpdate = onUpdate;
12927
+ const { latestValues, renderState } = visualState;
13039
12928
  this.latestValues = latestValues;
13040
12929
  this.baseTarget = { ...latestValues };
13041
12930
  this.initialValues = props.initial ? { ...latestValues } : {};
@@ -13237,7 +13126,6 @@ class VisualElement {
13237
13126
  if (this.handleChildMotionValue) {
13238
13127
  this.handleChildMotionValue();
13239
13128
  }
13240
- this.onUpdate && this.onUpdate(this);
13241
13129
  }
13242
13130
  getProps() {
13243
13131
  return this.props;
@@ -13631,6 +13519,14 @@ class DOMVisualElement extends VisualElement {
13631
13519
  }
13632
13520
  }
13633
13521
 
13522
+ function renderHTML(element, { style, vars }, styleProp, projection) {
13523
+ Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
13524
+ // Loop over any CSS variables and assign those.
13525
+ for (const key in vars) {
13526
+ element.style.setProperty(key, vars[key]);
13527
+ }
13528
+ }
13529
+
13634
13530
  function getComputedStyle$1(element) {
13635
13531
  return window.getComputedStyle(element);
13636
13532
  }
@@ -13663,17 +13559,48 @@ class HTMLVisualElement extends DOMVisualElement {
13663
13559
  }
13664
13560
  }
13665
13561
 
13562
+ /**
13563
+ * A set of attribute names that are always read/written as camel case.
13564
+ */
13565
+ const camelCaseAttributes = new Set([
13566
+ "baseFrequency",
13567
+ "diffuseConstant",
13568
+ "kernelMatrix",
13569
+ "kernelUnitLength",
13570
+ "keySplines",
13571
+ "keyTimes",
13572
+ "limitingConeAngle",
13573
+ "markerHeight",
13574
+ "markerWidth",
13575
+ "numOctaves",
13576
+ "targetX",
13577
+ "targetY",
13578
+ "surfaceScale",
13579
+ "specularConstant",
13580
+ "specularExponent",
13581
+ "stdDeviation",
13582
+ "tableValues",
13583
+ "viewBox",
13584
+ "gradientTransform",
13585
+ "pathLength",
13586
+ "startOffset",
13587
+ "textLength",
13588
+ "lengthAdjust",
13589
+ ]);
13590
+
13591
+ function renderSVG(element, renderState, _styleProp, projection) {
13592
+ renderHTML(element, renderState, undefined, projection);
13593
+ for (const key in renderState.attrs) {
13594
+ element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
13595
+ }
13596
+ }
13597
+
13666
13598
  class SVGVisualElement extends DOMVisualElement {
13667
13599
  constructor() {
13668
13600
  super(...arguments);
13669
13601
  this.type = "svg";
13670
13602
  this.isSVGTag = false;
13671
13603
  this.measureInstanceViewportBox = createBox;
13672
- this.updateDimensions = () => {
13673
- if (this.current && !this.renderState.dimensions) {
13674
- updateSVGDimensions(this.current, this.renderState);
13675
- }
13676
- };
13677
13604
  }
13678
13605
  getBaseTargetFromProps(props, key) {
13679
13606
  return props[key];
@@ -13689,11 +13616,6 @@ class SVGVisualElement extends DOMVisualElement {
13689
13616
  scrapeMotionValuesFromProps(props, prevProps, visualElement) {
13690
13617
  return scrapeMotionValuesFromProps(props, prevProps, visualElement);
13691
13618
  }
13692
- onBindTransform() {
13693
- if (this.current && !this.renderState.dimensions) {
13694
- frame.postRender(this.updateDimensions);
13695
- }
13696
- }
13697
13619
  build(renderState, latestValues, props) {
13698
13620
  buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
13699
13621
  }
@@ -34313,6 +34235,8 @@ const useFormStore = create()(persist((set) => ({
34313
34235
  setFormData: (formData) => set({ formData }),
34314
34236
  step: "customer",
34315
34237
  setStep: (step) => set({ step }),
34238
+ checkoutId: "",
34239
+ setCheckoutId: (checkoutId) => set({ checkoutId }),
34316
34240
  }), { name: `checkout` }));
34317
34241
 
34318
34242
  const motionSettings = {
@@ -34322,7 +34246,7 @@ const motionSettings = {
34322
34246
  transition: { duration: 0.2 },
34323
34247
  };
34324
34248
  function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }) {
34325
- const { formData, setFormData, step, setStep } = useFormStore();
34249
+ const { formData, setFormData, step, setStep, checkoutId: storedCheckoutId, setCheckoutId, } = useFormStore();
34326
34250
  const [paymentSecret, setPaymentSecret] = useState(null);
34327
34251
  const [publicKey, setPublicKey] = useState(null);
34328
34252
  const [shippingRates, setShippingRates] = useState([]);
@@ -34346,21 +34270,53 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
34346
34270
  validateStep();
34347
34271
  }, [step]);
34348
34272
  useEffect(() => {
34349
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
34350
- if (customer && !((_a = formData.customer) === null || _a === void 0 ? void 0 : _a.email)) {
34273
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
34274
+ if (checkoutId !== storedCheckoutId) {
34275
+ setStep("customer");
34276
+ setCheckoutId(checkoutId);
34277
+ if (customer) {
34278
+ setFormData({
34279
+ customerId: customer.id,
34280
+ customer: {
34281
+ firstName: (_c = (_b = (_a = customer.address) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split(" ")[0]) !== null && _c !== void 0 ? _c : "",
34282
+ lastName: (_f = (_e = (_d = customer.address) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.split(" ")[1]) !== null && _f !== void 0 ? _f : "",
34283
+ phone: (_h = (_g = customer.address) === null || _g === void 0 ? void 0 : _g.phone) !== null && _h !== void 0 ? _h : "",
34284
+ email: (_j = customer.email) !== null && _j !== void 0 ? _j : "",
34285
+ address: {
34286
+ line1: (_l = (_k = customer.address) === null || _k === void 0 ? void 0 : _k.line1) !== null && _l !== void 0 ? _l : "",
34287
+ line2: (_o = (_m = customer.address) === null || _m === void 0 ? void 0 : _m.line2) !== null && _o !== void 0 ? _o : "",
34288
+ city: (_q = (_p = customer.address) === null || _p === void 0 ? void 0 : _p.city) !== null && _q !== void 0 ? _q : "",
34289
+ zipCode: (_s = (_r = customer.address) === null || _r === void 0 ? void 0 : _r.zipCode) !== null && _s !== void 0 ? _s : "",
34290
+ country: (_u = (_t = customer.address) === null || _t === void 0 ? void 0 : _t.country) !== null && _u !== void 0 ? _u : "",
34291
+ countryCode: (_w = (_v = customer.address) === null || _v === void 0 ? void 0 : _v.countryCode) !== null && _w !== void 0 ? _w : "",
34292
+ },
34293
+ },
34294
+ });
34295
+ }
34296
+ else if ((_x = formData.customer) === null || _x === void 0 ? void 0 : _x.email) {
34297
+ setFormData({
34298
+ customer: formData.customer,
34299
+ });
34300
+ }
34301
+ else {
34302
+ setFormData({});
34303
+ }
34304
+ return;
34305
+ }
34306
+ if (customer && !((_y = formData.customer) === null || _y === void 0 ? void 0 : _y.email)) {
34351
34307
  const step = customer.id ? "shipping" : "customer";
34352
34308
  setFormData(Object.assign(Object.assign({}, formData), { customerId: customer.id, customer: {
34353
- firstName: (_d = (_c = (_b = customer.address) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split(" ")[0]) !== null && _d !== void 0 ? _d : "",
34354
- lastName: (_g = (_f = (_e = customer.address) === null || _e === void 0 ? void 0 : _e.name) === null || _f === void 0 ? void 0 : _f.split(" ")[1]) !== null && _g !== void 0 ? _g : "",
34355
- phone: (_j = (_h = customer.address) === null || _h === void 0 ? void 0 : _h.phone) !== null && _j !== void 0 ? _j : "",
34356
- email: (_k = customer.email) !== null && _k !== void 0 ? _k : "",
34309
+ firstName: (_1 = (_0 = (_z = customer.address) === null || _z === void 0 ? void 0 : _z.name) === null || _0 === void 0 ? void 0 : _0.split(" ")[0]) !== null && _1 !== void 0 ? _1 : "",
34310
+ lastName: (_4 = (_3 = (_2 = customer.address) === null || _2 === void 0 ? void 0 : _2.name) === null || _3 === void 0 ? void 0 : _3.split(" ")[1]) !== null && _4 !== void 0 ? _4 : "",
34311
+ phone: (_6 = (_5 = customer.address) === null || _5 === void 0 ? void 0 : _5.phone) !== null && _6 !== void 0 ? _6 : "",
34312
+ email: (_7 = customer.email) !== null && _7 !== void 0 ? _7 : "",
34357
34313
  address: {
34358
- line1: (_m = (_l = customer.address) === null || _l === void 0 ? void 0 : _l.line1) !== null && _m !== void 0 ? _m : "",
34359
- line2: (_p = (_o = customer.address) === null || _o === void 0 ? void 0 : _o.line2) !== null && _p !== void 0 ? _p : "",
34360
- city: (_r = (_q = customer.address) === null || _q === void 0 ? void 0 : _q.city) !== null && _r !== void 0 ? _r : "",
34361
- zipCode: (_t = (_s = customer.address) === null || _s === void 0 ? void 0 : _s.zipCode) !== null && _t !== void 0 ? _t : "",
34362
- country: (_v = (_u = customer.address) === null || _u === void 0 ? void 0 : _u.country) !== null && _v !== void 0 ? _v : "",
34363
- countryCode: (_x = (_w = customer.address) === null || _w === void 0 ? void 0 : _w.countryCode) !== null && _x !== void 0 ? _x : "",
34314
+ line1: (_9 = (_8 = customer.address) === null || _8 === void 0 ? void 0 : _8.line1) !== null && _9 !== void 0 ? _9 : "",
34315
+ line2: (_11 = (_10 = customer.address) === null || _10 === void 0 ? void 0 : _10.line2) !== null && _11 !== void 0 ? _11 : "",
34316
+ city: (_13 = (_12 = customer.address) === null || _12 === void 0 ? void 0 : _12.city) !== null && _13 !== void 0 ? _13 : "",
34317
+ zipCode: (_15 = (_14 = customer.address) === null || _14 === void 0 ? void 0 : _14.zipCode) !== null && _15 !== void 0 ? _15 : "",
34318
+ country: (_17 = (_16 = customer.address) === null || _16 === void 0 ? void 0 : _16.country) !== null && _17 !== void 0 ? _17 : "",
34319
+ countryCode: (_19 = (_18 = customer.address) === null || _18 === void 0 ? void 0 : _18.countryCode) !== null && _19 !== void 0 ? _19 : "",
34364
34320
  },
34365
34321
  } }));
34366
34322
  setStep(step);
@@ -34482,7 +34438,7 @@ function InputGroupLoading({ className }) {
34482
34438
  React__default.createElement(Skeleton, { className: "w-full h-9" })));
34483
34439
  }
34484
34440
 
34485
- function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }) {
34441
+ function CheckoutSummary({ lineItems, shipping, tax, currency, onCancel, exchangeRate, }) {
34486
34442
  var _a;
34487
34443
  const { formData } = useFormStore();
34488
34444
  const [isOpen, setIsOpen] = useState(false);
@@ -34509,8 +34465,7 @@ function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchan
34509
34465
  "rotate-180": isOpen,
34510
34466
  }) })),
34511
34467
  React__default.createElement("p", { className: "font-bold text-lg tracking-tight md:hidden" }, storeHelpers.formatPrice(total, currency, exchangeRate)),
34512
- React__default.createElement(Button, { className: "max-sm:hidden", variant: "link", size: "link", asChild: true },
34513
- React__default.createElement("a", { href: cancelUrl }, t("CheckoutEmbed.Summary.edit")))),
34468
+ React__default.createElement(Button, { className: "max-sm:hidden", variant: "link", size: "link", onClick: onCancel }, t("CheckoutEmbed.Summary.edit"))),
34514
34469
  React__default.createElement("hr", null),
34515
34470
  React__default.createElement("div", { className: clsx("gap-3 order-4 md:order-none", {
34516
34471
  "hidden md:grid": !isOpen,
@@ -34600,6 +34555,7 @@ function CheckoutEmbed({ checkoutId, config }) {
34600
34555
  const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
34601
34556
  const storeClient = createStoreClient({ proxy: clientProxy });
34602
34557
  React__default.useMemo(() => createI18nInstance(locale), []);
34558
+ const { formData, setFormData, step, setStep } = useFormStore();
34603
34559
  const [checkout, setCheckout] = useState(null);
34604
34560
  const [loading, setLoading] = useState(true);
34605
34561
  useEffect(() => {
@@ -34628,15 +34584,20 @@ function CheckoutEmbed({ checkoutId, config }) {
34628
34584
  };
34629
34585
  }, [checkoutId]); // Only re-run if checkoutId changes
34630
34586
  const onSuccess = () => {
34587
+ setStep("customer");
34588
+ setFormData({ customer: formData.customer });
34631
34589
  if (successUrl) {
34632
34590
  window.location.href = successUrl;
34633
34591
  }
34634
34592
  };
34635
- const onError = () => {
34593
+ const onCancel = () => {
34594
+ setStep("customer");
34595
+ setFormData({ customer: formData.customer });
34636
34596
  if (cancelUrl) {
34637
34597
  window.location.href = cancelUrl;
34638
34598
  }
34639
34599
  };
34600
+ const onError = () => { };
34640
34601
  if (!checkout && !loading) {
34641
34602
  throw new Error("Checkout not found");
34642
34603
  }
@@ -34648,7 +34609,7 @@ function CheckoutEmbed({ checkoutId, config }) {
34648
34609
  return (React__default.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
34649
34610
  React__default.createElement(Appearance, { appearance: appearance }),
34650
34611
  React__default.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1 }))),
34651
- React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
34612
+ React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, onCancel: onCancel, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
34652
34613
  }
34653
34614
  var index = memo$1(CheckoutEmbed);
34654
34615
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/react",
3
- "version": "0.2.44",
3
+ "version": "0.3.0",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {