@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/README.md CHANGED
@@ -33,7 +33,7 @@ import '@scopetickets/checkout/styles.css';
33
33
  <ScopeTicketsCheckout
34
34
  appKey="…"
35
35
  intent={{ subject: { kind: 'series', key: 'a-run-of-nights' } }}
36
- align="bottom" // or "top", or "center" — which way the card grows
36
+ align="bottom" // or "top", "center", "left", "right", or a corner such as "top-left"
37
37
  initialPresentation="card" // or "pill" — the state the page loads on
38
38
  />
39
39
  ```
@@ -42,6 +42,23 @@ The host supplies no copy, no styling and no steps: hand it what is already know
42
42
  about the order and it asks for the rest in its own words. `intent` is how much it
43
43
  already knows, and every field in it is a step the buyer is not asked for.
44
44
 
45
+ **One exception: `openingLabel`**, the words on the opening pill. It names what is on
46
+ sale, which the page knows and the widget does not, so a page selling one show can say
47
+ `openingLabel="Book Santo Panto"`. Absent or blank, the pill says "Get Tickets". Every
48
+ later pill names its step and stays the widget's own.
49
+
50
+ **Floating on the screen, or in the page — `placement`.** By default the widget sits
51
+ where it was mounted and `align` places it inside that box. `placement="screen"` pins it
52
+ to the window instead, so `align` names a corner of the screen and the host writes no
53
+ positioning CSS of its own:
54
+
55
+ ```tsx
56
+ <ScopeTicketsCheckout appKey="…" placement="screen" align="top-right" />
57
+ ```
58
+
59
+ A `transform`, `filter` or `contain` on any ancestor still captures a fixed box, so mount a
60
+ pinned widget at the end of `<body>` rather than inside a theme's wrapper.
61
+
45
62
  **Leave `intent` out and it mounts with nothing to sell.** No walk, no steps, no
46
63
  cart and nothing fetched — one card about the buyer's account, which is what
47
64
  belongs on a page that is not selling anything:
package/dist/index.cjs CHANGED
@@ -429,8 +429,22 @@ function IslandHeader({
429
429
  var import_react6 = require("react");
430
430
 
431
431
  // src/island/island-geometry.ts
432
- function pinEdge(align) {
433
- return align === "center" ? null : align;
432
+ var AXES = {
433
+ "top-left": { block: "top", inline: "left" },
434
+ top: { block: "top", inline: "center" },
435
+ "top-right": { block: "top", inline: "right" },
436
+ left: { block: "center", inline: "left" },
437
+ center: { block: "center", inline: "center" },
438
+ right: { block: "center", inline: "right" },
439
+ "bottom-left": { block: "bottom", inline: "left" },
440
+ bottom: { block: "bottom", inline: "center" },
441
+ "bottom-right": { block: "bottom", inline: "right" }
442
+ };
443
+ function alignmentAxes(align) {
444
+ return AXES[align];
445
+ }
446
+ function pinEdge(block) {
447
+ return block === "center" ? null : block;
434
448
  }
435
449
  var SPACE = {
436
450
  /** `$0.25` — the hairline step. */
@@ -522,12 +536,24 @@ function toLocal(rect, container, align, scale = 1) {
522
536
  height: rect.height / s
523
537
  };
524
538
  }
525
- var NO_GROWTH = Object.freeze({ surface: 0, bay: 0, gutter: 0 });
526
- function anchorTravel(growth, anchor) {
527
- return anchor === "CHROME" ? 0 : growth.surface - growth.bay - growth.gutter;
539
+ var NO_GROWTH = Object.freeze({ surface: 0, clip: 0, gutter: 0 });
540
+ function anchorTravel(growth, anchor, align) {
541
+ if (anchor === "CHROME") return 0;
542
+ switch (align) {
543
+ case "top":
544
+ return 0;
545
+ case "bottom":
546
+ return growth.clip - growth.gutter;
547
+ case "center":
548
+ return (growth.clip - growth.gutter) / 2;
549
+ default: {
550
+ const exhaustive = align;
551
+ return exhaustive;
552
+ }
553
+ }
528
554
  }
529
555
  function forSurfaceGrowth(rect, growth, anchor, align) {
530
- const travel = anchorTravel(growth, anchor);
556
+ const travel = anchorTravel(growth, anchor, align);
531
557
  switch (align) {
532
558
  case "top":
533
559
  return { ...rect, offset: rect.offset + travel };
@@ -535,6 +561,10 @@ function forSurfaceGrowth(rect, growth, anchor, align) {
535
561
  return { ...rect, offset: rect.offset + growth.surface - travel };
536
562
  case "center":
537
563
  return { ...rect, offset: rect.offset + travel - growth.surface / 2 };
564
+ default: {
565
+ const exhaustive = align;
566
+ return exhaustive;
567
+ }
538
568
  }
539
569
  }
540
570
  function carryTransform(from, to, align) {
@@ -665,6 +695,7 @@ var IslandSurface = (0, import_react5.forwardRef)(function IslandSurface2({
665
695
  rowHeight,
666
696
  edge,
667
697
  align,
698
+ placement,
668
699
  journeyFullscreen,
669
700
  popAxis = "both",
670
701
  press,
@@ -674,6 +705,7 @@ var IslandSurface = (0, import_react5.forwardRef)(function IslandSurface2({
674
705
  height,
675
706
  label,
676
707
  footprint,
708
+ footprintEdge,
677
709
  clipRef,
678
710
  bay,
679
711
  bayHeight,
@@ -683,6 +715,8 @@ var IslandSurface = (0, import_react5.forwardRef)(function IslandSurface2({
683
715
  shield,
684
716
  sealed = false
685
717
  }, ref) {
718
+ const axes = alignmentAxes(align);
719
+ const pinned = placement === "screen";
686
720
  const style = {
687
721
  "--scopetickets-island-radius": `${radius}px`,
688
722
  "--scopetickets-island-padding-block": `${padding.block}px`,
@@ -722,13 +756,19 @@ var IslandSurface = (0, import_react5.forwardRef)(function IslandSurface2({
722
756
  };
723
757
  return (
724
758
  // The reservation, and nothing else: it holds the island's collapsed footprint open
725
- // in the host page's flow and gives the frame something to be positioned against.
759
+ // in the host page's flow — or, placed on the screen, pinned to it — and gives the
760
+ // frame something to be positioned against.
726
761
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
727
762
  "div",
728
763
  {
729
764
  "data-scopetickets-island-anchor": true,
765
+ "data-placement": pinned ? "screen" : void 0,
766
+ "data-align-block": pinned ? axes.block : void 0,
730
767
  className: "scopetickets-island-anchor",
731
- style: { "--scopetickets-island-anchor-height": `${footprint}px` },
768
+ style: {
769
+ "--scopetickets-island-anchor-height": `${footprint}px`,
770
+ ...pinned ? { "--scopetickets-island-anchor-inset": `${footprintEdge}px` } : {}
771
+ },
732
772
  children: [
733
773
  shield,
734
774
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -737,7 +777,8 @@ var IslandSurface = (0, import_react5.forwardRef)(function IslandSurface2({
737
777
  ref,
738
778
  "data-scopetickets-island": true,
739
779
  "data-mode": modeAttribute(mode),
740
- "data-align": align,
780
+ "data-align-block": axes.block,
781
+ "data-align-inline": axes.inline,
741
782
  "data-journey": journeyFullscreen ? "fullscreen" : void 0,
742
783
  "data-pop-axis": popAxis === "block" ? "block" : void 0,
743
784
  "data-press": press ?? void 0,
@@ -789,6 +830,7 @@ var layoutScale = (element) => {
789
830
  };
790
831
  var startAtRest = (contentKey) => atRest(initialSlots(contentKey));
791
832
  var COLLAPSED_FOOTPRINT = footprintHeight("compact");
833
+ var COLLAPSED_EDGE = frameFor("compact").edge;
792
834
  function IslandHost({
793
835
  presentation,
794
836
  contentKey,
@@ -796,6 +838,7 @@ function IslandHost({
796
838
  label,
797
839
  mode,
798
840
  align = "bottom",
841
+ placement = "page",
799
842
  journeyFullscreen,
800
843
  chrome,
801
844
  bay,
@@ -808,6 +851,7 @@ function IslandHost({
808
851
  }) {
809
852
  const [state, dispatch] = (0, import_react6.useReducer)(reduceTransition, contentKey, startAtRest);
810
853
  const frame = frameFor(presentation);
854
+ const { block } = alignmentAxes(align);
811
855
  const [press, setPress] = (0, import_react6.useState)(null);
812
856
  const ledRef = (0, import_react6.useRef)("none");
813
857
  const letGo = (0, import_react6.useRef)(null);
@@ -892,7 +936,6 @@ function IslandHost({
892
936
  );
893
937
  const clipRef = (0, import_react6.useRef)(null);
894
938
  const layerRef = (0, import_react6.useRef)(null);
895
- const baySectionRef = (0, import_react6.useRef)(null);
896
939
  const bayRef = (0, import_react6.useRef)(null);
897
940
  const [bayContent, setBayContent] = (0, import_react6.useState)(0);
898
941
  const measureBay = (0, import_react6.useCallback)(() => {
@@ -994,14 +1037,16 @@ function IslandHost({
994
1037
  const scale = layoutScale(layer);
995
1038
  const arrivingPlane = activePlaneRef.current;
996
1039
  const bayTarget = bayShown ? bayRef.current?.offsetHeight ?? 0 : 0;
997
- const baySection = baySectionRef.current;
998
- const bayNow = baySection === null ? 0 : asRect(baySection).height / scale;
1040
+ const clipNow = clipRef.current === null ? 0 : asRect(clipRef.current).height / scale;
999
1041
  const gutter = gutterTravel();
1000
- const growth = arrivingPlane === null ? NO_GROWTH : {
1001
- surface: surfaceHeight(arrivingPlane.getBoundingClientRect().height / scale + gutter) + bayTarget - container.height / scale,
1002
- bay: bayTarget - bayNow,
1003
- gutter
1004
- };
1042
+ const growth = arrivingPlane === null ? NO_GROWTH : (() => {
1043
+ const planeTarget = arrivingPlane.getBoundingClientRect().height / scale + gutter;
1044
+ return {
1045
+ surface: planeTarget + bayTarget - container.height / scale,
1046
+ clip: planeTarget - clipNow,
1047
+ gutter
1048
+ };
1049
+ })();
1005
1050
  const found = [];
1006
1051
  for (const [name, entry] of registry.current) {
1007
1052
  const leavingEntry = entry[leaving] ?? entry[CHROME];
@@ -1010,14 +1055,14 @@ function IslandHost({
1010
1055
  const from = leavingEntry?.element;
1011
1056
  const arriving = arrivingEntry;
1012
1057
  if (!from || !arriving?.element) continue;
1013
- const fromRect = toLocal(asRect(from), container, align, scale);
1058
+ const fromRect = toLocal(asRect(from), container, block, scale);
1014
1059
  const toRect = forSurfaceGrowth(
1015
- toLocal(asRect(arriving.element), container, align, scale),
1060
+ toLocal(asRect(arriving.element), container, block, scale),
1016
1061
  growth,
1017
1062
  entry[active] === void 0 ? "CHROME" : "PLANE",
1018
- align
1063
+ block
1019
1064
  );
1020
- const transform = carryTransform(fromRect, toRect, align);
1065
+ const transform = carryTransform(fromRect, toRect, block);
1021
1066
  const moving = !isStationary(transform);
1022
1067
  if (arriving.carryWhen === "resized" && !isResized(transform)) continue;
1023
1068
  const fromLeaving = moving && drawsFromLeaving(fromRect, toRect);
@@ -1034,7 +1079,7 @@ function IslandHost({
1034
1079
  lift: toCssLift(transform),
1035
1080
  grow: toCssGrow(fromRect, raster),
1036
1081
  rest: toCssGrow(toRect, raster),
1037
- lead: carryLead(fromRect, toRect, align)
1082
+ lead: carryLead(fromRect, toRect, block)
1038
1083
  } : {}
1039
1084
  });
1040
1085
  }
@@ -1042,7 +1087,7 @@ function IslandHost({
1042
1087
  });
1043
1088
  if (next.length === 0) return;
1044
1089
  dispatch({ type: "CARRIES_MEASURED", carries: next });
1045
- }, [active, state.phase, atFinalWidth, gutterTravel, align, bayShown]);
1090
+ }, [active, state.phase, atFinalWidth, gutterTravel, block, bayShown]);
1046
1091
  (0, import_react6.useEffect)(() => {
1047
1092
  if (state.phase !== "PLACED") return void 0;
1048
1093
  const frame2 = requestAnimationFrame(() => dispatch({ type: "PAINTED" }));
@@ -1093,17 +1138,18 @@ function IslandHost({
1093
1138
  rowHeight: frame.rowHeight,
1094
1139
  edge: frame.edge,
1095
1140
  align,
1141
+ placement,
1096
1142
  journeyFullscreen,
1097
1143
  popAxis,
1098
1144
  press: transitioning ? null : press,
1099
1145
  gesture,
1100
1146
  footprint: COLLAPSED_FOOTPRINT,
1147
+ footprintEdge: COLLAPSED_EDGE,
1101
1148
  transitioning,
1102
1149
  height: height === null ? null : height + bayHeight,
1103
1150
  bay: bay === void 0 ? void 0 : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1104
1151
  "section",
1105
1152
  {
1106
- ref: baySectionRef,
1107
1153
  className: "scopetickets-island-surface__bay",
1108
1154
  "aria-label": bayLabel,
1109
1155
  "aria-hidden": !bayVisible,
@@ -1139,7 +1185,7 @@ function IslandHost({
1139
1185
  // Against whatever does not move while the card grows — an edge, or
1140
1186
  // the centre line where the island is pinned to neither. See
1141
1187
  // `toCssInset`, which used to be `[align]` and could not stay that.
1142
- ...toCssInset(carry.to.offset, carry.box.height, align),
1188
+ ...toCssInset(carry.to.offset, carry.box.height, block),
1143
1189
  width: `${carry.box.width}px`,
1144
1190
  height: `${carry.box.height}px`,
1145
1191
  transform: painted ? void 0 : carry.slide
@@ -1242,6 +1288,7 @@ function CheckoutIsland({
1242
1288
  headerTrail,
1243
1289
  mode,
1244
1290
  align,
1291
+ placement,
1245
1292
  journeyFullscreen
1246
1293
  }) {
1247
1294
  const flies = !(variant === "hold" || variant === "cart");
@@ -1277,6 +1324,7 @@ function CheckoutIsland({
1277
1324
  label: "Your order",
1278
1325
  mode,
1279
1326
  align,
1327
+ placement,
1280
1328
  journeyFullscreen,
1281
1329
  chrome,
1282
1330
  bay,
@@ -9306,6 +9354,7 @@ function RestingIsland({
9306
9354
  initialPresentation = "card",
9307
9355
  mode = "system",
9308
9356
  align = "bottom",
9357
+ placement = "page",
9309
9358
  simulate = false,
9310
9359
  onCheckOut
9311
9360
  }) {
@@ -9401,6 +9450,7 @@ function RestingIsland({
9401
9450
  {
9402
9451
  mode,
9403
9452
  align,
9453
+ placement,
9404
9454
  contentKey: `IDLE:NOTICE:${notice.id}`,
9405
9455
  avatar: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
9406
9456
  import_avatar3.Avatar,
@@ -9422,6 +9472,7 @@ function RestingIsland({
9422
9472
  {
9423
9473
  mode,
9424
9474
  align,
9475
+ placement,
9425
9476
  contentKey: "IDLE:FUNNEL",
9426
9477
  avatar: hero,
9427
9478
  ...funnelViewProps(funnel.state, {
@@ -9439,6 +9490,7 @@ function RestingIsland({
9439
9490
  {
9440
9491
  mode,
9441
9492
  align,
9493
+ placement,
9442
9494
  expanded,
9443
9495
  contentKey: "IDLE:CART",
9444
9496
  onToggle: toggle,
@@ -9469,6 +9521,7 @@ function RestingIsland({
9469
9521
  {
9470
9522
  mode,
9471
9523
  align,
9524
+ placement,
9472
9525
  expanded,
9473
9526
  contentKey: `IDLE:${prompt.card}`,
9474
9527
  onToggle: toggle,
@@ -10135,7 +10188,8 @@ function BookingIsland({
10135
10188
  walletBadge,
10136
10189
  initialPresentation = "card",
10137
10190
  mode = "system",
10138
- align = "bottom"
10191
+ align = "bottom",
10192
+ placement = "page"
10139
10193
  }) {
10140
10194
  const [expanded, setExpanded] = (0, import_react30.useState)(initialPresentation === "card");
10141
10195
  const [screen, setScreen] = (0, import_react30.useState)({ kind: "BOOKING" });
@@ -10214,7 +10268,7 @@ function BookingIsland({
10214
10268
  },
10215
10269
  [booking, commitHolder, retryable]
10216
10270
  );
10217
- const common = { mode, align, expanded, onToggle: onDismiss };
10271
+ const common = { mode, align, placement, expanded, onToggle: onDismiss };
10218
10272
  if (notice !== null) {
10219
10273
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
10220
10274
  CheckoutIsland,
@@ -11709,7 +11763,8 @@ function ScopeTicketsCheckout({
11709
11763
  buyerAvatar: buyerAvatarValue(auth.session.auth),
11710
11764
  buyerAvatarAssets: avatarAssetsFor(defaultProfilePhotos(props.source?.environment)),
11711
11765
  mode: props.mode,
11712
- align: props.align
11766
+ align: props.align,
11767
+ placement: props.placement
11713
11768
  }
11714
11769
  ) : (
11715
11770
  /* Nothing to sell, so nothing to check out: the account card, and no cart face. */
@@ -11743,8 +11798,10 @@ function PurchaseIsland({
11743
11798
  simulate = false,
11744
11799
  onCommit,
11745
11800
  initialPresentation = "card",
11801
+ openingLabel,
11746
11802
  mode = "system",
11747
11803
  align = "bottom",
11804
+ placement = "page",
11748
11805
  opensAt,
11749
11806
  onPlaced
11750
11807
  }) {
@@ -12747,6 +12804,7 @@ function PurchaseIsland({
12747
12804
  {
12748
12805
  mode,
12749
12806
  align,
12807
+ placement,
12750
12808
  contentKey: `NOTICE:${notice.id}`,
12751
12809
  avatar: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
12752
12810
  import_avatar5.Avatar,
@@ -12768,6 +12826,7 @@ function PurchaseIsland({
12768
12826
  {
12769
12827
  mode,
12770
12828
  align,
12829
+ placement,
12771
12830
  contentKey: "CART",
12772
12831
  bay,
12773
12832
  bayVisible: false,
@@ -12803,6 +12862,7 @@ function PurchaseIsland({
12803
12862
  {
12804
12863
  mode,
12805
12864
  align,
12865
+ placement,
12806
12866
  contentKey: "FUNNEL",
12807
12867
  avatar: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
12808
12868
  import_avatar5.Avatar,
@@ -12827,6 +12887,7 @@ function PurchaseIsland({
12827
12887
  {
12828
12888
  mode,
12829
12889
  align,
12890
+ placement,
12830
12891
  contentKey: "HOLD_TIMED_OUT",
12831
12892
  avatar: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
12832
12893
  import_avatar5.Avatar,
@@ -13138,6 +13199,7 @@ function PurchaseIsland({
13138
13199
  {
13139
13200
  mode,
13140
13201
  align,
13202
+ placement,
13141
13203
  expanded,
13142
13204
  journeyFullscreen: journeyInline && journeyFullscreen,
13143
13205
  contentKey: `${detour === null ? "" : "detour:"}${stepId}:${prompt?.kind === "CARD" ? prompt.card : ""}`,
@@ -13191,7 +13253,7 @@ function PurchaseIsland({
13191
13253
  ),
13192
13254
  pillCopy: { title: lines?.headline, subtitle: lines?.qualifier ?? void 0 },
13193
13255
  input,
13194
- actionLabel: detour === null && index === 0 ? OPENING_LABEL : step.collapsed.kind === "PILL" ? step.collapsed.actionLabel : step.name,
13256
+ actionLabel: detour === null && index === 0 ? openingLabel?.trim() || OPENING_LABEL : step.collapsed.kind === "PILL" ? step.collapsed.actionLabel : step.name,
13195
13257
  actions: toIslandActions(planeActions),
13196
13258
  bayActions: toIslandActions(bayActions)
13197
13259
  }