@adminide-stack/clock-tik-browser 12.0.33-alpha.0 → 12.0.34-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/pages/Home/__tests__/TourOverlay.test.d.ts +2 -0
  2. package/lib/pages/Home/__tests__/TourOverlay.test.d.ts.map +1 -0
  3. package/lib/pages/Home/__tests__/chatTour.test.d.ts +2 -0
  4. package/lib/pages/Home/__tests__/chatTour.test.d.ts.map +1 -0
  5. package/lib/pages/Home/__tests__/tourGeometry.test.d.ts +2 -0
  6. package/lib/pages/Home/__tests__/tourGeometry.test.d.ts.map +1 -0
  7. package/lib/pages/Home/chat/ChoresChat.d.ts.map +1 -1
  8. package/lib/pages/Home/chat/ChoresChat.js +25 -2
  9. package/lib/pages/Home/chat/ChoresChat.js.map +1 -1
  10. package/lib/pages/Home/chat/thread.d.ts +5 -0
  11. package/lib/pages/Home/chat/thread.d.ts.map +1 -1
  12. package/lib/pages/Home/chat/thread.js +14 -1
  13. package/lib/pages/Home/chat/thread.js.map +1 -1
  14. package/lib/pages/Home/chat/tour/ChatTour.d.ts +11 -0
  15. package/lib/pages/Home/chat/tour/ChatTour.d.ts.map +1 -0
  16. package/lib/pages/Home/chat/tour/ChatTour.js +17 -0
  17. package/lib/pages/Home/chat/tour/ChatTour.js.map +1 -0
  18. package/lib/pages/Home/chat/tour/TourDemos.d.ts +20 -0
  19. package/lib/pages/Home/chat/tour/TourDemos.d.ts.map +1 -0
  20. package/lib/pages/Home/chat/tour/TourDemos.js +165 -0
  21. package/lib/pages/Home/chat/tour/TourDemos.js.map +1 -0
  22. package/lib/pages/Home/chat/tour/TourOverlay.d.ts +14 -0
  23. package/lib/pages/Home/chat/tour/TourOverlay.d.ts.map +1 -0
  24. package/lib/pages/Home/chat/tour/TourOverlay.js +1006 -0
  25. package/lib/pages/Home/chat/tour/TourOverlay.js.map +1 -0
  26. package/lib/pages/Home/chat/tour/index.d.ts +3 -0
  27. package/lib/pages/Home/chat/tour/index.d.ts.map +1 -0
  28. package/lib/pages/Home/chat/tour/tourDom.d.ts +36 -0
  29. package/lib/pages/Home/chat/tour/tourDom.d.ts.map +1 -0
  30. package/lib/pages/Home/chat/tour/tourDom.js +81 -0
  31. package/lib/pages/Home/chat/tour/tourDom.js.map +1 -0
  32. package/lib/pages/Home/chat/tour/tourGeometry.d.ts +106 -0
  33. package/lib/pages/Home/chat/tour/tourGeometry.d.ts.map +1 -0
  34. package/lib/pages/Home/chat/tour/tourGeometry.js +348 -0
  35. package/lib/pages/Home/chat/tour/tourGeometry.js.map +1 -0
  36. package/lib/pages/Home/chat/tour/tourSteps.d.ts +45 -0
  37. package/lib/pages/Home/chat/tour/tourSteps.d.ts.map +1 -0
  38. package/lib/pages/Home/chat/tour/tourSteps.js +87 -0
  39. package/lib/pages/Home/chat/tour/tourSteps.js.map +1 -0
  40. package/lib/pages/Home/chat/tour/tourStyles.d.ts +15 -0
  41. package/lib/pages/Home/chat/tour/tourStyles.d.ts.map +1 -0
  42. package/lib/pages/Home/chat/tour/tourStyles.js +156 -0
  43. package/lib/pages/Home/chat/tour/tourStyles.js.map +1 -0
  44. package/lib/pages/Home/chat/tour/useChatTour.d.ts +17 -0
  45. package/lib/pages/Home/chat/tour/useChatTour.d.ts.map +1 -0
  46. package/lib/pages/Home/chat/tour/useChatTour.js +75 -0
  47. package/lib/pages/Home/chat/tour/useChatTour.js.map +1 -0
  48. package/package.json +2 -2
