@scopetickets/checkout 0.1.1 → 0.1.2

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
@@ -237,8 +237,22 @@ import {
237
237
  } from "react";
238
238
 
239
239
  // src/island/island-geometry.ts
240
- function pinEdge(align) {
241
- return align === "center" ? null : align;
240
+ var AXES = {
241
+ "top-left": { block: "top", inline: "left" },
242
+ top: { block: "top", inline: "center" },
243
+ "top-right": { block: "top", inline: "right" },
244
+ left: { block: "center", inline: "left" },
245
+ center: { block: "center", inline: "center" },
246
+ right: { block: "center", inline: "right" },
247
+ "bottom-left": { block: "bottom", inline: "left" },
248
+ bottom: { block: "bottom", inline: "center" },
249
+ "bottom-right": { block: "bottom", inline: "right" }
250
+ };
251
+ function alignmentAxes(align) {
252
+ return AXES[align];
253
+ }
254
+ function pinEdge(block) {
255
+ return block === "center" ? null : block;
242
256
  }
243
257
  var SPACE = {
244
258
  /** `$0.25` — the hairline step. */
@@ -330,12 +344,24 @@ function toLocal(rect, container, align, scale = 1) {
330
344
  height: rect.height / s
331
345
  };
332
346
  }
333
- var NO_GROWTH = Object.freeze({ surface: 0, bay: 0, gutter: 0 });
334
- function anchorTravel(growth, anchor) {
335
- return anchor === "CHROME" ? 0 : growth.surface - growth.bay - growth.gutter;
347
+ var NO_GROWTH = Object.freeze({ surface: 0, clip: 0, gutter: 0 });
348
+ function anchorTravel(growth, anchor, align) {
349
+ if (anchor === "CHROME") return 0;
350
+ switch (align) {
351
+ case "top":
352
+ return 0;
353
+ case "bottom":
354
+ return growth.clip - growth.gutter;
355
+ case "center":
356
+ return (growth.clip - growth.gutter) / 2;
357
+ default: {
358
+ const exhaustive = align;
359
+ return exhaustive;
360
+ }
361
+ }
336
362
  }
337
363
  function forSurfaceGrowth(rect, growth, anchor, align) {
338
- const travel = anchorTravel(growth, anchor);
364
+ const travel = anchorTravel(growth, anchor, align);
339
365
  switch (align) {
340
366
  case "top":
341
367
  return { ...rect, offset: rect.offset + travel };
@@ -343,6 +369,10 @@ function forSurfaceGrowth(rect, growth, anchor, align) {
343
369
  return { ...rect, offset: rect.offset + growth.surface - travel };
344
370
  case "center":
345
371
  return { ...rect, offset: rect.offset + travel - growth.surface / 2 };
372
+ default: {
373
+ const exhaustive = align;
374
+ return exhaustive;
375
+ }
346
376
  }
347
377
  }
348
378
  function carryTransform(from, to, align) {
@@ -473,6 +503,7 @@ var IslandSurface = forwardRef(function IslandSurface2({
473
503
  rowHeight,
474
504
  edge,
475
505
  align,
506
+ placement,
476
507
  journeyFullscreen,
477
508
  popAxis = "both",
478
509
  press,
@@ -482,6 +513,7 @@ var IslandSurface = forwardRef(function IslandSurface2({
482
513
  height,
483
514
  label,
484
515
  footprint,
516
+ footprintEdge,
485
517
  clipRef,
486
518
  bay,
487
519
  bayHeight,
@@ -491,6 +523,8 @@ var IslandSurface = forwardRef(function IslandSurface2({
491
523
  shield,
492
524
  sealed = false
493
525
  }, ref) {
526
+ const axes = alignmentAxes(align);
527
+ const pinned = placement === "screen";
494
528
  const style = {
495
529
  "--scopetickets-island-radius": `${radius}px`,
496
530
  "--scopetickets-island-padding-block": `${padding.block}px`,
@@ -530,13 +564,19 @@ var IslandSurface = forwardRef(function IslandSurface2({
530
564
  };
531
565
  return (
532
566
  // The reservation, and nothing else: it holds the island's collapsed footprint open
533
- // in the host page's flow and gives the frame something to be positioned against.
567
+ // in the host page's flow — or, placed on the screen, pinned to it — and gives the
568
+ // frame something to be positioned against.
534
569
  /* @__PURE__ */ jsxs3(
535
570
  "div",
536
571
  {
537
572
  "data-scopetickets-island-anchor": true,
573
+ "data-placement": pinned ? "screen" : void 0,
574
+ "data-align-block": pinned ? axes.block : void 0,
538
575
  className: "scopetickets-island-anchor",
539
- style: { "--scopetickets-island-anchor-height": `${footprint}px` },
576
+ style: {
577
+ "--scopetickets-island-anchor-height": `${footprint}px`,
578
+ ...pinned ? { "--scopetickets-island-anchor-inset": `${footprintEdge}px` } : {}
579
+ },
540
580
  children: [
541
581
  shield,
542
582
  /* @__PURE__ */ jsx5(
@@ -545,7 +585,8 @@ var IslandSurface = forwardRef(function IslandSurface2({
545
585
  ref,
546
586
  "data-scopetickets-island": true,
547
587
  "data-mode": modeAttribute(mode),
548
- "data-align": align,
588
+ "data-align-block": axes.block,
589
+ "data-align-inline": axes.inline,
549
590
  "data-journey": journeyFullscreen ? "fullscreen" : void 0,
550
591
  "data-pop-axis": popAxis === "block" ? "block" : void 0,
551
592
  "data-press": press ?? void 0,
@@ -597,6 +638,7 @@ var layoutScale = (element) => {
597
638
  };
598
639
  var startAtRest = (contentKey) => atRest(initialSlots(contentKey));
599
640
  var COLLAPSED_FOOTPRINT = footprintHeight("compact");
641
+ var COLLAPSED_EDGE = frameFor("compact").edge;
600
642
  function IslandHost({
601
643
  presentation,
602
644
  contentKey,
@@ -604,6 +646,7 @@ function IslandHost({
604
646
  label,
605
647
  mode,
606
648
  align = "bottom",
649
+ placement = "page",
607
650
  journeyFullscreen,
608
651
  chrome,
609
652
  bay,
@@ -616,6 +659,7 @@ function IslandHost({
616
659
  }) {
617
660
  const [state, dispatch] = useReducer(reduceTransition, contentKey, startAtRest);
618
661
  const frame = frameFor(presentation);
662
+ const { block } = alignmentAxes(align);
619
663
  const [press, setPress] = useState2(null);
620
664
  const ledRef = useRef3("none");
621
665
  const letGo = useRef3(null);
@@ -700,7 +744,6 @@ function IslandHost({
700
744
  );
701
745
  const clipRef = useRef3(null);
702
746
  const layerRef = useRef3(null);
703
- const baySectionRef = useRef3(null);
704
747
  const bayRef = useRef3(null);
705
748
  const [bayContent, setBayContent] = useState2(0);
706
749
  const measureBay = useCallback2(() => {
@@ -802,14 +845,16 @@ function IslandHost({
802
845
  const scale = layoutScale(layer);
803
846
  const arrivingPlane = activePlaneRef.current;
804
847
  const bayTarget = bayShown ? bayRef.current?.offsetHeight ?? 0 : 0;
805
- const baySection = baySectionRef.current;
806
- const bayNow = baySection === null ? 0 : asRect(baySection).height / scale;
848
+ const clipNow = clipRef.current === null ? 0 : asRect(clipRef.current).height / scale;
807
849
  const gutter = gutterTravel();
808
- const growth = arrivingPlane === null ? NO_GROWTH : {
809
- surface: surfaceHeight(arrivingPlane.getBoundingClientRect().height / scale + gutter) + bayTarget - container.height / scale,
810
- bay: bayTarget - bayNow,
811
- gutter
812
- };
850
+ const growth = arrivingPlane === null ? NO_GROWTH : (() => {
851
+ const planeTarget = arrivingPlane.getBoundingClientRect().height / scale + gutter;
852
+ return {
853
+ surface: planeTarget + bayTarget - container.height / scale,
854
+ clip: planeTarget - clipNow,
855
+ gutter
856
+ };
857
+ })();
813
858
  const found = [];
814
859
  for (const [name, entry] of registry.current) {
815
860
  const leavingEntry = entry[leaving] ?? entry[CHROME];
@@ -818,14 +863,14 @@ function IslandHost({
818
863
  const from = leavingEntry?.element;
819
864
  const arriving = arrivingEntry;
820
865
  if (!from || !arriving?.element) continue;
821
- const fromRect = toLocal(asRect(from), container, align, scale);
866
+ const fromRect = toLocal(asRect(from), container, block, scale);
822
867
  const toRect = forSurfaceGrowth(
823
- toLocal(asRect(arriving.element), container, align, scale),
868
+ toLocal(asRect(arriving.element), container, block, scale),
824
869
  growth,
825
870
  entry[active] === void 0 ? "CHROME" : "PLANE",
826
- align
871
+ block
827
872
  );
828
- const transform = carryTransform(fromRect, toRect, align);
873
+ const transform = carryTransform(fromRect, toRect, block);
829
874
  const moving = !isStationary(transform);
830
875
  if (arriving.carryWhen === "resized" && !isResized(transform)) continue;
831
876
  const fromLeaving = moving && drawsFromLeaving(fromRect, toRect);
@@ -842,7 +887,7 @@ function IslandHost({
842
887
  lift: toCssLift(transform),
843
888
  grow: toCssGrow(fromRect, raster),
844
889
  rest: toCssGrow(toRect, raster),
845
- lead: carryLead(fromRect, toRect, align)
890
+ lead: carryLead(fromRect, toRect, block)
846
891
  } : {}
847
892
  });
848
893
  }
@@ -850,7 +895,7 @@ function IslandHost({
850
895
  });
851
896
  if (next.length === 0) return;
852
897
  dispatch({ type: "CARRIES_MEASURED", carries: next });
853
- }, [active, state.phase, atFinalWidth, gutterTravel, align, bayShown]);
898
+ }, [active, state.phase, atFinalWidth, gutterTravel, block, bayShown]);
854
899
  useEffect2(() => {
855
900
  if (state.phase !== "PLACED") return void 0;
856
901
  const frame2 = requestAnimationFrame(() => dispatch({ type: "PAINTED" }));
@@ -901,17 +946,18 @@ function IslandHost({
901
946
  rowHeight: frame.rowHeight,
902
947
  edge: frame.edge,
903
948
  align,
949
+ placement,
904
950
  journeyFullscreen,
905
951
  popAxis,
906
952
  press: transitioning ? null : press,
907
953
  gesture,
908
954
  footprint: COLLAPSED_FOOTPRINT,
955
+ footprintEdge: COLLAPSED_EDGE,
909
956
  transitioning,
910
957
  height: height === null ? null : height + bayHeight,
911
958
  bay: bay === void 0 ? void 0 : /* @__PURE__ */ jsx6(
912
959
  "section",
913
960
  {
914
- ref: baySectionRef,
915
961
  className: "scopetickets-island-surface__bay",
916
962
  "aria-label": bayLabel,
917
963
  "aria-hidden": !bayVisible,
@@ -947,7 +993,7 @@ function IslandHost({
947
993
  // Against whatever does not move while the card grows — an edge, or
948
994
  // the centre line where the island is pinned to neither. See
949
995
  // `toCssInset`, which used to be `[align]` and could not stay that.
950
- ...toCssInset(carry.to.offset, carry.box.height, align),
996
+ ...toCssInset(carry.to.offset, carry.box.height, block),
951
997
  width: `${carry.box.width}px`,
952
998
  height: `${carry.box.height}px`,
953
999
  transform: painted ? void 0 : carry.slide
@@ -1050,6 +1096,7 @@ function CheckoutIsland({
1050
1096
  headerTrail,
1051
1097
  mode,
1052
1098
  align,
1099
+ placement,
1053
1100
  journeyFullscreen
1054
1101
  }) {
1055
1102
  const flies = !(variant === "hold" || variant === "cart");
@@ -1085,6 +1132,7 @@ function CheckoutIsland({
1085
1132
  label: "Your order",
1086
1133
  mode,
1087
1134
  align,
1135
+ placement,
1088
1136
  journeyFullscreen,
1089
1137
  chrome,
1090
1138
  bay,
@@ -8255,6 +8303,7 @@ function RestingIsland({
8255
8303
  initialPresentation = "card",
8256
8304
  mode = "system",
8257
8305
  align = "bottom",
8306
+ placement = "page",
8258
8307
  simulate = false,
8259
8308
  onCheckOut
8260
8309
  }) {
@@ -8350,6 +8399,7 @@ function RestingIsland({
8350
8399
  {
8351
8400
  mode,
8352
8401
  align,
8402
+ placement,
8353
8403
  contentKey: `IDLE:NOTICE:${notice.id}`,
8354
8404
  avatar: /* @__PURE__ */ jsx27(
8355
8405
  Avatar2,
@@ -8371,6 +8421,7 @@ function RestingIsland({
8371
8421
  {
8372
8422
  mode,
8373
8423
  align,
8424
+ placement,
8374
8425
  contentKey: "IDLE:FUNNEL",
8375
8426
  avatar: hero,
8376
8427
  ...funnelViewProps(funnel.state, {
@@ -8388,6 +8439,7 @@ function RestingIsland({
8388
8439
  {
8389
8440
  mode,
8390
8441
  align,
8442
+ placement,
8391
8443
  expanded,
8392
8444
  contentKey: "IDLE:CART",
8393
8445
  onToggle: toggle,
@@ -8418,6 +8470,7 @@ function RestingIsland({
8418
8470
  {
8419
8471
  mode,
8420
8472
  align,
8473
+ placement,
8421
8474
  expanded,
8422
8475
  contentKey: `IDLE:${prompt.card}`,
8423
8476
  onToggle: toggle,
@@ -9096,7 +9149,8 @@ function BookingIsland({
9096
9149
  walletBadge,
9097
9150
  initialPresentation = "card",
9098
9151
  mode = "system",
9099
- align = "bottom"
9152
+ align = "bottom",
9153
+ placement = "page"
9100
9154
  }) {
9101
9155
  const [expanded, setExpanded] = useState21(initialPresentation === "card");
9102
9156
  const [screen, setScreen] = useState21({ kind: "BOOKING" });
@@ -9175,7 +9229,7 @@ function BookingIsland({
9175
9229
  },
9176
9230
  [booking, commitHolder, retryable]
9177
9231
  );
9178
- const common = { mode, align, expanded, onToggle: onDismiss };
9232
+ const common = { mode, align, placement, expanded, onToggle: onDismiss };
9179
9233
  if (notice !== null) {
9180
9234
  return /* @__PURE__ */ jsx33(
9181
9235
  CheckoutIsland,
@@ -9962,7 +10016,8 @@ function ScopeTicketsCheckout({
9962
10016
  buyerAvatar: buyerAvatarValue(auth.session.auth),
9963
10017
  buyerAvatarAssets: avatarAssetsFor(defaultProfilePhotos(props.source?.environment)),
9964
10018
  mode: props.mode,
9965
- align: props.align
10019
+ align: props.align,
10020
+ placement: props.placement
9966
10021
  }
9967
10022
  ) : (
9968
10023
  /* Nothing to sell, so nothing to check out: the account card, and no cart face. */
@@ -9996,8 +10051,10 @@ function PurchaseIsland({
9996
10051
  simulate = false,
9997
10052
  onCommit,
9998
10053
  initialPresentation = "card",
10054
+ openingLabel,
9999
10055
  mode = "system",
10000
10056
  align = "bottom",
10057
+ placement = "page",
10001
10058
  opensAt,
10002
10059
  onPlaced
10003
10060
  }) {
@@ -11000,6 +11057,7 @@ function PurchaseIsland({
11000
11057
  {
11001
11058
  mode,
11002
11059
  align,
11060
+ placement,
11003
11061
  contentKey: `NOTICE:${notice.id}`,
11004
11062
  avatar: /* @__PURE__ */ jsx35(
11005
11063
  Avatar4,
@@ -11021,6 +11079,7 @@ function PurchaseIsland({
11021
11079
  {
11022
11080
  mode,
11023
11081
  align,
11082
+ placement,
11024
11083
  contentKey: "CART",
11025
11084
  bay,
11026
11085
  bayVisible: false,
@@ -11056,6 +11115,7 @@ function PurchaseIsland({
11056
11115
  {
11057
11116
  mode,
11058
11117
  align,
11118
+ placement,
11059
11119
  contentKey: "FUNNEL",
11060
11120
  avatar: /* @__PURE__ */ jsx35(
11061
11121
  Avatar4,
@@ -11080,6 +11140,7 @@ function PurchaseIsland({
11080
11140
  {
11081
11141
  mode,
11082
11142
  align,
11143
+ placement,
11083
11144
  contentKey: "HOLD_TIMED_OUT",
11084
11145
  avatar: /* @__PURE__ */ jsx35(
11085
11146
  Avatar4,
@@ -11391,6 +11452,7 @@ function PurchaseIsland({
11391
11452
  {
11392
11453
  mode,
11393
11454
  align,
11455
+ placement,
11394
11456
  expanded,
11395
11457
  journeyFullscreen: journeyInline && journeyFullscreen,
11396
11458
  contentKey: `${detour === null ? "" : "detour:"}${stepId}:${prompt?.kind === "CARD" ? prompt.card : ""}`,
@@ -11444,7 +11506,7 @@ function PurchaseIsland({
11444
11506
  ),
11445
11507
  pillCopy: { title: lines?.headline, subtitle: lines?.qualifier ?? void 0 },
11446
11508
  input,
11447
- actionLabel: detour === null && index === 0 ? OPENING_LABEL : step.collapsed.kind === "PILL" ? step.collapsed.actionLabel : step.name,
11509
+ actionLabel: detour === null && index === 0 ? openingLabel?.trim() || OPENING_LABEL : step.collapsed.kind === "PILL" ? step.collapsed.actionLabel : step.name,
11448
11510
  actions: toIslandActions(planeActions),
11449
11511
  bayActions: toIslandActions(bayActions)
11450
11512
  }