@scopetickets/checkout 0.6.3 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pickers.cjs DELETED
@@ -1,1999 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/pickers.ts
21
- var pickers_exports = {};
22
- __export(pickers_exports, {
23
- CalendarGrainButton: () => CalendarGrainButton,
24
- ContentFlag: () => ContentFlag,
25
- CounterRing: () => CounterRing,
26
- DATE_PICKER_ACCESSORY: () => DATE_PICKER_ACCESSORY,
27
- DayPicker: () => DayPicker,
28
- PartyStepper: () => PartyStepper,
29
- SOLO_KEY: () => SOLO_KEY,
30
- Switch: () => Switch,
31
- TimePicker: () => TimePicker,
32
- TimeslotPicker: () => TimeslotPicker,
33
- addDays: () => addDays,
34
- assignmentFor: () => assignmentFor,
35
- availabilityColor: () => availabilityColor,
36
- buildMonthGrid: () => buildMonthGrid,
37
- buildTimeslotGroups: () => buildTimeslotGroups,
38
- buildWeekRow: () => buildWeekRow,
39
- dateRange: () => dateRange,
40
- eventKeyForDay: () => eventKeyForDay,
41
- eventsOn: () => eventsOn,
42
- formatDayDate: () => formatDayDate,
43
- formatDayWeekday: () => formatDayWeekday,
44
- formatMonthName: () => formatMonthName,
45
- formatMonthNameShort: () => formatMonthNameShort,
46
- formatMonthYear: () => formatMonthYear,
47
- formatSlotDuration: () => formatSlotDuration,
48
- formatSlotRange: () => formatSlotRange,
49
- formatWeekdayAndDate: () => formatWeekdayAndDate,
50
- groupUserTypes: () => groupUserTypes,
51
- isDatePickerCellSelectable: () => isDatePickerCellSelectable,
52
- isSelectableCalendarCell: () => isSelectableCalendarCell,
53
- locateDayInMonthStack: () => locateDayInMonthStack,
54
- monthAtRow: () => monthAtRow,
55
- monthOfDay: () => monthOfDay,
56
- monthOfWeek: () => monthOfWeek,
57
- monthOpeningRow: () => monthOpeningRow,
58
- monthStartRows: () => monthStartRows,
59
- monthsInSeries: () => monthsInSeries,
60
- openingMonth: () => openingMonth,
61
- parseWallClockTime: () => parseWallClockTime,
62
- partOfDay: () => partOfDay,
63
- partOfDayLabel: () => partOfDayLabel,
64
- readAvailability: () => readAvailability,
65
- sameTimeslots: () => sameTimeslots,
66
- soonestRelevantDay: () => soonestRelevantDay,
67
- startOfWeek: () => startOfWeek,
68
- stepMonth: () => stepMonth,
69
- timeOfDayInZone: () => timeOfDayInZone,
70
- timeslotRequest: () => timeslotRequest,
71
- toAvailabilityLevel: () => toAvailabilityLevel,
72
- toggleSelectedDay: () => toggleSelectedDay,
73
- userTypeNames: () => userTypeNames,
74
- weekContainingDay: () => weekContainingDay,
75
- weeksInCalendar: () => weeksInCalendar,
76
- weeksInSeries: () => weeksInSeries,
77
- withSelectedDay: () => withSelectedDay,
78
- withSelectedTime: () => withSelectedTime
79
- });
80
- module.exports = __toCommonJS(pickers_exports);
81
-
82
- // src/island/DayPicker.tsx
83
- var import_react3 = require("react");
84
-
85
- // ../checkout-core/src/domain/island-calendar.ts
86
- var HIGH_FROM = 2 / 3;
87
- var MEDIUM_FROM = 1 / 3;
88
- function toAvailabilityLevel(remaining) {
89
- if (!Number.isFinite(remaining) || remaining <= 0) return null;
90
- if (remaining > HIGH_FROM) return "HIGH";
91
- if (remaining > MEDIUM_FROM) return "MEDIUM";
92
- return "LOW";
93
- }
94
- function readAvailability(remaining) {
95
- if (remaining === null) return null;
96
- const level = toAvailabilityLevel(remaining);
97
- if (level === null) return null;
98
- const percent = Math.round(Math.min(remaining, 1) * 100);
99
- return { level, announcement: `about ${percent}% availability` };
100
- }
101
- var RAMP = [
102
- [0, 0],
103
- [MEDIUM_FROM, 33],
104
- [HIGH_FROM, 67],
105
- [1, 100]
106
- ];
107
- function availabilityMix(remaining) {
108
- const flat = (stop) => ({
109
- from: stop,
110
- to: stop,
111
- towards: 100
112
- });
113
- if (remaining === null || !Number.isFinite(remaining) || remaining <= 0) return flat(0);
114
- if (remaining >= 1) return flat(100);
115
- const top = RAMP.findIndex(([at]) => remaining <= at);
116
- const [lowAt, lowStop] = RAMP[top - 1];
117
- const [highAt, highStop] = RAMP[top];
118
- return {
119
- from: lowStop,
120
- to: highStop,
121
- towards: Math.round((remaining - lowAt) / (highAt - lowAt) * 100)
122
- };
123
- }
124
- function availabilityColor(remaining) {
125
- const stop = (suffix) => `var(--scopetickets-island-availability-${suffix})`;
126
- const { from, to, towards } = availabilityMix(remaining);
127
- if (from === to) return stop(from);
128
- return `color-mix(in srgb, ${stop(to)} ${towards}%, ${stop(from)})`;
129
- }
130
- function isDatePickerCellSelectable(state) {
131
- return state === "AVAILABLE" || state === "SELECTED";
132
- }
133
- function isSelectableCalendarCell(cell) {
134
- return cell.kind !== "EMPTY" && isDatePickerCellSelectable(cell.kind);
135
- }
136
- function parseMonth(month) {
137
- return { year: Number(month.slice(0, 4)), monthIndex: Number(month.slice(5, 7)) - 1 };
138
- }
139
- function mondayFirstWeekday(date) {
140
- return (date.getUTCDay() + 6) % 7;
141
- }
142
- function toDay(year, monthIndex, dayOfMonth) {
143
- const month = String(monthIndex + 1).padStart(2, "0");
144
- return `${year}-${month}-${String(dayOfMonth).padStart(2, "0")}`;
145
- }
146
- function eventsOn(series, day) {
147
- return series.events.filter((event) => event.day === day);
148
- }
149
- function eventKeyForDay(series, day) {
150
- return series === void 0 ? void 0 : eventsOn(series, day)[0]?.eventKey;
151
- }
152
- function dateRange(series) {
153
- let first = null;
154
- let last = null;
155
- for (const event of series.events) {
156
- if (first === null || event.day < first) first = event.day;
157
- if (last === null || event.day > last) last = event.day;
158
- }
159
- return first === null || last === null ? null : { first, last };
160
- }
161
- function soonestRelevantDay(series, today) {
162
- const days = [...new Set(series.events.map((event) => event.day))].sort();
163
- return days.find((day) => day >= today) ?? days[days.length - 1] ?? null;
164
- }
165
- function classifyDay(series, day, span, today, selectedDay) {
166
- const dayOfMonth = Number(day.slice(8, 10));
167
- const events = eventsOn(series, day);
168
- const elapsed = day < today;
169
- if (events.length > 0) {
170
- if (elapsed) return { kind: "PAST_BUT_RELEVANT", day, dayOfMonth, events };
171
- if (day === selectedDay) return { kind: "SELECTED", day, dayOfMonth, events };
172
- return { kind: "AVAILABLE", day, dayOfMonth, events };
173
- }
174
- const insideSpan = span !== null && day >= span.first && day <= span.last;
175
- return insideSpan && !elapsed ? { kind: "UNAVAILABLE", day, dayOfMonth } : { kind: "OUT_OF_SERIES", day, dayOfMonth };
176
- }
177
- function addDays(day, count) {
178
- const at = /* @__PURE__ */ new Date(`${day}T00:00:00.000Z`);
179
- at.setUTCDate(at.getUTCDate() + count);
180
- return at.toISOString().slice(0, 10);
181
- }
182
- function startOfWeek(day) {
183
- return addDays(day, -mondayFirstWeekday(/* @__PURE__ */ new Date(`${day}T00:00:00.000Z`)));
184
- }
185
- function monthOfWeek(weekStart) {
186
- return monthOfDay(addDays(weekStart, 3));
187
- }
188
- function weeksInSeries(series) {
189
- const span = dateRange(series);
190
- if (!span) return [];
191
- const last = startOfWeek(span.last);
192
- const weeks = [];
193
- for (let week = startOfWeek(span.first); week <= last; week = addDays(week, 7)) {
194
- weeks.push(week);
195
- }
196
- return weeks;
197
- }
198
- function weeksInCalendar(series) {
199
- const span = dateRange(series);
200
- if (!span) return [];
201
- const from = parseMonth(monthOfDay(span.first));
202
- const to = parseMonth(monthOfDay(span.last));
203
- const lastOfMonth = new Date(Date.UTC(to.year, to.monthIndex + 1, 0)).getUTCDate();
204
- const first = startOfWeek(toDay(from.year, from.monthIndex, 1));
205
- const last = startOfWeek(toDay(to.year, to.monthIndex, lastOfMonth));
206
- const weeks = [];
207
- for (let week = first; week <= last; week = addDays(week, 7)) weeks.push(week);
208
- const finalMonth = monthOfDay(span.last);
209
- const finalMonthRow = monthStartRows(weeks).find(({ month }) => month === finalMonth)?.row ?? 0;
210
- while (weeks.length < finalMonthRow + CALENDAR_VIEWPORT_ROWS) {
211
- weeks.push(addDays(weeks[weeks.length - 1], 7));
212
- }
213
- return weeks;
214
- }
215
- function buildWeekRow(series, weekStart, { today, selectedDay = null }) {
216
- const span = dateRange(series);
217
- return Array.from(
218
- { length: 7 },
219
- (_unused, offset) => classifyDay(series, addDays(weekStart, offset), span, today, selectedDay)
220
- );
221
- }
222
- function buildMonthGrid(series, month, { today, selectedDay = null }) {
223
- const { year, monthIndex } = parseMonth(month);
224
- const first = new Date(Date.UTC(year, monthIndex, 1));
225
- const dayCount = new Date(Date.UTC(year, monthIndex + 1, 0)).getUTCDate();
226
- const span = dateRange(series);
227
- const cells = [];
228
- for (let i = 0; i < mondayFirstWeekday(first); i += 1) cells.push({ kind: "EMPTY" });
229
- for (let dayOfMonth = 1; dayOfMonth <= dayCount; dayOfMonth += 1) {
230
- cells.push(classifyDay(series, toDay(year, monthIndex, dayOfMonth), span, today, selectedDay));
231
- }
232
- while (cells.length % 7 !== 0) cells.push({ kind: "EMPTY" });
233
- const weeks = [];
234
- for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));
235
- return weeks;
236
- }
237
- function weekContainingDay(weeks, day) {
238
- return weeks.find((week) => week.some((cell) => cell.kind !== "EMPTY" && cell.day === day)) ?? null;
239
- }
240
- function locateDayInMonthStack(series, day, { today }) {
241
- const months = monthsInSeries(series);
242
- const monthIndex = months.indexOf(monthOfDay(day));
243
- if (monthIndex < 0) return null;
244
- const weeks = buildMonthGrid(series, months[monthIndex] ?? day.slice(0, 7), { today });
245
- const weekIndex = weeks.findIndex(
246
- (week) => week.some((cell) => cell.kind !== "EMPTY" && cell.day === day)
247
- );
248
- if (weekIndex < 0) return null;
249
- return { monthIndex, weekIndex };
250
- }
251
- function monthOfDay(day) {
252
- return day.slice(0, 7);
253
- }
254
- function monthsInSeries(series) {
255
- const months = [];
256
- for (const event of series.events) {
257
- const month = monthOfDay(event.day);
258
- if (!months.includes(month)) months.push(month);
259
- }
260
- return months.sort();
261
- }
262
- function openingMonth(series, today) {
263
- const day = soonestRelevantDay(series, today);
264
- if (day) return monthOfDay(day);
265
- return monthsInSeries(series)[0] ?? null;
266
- }
267
- function stepMonth(series, month, step) {
268
- const months = monthsInSeries(series);
269
- const index = months.indexOf(month);
270
- if (index === -1) return null;
271
- return months[index + step] ?? null;
272
- }
273
- var CALENDAR_LOCALE = "en-IE";
274
- function formatMonthYear(month) {
275
- return month.slice(0, 4);
276
- }
277
- function formatMonthName(month) {
278
- const { year, monthIndex } = parseMonth(month);
279
- return new Date(Date.UTC(year, monthIndex, 1, 12)).toLocaleDateString(CALENDAR_LOCALE, {
280
- month: "long",
281
- timeZone: "UTC"
282
- });
283
- }
284
- function formatMonthNameShort(month) {
285
- const long = formatMonthName(month);
286
- const { year, monthIndex } = parseMonth(month);
287
- const short = new Date(Date.UTC(year, monthIndex, 1, 12)).toLocaleDateString(CALENDAR_LOCALE, {
288
- month: "short",
289
- timeZone: "UTC"
290
- });
291
- return short.length < long.length ? `${short}.` : long;
292
- }
293
- function formatDayDate(day) {
294
- return (/* @__PURE__ */ new Date(`${day}T12:00:00.000Z`)).toLocaleDateString(CALENDAR_LOCALE, {
295
- day: "numeric",
296
- month: "long",
297
- year: "numeric",
298
- timeZone: "UTC"
299
- });
300
- }
301
- function formatWeekdayAndDate(day) {
302
- return (/* @__PURE__ */ new Date(`${day}T12:00:00.000Z`)).toLocaleDateString(CALENDAR_LOCALE, {
303
- weekday: "long",
304
- day: "numeric",
305
- month: "long",
306
- timeZone: "UTC"
307
- });
308
- }
309
- function formatDayWeekday(day) {
310
- return (/* @__PURE__ */ new Date(`${day}T12:00:00.000Z`)).toLocaleDateString(CALENDAR_LOCALE, {
311
- weekday: "long",
312
- timeZone: "UTC"
313
- });
314
- }
315
- var DATE_PICKER_ACCESSORY = "NONE";
316
- var CALENDAR_VIEWPORT_ROWS = 6;
317
- function monthStartRows(weeks) {
318
- if (weeks.length === 0) return [];
319
- const starts = [{ month: monthOfDay(weeks[0]), row: 0 }];
320
- weeks.forEach((weekStart, row) => {
321
- for (let offset = 0; offset < 7; offset += 1) {
322
- const day = addDays(weekStart, offset);
323
- if (!day.endsWith("-01")) continue;
324
- const month = monthOfDay(day);
325
- if (!starts.some((start) => start.month === month)) starts.push({ month, row });
326
- }
327
- });
328
- return starts;
329
- }
330
- function monthAtRow(starts, topRow) {
331
- let current = starts[0]?.month ?? null;
332
- for (const start of starts) {
333
- if (start.row <= topRow) current = start.month;
334
- }
335
- return current;
336
- }
337
- function lastTopRow({ rowCount, viewportRows }) {
338
- return Math.max(0, rowCount - viewportRows);
339
- }
340
- function rowAfterDrag(drag) {
341
- const { row, offset, rowHeight } = drag;
342
- if (rowHeight <= 0) return clampRow(row, drag);
343
- return clampRow(Math.round(row - offset / rowHeight), drag);
344
- }
345
- var CALENDAR_ROW_OVERSHOOT = 1;
346
- function resist(overshoot, rowHeight) {
347
- const limit = rowHeight * CALENDAR_ROW_OVERSHOOT;
348
- return limit * overshoot / (limit + overshoot);
349
- }
350
- function rowDragOffset(drag) {
351
- const { row, offset, rowHeight } = drag;
352
- if (rowHeight <= 0) return 0;
353
- const wanted = row * rowHeight - offset;
354
- const furthest = lastTopRow(drag) * rowHeight;
355
- const held = wanted < 0 ? -resist(-wanted, rowHeight) : wanted > furthest ? furthest + resist(wanted - furthest, rowHeight) : wanted;
356
- return row * rowHeight - held;
357
- }
358
- function clampRow(row, drag) {
359
- return Math.max(0, Math.min(lastTopRow(drag), row));
360
- }
361
- function rowContainingDay(weeks, day) {
362
- if (day === null || weeks.length === 0) return 0;
363
- const rows = Math.floor(daysBetween(weeks[0], day) / 7);
364
- const lastTop = Math.max(0, weeks.length - CALENDAR_VIEWPORT_ROWS);
365
- return Math.max(0, Math.min(lastTop, rows));
366
- }
367
- function monthOpeningRow(weeks, starts, day) {
368
- if (day === null || weeks.length === 0) return 0;
369
- const start = starts.find((candidate) => candidate.month === monthOfDay(day));
370
- if (start === void 0) return rowContainingDay(weeks, day);
371
- return Math.min(Math.max(0, weeks.length - CALENDAR_VIEWPORT_ROWS), start.row);
372
- }
373
- function daysBetween(from, to) {
374
- const ms = Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`);
375
- return Math.round(ms / 864e5);
376
- }
377
- function toggleSelectedDay(selected, day) {
378
- return selected === day ? null : day;
379
- }
380
-
381
- // src/island/CalendarMonthHeading.tsx
382
- var import_jsx_runtime = require("react/jsx-runtime");
383
- function CalendarMonthHeading({ month }) {
384
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: "scopetickets-island-calendar__heading", children: formatMonthName(month) });
385
- }
386
-
387
- // src/island/CalendarDayIndicator.tsx
388
- var import_jsx_runtime2 = (
389
- // DECORATIVE, and now correctly so.
390
- require("react/jsx-runtime")
391
- );
392
- var SEGMENTS = 3;
393
- var FILLED_SEGMENTS = {
394
- LOW: 1,
395
- MEDIUM: 2,
396
- HIGH: 3
397
- };
398
- function CalendarDayIndicator({ level }) {
399
- const filled = FILLED_SEGMENTS[level];
400
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "scopetickets-island-day-indicator", "aria-hidden": "true", children: [
401
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
402
- "span",
403
- {
404
- className: `scopetickets-island-day-indicator__fill scopetickets-island-day-indicator__fill--${level.toLowerCase()}`,
405
- style: { flexGrow: filled }
406
- }
407
- ),
408
- filled < SEGMENTS ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { flexGrow: SEGMENTS - filled } }) : null
409
- ] });
410
- }
411
-
412
- // src/island/island-press.ts
413
- var import_react = require("react");
414
-
415
- // ../checkout-core/src/motion/island-motion.ts
416
- var SURFACE_MORPH_MS = 250;
417
- var SURFACE_DAMPING = 0.82;
418
- var SURFACE_SPRING = {
419
- response: responseForSettle(SURFACE_MORPH_MS / 1e3, SURFACE_DAMPING),
420
- damping: SURFACE_DAMPING,
421
- clampOvershoot: false
422
- };
423
- var CARRY_SPRING = {
424
- response: responseForSettle(SURFACE_MORPH_MS / 1e3, 0.95),
425
- damping: 0.95,
426
- clampOvershoot: true
427
- };
428
- var POP_RETURN_SPRING = { ...SURFACE_SPRING, clampOvershoot: true };
429
- function responseForSettle(settleSeconds, damping) {
430
- return settleSeconds * damping * 2 * Math.PI / 4;
431
- }
432
- function naturalFrequency({ response }) {
433
- return 2 * Math.PI / response;
434
- }
435
- function settleMs(spring) {
436
- const exact = 4 / (spring.damping * naturalFrequency(spring)) * 1e3;
437
- return Math.ceil(Number(exact.toFixed(9)));
438
- }
439
- var OUTGOING_FADE_MS = 125;
440
- var SURFACE_MORPH_DELAY_MS = OUTGOING_FADE_MS;
441
- var INCOMING_FADE_DELAY_MS = SURFACE_MORPH_DELAY_MS + SURFACE_MORPH_MS;
442
- var INCOMING_FADE_MS = 175;
443
- var DAY_SWAP_STRETCH = 1.6;
444
- var DAY_SWAP_OUT_MS = Math.round(OUTGOING_FADE_MS * DAY_SWAP_STRETCH);
445
- var DAY_SWAP_IN_MS = Math.round(INCOMING_FADE_MS * DAY_SWAP_STRETCH);
446
- var CARRY_MOVE_DELAY_MS = SURFACE_MORPH_DELAY_MS;
447
- var CARRY_MOVE_MS = settleMs(CARRY_SPRING);
448
- var POP_SCALE = 0.95;
449
- var SHIELD_POP_SCALE = 1 - (1 - POP_SCALE) / 2;
450
- var POP_CONTRACT_MS = OUTGOING_FADE_MS;
451
- var POP_RETURN_MS = settleMs(POP_RETURN_SPRING);
452
- var POP_MS = POP_CONTRACT_MS + POP_RETURN_MS;
453
- var POP_TURN_PERCENT = Number((POP_CONTRACT_MS / POP_MS * 100).toFixed(3));
454
- var PRESS_IN_MS = POP_CONTRACT_MS;
455
- var PRESS_RETURN_MS = SURFACE_MORPH_DELAY_MS + SURFACE_MORPH_MS;
456
- var ISLAND_TRANSITION_MS = Math.max(
457
- INCOMING_FADE_DELAY_MS + INCOMING_FADE_MS,
458
- CARRY_MOVE_DELAY_MS + CARRY_MOVE_MS,
459
- POP_MS
460
- );
461
- var BAY_SWAP_IN_PERCENT = Number(
462
- (INCOMING_FADE_DELAY_MS / ISLAND_TRANSITION_MS * 100).toFixed(3)
463
- );
464
-
465
- // src/island/island-press.ts
466
- var PressContext = (0, import_react.createContext)(null);
467
- var primaryHeld = (event) => (event.buttons & 1) === 1;
468
- var AT_REST = { at: "rest" };
469
- var RISEN = { at: "rising", timer: null };
470
- function stopWaiting(sink) {
471
- if (sink.at === "rising" && sink.timer !== null) window.clearTimeout(sink.timer);
472
- }
473
- function useIslandPress(scope = "island") {
474
- const api = (0, import_react.useContext)(PressContext);
475
- const [pressedHere, setPressedHere] = (0, import_react.useState)(false);
476
- const whole = scope === "island";
477
- const sink = (0, import_react.useRef)(AT_REST);
478
- (0, import_react.useEffect)(() => () => stopWaiting(sink.current), []);
479
- const handlers = (0, import_react.useMemo)(() => {
480
- const letGo = () => {
481
- if (sink.current.at !== "down") return;
482
- const left = PRESS_IN_MS - (Date.now() - sink.current.since);
483
- if (left <= 0) {
484
- sink.current = RISEN;
485
- setPressedHere(false);
486
- return;
487
- }
488
- sink.current = {
489
- at: "rising",
490
- timer: window.setTimeout(() => {
491
- sink.current = AT_REST;
492
- setPressedHere(false);
493
- }, left)
494
- };
495
- };
496
- const undo = () => {
497
- if (sink.current.at !== "down") return;
498
- sink.current = AT_REST;
499
- setPressedHere(false);
500
- };
501
- const begin = whole ? () => api?.press("island") : () => {
502
- api?.press("element");
503
- stopWaiting(sink.current);
504
- sink.current = { at: "down", since: Date.now() };
505
- setPressedHere(true);
506
- };
507
- const end = whole ? () => api?.release() : () => {
508
- api?.release();
509
- letGo();
510
- };
511
- const cancel = whole ? () => api?.abandon() : () => {
512
- api?.abandon();
513
- undo();
514
- };
515
- return {
516
- onPointerDown: (event) => {
517
- if (primaryHeld(event)) begin();
518
- },
519
- onPointerUp: end,
520
- onPointerLeave: cancel,
521
- onPointerEnter: (event) => {
522
- if (primaryHeld(event)) begin();
523
- },
524
- onPointerCancel: cancel
525
- };
526
- }, [api, whole]);
527
- return whole || !pressedHere ? handlers : { ...handlers, "data-pressed": "" };
528
- }
529
-
530
- // src/island/CalendarDay.tsx
531
- var import_jsx_runtime3 = require("react/jsx-runtime");
532
- function CalendarDay({
533
- cell,
534
- accessory,
535
- remaining,
536
- label,
537
- outsideMonth = false,
538
- onSelect
539
- }) {
540
- const press = useIslandPress("element");
541
- const dimmed = outsideMonth ? { "data-outside-month": "" } : null;
542
- if (cell.kind === "EMPTY") {
543
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day", "aria-hidden": "true" });
544
- }
545
- if (isSelectableCalendarCell(cell)) {
546
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
547
- CalendarDayButton,
548
- {
549
- cell,
550
- accessory,
551
- remaining,
552
- label,
553
- onSelect,
554
- outsideMonth,
555
- press
556
- }
557
- );
558
- }
559
- if (cell.kind === "UNAVAILABLE") {
560
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
561
- CalendarDayButton,
562
- {
563
- cell,
564
- accessory,
565
- remaining: null,
566
- label,
567
- outsideMonth,
568
- press
569
- }
570
- );
571
- }
572
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day", ...dimmed, ...press, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day__well", "data-state": cell.kind, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day__number", children: cell.dayOfMonth }) }) });
573
- }
574
- function CalendarDayButton({
575
- cell,
576
- accessory,
577
- remaining,
578
- label,
579
- outsideMonth = false,
580
- press,
581
- onSelect
582
- }) {
583
- const selected = cell.kind === "SELECTED";
584
- const availability = readAvailability(remaining);
585
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
586
- "button",
587
- {
588
- type: "button",
589
- className: "scopetickets-island-day",
590
- ...outsideMonth ? { "data-outside-month": "" } : null,
591
- "aria-pressed": onSelect ? selected : void 0,
592
- "aria-disabled": onSelect ? void 0 : true,
593
- "aria-label": availability === null ? label : `${label}, ${availability.announcement}`,
594
- onClick: onSelect ? () => onSelect(cell.day) : void 0,
595
- ...press,
596
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "scopetickets-island-day__well", "data-state": cell.kind, children: [
597
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day__number", children: cell.dayOfMonth }),
598
- cell.kind === "UNAVAILABLE" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day__strike", "aria-hidden": "true" }) : null,
599
- accessory === "LINE" && availability !== null ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "scopetickets-island-day__accessory", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CalendarDayIndicator, { level: availability.level }) }) : null
600
- ] })
601
- }
602
- );
603
- }
604
-
605
- // src/island/CalendarRunGrid.tsx
606
- var import_jsx_runtime4 = require("react/jsx-runtime");
607
- function CalendarRunGrid({
608
- series,
609
- weeks,
610
- currentMonth,
611
- accessory,
612
- remaining,
613
- today,
614
- selectedDay,
615
- onSelectDay
616
- }) {
617
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "scopetickets-island-calendar__grid", children: weeks.map((weekStart) => (
618
- // A presentational row: the seven columns are a layout, and announcing "row 3
619
- // of 9" describes the grid rather than the run.
620
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "scopetickets-island-calendar__week", children: buildWeekRow(series, weekStart, { today, selectedDay }).map((cell, dayIndex) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
621
- CalendarDay,
622
- {
623
- cell,
624
- accessory,
625
- remaining: cell.kind === "EMPTY" ? null : remaining?.[cell.day] ?? null,
626
- label: cell.kind === "EMPTY" ? "" : formatDayDate(cell.day),
627
- outsideMonth: cell.kind !== "EMPTY" && monthOfDay(cell.day) !== currentMonth,
628
- onSelect: onSelectDay
629
- },
630
- cell.kind === "EMPTY" ? `empty-${dayIndex}` : cell.day
631
- )) }, weekStart)
632
- )) });
633
- }
634
-
635
- // src/island/CalendarScroller.tsx
636
- var import_react2 = require("react");
637
- var import_jsx_runtime5 = require("react/jsx-runtime");
638
- var WHEEL_IDLE_MS = 200;
639
- var CALENDAR_DRAG_SLOP = 4;
640
- function CalendarScroller({
641
- children,
642
- rowCount,
643
- row,
644
- onRowChange,
645
- onRowPreview,
646
- label
647
- }) {
648
- const viewportRef = (0, import_react2.useRef)(null);
649
- const trackRef = (0, import_react2.useRef)(null);
650
- const startY = (0, import_react2.useRef)(null);
651
- const [offset, setOffset] = (0, import_react2.useState)(0);
652
- const [dragging, setDragging] = (0, import_react2.useState)(false);
653
- const rowRef = (0, import_react2.useRef)(row);
654
- rowRef.current = row;
655
- const [rowStep, setRowStep] = (0, import_react2.useState)(0);
656
- const gapPx = (box) => {
657
- const gap = Number.parseFloat(
658
- getComputedStyle(box).getPropertyValue("--scopetickets-island-day-column-gap")
659
- );
660
- return Number.isFinite(gap) ? gap : 0;
661
- };
662
- (0, import_react2.useEffect)(() => {
663
- const track = trackRef.current;
664
- if (!track) return void 0;
665
- const measure = () => {
666
- const row2 = track.querySelector(".scopetickets-island-calendar__week");
667
- if (!row2) return;
668
- const height = row2.getBoundingClientRect().height;
669
- if (height <= 0) return;
670
- const step = height + gapPx(track);
671
- setRowStep((was) => Math.abs(was - step) < 0.5 ? was : step);
672
- };
673
- measure();
674
- if (typeof ResizeObserver === "undefined") return void 0;
675
- const observer = new ResizeObserver(measure);
676
- observer.observe(track);
677
- return () => observer.disconnect();
678
- }, [rowCount]);
679
- const rowHeight = (0, import_react2.useCallback)(() => {
680
- if (rowStep > 0) return rowStep;
681
- const box = viewportRef.current;
682
- if (!box) return 0;
683
- return (box.clientHeight + gapPx(box)) / CALENDAR_VIEWPORT_ROWS;
684
- }, [rowStep]);
685
- const drag = (0, import_react2.useCallback)(
686
- (dy) => ({
687
- row: rowRef.current,
688
- rowCount,
689
- viewportRows: CALENDAR_VIEWPORT_ROWS,
690
- offset: dy,
691
- rowHeight: rowHeight()
692
- }),
693
- [rowCount, rowHeight]
694
- );
695
- const draw = (0, import_react2.useCallback)(
696
- (dy) => {
697
- const moving = drag(dy);
698
- setOffset(rowDragOffset(moving));
699
- onRowPreview?.(rowAfterDrag(moving));
700
- },
701
- [drag, onRowPreview]
702
- );
703
- const settle = (0, import_react2.useCallback)(
704
- (dy) => {
705
- setOffset(0);
706
- const landed = rowAfterDrag(drag(dy));
707
- if (landed !== rowRef.current) onRowChange(landed);
708
- },
709
- [drag, onRowChange]
710
- );
711
- const dragged = (0, import_react2.useRef)(false);
712
- const onPointerDown = (event) => {
713
- if ((event.buttons & 1) !== 1) return;
714
- startY.current = event.clientY;
715
- dragged.current = false;
716
- };
717
- const onPointerMove = (event) => {
718
- if (startY.current === null) return;
719
- const dy = event.clientY - startY.current;
720
- if (!dragged.current) {
721
- if (Math.abs(dy) < CALENDAR_DRAG_SLOP) return;
722
- dragged.current = true;
723
- setDragging(true);
724
- event.currentTarget.setPointerCapture(event.pointerId);
725
- }
726
- draw(dy);
727
- };
728
- const onPointerUp = (event) => {
729
- if (startY.current === null) return;
730
- const dy = event.clientY - startY.current;
731
- startY.current = null;
732
- if (!dragged.current) return;
733
- setDragging(false);
734
- settle(dy);
735
- };
736
- const onClickCapture = (event) => {
737
- if (!dragged.current) return;
738
- dragged.current = false;
739
- event.stopPropagation();
740
- event.preventDefault();
741
- };
742
- const onPointerCancel = () => {
743
- startY.current = null;
744
- dragged.current = false;
745
- setDragging(false);
746
- setOffset(0);
747
- };
748
- const wheel = (0, import_react2.useRef)(0);
749
- const settleTimer = (0, import_react2.useRef)(null);
750
- (0, import_react2.useEffect)(() => {
751
- const viewport = viewportRef.current;
752
- if (!viewport) return void 0;
753
- const onWheel = (event) => {
754
- event.preventDefault();
755
- wheel.current -= event.deltaY;
756
- wheel.current = rowDragOffset(drag(wheel.current));
757
- draw(wheel.current);
758
- if (settleTimer.current !== null) window.clearTimeout(settleTimer.current);
759
- settleTimer.current = window.setTimeout(() => {
760
- settleTimer.current = null;
761
- const travelled = wheel.current;
762
- wheel.current = 0;
763
- settle(travelled);
764
- }, WHEEL_IDLE_MS);
765
- };
766
- viewport.addEventListener("wheel", onWheel, { passive: false });
767
- return () => viewport.removeEventListener("wheel", onWheel);
768
- }, [drag, draw, settle]);
769
- (0, import_react2.useEffect)(
770
- () => () => {
771
- if (settleTimer.current !== null) window.clearTimeout(settleTimer.current);
772
- },
773
- []
774
- );
775
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
776
- "div",
777
- {
778
- ref: viewportRef,
779
- className: "scopetickets-island-calendar-scroller",
780
- role: "group",
781
- "aria-label": label,
782
- style: {
783
- "--scopetickets-island-viewport-rows": CALENDAR_VIEWPORT_ROWS,
784
- ...rowStep > 0 ? { "--scopetickets-island-calendar-row-step": `${rowStep}px` } : null
785
- },
786
- onPointerDown,
787
- onPointerMove,
788
- onPointerUp,
789
- onPointerCancel,
790
- onClickCapture,
791
- children: [
792
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "scopetickets-island-calendar-scroller__window", "aria-hidden": "true" }),
793
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
794
- "div",
795
- {
796
- ref: trackRef,
797
- className: "scopetickets-island-calendar-scroller__track",
798
- "data-dragging": dragging || offset !== 0 ? "" : void 0,
799
- style: {
800
- translate: `0 calc(${-row} * var(--scopetickets-island-calendar-row-step) + ${offset}px)`
801
- },
802
- children
803
- }
804
- )
805
- ]
806
- }
807
- );
808
- }
809
-
810
- // src/island/CalendarWeekdayNames.tsx
811
- var import_jsx_runtime6 = require("react/jsx-runtime");
812
- var WEEKDAY_NAMES = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
813
- function CalendarWeekdayNames() {
814
- return (
815
- // `aria-hidden`, and it is not a shortcut.
816
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "scopetickets-island-calendar__weekdays", "aria-hidden": "true", children: WEEKDAY_NAMES.map((name) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "scopetickets-island-calendar__weekday", children: name }, name)) })
817
- );
818
- }
819
-
820
- // ../checkout-core/src/view/component-copy.ts
821
- var PARTY_COPY = {
822
- remove: (name) => `Remove one ${name}`,
823
- add: (name) => `Add one ${name}`,
824
- count: (count, name) => `${count} ${name}. Change the number`,
825
- field: (name) => `Number of ${name}`,
826
- /**
827
- * AND WHAT AN UNDIFFERENTIATED PARTY IS CALLED — a run selling a single UserType has no
828
- * name worth showing per row, so the one line it draws names the whole party.
829
- *
830
- * A PROP DEFAULT ON THE WEB IS INVISIBLE TO THE OTHER RENDERER, which is why this is
831
- * here: `PartyStepper`'s own `soloName = 'Guests'` could not be read from native, so
832
- * native re-typed it.
833
- */
834
- soloName: "Guests"
835
- };
836
- var ISLAND_COPY = {
837
- order: "Your order",
838
- runWeeks: "Weeks of the run",
839
- inventories: "Show sessions"
840
- };
841
- var TIMESLOT_COPY = {
842
- /**
843
- * WHAT A SLOT WITH NOTHING LEFT SAYS, IN WORDS. The ring is a reading of how full a
844
- * slot is, and at zero it draws nothing — an arc of no length is an absence, not a
845
- * statement, and a buyer scanning a column for a time cannot be asked to notice an
846
- * opacity.
847
- */
848
- soldOut: "Sold Out",
849
- /**
850
- * AND WHAT QUALIFIES THE PRICE — IN THE ROW'S NAME ONLY, not on its face. A column of
851
- * forty rows each repeating the word says it forty times and the figure once. A screen
852
- * reader gets one row at a time and no column, so a bare "€17.90" beside a time is a
853
- * price with no qualifier at all.
854
- */
855
- from: "From"
856
- };
857
-
858
- // src/island/DayPicker.tsx
859
- var import_jsx_runtime7 = require("react/jsx-runtime");
860
- function DayPicker({
861
- series,
862
- offered = series,
863
- today,
864
- selectedDay,
865
- onSelectDay,
866
- remaining,
867
- accessory = DATE_PICKER_ACCESSORY,
868
- onVisibleMonthChange
869
- }) {
870
- const weeks = (0, import_react3.useMemo)(() => weeksInCalendar(series), [series]);
871
- const starts = (0, import_react3.useMemo)(() => monthStartRows(weeks), [weeks]);
872
- const [row, setRow] = (0, import_react3.useState)(
873
- () => monthOpeningRow(weeks, starts, selectedDay ?? soonestRelevantDay(offered, today))
874
- );
875
- const [shownRow, setShownRow] = (0, import_react3.useState)(row);
876
- const currentMonth = monthAtRow(starts, shownRow);
877
- (0, import_react3.useEffect)(() => {
878
- if (currentMonth !== null) onVisibleMonthChange?.(currentMonth);
879
- }, [currentMonth, onVisibleMonthChange]);
880
- const selectDay = (0, import_react3.useCallback)(
881
- (day) => {
882
- const month = monthOfDay(day);
883
- const start = starts.find((candidate) => candidate.month === month);
884
- if (start !== void 0 && month !== currentMonth) {
885
- setRow(start.row);
886
- setShownRow(start.row);
887
- }
888
- onSelectDay(day);
889
- },
890
- [starts, currentMonth, onSelectDay]
891
- );
892
- if (weeks.length === 0) return null;
893
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "scopetickets-island-calendar", "data-accessory": accessory, children: [
894
- currentMonth !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CalendarMonthHeading, { month: currentMonth }),
895
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CalendarWeekdayNames, {}),
896
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
897
- CalendarScroller,
898
- {
899
- rowCount: weeks.length,
900
- row,
901
- onRowChange: setRow,
902
- onRowPreview: setShownRow,
903
- label: ISLAND_COPY.runWeeks,
904
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
905
- CalendarRunGrid,
906
- {
907
- series: offered,
908
- weeks,
909
- currentMonth,
910
- accessory,
911
- remaining,
912
- today,
913
- selectedDay,
914
- onSelectDay: selectDay
915
- }
916
- )
917
- }
918
- )
919
- ] });
920
- }
921
-
922
- // src/island/TimePicker.tsx
923
- var import_react6 = require("react");
924
-
925
- // src/island/CalendarWeekSection.tsx
926
- var import_react4 = require("react");
927
- var import_jsx_runtime8 = require("react/jsx-runtime");
928
- function CalendarWeekSection({
929
- series,
930
- today,
931
- selectedDay,
932
- onSelectDay,
933
- remaining,
934
- accessory,
935
- onVisibleMonthChange
936
- }) {
937
- const weeks = weeksInSeries(series);
938
- const selectedWeek = startOfWeek(selectedDay);
939
- const selectedIndex = Math.max(weeks.indexOf(selectedWeek), 0);
940
- const pagerRef = (0, import_react4.useRef)(null);
941
- const pageRefs = (0, import_react4.useRef)([]);
942
- const [visibleIndex, setVisibleIndex] = (0, import_react4.useState)(selectedIndex);
943
- (0, import_react4.useEffect)(() => {
944
- setVisibleIndex(selectedIndex);
945
- }, [selectedIndex]);
946
- const strideOf = (pager) => {
947
- const first = pageRefs.current[0];
948
- const second = pageRefs.current[1];
949
- if (first && second) return second.offsetLeft - first.offsetLeft;
950
- return first?.offsetWidth ?? pager.clientWidth;
951
- };
952
- const paint = (0, import_react4.useCallback)(() => {
953
- const pager = pagerRef.current;
954
- if (!pager) return;
955
- const stride = strideOf(pager);
956
- if (stride <= 0) return;
957
- const at = pager.scrollLeft / stride;
958
- pageRefs.current.forEach((page2, index) => {
959
- if (!page2) return;
960
- page2.style.setProperty(
961
- "--scopetickets-island-week-distance",
962
- String(Math.min(Math.abs(index - at), 1))
963
- );
964
- });
965
- const page = Math.round(at);
966
- setVisibleIndex(Math.min(Math.max(page, 0), Math.max(weeks.length - 1, 0)));
967
- }, [weeks.length]);
968
- (0, import_react4.useLayoutEffect)(() => {
969
- const pager = pagerRef.current;
970
- if (!pager) return;
971
- pager.scrollLeft = selectedIndex * strideOf(pager);
972
- paint();
973
- }, [selectedIndex, paint]);
974
- const visibleWeek = weeks[Math.min(visibleIndex, weeks.length - 1)] ?? selectedWeek;
975
- (0, import_react4.useEffect)(() => {
976
- if (weeks.length === 0) return;
977
- onVisibleMonthChange?.(
978
- visibleWeek === selectedWeek ? monthOfDay(selectedDay) : monthOfWeek(visibleWeek)
979
- );
980
- }, [weeks.length, visibleWeek, selectedWeek, selectedDay, onVisibleMonthChange]);
981
- if (weeks.length === 0) return null;
982
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "scopetickets-island-week", children: [
983
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CalendarWeekdayNames, {}),
984
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "scopetickets-island-week__pager", ref: pagerRef, onScroll: paint, children: weeks.map((weekStart, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
985
- "div",
986
- {
987
- className: "scopetickets-island-week__page",
988
- ref: (node) => {
989
- pageRefs.current[index] = node;
990
- },
991
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "scopetickets-island-week__row", children: buildWeekRow(series, weekStart, { today, selectedDay }).map((cell, dayIndex) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
992
- CalendarDay,
993
- {
994
- cell,
995
- accessory,
996
- remaining: cell.kind === "EMPTY" ? null : remaining?.[cell.day] ?? null,
997
- label: cell.kind === "EMPTY" ? "" : formatDayDate(cell.day),
998
- onSelect: onSelectDay
999
- },
1000
- cell.kind === "EMPTY" ? `empty-${dayIndex}` : cell.day
1001
- )) })
1002
- },
1003
- weekStart
1004
- )) })
1005
- ] });
1006
- }
1007
-
1008
- // src/island/SelectedDayHeading.tsx
1009
- var import_jsx_runtime9 = require("react/jsx-runtime");
1010
- function SelectedDayHeading({ day }) {
1011
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("h3", { className: "scopetickets-island-day-heading", children: [
1012
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "scopetickets-island-day-heading__weekday", children: [
1013
- formatDayWeekday(day),
1014
- ","
1015
- ] }),
1016
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "scopetickets-island-day-heading__date", children: formatDayDate(day) })
1017
- ] });
1018
- }
1019
-
1020
- // src/island/TimeslotPicker.tsx
1021
- var import_react5 = require("react");
1022
-
1023
- // src/island/CounterRing.tsx
1024
- var import_icons2 = require("@scopetickets/icons");
1025
-
1026
- // ../checkout-core/src/geometry/island-timer.ts
1027
- var TIMER_GRID = 20;
1028
- var TIMER_CENTRE = TIMER_GRID / 2;
1029
- var RING_OUTER = 10;
1030
- var RING_INNER = 8;
1031
- var RING_RADIUS = (RING_OUTER + RING_INNER) / 2;
1032
- var RING_WIDTH = RING_OUTER - RING_INNER;
1033
- var TURN_DEGREES = 360;
1034
- var SOURCE_GRID = 100;
1035
- var SOURCE_SCALE = TIMER_GRID / SOURCE_GRID;
1036
- function n(value) {
1037
- const rounded = Number(value.toFixed(3));
1038
- return String(Object.is(rounded, -0) ? 0 : rounded);
1039
- }
1040
- function pointAt(radius, degrees) {
1041
- const radians = degrees * Math.PI / 180;
1042
- return {
1043
- x: TIMER_CENTRE + radius * Math.sin(radians),
1044
- y: TIMER_CENTRE - radius * Math.cos(radians)
1045
- };
1046
- }
1047
- function circlePath(centre, radius) {
1048
- const r = `${n(radius)},${n(radius)}`;
1049
- return `M${n(centre.x - radius)},${n(centre.y)}A${r} 0 1 0 ${n(centre.x + radius)},${n(centre.y)}A${r} 0 1 0 ${n(centre.x - radius)},${n(centre.y)}Z`;
1050
- }
1051
- function clampRemaining(remaining) {
1052
- if (!Number.isFinite(remaining)) return 0;
1053
- return Math.min(1, Math.max(0, remaining));
1054
- }
1055
- function annulus(outer = RING_OUTER, inner = RING_INNER) {
1056
- const centre = pointAt(0, 0);
1057
- return circlePath(centre, outer) + circlePath(centre, inner);
1058
- }
1059
- function ringSector(fraction, outer, inner, direction = "cw") {
1060
- const filled = clampRemaining(fraction);
1061
- if (filled <= 0 || filled >= 1) return null;
1062
- const mirrored = direction === "ccw";
1063
- const sweep = filled * TURN_DEGREES * (mirrored ? -1 : 1);
1064
- const capRadius = (outer - inner) / 2;
1065
- const outerStart = pointAt(outer, 0);
1066
- const outerEnd = pointAt(outer, sweep);
1067
- const innerEnd = pointAt(inner, sweep);
1068
- const innerStart = pointAt(inner, 0);
1069
- const out = mirrored ? 0 : 1;
1070
- const back = mirrored ? 1 : 0;
1071
- const large = Math.abs(sweep) > 180 ? 1 : 0;
1072
- const cap = `${n(capRadius)},${n(capRadius)}`;
1073
- const at = (p) => `${n(p.x)},${n(p.y)}`;
1074
- return {
1075
- d: `M${at(outerStart)}A${n(outer)},${n(outer)} 0 ${large} ${out} ${at(outerEnd)}A${cap} 0 0 ${out} ${at(innerEnd)}A${n(inner)},${n(inner)} 0 ${large} ${back} ${at(innerStart)}A${cap} 0 0 ${out} ${at(outerStart)}Z`
1076
- };
1077
- }
1078
- function ringAnnulus(outer, inner) {
1079
- return { d: annulus(outer, inner), evenodd: true };
1080
- }
1081
-
1082
- // ../checkout-core/src/geometry/island-counter-ring.ts
1083
- var RING_OUTER2 = 10;
1084
- var RING_STROKE = 2.5;
1085
- var RING_INNER2 = RING_OUTER2 - RING_STROKE;
1086
- function counterTrackPaths() {
1087
- return [ringAnnulus(RING_OUTER2, RING_INNER2)];
1088
- }
1089
- function counterRingPaths(progress, direction = "cw") {
1090
- if (progress >= 1) return [ringAnnulus(RING_OUTER2, RING_INNER2)];
1091
- const sector = ringSector(progress, RING_OUTER2, RING_INNER2, direction);
1092
- return sector ? [sector] : [];
1093
- }
1094
-
1095
- // src/island/ContentFlag.tsx
1096
- var import_icons = require("@scopetickets/icons");
1097
- var import_jsx_runtime10 = require("react/jsx-runtime");
1098
- var GLYPH = {
1099
- success: import_icons.CheckInCircleFilledIcon,
1100
- warning: import_icons.ExclamationMarkInCircleFilledIcon,
1101
- error: import_icons.XMarkInCircleFilledIcon
1102
- };
1103
- function ContentFlag({ tone, title }) {
1104
- const Glyph = GLYPH[tone];
1105
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: `scopetickets-island-content-flag scopetickets-island-content-flag--${tone}`, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Glyph, { fill: true, color: "currentColor", title }) });
1106
- }
1107
-
1108
- // src/island/CounterRing.tsx
1109
- var import_jsx_runtime11 = require("react/jsx-runtime");
1110
- var LAYER = { position: "absolute", inset: 0 };
1111
- var DEFAULT_FILL = "var(--scopetickets-island-counter-ring-fill)";
1112
- var DEFAULT_TRACK = "var(--scopetickets-island-counter-ring-track)";
1113
- function CounterRing({
1114
- progress,
1115
- complete,
1116
- size = "1em",
1117
- title,
1118
- color = DEFAULT_FILL,
1119
- trackColor = DEFAULT_TRACK,
1120
- direction = "cw",
1121
- track = true
1122
- }) {
1123
- if (complete !== void 0) {
1124
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1125
- "span",
1126
- {
1127
- className: "scopetickets-island-counter-ring",
1128
- style: { width: size, height: size, flex: "none" },
1129
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ContentFlag, { tone: complete, title })
1130
- }
1131
- );
1132
- }
1133
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1134
- "span",
1135
- {
1136
- className: "scopetickets-island-counter-ring",
1137
- style: { position: "relative", display: "block", width: size, height: size, flex: "none" },
1138
- children: [
1139
- track ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { style: LAYER, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1140
- import_icons2.IconGlyph,
1141
- {
1142
- glyph: "StepCompletionProgressRingTrack",
1143
- paths: counterTrackPaths(),
1144
- color: trackColor,
1145
- fill: true
1146
- }
1147
- ) }) : null,
1148
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { style: LAYER, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1149
- import_icons2.IconGlyph,
1150
- {
1151
- glyph: "StepCompletionProgressRing",
1152
- paths: counterRingPaths(progress, direction),
1153
- color,
1154
- title,
1155
- fill: true
1156
- }
1157
- ) })
1158
- ]
1159
- }
1160
- );
1161
- }
1162
-
1163
- // ../checkout-core/src/domain/money.ts
1164
- var MONEY_LOCALE = "en-IE";
1165
- function formatterFor(currency) {
1166
- return new Intl.NumberFormat(MONEY_LOCALE, { style: "currency", currency });
1167
- }
1168
- function minorUnitDigits(formatter) {
1169
- return formatter.resolvedOptions().maximumFractionDigits ?? 2;
1170
- }
1171
- function formatMoney(minorUnits, currency) {
1172
- const formatter = formatterFor(currency);
1173
- return formatter.format(minorUnits / 10 ** minorUnitDigits(formatter));
1174
- }
1175
-
1176
- // src/island/Timeslot.tsx
1177
- var import_jsx_runtime12 = require("react/jsx-runtime");
1178
- var REMAINING_SIZE = "var(--scopetickets-island-space-4)";
1179
- var SELECTED_ARC = "var(--scopetickets-island-timeslot-ring-selected)";
1180
- var TRACK = "var(--scopetickets-island-timeslot-track)";
1181
- var SELECTED_TRACK = "var(--scopetickets-island-timeslot-track-selected)";
1182
- var { soldOut: SOLD_OUT, from: FROM } = TIMESLOT_COPY;
1183
- function Timeslot({ cell, accessory, onSelect }) {
1184
- if (isDatePickerCellSelectable(cell.state)) {
1185
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TimeslotButton, { cell, accessory, onSelect });
1186
- }
1187
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TimeslotFixed, { cell });
1188
- }
1189
- function TimeslotRow({ cell }) {
1190
- const price = slotPrice(cell);
1191
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "scopetickets-island-timeslot__times", children: [
1192
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__time", children: cell.slot.startTime }),
1193
- cell.slot.endTime === null ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1194
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__dash", "aria-hidden": "true", children: "-" }),
1195
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__time", children: cell.slot.endTime })
1196
- ] }),
1197
- /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "scopetickets-island-timeslot__trailing", children: [
1198
- price === null ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__price", children: price }),
1199
- cell.state === "UNAVAILABLE" ? (
1200
- /*
1201
- * THE WORDS INSTEAD OF THE MARK, AND ONLY WHERE THE MARK WOULD SAY NOTHING.
1202
- *
1203
- * `UNAVAILABLE` is the one state the ring cannot draw: `timeslotState` reaches it
1204
- * only for `remaining <= 0`, which is an arc of zero length. A slot that has
1205
- * merely BEGUN keeps its ring — it still has seats, and "Sold Out" over them
1206
- * would be false.
1207
- */
1208
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__soldout", children: SOLD_OUT })
1209
- ) : cell.slot.remaining === null ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__remaining", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1210
- CounterRing,
1211
- {
1212
- progress: cell.slot.remaining,
1213
- color: cell.state === "SELECTED" ? SELECTED_ARC : availabilityColor(cell.slot.remaining),
1214
- trackColor: cell.state === "SELECTED" ? SELECTED_TRACK : TRACK,
1215
- size: REMAINING_SIZE
1216
- }
1217
- ) })
1218
- ] })
1219
- ] });
1220
- }
1221
- function slotPrice(cell, spoken = false) {
1222
- if (!isDatePickerCellSelectable(cell.state)) return null;
1223
- const price = cell.slot.fromPrice;
1224
- if (price === void 0 || price === null) return null;
1225
- const money = formatMoney(price.minorUnits, price.currency);
1226
- return spoken ? `${FROM} ${money}` : money;
1227
- }
1228
- function timeslotLabel(cell, announcement) {
1229
- const range = cell.slot.endTime === null ? cell.slot.startTime : `${cell.slot.startTime} - ${cell.slot.endTime}`;
1230
- return [range, cell.duration, slotPrice(cell, true), announcement].filter((part) => part !== null).join(", ");
1231
- }
1232
- function TimeslotButton({ cell, accessory, onSelect }) {
1233
- const press = useIslandPress("element");
1234
- const selected = cell.state === "SELECTED";
1235
- const availability = readAvailability(cell.slot.remaining);
1236
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1237
- "button",
1238
- {
1239
- type: "button",
1240
- className: "scopetickets-island-timeslot",
1241
- "aria-pressed": selected,
1242
- "aria-label": timeslotLabel(cell, availability?.announcement ?? null),
1243
- onClick: () => onSelect(cell.slot.startTime),
1244
- ...press,
1245
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "scopetickets-island-timeslot__pill", "data-state": cell.state, children: [
1246
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TimeslotRow, { cell }),
1247
- accessory === "LINE" && availability !== null ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__accessory", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CalendarDayIndicator, { level: availability.level }) }) : null
1248
- ] })
1249
- }
1250
- );
1251
- }
1252
- function TimeslotFixed({ cell }) {
1253
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "scopetickets-island-timeslot__pill", "data-state": cell.state, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(TimeslotRow, { cell }) }) });
1254
- }
1255
-
1256
- // src/island/TimeslotGroupSection.tsx
1257
- var import_jsx_runtime13 = require("react/jsx-runtime");
1258
- function TimeslotGroupSection({ group, accessory, onSelect }) {
1259
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("section", { className: "scopetickets-island-timeslots__group", children: [
1260
- group.label === null ? null : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h4", { className: "scopetickets-island-timeslots__label", children: group.label }),
1261
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "scopetickets-island-timeslots__list", children: group.cells.map((cell, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1262
- Timeslot,
1263
- {
1264
- cell,
1265
- accessory,
1266
- onSelect
1267
- },
1268
- `${cell.slot.startTime}-${index}`
1269
- )) })
1270
- ] });
1271
- }
1272
-
1273
- // ../checkout-core/src/domain/island-timeslots.ts
1274
- var MAX_TIME_INPUT = 40;
1275
- var WALL_CLOCK = /^(?:\d{4}-\d{2}-\d{2}[T ])?(\d{2}):(\d{2})(?::\d{2})?/;
1276
- function parseWallClockTime(value) {
1277
- if (typeof value !== "string" || value.length > MAX_TIME_INPUT) return null;
1278
- const match = WALL_CLOCK.exec(value.trim());
1279
- if (!match) return null;
1280
- if (Number(match[1]) > 23 || Number(match[2]) > 59) return null;
1281
- return `${match[1]}:${match[2]}`;
1282
- }
1283
- function timeOfDayInZone(now, timeZone) {
1284
- const read = (zone) => {
1285
- const parts = new Intl.DateTimeFormat("en-GB", {
1286
- timeZone: zone,
1287
- hour: "2-digit",
1288
- minute: "2-digit",
1289
- hourCycle: "h23"
1290
- }).formatToParts(now);
1291
- const hour = parts.find((part) => part.type === "hour")?.value ?? "00";
1292
- const minute = parts.find((part) => part.type === "minute")?.value ?? "00";
1293
- return `${String(Number(hour) % 24).padStart(2, "0")}:${minute}`;
1294
- };
1295
- try {
1296
- return read(timeZone ?? "UTC");
1297
- } catch {
1298
- return read("UTC");
1299
- }
1300
- }
1301
- var PART_OF_DAY_LABELS = {
1302
- OVERNIGHT: "OVERNIGHT",
1303
- PRE_DAWN: "PRE-DAWN",
1304
- EARLY_MORNING: "EARLY MORNING",
1305
- LATE_MORNING: "LATE MORNING",
1306
- EARLY_AFTERNOON: "EARLY AFTERNOON",
1307
- LATE_AFTERNOON: "LATE AFTERNOON",
1308
- EARLY_EVENING: "EARLY EVENING",
1309
- LATE_EVENING: "LATE EVENING"
1310
- };
1311
- function partOfDayLabel(part) {
1312
- return PART_OF_DAY_LABELS[part];
1313
- }
1314
- function partOfDay(time) {
1315
- const hour = Number(time.slice(0, 2));
1316
- if (hour < 3) return "OVERNIGHT";
1317
- if (hour < 6) return "PRE_DAWN";
1318
- if (hour < 9) return "EARLY_MORNING";
1319
- if (hour < 12) return "LATE_MORNING";
1320
- if (hour < 15) return "EARLY_AFTERNOON";
1321
- if (hour < 18) return "LATE_AFTERNOON";
1322
- if (hour < 21) return "EARLY_EVENING";
1323
- return "LATE_EVENING";
1324
- }
1325
- var MINUTES_IN_DAY = 24 * 60;
1326
- function minutesOfDay(time) {
1327
- return Number(time.slice(0, 2)) * 60 + Number(time.slice(3, 5));
1328
- }
1329
- function formatSlotRange(startTime, endTime) {
1330
- return endTime === null ? startTime : `${startTime} - ${endTime}`;
1331
- }
1332
- function formatSlotDuration(startTime, endTime) {
1333
- if (endTime === null) return null;
1334
- const minutes = (minutesOfDay(endTime) - minutesOfDay(startTime) + MINUTES_IN_DAY) % MINUTES_IN_DAY;
1335
- if (!Number.isFinite(minutes) || minutes <= 0) return null;
1336
- const hours = Math.floor(minutes / 60);
1337
- const rest = minutes % 60;
1338
- if (hours === 0) return `${rest}m`;
1339
- return rest === 0 ? `${hours}h` : `${hours}h ${rest}m`;
1340
- }
1341
- function withSelectedDay(selection, day) {
1342
- return selection.day === day ? selection : { day, startTime: null };
1343
- }
1344
- function withSelectedTime(selection, startTime) {
1345
- return { day: selection.day, startTime };
1346
- }
1347
- function hasStarted(slot, options) {
1348
- if (options.selection.day < options.today) return true;
1349
- if (options.selection.day > options.today) return false;
1350
- return slot.startTime <= options.nowTime;
1351
- }
1352
- function timeslotState(slot, options) {
1353
- if (hasStarted(slot, options)) return "PAST_BUT_RELEVANT";
1354
- if (slot.remaining !== null && slot.remaining <= 0) return "UNAVAILABLE";
1355
- return slot.startTime === options.selection.startTime ? "SELECTED" : "AVAILABLE";
1356
- }
1357
- function sameTimeslots(a, b) {
1358
- if (a === b) return true;
1359
- if (a.length !== b.length) return false;
1360
- return a.every((slot, index) => {
1361
- const other = b[index];
1362
- return slot.startTime === other.startTime && slot.endTime === other.endTime && slot.remaining === other.remaining && slot.product === other.product;
1363
- });
1364
- }
1365
- function buildTimeslotGroups(slots, options) {
1366
- const groups = [];
1367
- const chronological = [...slots].sort((a, b) => a.startTime.localeCompare(b.startTime));
1368
- const cellFor = (slot) => ({
1369
- slot,
1370
- part: partOfDay(slot.startTime),
1371
- state: timeslotState(slot, options),
1372
- duration: formatSlotDuration(slot.startTime, slot.endTime)
1373
- });
1374
- const grouping = options.grouping ?? "PART_OF_DAY";
1375
- if (grouping === "NONE") {
1376
- return chronological.length === 0 ? [] : [{ key: "ALL", part: null, label: null, cells: chronological.map(cellFor) }];
1377
- }
1378
- const byKey = /* @__PURE__ */ new Map();
1379
- const groupOf = (slot) => {
1380
- if (grouping === "PRODUCT") {
1381
- const product = slot.product?.trim() ?? "";
1382
- return product === "" ? { key: "PRODUCT:", part: null, label: null } : { key: `PRODUCT:${product}`, part: null, label: product };
1383
- }
1384
- const part = partOfDay(slot.startTime);
1385
- return { key: part, part, label: partOfDayLabel(part) };
1386
- };
1387
- for (const slot of chronological) {
1388
- const head = groupOf(slot);
1389
- let group = byKey.get(head.key);
1390
- if (!group) {
1391
- group = { ...head, cells: [] };
1392
- byKey.set(head.key, group);
1393
- groups.push(group);
1394
- }
1395
- group.cells.push(cellFor(slot));
1396
- }
1397
- return groups;
1398
- }
1399
- function timeslotRequest(day, startTime, schedule) {
1400
- if (day === void 0 || startTime === void 0 || startTime === "") return void 0;
1401
- const slot = schedule?.slotsByDay?.[day]?.find((candidate) => candidate.startTime === startTime);
1402
- if (slot === void 0) return void 0;
1403
- const ends = slot.endTime ?? slot.startTime;
1404
- return { LocalStartTime: `${slot.startTime}:00`, LocalEndTime: `${ends}:00` };
1405
- }
1406
-
1407
- // src/island/TimeslotPicker.tsx
1408
- var import_jsx_runtime14 = require("react/jsx-runtime");
1409
- function TimeslotPicker({
1410
- slots,
1411
- selection,
1412
- today,
1413
- nowTime,
1414
- onSelect,
1415
- accessory,
1416
- grouping
1417
- }) {
1418
- const groups = (0, import_react5.useMemo)(
1419
- () => buildTimeslotGroups(slots, { selection, today, nowTime, grouping }),
1420
- [slots, selection, today, nowTime, grouping]
1421
- );
1422
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "scopetickets-island-timeslots", children: groups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1423
- TimeslotGroupSection,
1424
- {
1425
- group,
1426
- accessory,
1427
- onSelect
1428
- },
1429
- group.key
1430
- )) });
1431
- }
1432
-
1433
- // ../checkout-core/src/motion/island-step-order.ts
1434
- function dayDirection(from, to) {
1435
- if (from === to) return "NONE";
1436
- return to > from ? "FORWARD" : "BACKWARD";
1437
- }
1438
- function stepDirectionSign(direction) {
1439
- if (direction === "FORWARD") return 1;
1440
- if (direction === "BACKWARD") return -1;
1441
- return 0;
1442
- }
1443
-
1444
- // ../checkout-core/src/motion/island-day-swap.ts
1445
- function daySwapAtRest(content) {
1446
- return { phase: "REST", shown: content };
1447
- }
1448
- function reduceDaySwap(state, event) {
1449
- switch (event.type) {
1450
- case "CONTENT_CHANGED": {
1451
- const next = event.content;
1452
- if (next.day === state.shown.day) {
1453
- const shown = { day: state.shown.day, slots: next.slots };
1454
- if (state.phase === "LEAVING") {
1455
- return { phase: "ENTERING", shown, sign: state.sign === 1 ? -1 : 1 };
1456
- }
1457
- if (sameTimeslots(next.slots, state.shown.slots)) return state;
1458
- return { ...state, shown };
1459
- }
1460
- if (state.phase === "LEAVING" && state.to === next.day) return state;
1461
- const sign = stepDirectionSign(dayDirection(state.shown.day, next.day));
1462
- if (sign === 0) return state;
1463
- return { phase: "LEAVING", shown: state.shown, to: next.day, sign };
1464
- }
1465
- case "LEFT":
1466
- if (state.phase !== "LEAVING") return state;
1467
- return { phase: "ENTERING", shown: event.content, sign: state.sign };
1468
- case "ARRIVED":
1469
- if (state.phase !== "ENTERING") return state;
1470
- return { phase: "REST", shown: state.shown };
1471
- }
1472
- }
1473
-
1474
- // src/island/island-day-swap-css.ts
1475
- var DAY_SWAP_OUT_ANIMATION = "scopetickets-island-day-swap-out";
1476
- var DAY_SWAP_IN_ANIMATION = "scopetickets-island-day-swap-in";
1477
-
1478
- // src/island/TimePicker.tsx
1479
- var import_jsx_runtime15 = require("react/jsx-runtime");
1480
- function TimePicker({
1481
- series,
1482
- today,
1483
- nowTime,
1484
- selection,
1485
- onSelectDay,
1486
- slots,
1487
- onSelectTime,
1488
- remaining,
1489
- accessory = DATE_PICKER_ACCESSORY,
1490
- onVisibleMonthChange,
1491
- grouping
1492
- }) {
1493
- const [swap, dispatch] = (0, import_react6.useReducer)(reduceDaySwap, { day: selection.day, slots }, daySwapAtRest);
1494
- (0, import_react6.useEffect)(() => {
1495
- dispatch({ type: "CONTENT_CHANGED", content: { day: selection.day, slots } });
1496
- }, [selection.day, slots]);
1497
- const onSwapAnimationEnd = (event) => {
1498
- if (event.animationName === DAY_SWAP_OUT_ANIMATION) {
1499
- dispatch({ type: "LEFT", content: { day: selection.day, slots } });
1500
- } else if (event.animationName === DAY_SWAP_IN_ANIMATION) {
1501
- dispatch({ type: "ARRIVED" });
1502
- }
1503
- };
1504
- const shownSelection = swap.shown.day === selection.day ? selection : { day: swap.shown.day, startTime: null };
1505
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "scopetickets-island-time", "data-accessory": accessory, children: [
1506
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1507
- CalendarWeekSection,
1508
- {
1509
- series,
1510
- today,
1511
- selectedDay: selection.day,
1512
- onSelectDay,
1513
- remaining,
1514
- accessory,
1515
- onVisibleMonthChange
1516
- }
1517
- ),
1518
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1519
- "div",
1520
- {
1521
- className: "scopetickets-island-time__swap",
1522
- "data-day-swap": swap.phase,
1523
- style: swap.phase === "REST" ? void 0 : { "--scopetickets-island-swap-sign": swap.sign },
1524
- onAnimationEnd: onSwapAnimationEnd,
1525
- children: [
1526
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SelectedDayHeading, { day: swap.shown.day }),
1527
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1528
- TimeslotPicker,
1529
- {
1530
- slots: swap.shown.slots,
1531
- selection: shownSelection,
1532
- today,
1533
- nowTime,
1534
- onSelect: onSelectTime,
1535
- accessory,
1536
- grouping
1537
- }
1538
- )
1539
- ]
1540
- }
1541
- )
1542
- ] });
1543
- }
1544
-
1545
- // src/island/PartyStepper.tsx
1546
- var import_react7 = require("react");
1547
- var import_icons3 = require("@scopetickets/icons");
1548
-
1549
- // ../checkout-core/src/domain/user-types.ts
1550
- var SOLO_KEY = "default";
1551
- function agreed(values) {
1552
- const first = values[0];
1553
- if (first === void 0) return null;
1554
- return values.every((value) => value === first) ? first : null;
1555
- }
1556
- function groupUserTypes(rows) {
1557
- const byName = /* @__PURE__ */ new Map();
1558
- for (const row of rows) {
1559
- if (row.Name === "") continue;
1560
- const group = byName.get(row.Name);
1561
- if (group === void 0) byName.set(row.Name, [row]);
1562
- else group.push(row);
1563
- }
1564
- return [...byName.entries()].map(([name, group]) => ({
1565
- key: name,
1566
- name,
1567
- note: agreed(group.map((row) => row.Note ?? null))
1568
- }));
1569
- }
1570
- function assignmentFor(product, key) {
1571
- if (product.UserTypes === void 0) return key;
1572
- const offered = product.UserTypes ?? [];
1573
- const byName = offered.find((type) => type.Name === key);
1574
- if (byName !== void 0) return byName.AssignmentKey;
1575
- return offered.some((type) => type.AssignmentKey === key) ? key : void 0;
1576
- }
1577
- function userTypeNames(rows) {
1578
- return Object.fromEntries(rows.map((row) => [row.AssignmentKey, row.Name]));
1579
- }
1580
-
1581
- // src/island/PartyStepper.tsx
1582
- var import_jsx_runtime16 = require("react/jsx-runtime");
1583
- function UserTypeRow({
1584
- option,
1585
- count,
1586
- atLimit,
1587
- onAdd,
1588
- onRemove,
1589
- onSet,
1590
- max,
1591
- onRefuse
1592
- }) {
1593
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "scopetickets-island-party-row", children: [
1594
- /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { className: "scopetickets-island-party-row__text", children: [
1595
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "scopetickets-island-party-row__name", children: option.name }),
1596
- option.note !== null && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "scopetickets-island-party-row__note", children: option.note })
1597
- ] }),
1598
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1599
- UserTypeStepper,
1600
- {
1601
- name: option.name,
1602
- count,
1603
- atLimit,
1604
- onAdd,
1605
- onRemove,
1606
- onSet,
1607
- max,
1608
- onRefuse
1609
- }
1610
- )
1611
- ] });
1612
- }
1613
- function UserTypeStepper({
1614
- name,
1615
- count,
1616
- atLimit,
1617
- onAdd,
1618
- onRemove,
1619
- onSet,
1620
- max,
1621
- onRefuse
1622
- }) {
1623
- const chosen = count > 0;
1624
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { className: "scopetickets-island-stepper", "data-expanded": chosen ? "" : void 0, children: [
1625
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1626
- "span",
1627
- {
1628
- className: "scopetickets-island-stepper__opening",
1629
- "aria-hidden": chosen ? void 0 : "true",
1630
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { className: "scopetickets-island-stepper__opening-inner", children: [
1631
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1632
- StepperButton,
1633
- {
1634
- label: PARTY_COPY.remove(name),
1635
- onPress: onRemove,
1636
- kind: "remove",
1637
- state: chosen ? "LIVE" : "CLOSED"
1638
- }
1639
- ),
1640
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1641
- TypedCount,
1642
- {
1643
- count,
1644
- name,
1645
- onSet,
1646
- valueClassName: "scopetickets-island-stepper__value",
1647
- inputClassName: "scopetickets-island-stepper__input",
1648
- closed: !chosen,
1649
- max,
1650
- onRefuse
1651
- }
1652
- )
1653
- ] })
1654
- }
1655
- ),
1656
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1657
- StepperButton,
1658
- {
1659
- label: PARTY_COPY.add(name),
1660
- onPress: onAdd,
1661
- kind: "add",
1662
- state: atLimit ? "REFUSING" : "LIVE"
1663
- }
1664
- )
1665
- ] });
1666
- }
1667
- function StepperButton({
1668
- label,
1669
- onPress,
1670
- kind,
1671
- state = "LIVE"
1672
- }) {
1673
- const press = useIslandPress("element");
1674
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1675
- "button",
1676
- {
1677
- type: "button",
1678
- className: "scopetickets-island-stepper__button",
1679
- "data-kind": kind,
1680
- "aria-label": label,
1681
- "aria-disabled": state === "REFUSING" ? true : void 0,
1682
- disabled: state === "CLOSED",
1683
- onClick: state === "LIVE" ? onPress : void 0,
1684
- ...press,
1685
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "scopetickets-island-stepper__mark", children: kind === "add" ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_icons3.PlusMarkIcon, { fill: true, color: "currentColor" }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_icons3.MinusMarkIcon, { fill: true, color: "currentColor" }) })
1686
- }
1687
- );
1688
- }
1689
- function SoloPartyStepper({ max, name, count, onSet, onRemove, onRefuse }) {
1690
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "scopetickets-island-party-solo", children: [
1691
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1692
- StepperButton,
1693
- {
1694
- label: PARTY_COPY.remove(name),
1695
- onPress: onRemove,
1696
- kind: "remove",
1697
- state: count === 0 ? "REFUSING" : "LIVE"
1698
- }
1699
- ),
1700
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1701
- TypedCount,
1702
- {
1703
- count,
1704
- name,
1705
- onSet,
1706
- valueClassName: "scopetickets-island-party-solo__value",
1707
- inputClassName: "scopetickets-island-party-solo__input",
1708
- max,
1709
- onRefuse
1710
- }
1711
- ),
1712
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1713
- StepperButton,
1714
- {
1715
- label: PARTY_COPY.add(name),
1716
- onPress: () => onSet(count + 1),
1717
- kind: "add",
1718
- state: count >= max ? "REFUSING" : "LIVE"
1719
- }
1720
- )
1721
- ] });
1722
- }
1723
- function TypedCount({
1724
- count,
1725
- name,
1726
- onSet,
1727
- valueClassName,
1728
- inputClassName,
1729
- onRefuse,
1730
- closed = false,
1731
- max
1732
- }) {
1733
- const [typing, setTyping] = (0, import_react7.useState)(null);
1734
- const field = (0, import_react7.useRef)(null);
1735
- const editing = typing !== null;
1736
- (0, import_react7.useEffect)(() => {
1737
- if (!editing) return;
1738
- field.current?.focus({ preventScroll: true });
1739
- }, [editing]);
1740
- const commit = () => {
1741
- if (typing === null) return;
1742
- const asked = Number.parseInt(typing, 10);
1743
- setTyping(null);
1744
- if (!Number.isFinite(asked)) return;
1745
- if (max !== void 0 && asked > max) {
1746
- onRefuse?.(asked);
1747
- return;
1748
- }
1749
- onRefuse?.(null);
1750
- onSet(Math.max(0, asked));
1751
- };
1752
- if (typing === null) {
1753
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1754
- "button",
1755
- {
1756
- type: "button",
1757
- className: valueClassName,
1758
- "aria-label": PARTY_COPY.count(count, name),
1759
- onClick: () => setTyping(String(count)),
1760
- disabled: closed,
1761
- children: count
1762
- }
1763
- );
1764
- }
1765
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1766
- "input",
1767
- {
1768
- className: inputClassName,
1769
- type: "text",
1770
- inputMode: "numeric",
1771
- pattern: "[0-9]*",
1772
- size: 1,
1773
- ref: field,
1774
- "aria-label": PARTY_COPY.field(name),
1775
- value: typing,
1776
- onChange: (event) => setTyping(event.target.value.replace(/\D/g, "")),
1777
- onBlur: commit,
1778
- onKeyDown: (event) => {
1779
- if (event.key === "Enter") commit();
1780
- else if (event.key === "Escape") setTyping(null);
1781
- else return;
1782
- event.preventDefault();
1783
- event.stopPropagation();
1784
- }
1785
- }
1786
- );
1787
- }
1788
- function PartyStepper({
1789
- userTypes,
1790
- counts,
1791
- onChange,
1792
- max,
1793
- soloName = PARTY_COPY.soloName,
1794
- onRefuse,
1795
- refused = null
1796
- }) {
1797
- const headcount = Object.values(counts).reduce((total, n2) => total + n2, 0);
1798
- const refuse = (asked) => onRefuse?.(asked);
1799
- const shown = (count) => refused === null ? count : refused;
1800
- if (userTypes.length === 0) {
1801
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "scopetickets-island-party", "data-excess": refused === null ? void 0 : "", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1802
- SoloPartyStepper,
1803
- {
1804
- max,
1805
- name: soloName,
1806
- count: shown(headcount),
1807
- onSet: (next) => {
1808
- refuse(null);
1809
- onChange(SOLO_KEY, next);
1810
- },
1811
- onRemove: () => refused === null ? onChange(SOLO_KEY, Math.max(0, headcount - 1)) : (refuse(null), onChange(SOLO_KEY, max)),
1812
- onRefuse: refuse
1813
- }
1814
- ) });
1815
- }
1816
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "scopetickets-island-party", "data-excess": refused === null ? void 0 : "", children: userTypes.map((option) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1817
- UserTypeRow,
1818
- {
1819
- option,
1820
- count: counts[option.key] ?? 0,
1821
- atLimit: headcount >= max,
1822
- onAdd: () => {
1823
- refuse(null);
1824
- onChange(option.key, (counts[option.key] ?? 0) + 1);
1825
- },
1826
- onRemove: () => {
1827
- refuse(null);
1828
- onChange(option.key, Math.max(0, (counts[option.key] ?? 0) - 1));
1829
- },
1830
- onSet: (next) => {
1831
- refuse(null);
1832
- onChange(option.key, next);
1833
- },
1834
- max,
1835
- onRefuse: refuse
1836
- },
1837
- option.key
1838
- )) });
1839
- }
1840
-
1841
- // src/island/CalendarGrainButton.tsx
1842
- var import_react8 = require("react");
1843
- var import_jsx_runtime17 = require("react/jsx-runtime");
1844
- function useShortenedMonth(long) {
1845
- const [short, setShort] = (0, import_react8.useState)(false);
1846
- const title = (0, import_react8.useRef)(null);
1847
- const probe = (0, import_react8.useRef)(null);
1848
- const measure = (0, import_react8.useCallback)(() => {
1849
- const box = title.current;
1850
- const full = probe.current;
1851
- if (!box || !full) return;
1852
- const wanted = Math.ceil(full.getBoundingClientRect().width);
1853
- box.style.setProperty("--scopetickets-island-grain-width", `${wanted}px`);
1854
- setShort(box.clientWidth + 1 < wanted);
1855
- }, []);
1856
- (0, import_react8.useLayoutEffect)(() => {
1857
- measure();
1858
- if (typeof ResizeObserver === "undefined") return;
1859
- const observer = new ResizeObserver(measure);
1860
- if (title.current) observer.observe(title.current);
1861
- return () => observer.disconnect();
1862
- }, [measure, long]);
1863
- return {
1864
- short,
1865
- titleRef: (0, import_react8.useCallback)(
1866
- (node) => {
1867
- title.current = node;
1868
- measure();
1869
- },
1870
- [measure]
1871
- ),
1872
- probeRef: (0, import_react8.useCallback)(
1873
- (node) => {
1874
- probe.current = node;
1875
- measure();
1876
- },
1877
- [measure]
1878
- )
1879
- };
1880
- }
1881
- function CalendarGrainButton({ month, grain, onPress }) {
1882
- const press = useIslandPress("element");
1883
- const long = grain === "YEAR" ? formatMonthYear(month) : formatMonthName(month);
1884
- const { short, titleRef, probeRef } = useShortenedMonth(long);
1885
- const shown = grain === "MONTH" && short ? formatMonthNameShort(month) : long;
1886
- const title = /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
1887
- "span",
1888
- {
1889
- className: "scopetickets-island-header-button__title",
1890
- ref: titleRef,
1891
- ...grain === "MONTH" && short ? { "data-grain-short": "" } : null,
1892
- children: [
1893
- shown,
1894
- grain === "MONTH" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1895
- "span",
1896
- {
1897
- className: "scopetickets-island-header-button__probe",
1898
- ref: probeRef,
1899
- "aria-hidden": "true",
1900
- children: long
1901
- }
1902
- ) : null
1903
- ]
1904
- }
1905
- );
1906
- if (onPress === void 0) {
1907
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "scopetickets-island-chrome-pill scopetickets-island-grain-pill", children: title });
1908
- }
1909
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1910
- "button",
1911
- {
1912
- type: "button",
1913
- className: "scopetickets-island-chrome-pill scopetickets-island-header-button scopetickets-island-grain-pill",
1914
- onClick: onPress,
1915
- ...press,
1916
- children: title
1917
- }
1918
- );
1919
- }
1920
-
1921
- // src/island/Switch.tsx
1922
- var import_jsx_runtime18 = require("react/jsx-runtime");
1923
- function Switch({ checked, onChange, label, size = "wide", disabled = false }) {
1924
- const press = useIslandPress("element");
1925
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1926
- "button",
1927
- {
1928
- type: "button",
1929
- role: "switch",
1930
- "aria-checked": checked,
1931
- "aria-label": label,
1932
- disabled,
1933
- className: `scopetickets-island-switch scopetickets-island-switch--${size}`,
1934
- onClick: () => onChange(!checked),
1935
- ...disabled ? {} : press,
1936
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "scopetickets-island-switch__thumb", "aria-hidden": "true" })
1937
- }
1938
- );
1939
- }
1940
- // Annotate the CommonJS export names for ESM import in node:
1941
- 0 && (module.exports = {
1942
- CalendarGrainButton,
1943
- ContentFlag,
1944
- CounterRing,
1945
- DATE_PICKER_ACCESSORY,
1946
- DayPicker,
1947
- PartyStepper,
1948
- SOLO_KEY,
1949
- Switch,
1950
- TimePicker,
1951
- TimeslotPicker,
1952
- addDays,
1953
- assignmentFor,
1954
- availabilityColor,
1955
- buildMonthGrid,
1956
- buildTimeslotGroups,
1957
- buildWeekRow,
1958
- dateRange,
1959
- eventKeyForDay,
1960
- eventsOn,
1961
- formatDayDate,
1962
- formatDayWeekday,
1963
- formatMonthName,
1964
- formatMonthNameShort,
1965
- formatMonthYear,
1966
- formatSlotDuration,
1967
- formatSlotRange,
1968
- formatWeekdayAndDate,
1969
- groupUserTypes,
1970
- isDatePickerCellSelectable,
1971
- isSelectableCalendarCell,
1972
- locateDayInMonthStack,
1973
- monthAtRow,
1974
- monthOfDay,
1975
- monthOfWeek,
1976
- monthOpeningRow,
1977
- monthStartRows,
1978
- monthsInSeries,
1979
- openingMonth,
1980
- parseWallClockTime,
1981
- partOfDay,
1982
- partOfDayLabel,
1983
- readAvailability,
1984
- sameTimeslots,
1985
- soonestRelevantDay,
1986
- startOfWeek,
1987
- stepMonth,
1988
- timeOfDayInZone,
1989
- timeslotRequest,
1990
- toAvailabilityLevel,
1991
- toggleSelectedDay,
1992
- userTypeNames,
1993
- weekContainingDay,
1994
- weeksInCalendar,
1995
- weeksInSeries,
1996
- withSelectedDay,
1997
- withSelectedTime
1998
- });
1999
- //# sourceMappingURL=pickers.cjs.map