@@ -0,0 +1,1006 @@
1
+ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {Check,Receipt,PhoneCall,CalendarCheck,MessageCircle,ShieldCheck,ArrowRight,X,ArrowLeft}from'lucide-react';import {useState,useId,useRef,useLayoutEffect,useEffect,useCallback,useMemo}from'react';import {Mark}from'../../Logo.js';import {usePrefersReducedMotion,TourDemo}from'./TourDemos.js';import {findTarget,cornerRadius,scrollerOf,toBox,scrollDelta,scrollTarget}from'./tourDom.js';import {grow,RING_OFFSET,cutoutBox,placeCard,centreCard,clamp,roundedRectPath,easeOutCubic,arrowBetween,fitRadius,SHEET_BELOW,EDGE,veilPath,stepSpring}from'./tourGeometry.js';import {CHAT_TOUR_STEPS,TOUR_TRIES}from'./tourSteps.js';import {CHAT_TOUR_CSS}from'./tourStyles.js';const WELCOME_TILES = [{
2
+ Icon: MessageCircle,
3
+ title: 'Say it like a text',
4
+ text: 'No forms, no phone menus.'
5
+ }, {
6
+ Icon: PhoneCall,
7
+ title: 'I make the calls',
8
+ text: 'And wait on hold, so you don’t.'
9
+ }, {
10
+ Icon: ShieldCheck,
11
+ title: 'You approve what matters',
12
+ text: 'Nothing is paid or changed without your yes.'
13
+ }];
14
+ /** Chores Lucy has done, floating round the welcome window, and where (relative to it). Drawn, not real. */
15
+ const WELCOME_FLOATS = [{
16
+ Icon: Check,
17
+ text: 'Gym cancelled',
18
+ style: {
19
+ left: -178,
20
+ top: '13%'
21
+ },
22
+ delay: 0.5
23
+ }, {
24
+ Icon: Receipt,
25
+ text: '$35 a month back',
26
+ style: {
27
+ right: -198,
28
+ top: '40%'
29
+ },
30
+ delay: 0.62
31
+ }, {
32
+ Icon: PhoneCall,
33
+ text: 'Hold music skipped',
34
+ style: {
35
+ left: -196,
36
+ top: '64%'
37
+ },
38
+ delay: 0.74
39
+ }, {
40
+ Icon: CalendarCheck,
41
+ text: 'Dentist booked',
42
+ style: {
43
+ right: -180,
44
+ top: '80%'
45
+ },
46
+ delay: 0.86
47
+ }];
48
+ /** The confetti's colours: Clockbook's oranges and the page's warm accents. */
49
+ const BURST_COLOURS = ['#FF5A00', '#FF8A3D', '#FFC45C', '#FF8FA3', '#1FA855', '#FFB36B'];
50
+ const BURST_PIECES = 38;
51
+ const BURST_MS = 1700;
52
+ /** Bubbles; the welcome window is wider. A phone gets a sheet across the window instead. */
53
+ const STEP_CARD_WIDTH = 344;
54
+ const WELCOME_CARD_WIDTH = 540;
55
+ /** Lucy's radius on screen, and how much bigger she greets you in the welcome window. */
56
+ const GUIDE_RADIUS = 26;
57
+ const GUIDE_WELCOME_SCALE = 1.6;
58
+ /** Where Lucy sits in the welcome window: below its title bar, in the room left for her. */
59
+ const GUIDE_WELCOME_DROP = 93;
60
+ /** The cut-out glides without overshoot; the bubble settles with a little give; Lucy bounces. */
61
+ const HOLE_SPRING = {
62
+ omega: 17,
63
+ zeta: 1
64
+ };
65
+ const CARD_SPRING = {
66
+ omega: 14,
67
+ zeta: 0.8
68
+ };
69
+ const GUIDE_SPRING = {
70
+ omega: 13,
71
+ zeta: 0.55
72
+ };
73
+ const RING_DRAW_S = 0.5;
74
+ const ARROW_DRAW_S = 0.4;
75
+ const PING_S = 0.75;
76
+ const EXIT_MS = 320;
77
+ /** Longest a smooth scroll is waited on before the cut-out follows the control where it is. */
78
+ const SCROLL_AIM_MS = 900;
79
+ /** `.cbt-win`'s top margin (tourStyles), which goes with it in a compact bubble. */
80
+ const DEMO_MARGIN = 14;
81
+ /** The chat's composer (the kit's), where focus goes when the tour ends. */
82
+ const COMPOSER_INPUT = '.cbh-chat .ysc-composer-root textarea';
83
+ const BOX_KEYS = ['x', 'y', 'w', 'h'];
84
+ const spring = (value = 0) => ({
85
+ value,
86
+ velocity: 0
87
+ });
88
+ function springBox() {
89
+ return {
90
+ x: spring(),
91
+ y: spring(),
92
+ w: spring(),
93
+ h: spring()
94
+ };
95
+ }
96
+ function glide(target, goal, dt, jump, omega, zeta) {
97
+ Object.assign(target, jump ? {
98
+ value: goal,
99
+ velocity: 0
100
+ } : stepSpring(target, goal, dt, omega, zeta));
101
+ }
102
+ function glideBox(springs, goal, dt, jump, omega, zeta) {
103
+ for (const key of BOX_KEYS) glide(springs[key], goal[key], dt, jump, omega, zeta);
104
+ }
105
+ function boxOf(springs) {
106
+ return {
107
+ x: springs.x.value,
108
+ y: springs.y.value,
109
+ w: springs.w.value,
110
+ h: springs.h.value
111
+ };
112
+ }
113
+ function atRest(springs, goal) {
114
+ return BOX_KEYS.every(key => Math.abs(springs[key].value - goal[key]) < 1.5 && Math.abs(springs[key].velocity) < 40);
115
+ }
116
+ /** Two decimals: enough for a smooth glide, and a settled value stops changing (so stops writing). */
117
+ function n2(value) {
118
+ return String(Math.round(value * 100) / 100);
119
+ }
120
+ function viewportNow() {
121
+ return {
122
+ width: window.innerWidth,
123
+ height: window.innerHeight
124
+ };
125
+ }
126
+ function cardWidth(kind, viewport) {
127
+ if (viewport.width < SHEET_BELOW) return viewport.width - EDGE * 2;
128
+ return Math.min(kind === 'welcome' ? WELCOME_CARD_WIDTH : STEP_CARD_WIDTH, viewport.width - EDGE * 2);
129
+ }
130
+ /** Where Lucy perches on a bubble: on the middle of the edge that faces its control. */
131
+ function perch(card, side) {
132
+ switch (side) {
133
+ case 'bottom':
134
+ return {
135
+ x: card.x + card.w / 2,
136
+ y: card.y
137
+ };
138
+ case 'top':
139
+ return {
140
+ x: card.x + card.w / 2,
141
+ y: card.y + card.h
142
+ };
143
+ case 'right':
144
+ return {
145
+ x: card.x,
146
+ y: card.y + card.h / 2
147
+ };
148
+ case 'left':
149
+ return {
150
+ x: card.x + card.w,
151
+ y: card.y + card.h / 2
152
+ };
153
+ }
154
+ }
155
+ /** Keeps Tab inside the bubble while the tour is up. */
156
+ function trapFocus(event, container) {
157
+ if (!container) return;
158
+ const focusable = Array.from(container.querySelectorAll('button:not([disabled])'));
159
+ if (focusable.length === 0) {
160
+ event.preventDefault();
161
+ return;
162
+ }
163
+ const first = focusable[0];
164
+ const last = focusable[focusable.length - 1];
165
+ const active = document.activeElement;
166
+ const inside = active instanceof Node && container.contains(active);
167
+ if (event.shiftKey && (active === first || !inside)) {
168
+ event.preventDefault();
169
+ last.focus();
170
+ } else if (!event.shiftKey && (active === last || !inside)) {
171
+ event.preventDefault();
172
+ first.focus();
173
+ }
174
+ }
175
+ /** Confetti from the composer as the tour hands over to it. Deterministic, so every run looks alike. */
176
+ function Burst({
177
+ x,
178
+ y
179
+ }) {
180
+ const pieces = useMemo(() => Array.from({
181
+ length: BURST_PIECES
182
+ }, (_, i) => {
183
+ const angle = (i / BURST_PIECES * 360 + i % 5 * 7) * (Math.PI / 180);
184
+ const distance = 80 + i * 37 % 110;
185
+ return {
186
+ '--dx': `${Math.round(Math.cos(angle) * distance * 1.25)}px`,
187
+ '--dy': `${Math.round(Math.sin(angle) * distance * 0.8 + 50)}px`,
188
+ '--r': `${i * 73 % 540 - 270}deg`,
189
+ '--s': `${5 + i % 3 * 2}px`,
190
+ '--k': i % 4 === 0 ? 2.6 : 1,
191
+ '--c': BURST_COLOURS[i % BURST_COLOURS.length],
192
+ '--d': `${i % 6 * 22}ms`
193
+ };
194
+ }), []);
195
+ return jsx("div", {
196
+ className: "cbt-burst",
197
+ style: {
198
+ transform: `translate(${x}px, ${y}px)`
199
+ },
200
+ "aria-hidden": true,
201
+ children: pieces.map((style, i) =>
202
+ // eslint-disable-next-line react/no-array-index-key
203
+ jsx("i", {
204
+ style: style
205
+ }, i))
206
+ });
207
+ }
208
+ function TourOverlay({
209
+ firstName,
210
+ onClose,
211
+ onTryPrompt,
212
+ steps = CHAT_TOUR_STEPS
213
+ }) {
214
+ const reduced = usePrefersReducedMotion();
215
+ const [stage, setStage] = useState({
216
+ kind: 'welcome'
217
+ });
218
+ // The steps whose controls were on screen when the walk began; Next re-checks as it goes.
219
+ const [plan, setPlan] = useState([]);
220
+ const [exiting, setExiting] = useState(false);
221
+ const [burst, setBurst] = useState(null);
222
+ const step = stage.kind === 'step' ? plan[stage.index] ?? null : null;
223
+ const index = stage.kind === 'step' ? stage.index : -1;
224
+ const uid = useId().replace(/[^a-zA-Z0-9_-]/g, '');
225
+ const ringMaskId = `cbt-ring-${uid}`;
226
+ const arrowMaskId = `cbt-arrow-${uid}`;
227
+ const titleId = `cbt-title-${uid}`;
228
+ const cardRef = useRef(null);
229
+ const innerRef = useRef(null);
230
+ const primaryRef = useRef(null);
231
+ const veilRef = useRef(null);
232
+ const guideRef = useRef(null);
233
+ const decoRef = useRef(null);
234
+ const ringRef = useRef(null);
235
+ const ringMaskRef = useRef(null);
236
+ const pingRef = useRef(null);
237
+ const arrowRef = useRef(null);
238
+ const shaftRef = useRef(null);
239
+ const shaftMaskRef = useRef(null);
240
+ const headRef = useRef(null);
241
+ const motion = useRef({
242
+ hole: springBox(),
243
+ radius: spring(24),
244
+ card: springBox(),
245
+ guide: {
246
+ x: spring(),
247
+ y: spring(),
248
+ scale: spring(GUIDE_WELCOME_SCALE)
249
+ },
250
+ target: null,
251
+ targetRadius: 16,
252
+ side: null,
253
+ compact: false,
254
+ aim: null,
255
+ ring: 0,
256
+ arrow: 0,
257
+ ping: -1,
258
+ settled: 0,
259
+ burst: false,
260
+ last: 0,
261
+ fresh: true,
262
+ written: {}
263
+ });
264
+ // What the frame loop reads, kept current after each commit.
265
+ const live = useRef({
266
+ step,
267
+ kind: stage.kind,
268
+ reduced,
269
+ setBurst
270
+ });
271
+ useLayoutEffect(() => {
272
+ live.current = {
273
+ step,
274
+ kind: stage.kind,
275
+ reduced,
276
+ setBurst
277
+ };
278
+ });
279
+ // Scrollers the tour moved, with where each was, to put them back at the end.
280
+ const scrolled = useRef(new Map());
281
+ const exitingRef = useRef(false);
282
+ // The page behind is inert while the tour is up, so a screen reader stays in the bubble the
283
+ // way the pointer and keys do. It is handed back as the exit starts, before focus returns to
284
+ // the composer (an inert element cannot take focus).
285
+ const rootRef = useRef(null);
286
+ const releasePage = useRef(() => undefined);
287
+ useEffect(() => {
288
+ const root = rootRef.current;
289
+ if (!root) return undefined;
290
+ const page = Array.from(document.body.children).filter(el => el !== root && !el.contains(root) && !el.hasAttribute('inert'));
291
+ page.forEach(el => el.setAttribute('inert', ''));
292
+ const release = () => {
293
+ page.forEach(el => el.removeAttribute('inert'));
294
+ page.length = 0;
295
+ };
296
+ releasePage.current = release;
297
+ return release;
298
+ }, []);
299
+ const exit = useCallback((outcome, then) => {
300
+ if (exitingRef.current) return;
301
+ exitingRef.current = true;
302
+ setExiting(true);
303
+ releasePage.current();
304
+ scrolled.current.forEach((top, scroller) => {
305
+ if (typeof scroller.scrollTo === 'function') {
306
+ scroller.scrollTo({
307
+ top,
308
+ behavior: reduced ? 'auto' : 'smooth'
309
+ });
310
+ } else {
311
+ scroller.scrollTop = top;
312
+ }
313
+ });
314
+ window.setTimeout(() => {
315
+ onClose(outcome);
316
+ then?.();
317
+ document.querySelector(COMPOSER_INPUT)?.focus({
318
+ preventScroll: true
319
+ });
320
+ }, reduced ? 0 : EXIT_MS);
321
+ }, [onClose, reduced]);
322
+ const begin = useCallback(() => {
323
+ const available = steps.filter(candidate => findTarget(candidate.targets));
324
+ if (available.length === 0) {
325
+ exit('skipped');
326
+ return;
327
+ }
328
+ setPlan(available);
329
+ setStage({
330
+ kind: 'step',
331
+ index: 0
332
+ });
333
+ }, [exit, steps]);
334
+ // Forward or back, past any step whose control has since left the screen.
335
+ const move = useCallback(direction => {
336
+ if (exitingRef.current) return;
337
+ if (stage.kind === 'welcome') {
338
+ if (direction > 0) begin();
339
+ return;
340
+ }
341
+ let next = stage.index + direction;
342
+ while (next >= 0 && next < plan.length && !findTarget(plan[next].targets)) next += direction;
343
+ if (next < 0) setStage({
344
+ kind: 'welcome'
345
+ });else if (next >= plan.length) exit('finished');else setStage({
346
+ kind: 'step',
347
+ index: next
348
+ });
349
+ }, [begin, exit, plan, stage]);
350
+ const moveRef = useRef(move);
351
+ useLayoutEffect(() => {
352
+ moveRef.current = move;
353
+ });
354
+ // A new stage: aim at its control, scroll it to where its bubble fits, start the drawing over.
355
+ useLayoutEffect(() => {
356
+ const m = motion.current;
357
+ m.ring = 0;
358
+ m.arrow = 0;
359
+ m.ping = -1;
360
+ m.settled = 0;
361
+ m.side = null;
362
+ m.compact = false;
363
+ cardRef.current?.removeAttribute('data-compact');
364
+ m.aim = null;
365
+ // The welcome's decorations mount afresh each time it shows: place them again.
366
+ delete m.written.deco;
367
+ m.target = step ? findTarget(step.targets) : null;
368
+ m.targetRadius = m.target && step ? step.radius ?? cornerRadius(m.target, 12) : 16;
369
+ const inner = innerRef.current;
370
+ const scroller = m.target ? scrollerOf(m.target) : null;
371
+ if (m.target && inner && scroller && step) {
372
+ const viewport = viewportNow();
373
+ inner.style.width = `${cardWidth(stage.kind, viewport)}px`;
374
+ const ring = grow(toBox(m.target.getBoundingClientRect()), (step.pad ?? 8) + RING_OFFSET);
375
+ const delta = scrollDelta(ring, toBox(scroller.getBoundingClientRect()), inner.offsetHeight, viewport);
376
+ if (Math.abs(delta) >= 2) {
377
+ if (!scrolled.current.has(scroller)) scrolled.current.set(scroller, scroller.scrollTop);
378
+ const top = scrollTarget(scroller, delta);
379
+ m.aim = {
380
+ scroller,
381
+ top,
382
+ until: performance.now() + SCROLL_AIM_MS
383
+ };
384
+ if (typeof scroller.scrollTo === 'function') {
385
+ scroller.scrollTo({
386
+ top,
387
+ behavior: reduced ? 'auto' : 'smooth'
388
+ });
389
+ } else {
390
+ scroller.scrollTop = top;
391
+ }
392
+ }
393
+ }
394
+ primaryRef.current?.focus({
395
+ preventScroll: true
396
+ });
397
+ // `step` changes with the stage; `reduced` only matters for the next scroll.
398
+ // eslint-disable-next-line react-hooks/exhaustive-deps
399
+ }, [step, stage.kind]);
400
+ // The confetti clears itself once it has fallen.
401
+ useEffect(() => {
402
+ if (!burst) return undefined;
403
+ const timer = window.setTimeout(() => setBurst(null), BURST_MS);
404
+ return () => window.clearTimeout(timer);
405
+ }, [burst]);
406
+ // Keys belong to the tour while it is up.
407
+ useEffect(() => {
408
+ const onKey = event => {
409
+ if (exitingRef.current) return;
410
+ const card = cardRef.current;
411
+ const active = document.activeElement;
412
+ const onButton = active instanceof HTMLButtonElement && Boolean(card?.contains(active));
413
+ if (event.key === 'Escape') {
414
+ event.preventDefault();
415
+ exit('skipped');
416
+ } else if (event.key === 'ArrowRight' || event.key === 'Enter' && !onButton) {
417
+ event.preventDefault();
418
+ moveRef.current(1);
419
+ } else if (event.key === 'ArrowLeft') {
420
+ event.preventDefault();
421
+ moveRef.current(-1);
422
+ } else if (event.key === 'Tab') {
423
+ trapFocus(event, card);
424
+ }
425
+ // Enter and Space on a focused button still press it: stopping propagation does not
426
+ // cancel the default action, only the page's own listeners.
427
+ event.stopPropagation();
428
+ };
429
+ window.addEventListener('keydown', onKey, true);
430
+ return () => window.removeEventListener('keydown', onKey, true);
431
+ }, [exit]);
432
+ // The frame loop.
433
+ useEffect(() => {
434
+ let raf = 0;
435
+ const m = motion.current;
436
+ // Writes a DOM value only when it differs from the last one written.
437
+ const put = (key, value, apply) => {
438
+ if (m.written[key] === value) return;
439
+ m.written[key] = value;
440
+ apply(value);
441
+ };
442
+ const frame = now => {
443
+ raf = window.requestAnimationFrame(frame);
444
+ const card = cardRef.current;
445
+ const inner = innerRef.current;
446
+ if (!card || !inner) return;
447
+ const {
448
+ step: current,
449
+ kind,
450
+ reduced: still,
451
+ setBurst: fireBurst
452
+ } = live.current;
453
+ const viewport = viewportNow();
454
+ const phone = viewport.width < SHEET_BELOW;
455
+ const dt = m.last ? Math.min((now - m.last) / 1000, 1 / 20) : 1 / 60;
456
+ m.last = now;
457
+ // The cut-out: round the step's control, or shut in the middle for the welcome.
458
+ let goal = {
459
+ x: viewport.width / 2,
460
+ y: viewport.height * 0.46,
461
+ w: 0,
462
+ h: 0
463
+ };
464
+ let lit = false;
465
+ if (current) {
466
+ // A step with fallbacks moves to a better target the moment one shows up, and back
467
+ // if it goes away.
468
+ const best = current.targets.length > 1 || !m.target?.isConnected ? findTarget(current.targets) : m.target;
469
+ if (best !== m.target) {
470
+ m.target = best;
471
+ m.targetRadius = best ? current.radius ?? cornerRadius(best, 12) : 16;
472
+ m.ring = 0;
473
+ m.arrow = 0;
474
+ m.ping = -1;
475
+ m.settled = 0;
476
+ m.side = null;
477
+ }
478
+ if (m.target) {
479
+ const rect = toBox(m.target.getBoundingClientRect());
480
+ // Mid-scroll, aim at where the control is heading (see Motion.aim).
481
+ if (m.aim) {
482
+ const ahead = m.aim.top - m.aim.scroller.scrollTop;
483
+ if (Math.abs(ahead) < 1 || now > m.aim.until) m.aim = null;else rect.y -= ahead;
484
+ }
485
+ const box = cutoutBox(rect, current.pad ?? 8, viewport);
486
+ if (box.w > 0 && box.h > 0) {
487
+ goal = box;
488
+ lit = true;
489
+ }
490
+ }
491
+ }
492
+ const goalRadius = lit ? m.targetRadius + (current?.pad ?? 8) : 24;
493
+ // The bubble, measured at the width it is heading for so its height is the real one.
494
+ const width = cardWidth(kind, viewport);
495
+ put('inner.width', `${width}px`, value => {
496
+ inner.style.width = value;
497
+ });
498
+ let height = inner.offsetHeight;
499
+ const prefer = m.side ? [m.side, ...(current?.prefer ?? [])] : current?.prefer;
500
+ let spot = lit && current ? placeCard(goal, {
501
+ w: width,
502
+ h: height
503
+ }, viewport, prefer) : centreCard({
504
+ w: width,
505
+ h: height
506
+ }, viewport);
507
+ // No side has room for the whole bubble: try it without its demo before covering anything.
508
+ const demo = !spot.fits && !m.compact ? inner.querySelector('.cbt-win') : null;
509
+ if (lit && demo) {
510
+ const compactHeight = height - demo.offsetHeight - DEMO_MARGIN;
511
+ const compactSpot = placeCard(goal, {
512
+ w: width,
513
+ h: compactHeight
514
+ }, viewport, prefer);
515
+ if (compactSpot.fits || compactSpot.inside) {
516
+ m.compact = true;
517
+ card.setAttribute('data-compact', '');
518
+ height = compactHeight;
519
+ spot = compactSpot;
520
+ }
521
+ }
522
+ if (lit && spot.fits) m.side = spot.side;
523
+ const cardGoal = {
524
+ x: spot.x,
525
+ y: spot.y,
526
+ w: width,
527
+ h: height
528
+ };
529
+ const pointing = lit && !spot.inside;
530
+ put('card.side', pointing && !phone ? spot.side : 'none', value => card.setAttribute('data-side', value));
531
+ // Lucy: big in the welcome window, else perched on the bubble's edge that faces the
532
+ // control. She aims at where the bubble is going, not where it is, so she flies ahead.
533
+ let guideGoal;
534
+ let guideScale = phone ? 0.9 : 1;
535
+ if (kind === 'welcome') {
536
+ guideGoal = {
537
+ x: cardGoal.x + cardGoal.w / 2,
538
+ y: cardGoal.y + GUIDE_WELCOME_DROP
539
+ };
540
+ guideScale = phone ? 1.35 : GUIDE_WELCOME_SCALE;
541
+ } else if (pointing) {
542
+ guideGoal = perch(cardGoal, spot.side);
543
+ } else {
544
+ guideGoal = {
545
+ x: cardGoal.x + 30,
546
+ y: cardGoal.y
547
+ };
548
+ }
549
+ const jump = still || m.fresh;
550
+ m.fresh = false;
551
+ glideBox(m.hole, goal, dt, jump, HOLE_SPRING.omega, HOLE_SPRING.zeta);
552
+ glide(m.radius, goalRadius, dt, jump, HOLE_SPRING.omega, HOLE_SPRING.zeta);
553
+ glideBox(m.card, cardGoal, dt, jump, CARD_SPRING.omega, CARD_SPRING.zeta);
554
+ glide(m.guide.x, guideGoal.x, dt, jump, GUIDE_SPRING.omega, GUIDE_SPRING.zeta);
555
+ glide(m.guide.y, guideGoal.y, dt, jump, GUIDE_SPRING.omega, GUIDE_SPRING.zeta);
556
+ glide(m.guide.scale, guideScale, dt, jump, GUIDE_SPRING.omega, 0.8);
557
+ const hole = boxOf(m.hole);
558
+ const ring = grow(hole, RING_OFFSET);
559
+ const radius = m.radius.value;
560
+ const veil = veilRef.current;
561
+ if (veil) {
562
+ put('veil', veilPath(hole, radius, viewport), path => {
563
+ const clip = `path(evenodd, "${path}")`;
564
+ veil.style.clipPath = clip;
565
+ veil.style.setProperty('-webkit-clip-path', clip);
566
+ });
567
+ }
568
+ const cardBox = boxOf(m.card);
569
+ put('card.transform', `translate3d(${n2(cardBox.x)}px, ${n2(cardBox.y)}px, 0)`, value => {
570
+ card.style.transform = value;
571
+ });
572
+ put('card.width', `${n2(cardBox.w)}px`, value => {
573
+ card.style.width = value;
574
+ });
575
+ put('card.height', `${n2(cardBox.h)}px`, value => {
576
+ card.style.height = value;
577
+ });
578
+ const deco = decoRef.current;
579
+ if (deco) {
580
+ put('deco', `${n2(cardBox.x)},${n2(cardBox.y)},${n2(cardBox.w)},${n2(cardBox.h)}`, () => {
581
+ deco.style.transform = `translate3d(${n2(cardBox.x)}px, ${n2(cardBox.y)}px, 0)`;
582
+ deco.style.width = `${n2(cardBox.w)}px`;
583
+ deco.style.height = `${n2(cardBox.h)}px`;
584
+ });
585
+ }
586
+ const guide = guideRef.current;
587
+ if (guide) {
588
+ // She leans into the way she is flying.
589
+ const tilt = still ? 0 : clamp(m.guide.x.velocity * 0.02, -16, 16);
590
+ put('guide', `translate3d(${n2(m.guide.x.value)}px, ${n2(m.guide.y.value)}px, 0) rotate(${n2(tilt)}deg) scale(${n2(m.guide.scale.value)})`, value => {
591
+ guide.style.transform = value;
592
+ });
593
+ }
594
+ // Once everything has arrived the marker draws the dotted box round the control, then
595
+ // the arrow from Lucy to it.
596
+ m.settled = lit && atRest(m.hole, goal) && atRest(m.card, cardGoal) ? m.settled + 1 : 0;
597
+ if (lit && (m.ring > 0 || m.settled >= 2)) m.ring = still ? 1 : Math.min(1, m.ring + dt / RING_DRAW_S);
598
+ if (pointing && m.ring >= 0.55) m.arrow = still ? 1 : Math.min(1, m.arrow + dt / ARROW_DRAW_S);
599
+ const ringPath = ringRef.current;
600
+ const ringMask = ringMaskRef.current;
601
+ if (ringPath && ringMask) {
602
+ put('ring.d', lit ? roundedRectPath(ring, radius + RING_OFFSET) : '', d => {
603
+ ringPath.setAttribute('d', d);
604
+ ringMask.setAttribute('d', d);
605
+ });
606
+ put('ring.draw', n2(1 - easeOutCubic(m.ring)), value => {
607
+ ringMask.style.strokeDashoffset = value;
608
+ });
609
+ put('ring.on', lit ? '1' : '0', value => {
610
+ ringPath.style.opacity = value;
611
+ });
612
+ }
613
+ const arrow = pointing && m.arrow > 0 ? arrowBetween(grow(cardBox, GUIDE_RADIUS + 2), ring, spot.side, viewport) : null;
614
+ const group = arrowRef.current;
615
+ if (arrow && group && shaftRef.current && shaftMaskRef.current && headRef.current) {
616
+ const length = arrow.length + 2;
617
+ const shaft = shaftRef.current;
618
+ const mask = shaftMaskRef.current;
619
+ const head = headRef.current;
620
+ put('arrow.d', arrow.shaft, d => {
621
+ shaft.setAttribute('d', d);
622
+ mask.setAttribute('d', d);
623
+ mask.style.strokeDasharray = `${n2(length)} ${n2(length)}`;
624
+ });
625
+ put('arrow.offset', n2(length * (1 - easeOutCubic(m.arrow))), value => {
626
+ mask.style.strokeDashoffset = value;
627
+ });
628
+ put('arrow.head', arrow.head, d => head.setAttribute('d', d));
629
+ put('arrow.headIn', n2(clamp((m.arrow - 0.8) / 0.2, 0, 1)), value => {
630
+ head.style.opacity = value;
631
+ });
632
+ put('arrow.on', '1', value => {
633
+ group.style.opacity = value;
634
+ });
635
+ } else if (group) {
636
+ put('arrow.on', '0', value => {
637
+ group.style.opacity = value;
638
+ });
639
+ }
640
+ // As the drawing lands the box pings: an echo that grows out and fades. On the finale,
641
+ // the composer also throws a little confetti.
642
+ const landed = pointing ? m.arrow >= 0.9 : m.ring >= 0.9;
643
+ if (lit && landed && m.ping < 0) {
644
+ m.ping = still ? 1 : 0;
645
+ if (current?.finale && !m.burst && !still) {
646
+ m.burst = true;
647
+ fireBurst({
648
+ x: ring.x + ring.w / 2,
649
+ y: ring.y
650
+ });
651
+ }
652
+ }
653
+ const ping = pingRef.current;
654
+ if (ping) {
655
+ if (lit && m.ping >= 0 && m.ping < 1) {
656
+ m.ping = Math.min(1, m.ping + dt / PING_S);
657
+ const spread = 16 * easeOutCubic(m.ping);
658
+ const echo = grow(ring, spread);
659
+ const r = n2(fitRadius(radius + RING_OFFSET + spread, echo));
660
+ put('ping', `${n2(echo.x)},${n2(echo.y)},${n2(echo.w)},${n2(echo.h)},${r}`, () => {
661
+ ping.setAttribute('x', n2(echo.x));
662
+ ping.setAttribute('y', n2(echo.y));
663
+ ping.setAttribute('width', n2(echo.w));
664
+ ping.setAttribute('height', n2(echo.h));
665
+ ping.setAttribute('rx', r);
666
+ ping.setAttribute('ry', r);
667
+ });
668
+ put('ping.opacity', n2(0.55 * (1 - m.ping) ** 2), value => {
669
+ ping.style.opacity = value;
670
+ });
671
+ } else {
672
+ put('ping.opacity', '0', value => {
673
+ ping.style.opacity = value;
674
+ });
675
+ }
676
+ }
677
+ };
678
+ raf = window.requestAnimationFrame(frame);
679
+ return () => window.cancelAnimationFrame(raf);
680
+ }, []);
681
+ // A press on the frost says "use the bubble": it gives a small bounce and takes focus.
682
+ const nudge = () => {
683
+ primaryRef.current?.focus({
684
+ preventScroll: true
685
+ });
686
+ if (reduced) return;
687
+ innerRef.current?.animate?.([{
688
+ transform: 'none'
689
+ }, {
690
+ transform: 'scale(1.03)'
691
+ }, {
692
+ transform: 'none'
693
+ }], {
694
+ duration: 300,
695
+ easing: 'cubic-bezier(.34,1.56,.64,1)'
696
+ });
697
+ };
698
+ const announcement = step ? `Step ${index + 1} of ${plan.length}: ${step.title}` : '';
699
+ const count = value => String(value).padStart(2, '0');
700
+ return jsxs("div", {
701
+ ref: rootRef,
702
+ className: "cbt",
703
+ role: "dialog",
704
+ "aria-modal": "true",
705
+ "aria-labelledby": titleId,
706
+ "data-exiting": exiting ? '' : undefined,
707
+ onPointerDown: event => {
708
+ if (cardRef.current?.contains(event.target)) return;
709
+ event.preventDefault();
710
+ nudge();
711
+ },
712
+ children: [jsx("style", {
713
+ children: CHAT_TOUR_CSS
714
+ }), jsx("div", {
715
+ ref: veilRef,
716
+ className: "cbt-veil"
717
+ }), jsxs("svg", {
718
+ className: "cbt-svg",
719
+ "aria-hidden": true,
720
+ focusable: "false",
721
+ children: [jsxs("defs", {
722
+ children: [jsx("mask", {
723
+ id: ringMaskId,
724
+ maskUnits: "userSpaceOnUse",
725
+ x: "0",
726
+ y: "0",
727
+ width: "100%",
728
+ height: "100%",
729
+ children: jsx("path", {
730
+ ref: ringMaskRef,
731
+ className: "cbt-ring-mask",
732
+ pathLength: 1,
733
+ style: {
734
+ strokeDasharray: '1 1',
735
+ strokeDashoffset: 1
736
+ }
737
+ })
738
+ }), jsx("mask", {
739
+ id: arrowMaskId,
740
+ maskUnits: "userSpaceOnUse",
741
+ x: "0",
742
+ y: "0",
743
+ width: "100%",
744
+ height: "100%",
745
+ children: jsx("path", {
746
+ ref: shaftMaskRef,
747
+ className: "cbt-arrow-mask"
748
+ })
749
+ })]
750
+ }), jsx("rect", {
751
+ ref: pingRef,
752
+ className: "cbt-ping",
753
+ style: {
754
+ opacity: 0
755
+ }
756
+ }), jsx("path", {
757
+ ref: ringRef,
758
+ className: "cbt-ring",
759
+ mask: `url(#${ringMaskId})`,
760
+ style: {
761
+ opacity: 0
762
+ }
763
+ }), jsxs("g", {
764
+ ref: arrowRef,
765
+ style: {
766
+ opacity: 0
767
+ },
768
+ children: [jsx("path", {
769
+ ref: shaftRef,
770
+ className: "cbt-arrow",
771
+ mask: `url(#${arrowMaskId})`
772
+ }), jsx("path", {
773
+ ref: headRef,
774
+ className: "cbt-head",
775
+ style: {
776
+ opacity: 0
777
+ }
778
+ })]
779
+ })]
780
+ }), stage.kind === 'welcome' && jsxs("div", {
781
+ ref: decoRef,
782
+ className: "cbt-deco",
783
+ "aria-hidden": true,
784
+ children: [WELCOME_FLOATS.map(({
785
+ Icon,
786
+ text,
787
+ style,
788
+ delay
789
+ }) => jsxs("span", {
790
+ className: "cbt-float",
791
+ style: {
792
+ ...style,
793
+ ...{
794
+ '--d': `${delay}s`
795
+ }
796
+ },
797
+ children: [jsx("i", {
798
+ children: jsx(Icon, {
799
+ strokeWidth: 2.6
800
+ })
801
+ }), text]
802
+ }, text)), jsxs("div", {
803
+ className: "cbt-sticker",
804
+ children: [jsx("b", {
805
+ children: "HELLO"
806
+ }), jsx("small", {
807
+ children: "my name is"
808
+ }), jsx("em", {
809
+ children: "Lucy"
810
+ })]
811
+ })]
812
+ }), jsx("div", {
813
+ ref: cardRef,
814
+ className: "cbt-card",
815
+ "data-kind": stage.kind === 'welcome' ? 'welcome' : 'bubble',
816
+ style: {
817
+ transform: 'translate3d(-200vw, 0, 0)'
818
+ },
819
+ children: jsx("div", {
820
+ ref: innerRef,
821
+ className: "cbt-inner",
822
+ children: stage.kind === 'welcome' ? jsxs(Fragment, {
823
+ children: [jsxs("div", {
824
+ className: "cbt-titlebar",
825
+ "aria-hidden": true,
826
+ children: [jsxs("span", {
827
+ className: "cbt-lights",
828
+ children: [jsx("i", {}), jsx("i", {}), jsx("i", {})]
829
+ }), jsx("span", {
830
+ className: "cbt-wintitle",
831
+ children: "Clockbook"
832
+ })]
833
+ }), jsxs("div", {
834
+ className: "cbt-hello cbt-rise",
835
+ children: [jsx("div", {
836
+ className: "cbt-buddy-room"
837
+ }), jsxs("h2", {
838
+ id: titleId,
839
+ className: "cbt-hello-title",
840
+ children: [firstName ? `Hi ${firstName}, I’m ` : 'Hi, I’m ', jsx("em", {
841
+ children: "Lucy."
842
+ })]
843
+ }), jsx("p", {
844
+ className: "cbt-hello-sub",
845
+ children: "Your assistant for life admin."
846
+ }), jsx("p", {
847
+ className: "cbt-hello-lede",
848
+ children: "The calls, the bills, the cancellations and the appointments. Tell me what\u2019s on your plate, and I\u2019ll do the steps."
849
+ }), jsx("div", {
850
+ className: "cbt-tiles",
851
+ children: WELCOME_TILES.map(({
852
+ Icon,
853
+ title,
854
+ text
855
+ }) => jsxs("div", {
856
+ className: "cbt-tile",
857
+ children: [jsx("span", {
858
+ className: "cbt-tile-icon",
859
+ children: jsx(Icon, {
860
+ "aria-hidden": true
861
+ })
862
+ }), jsx("b", {
863
+ className: "cbt-tile-title",
864
+ children: title
865
+ }), jsx("span", {
866
+ className: "cbt-tile-text",
867
+ children: text
868
+ })]
869
+ }, title))
870
+ }), jsxs("div", {
871
+ className: "cbt-cta",
872
+ children: [jsxs("button", {
873
+ ref: primaryRef,
874
+ type: "button",
875
+ "data-track": "tour_start",
876
+ onClick: () => move(1),
877
+ className: "cbt-btn cbt-btn-lg",
878
+ children: [jsx("span", {
879
+ children: "Show me around"
880
+ }), jsx(ArrowRight, {
881
+ "aria-hidden": true
882
+ })]
883
+ }), jsx("button", {
884
+ type: "button",
885
+ "data-track": "tour_skip",
886
+ onClick: () => exit('skipped'),
887
+ className: "cbt-btn cbt-btn-line cbt-btn-lg",
888
+ children: jsx("span", {
889
+ children: "Skip"
890
+ })
891
+ })]
892
+ }), jsxs("p", {
893
+ className: "cbt-mono",
894
+ children: [jsxs("span", {
895
+ className: "cbt-mono-keys",
896
+ children: ["Takes about a minute \u00B7 ", jsx("kbd", {
897
+ className: "cbt-kbd",
898
+ children: "\u2190"
899
+ }), jsx("kbd", {
900
+ className: "cbt-kbd",
901
+ children: "\u2192"
902
+ }), " to move \u00B7 ", jsx("kbd", {
903
+ className: "cbt-kbd",
904
+ children: "esc"
905
+ }), " to skip"]
906
+ }), jsx("span", {
907
+ className: "cbt-mono-touch",
908
+ children: "Takes about a minute. Replay it from the ? at the top."
909
+ })]
910
+ })]
911
+ }, "welcome")]
912
+ }) : step && jsxs(Fragment, {
913
+ children: [jsxs("div", {
914
+ className: "cbt-rise",
915
+ children: [jsxs("div", {
916
+ className: "cbt-bhead",
917
+ children: [jsxs("span", {
918
+ className: "cbt-count",
919
+ children: [count(index + 1), "/", count(plan.length)]
920
+ }), jsx("button", {
921
+ type: "button",
922
+ "data-track": "tour_skip",
923
+ onClick: () => exit('skipped'),
924
+ "aria-label": "Skip the tour",
925
+ title: "Skip the tour",
926
+ className: "cbt-x",
927
+ children: jsx(X, {
928
+ size: 16,
929
+ "aria-hidden": true
930
+ })
931
+ })]
932
+ }), jsx("h2", {
933
+ id: titleId,
934
+ className: "cbt-title",
935
+ children: step.title
936
+ }), jsx("p", {
937
+ className: "cbt-body",
938
+ children: step.body
939
+ }), step.demo && jsx(TourDemo, {
940
+ id: step.demo
941
+ }), step.finale && jsx("div", {
942
+ className: "cbt-says",
943
+ children: TOUR_TRIES.map(({
944
+ label,
945
+ prompt
946
+ }) => jsxs("button", {
947
+ type: "button",
948
+ "data-track": "tour_try",
949
+ "data-track-item": label,
950
+ onClick: () => exit('finished', () => onTryPrompt?.(prompt)),
951
+ className: "cbt-say",
952
+ children: [jsx("span", {
953
+ children: label
954
+ }), jsx(ArrowRight, {
955
+ "aria-hidden": true
956
+ })]
957
+ }, label))
958
+ })]
959
+ }, step.id), jsxs("div", {
960
+ className: "cbt-foot",
961
+ children: [jsxs("button", {
962
+ type: "button",
963
+ "data-track": "tour_back",
964
+ onClick: () => move(-1),
965
+ className: "cbt-btn cbt-btn-line",
966
+ children: [jsx(ArrowLeft, {
967
+ "aria-hidden": true
968
+ }), jsx("span", {
969
+ children: "Back"
970
+ })]
971
+ }), jsx("span", {
972
+ className: "cbt-spacer"
973
+ }), jsxs("button", {
974
+ ref: primaryRef,
975
+ type: "button",
976
+ "data-track": step.finale ? 'tour_done' : 'tour_next',
977
+ onClick: () => step.finale ? exit('finished') : move(1),
978
+ className: "cbt-btn",
979
+ children: [jsx("span", {
980
+ children: step.finale ? 'Done' : 'Next'
981
+ }), !step.finale && jsx(ArrowRight, {
982
+ "aria-hidden": true
983
+ })]
984
+ })]
985
+ })]
986
+ })
987
+ })
988
+ }), jsx("div", {
989
+ ref: guideRef,
990
+ className: "cbt-buddy",
991
+ "aria-hidden": true,
992
+ children: jsx("span", {
993
+ children: jsx(Mark, {
994
+ size: 30
995
+ })
996
+ })
997
+ }), burst && jsx(Burst, {
998
+ x: burst.x,
999
+ y: burst.y
1000
+ }), jsx("p", {
1001
+ className: "cbt-sr",
1002
+ "aria-live": "polite",
1003
+ children: announcement
1004
+ })]
1005
+ });
1006
+ }export{TourOverlay as default};//# sourceMappingURL=TourOverlay.js.map