nucleus-core-ts 0.10.237 → 0.10.239

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 (108) hide show
  1. package/dist/.build-ok +1 -1
  2. package/dist/fe/components/Replay/_components/ReplayCaption/index.d.ts +3 -0
  3. package/dist/fe/components/Replay/_components/ReplayCaption/index.js +53 -0
  4. package/dist/fe/components/Replay/_components/ReplayCaption/types.d.ts +12 -0
  5. package/dist/fe/components/Replay/_components/ReplayCaption/types.js +1 -0
  6. package/dist/fe/components/Replay/_components/ReplayChapters/index.d.ts +3 -0
  7. package/dist/fe/components/Replay/_components/ReplayChapters/index.js +56 -0
  8. package/dist/fe/components/Replay/_components/ReplayChapters/types.d.ts +8 -0
  9. package/dist/fe/components/Replay/_components/ReplayChapters/types.js +1 -0
  10. package/dist/fe/components/Replay/_components/ReplayControls/index.d.ts +3 -0
  11. package/dist/fe/components/Replay/_components/ReplayControls/index.js +88 -0
  12. package/dist/fe/components/Replay/_components/ReplayControls/types.d.ts +15 -0
  13. package/dist/fe/components/Replay/_components/ReplayControls/types.js +1 -0
  14. package/dist/fe/components/Replay/_components/ReplayCursor/index.d.ts +6 -0
  15. package/dist/fe/components/Replay/_components/ReplayCursor/index.js +91 -0
  16. package/dist/fe/components/Replay/_components/ReplayCursor/types.d.ts +11 -0
  17. package/dist/fe/components/Replay/_components/ReplayCursor/types.js +1 -0
  18. package/dist/fe/components/Replay/_components/ReplayEnded/index.d.ts +9 -0
  19. package/dist/fe/components/Replay/_components/ReplayEnded/index.js +36 -0
  20. package/dist/fe/components/Replay/_components/ReplayFailure/index.d.ts +3 -0
  21. package/dist/fe/components/Replay/_components/ReplayFailure/index.js +32 -0
  22. package/dist/fe/components/Replay/_components/ReplayFailure/types.d.ts +6 -0
  23. package/dist/fe/components/Replay/_components/ReplayFailure/types.js +1 -0
  24. package/dist/fe/components/Replay/_components/ReplayPlayer/ReplayView.d.ts +10 -0
  25. package/dist/fe/components/Replay/_components/ReplayPlayer/ReplayView.js +100 -0
  26. package/dist/fe/components/Replay/_components/ReplayPlayer/index.d.ts +6 -0
  27. package/dist/fe/components/Replay/_components/ReplayPlayer/index.js +28 -0
  28. package/dist/fe/components/Replay/_components/ReplayPlayer/types.d.ts +9 -0
  29. package/dist/fe/components/Replay/_components/ReplayPlayer/types.js +1 -0
  30. package/dist/fe/components/Replay/_components/ReplaySkeleton/index.d.ts +4 -0
  31. package/dist/fe/components/Replay/_components/ReplaySkeleton/index.js +148 -0
  32. package/dist/fe/components/Replay/_components/ReplayStage/ReplayVeil.d.ts +2 -0
  33. package/dist/fe/components/Replay/_components/ReplayStage/ReplayVeil.js +34 -0
  34. package/dist/fe/components/Replay/_components/ReplayStage/index.d.ts +6 -0
  35. package/dist/fe/components/Replay/_components/ReplayStage/index.js +76 -0
  36. package/dist/fe/components/Replay/_components/ReplayStage/types.d.ts +18 -0
  37. package/dist/fe/components/Replay/_components/ReplayStage/types.js +1 -0
  38. package/dist/fe/components/Replay/_components/index.d.ts +11 -0
  39. package/dist/fe/components/Replay/_components/index.js +10 -0
  40. package/dist/fe/components/Replay/_hooks/index.d.ts +3 -0
  41. package/dist/fe/components/Replay/_hooks/index.js +3 -0
  42. package/dist/fe/components/Replay/_hooks/useReplayPlayer.d.ts +6 -0
  43. package/dist/fe/components/Replay/_hooks/useReplayPlayer.js +63 -0
  44. package/dist/fe/components/Replay/_hooks/useShimmer.d.ts +3 -0
  45. package/dist/fe/components/Replay/_hooks/useShimmer.js +31 -0
  46. package/dist/fe/components/Replay/_hooks/useStageScale.d.ts +5 -0
  47. package/dist/fe/components/Replay/_hooks/useStageScale.js +24 -0
  48. package/dist/fe/components/Replay/_store/index.d.ts +1 -0
  49. package/dist/fe/components/Replay/_store/index.js +1 -0
  50. package/dist/fe/components/Replay/_store/replayStore.d.ts +13 -0
  51. package/dist/fe/components/Replay/_store/replayStore.js +74 -0
  52. package/dist/fe/components/Replay/_types/index.d.ts +1 -0
  53. package/dist/fe/components/Replay/_types/index.js +1 -0
  54. package/dist/fe/components/Replay/_types/player.d.ts +105 -0
  55. package/dist/fe/components/Replay/_types/player.js +1 -0
  56. package/dist/fe/components/Replay/_utils/controller.d.ts +10 -0
  57. package/dist/fe/components/Replay/_utils/controller.js +208 -0
  58. package/dist/fe/components/Replay/_utils/controllerReports.d.ts +18 -0
  59. package/dist/fe/components/Replay/_utils/controllerReports.js +70 -0
  60. package/dist/fe/components/Replay/_utils/copy.d.ts +29 -0
  61. package/dist/fe/components/Replay/_utils/copy.js +75 -0
  62. package/dist/fe/components/Replay/_utils/cursorMotion.d.ts +38 -0
  63. package/dist/fe/components/Replay/_utils/cursorMotion.js +98 -0
  64. package/dist/fe/components/Replay/_utils/frameBridge.d.ts +40 -0
  65. package/dist/fe/components/Replay/_utils/frameBridge.js +167 -0
  66. package/dist/fe/components/Replay/_utils/framePoints.d.ts +17 -0
  67. package/dist/fe/components/Replay/_utils/framePoints.js +24 -0
  68. package/dist/fe/components/Replay/_utils/frameUrl.d.ts +21 -0
  69. package/dist/fe/components/Replay/_utils/frameUrl.js +23 -0
  70. package/dist/fe/components/Replay/_utils/index.d.ts +7 -0
  71. package/dist/fe/components/Replay/_utils/index.js +7 -0
  72. package/dist/fe/components/Replay/_utils/replayCss.d.ts +2 -0
  73. package/dist/fe/components/Replay/_utils/replayCss.js +4 -0
  74. package/dist/fe/components/Replay/_utils/replayLayout.d.ts +2 -0
  75. package/dist/fe/components/Replay/_utils/replayLayout.js +20 -0
  76. package/dist/fe/components/Replay/_utils/replayPalette.d.ts +1 -0
  77. package/dist/fe/components/Replay/_utils/replayPalette.js +8 -0
  78. package/dist/fe/components/Replay/_utils/replayParts.d.ts +1 -0
  79. package/dist/fe/components/Replay/_utils/replayParts.js +56 -0
  80. package/dist/fe/components/Replay/_utils/replayProgress.d.ts +14 -0
  81. package/dist/fe/components/Replay/_utils/replayProgress.js +39 -0
  82. package/dist/fe/components/Replay/index.d.ts +5 -0
  83. package/dist/fe/components/Replay/index.js +5 -0
  84. package/dist/src/Client/Replay/index.d.ts +1 -0
  85. package/dist/src/Client/Replay/index.js +1 -0
  86. package/dist/src/Client/Replay/recorder/anchors.d.ts +18 -0
  87. package/dist/src/Client/Replay/recorder/anchors.js +39 -0
  88. package/dist/src/Client/Replay/recorder/bundle.d.ts +60 -0
  89. package/dist/src/Client/Replay/recorder/bundle.js +103 -0
  90. package/dist/src/Client/Replay/recorder/clock.d.ts +13 -0
  91. package/dist/src/Client/Replay/recorder/clock.js +9 -0
  92. package/dist/src/Client/Replay/recorder/factoryTap.d.ts +22 -0
  93. package/dist/src/Client/Replay/recorder/factoryTap.js +24 -0
  94. package/dist/src/Client/Replay/recorder/fetchTee.d.ts +37 -0
  95. package/dist/src/Client/Replay/recorder/fetchTee.js +121 -0
  96. package/dist/src/Client/Replay/recorder/index.d.ts +9 -0
  97. package/dist/src/Client/Replay/recorder/index.js +9 -0
  98. package/dist/src/Client/Replay/recorder/privacy.d.ts +27 -0
  99. package/dist/src/Client/Replay/recorder/privacy.js +115 -0
  100. package/dist/src/Client/Replay/recorder/redact.d.ts +8 -0
  101. package/dist/src/Client/Replay/recorder/redact.js +100 -0
  102. package/dist/src/Client/Replay/recorder/socketTap.d.ts +21 -0
  103. package/dist/src/Client/Replay/recorder/socketTap.js +43 -0
  104. package/dist/src/Client/Replay/recorder/sse.d.ts +15 -0
  105. package/dist/src/Client/Replay/recorder/sse.js +56 -0
  106. package/dist/src/Client/Replay/recorder/steps.d.ts +27 -0
  107. package/dist/src/Client/Replay/recorder/steps.js +152 -0
  108. package/package.json +5 -1
@@ -0,0 +1,105 @@
1
+ import type { RefObject } from 'react';
2
+ import type { FailureReason, Localized, Ms, PointBox, ReplayManifest } from '../../../../src/Client/Replay';
3
+ export type ReplayStatus = 'loading' | 'ready' | 'playing' | 'paused' | 'ended' | 'failed';
4
+ /** Why playback stopped: a driver failure, or one of the player's own load and handshake failures. */
5
+ export type ReplayFailureReason = FailureReason | 'manifest_unreachable' | 'manifest_invalid' | 'frame_timeout';
6
+ export interface ReplayFailure {
7
+ reason: ReplayFailureReason;
8
+ stepId: string | null;
9
+ actionIndex: number | null;
10
+ /** Validation issues or the HTTP status; for logs, never for display. */
11
+ detail: string | null;
12
+ }
13
+ /** The box the frame reported for the current pointer action; `arrived` flips once the drawn cursor got there. */
14
+ export interface ReplayCursor {
15
+ stepId: string;
16
+ mark: number;
17
+ box: PointBox;
18
+ arrived: boolean;
19
+ }
20
+ export type ReplayPlayerState = {
21
+ status: ReplayStatus;
22
+ manifest: ReplayManifest | null;
23
+ chapterId: string | null;
24
+ stepId: string | null;
25
+ /** Caption of the current step in every language it has; pick one with `pickLocalized`. */
26
+ caption: Localized | null;
27
+ playhead: Ms;
28
+ rate: number;
29
+ locale: string;
30
+ cursor: ReplayCursor | null;
31
+ /** Endpoint keys the recording could not answer, each once: the audit wants none. */
32
+ unanswered: string[];
33
+ failure: ReplayFailure | null;
34
+ };
35
+ export type ReplayPlayerMethods = {
36
+ reset: () => void;
37
+ setManifest: (manifest: ReplayManifest) => void;
38
+ setStatus: (status: ReplayStatus) => void;
39
+ setChapter: (chapterId: string | null) => void;
40
+ startStep: (stepId: string, caption: Localized) => void;
41
+ clearStep: () => void;
42
+ setPlayhead: (playhead: Ms) => void;
43
+ setRate: (rate: number) => void;
44
+ setLocale: (locale: string) => void;
45
+ setCursor: (cursor: ReplayCursor | null) => void;
46
+ reportUnanswered: (key: string) => void;
47
+ fail: (failure: ReplayFailure) => void;
48
+ clearFailure: () => void;
49
+ };
50
+ /** What the controller reads and writes; the h-state store satisfies it, and so can a plain object in a test. */
51
+ export type ReplayStoreApi = ReplayPlayerState & ReplayPlayerMethods;
52
+ /** The window the player talks to: the iframe's `contentWindow`. */
53
+ export interface ReplayFrameTarget {
54
+ postMessage: (message: object, targetOrigin: string) => void;
55
+ }
56
+ /** The window the player listens on: the page's own `window`. */
57
+ export interface ReplayListenTarget {
58
+ addEventListener: (type: 'message', listener: (event: MessageEvent) => void) => void;
59
+ removeEventListener: (type: 'message', listener: (event: MessageEvent) => void) => void;
60
+ }
61
+ export interface ReplayControllerOptions {
62
+ /** Read on every use so a re-created iframe is followed; null until the iframe exists. */
63
+ frameWindow: () => ReplayFrameTarget | null;
64
+ /** The page's origin; the frame is same-origin, anything else is ignored. */
65
+ origin: string;
66
+ /** The recording folder's `manifest.json` URL. */
67
+ manifestUrl: string;
68
+ /** The session nonce; the same value is in the frame's URL (`replayFrameUrl`). */
69
+ nonce: string;
70
+ store: ReplayStoreApi;
71
+ /** Real-time timers (hello retries, handshake timeout); tests pass a fake. */
72
+ clock?: {
73
+ setTimeout: (run: () => void, ms: number) => number;
74
+ clearTimeout: (id: number) => void;
75
+ };
76
+ fetch?: (url: string) => Promise<Response>;
77
+ listenWindow?: ReplayListenTarget;
78
+ /** Real ms to wait for the frame's `ready` before failing; default 20000. */
79
+ readyTimeoutMs?: number;
80
+ }
81
+ export interface ReplayController {
82
+ play: () => void;
83
+ pause: () => void;
84
+ setRate: (rate: number) => void;
85
+ /** Chapter starts are the only seek points; an unknown id is ignored. */
86
+ seekChapter: (chapterId: string) => void;
87
+ setLocale: (locale: string) => void;
88
+ /** The drawn cursor reached the reported box: lets the frame's driver act. */
89
+ cursorArrived: (mark: number) => void;
90
+ dispose: () => void;
91
+ }
92
+ export interface ReplayPlayerOptions {
93
+ /** The recording folder's `manifest.json` URL. */
94
+ manifestUrl: string;
95
+ locale?: string;
96
+ /** Start playing as soon as the frame is ready. */
97
+ autoplay?: boolean;
98
+ }
99
+ /** What `useReplayPlayer` hands to the stage and controls: render the iframe from `frameRef` + `frameSrc`, read `state`. */
100
+ export interface ReplayPlayer extends Omit<ReplayController, 'dispose'> {
101
+ frameRef: RefObject<HTMLIFrameElement | null>;
102
+ /** The iframe URL; null until the manifest is loaded. */
103
+ frameSrc: string | null;
104
+ state: ReplayPlayerState;
105
+ }
@@ -0,0 +1 @@
1
+ /** What `useReplayPlayer` hands to the stage and controls: render the iframe from `frameRef` + `frameSrc`, read `state`. */ export { };
@@ -0,0 +1,10 @@
1
+ import { createNonce } from '../../../../src/Client/Replay';
2
+ import type { ReplayController, ReplayControllerOptions } from '../_types';
3
+ /** A fresh session nonce for a player; the frame's URL carries the same value. */
4
+ export declare const createReplayNonce: typeof createNonce;
5
+ /**
6
+ * The parent side of a replay. Loads and validates the manifest, performs the handshake with the frame, forwards
7
+ * play, pause, rate and chapter seeks, and mirrors what the frame reports (steps, cursor box, playhead, failures)
8
+ * into the store. The frame owns the timeline and runs the steps (`startReplayFrame`); nothing here reaches the product.
9
+ */
10
+ export declare function createReplayController(options: ReplayControllerOptions): ReplayController;
@@ -0,0 +1,208 @@
1
+ import { createNonce, envelopeFor, parseManifest, readFrameMessage, sendMessage } from '../../../../src/Client/Replay';
2
+ import { createReportHandler, enterChapter } from './controllerReports';
3
+ const HELLO_INTERVAL_MS = 500;
4
+ const READY_TIMEOUT_MS = 20000;
5
+ const MAX_RATE = 64;
6
+ const realClock = {
7
+ setTimeout: (run, ms)=>Number(setTimeout(run, ms)),
8
+ clearTimeout: (id)=>clearTimeout(id)
9
+ };
10
+ /** A fresh session nonce for a player; the frame's URL carries the same value. */ export const createReplayNonce = createNonce;
11
+ /**
12
+ * The parent side of a replay. Loads and validates the manifest, performs the handshake with the frame, forwards
13
+ * play, pause, rate and chapter seeks, and mirrors what the frame reports (steps, cursor box, playhead, failures)
14
+ * into the store. The frame owns the timeline and runs the steps (`startReplayFrame`); nothing here reaches the product.
15
+ */ export function createReplayController(options) {
16
+ const { store, origin, nonce } = options;
17
+ const clock = options.clock ?? realClock;
18
+ const listen = options.listenWindow ?? window;
19
+ const load = options.fetch ?? ((url)=>fetch(url));
20
+ const wants = {
21
+ playing: false,
22
+ rate: null,
23
+ seekAt: null
24
+ };
25
+ const timers = new Set();
26
+ let ready = false;
27
+ let disposed = false;
28
+ const after = (ms, run)=>{
29
+ const id = clock.setTimeout(()=>{
30
+ timers.delete(id);
31
+ run();
32
+ }, ms);
33
+ timers.add(id);
34
+ return id;
35
+ };
36
+ const cancel = (id)=>{
37
+ clock.clearTimeout(id);
38
+ timers.delete(id);
39
+ };
40
+ const send = (build)=>{
41
+ const frame = options.frameWindow();
42
+ if (frame) sendMessage(frame, origin, build(envelopeFor(nonce)));
43
+ };
44
+ const failWith = (reason, detail)=>{
45
+ store.fail({
46
+ reason,
47
+ detail,
48
+ stepId: null,
49
+ actionIndex: null
50
+ });
51
+ };
52
+ const flush = ()=>{
53
+ const seekAt = wants.seekAt;
54
+ if (seekAt !== null) send((e)=>({
55
+ ...e,
56
+ type: 'seek',
57
+ at: seekAt
58
+ }));
59
+ wants.seekAt = null;
60
+ const rate = wants.rate;
61
+ if (rate !== null) send((e)=>({
62
+ ...e,
63
+ type: 'rate',
64
+ rate
65
+ }));
66
+ if (wants.playing) send((e)=>({
67
+ ...e,
68
+ type: 'play'
69
+ }));
70
+ };
71
+ const handle = createReportHandler({
72
+ store,
73
+ send,
74
+ isReady: ()=>ready,
75
+ chosenRate: ()=>wants.rate,
76
+ stopPlaying: ()=>{
77
+ wants.playing = false;
78
+ },
79
+ onReady: (recordingId)=>{
80
+ if (recordingId !== store.manifest?.id) return;
81
+ const first = !ready;
82
+ ready = true;
83
+ if (first) store.setStatus(wants.playing ? 'playing' : 'ready');
84
+ else store.clearStep();
85
+ flush();
86
+ }
87
+ });
88
+ const onMessage = (event)=>{
89
+ const own = {
90
+ origin,
91
+ peer: options.frameWindow(),
92
+ nonce
93
+ };
94
+ const message = readFrameMessage({
95
+ origin: event.origin,
96
+ source: event.source,
97
+ data: event.data
98
+ }, own);
99
+ if (message && !disposed) handle(message);
100
+ };
101
+ listen.addEventListener('message', onMessage);
102
+ const awaitFrame = ()=>{
103
+ const giveUp = after(options.readyTimeoutMs ?? READY_TIMEOUT_MS, ()=>{
104
+ if (!ready) failWith('frame_timeout', null);
105
+ });
106
+ const ask = ()=>{
107
+ if (ready || disposed) {
108
+ cancel(giveUp);
109
+ return;
110
+ }
111
+ send((e)=>({
112
+ ...e,
113
+ type: 'hello'
114
+ }));
115
+ after(HELLO_INTERVAL_MS, ask);
116
+ };
117
+ ask();
118
+ };
119
+ const boot = async ()=>{
120
+ const response = await load(options.manifestUrl).catch(()=>null);
121
+ if (disposed) return;
122
+ if (!response?.ok) {
123
+ failWith('manifest_unreachable', response ? String(response.status) : null);
124
+ return;
125
+ }
126
+ const parsed = parseManifest(await response.text());
127
+ if (disposed) return;
128
+ if (!parsed.ok) {
129
+ failWith('manifest_invalid', parsed.errors.join('; '));
130
+ return;
131
+ }
132
+ store.setManifest(parsed.value);
133
+ awaitFrame();
134
+ };
135
+ void boot();
136
+ const seekChapter = (chapterId)=>{
137
+ const chapter = store.manifest?.chapters.find((item)=>item.id === chapterId);
138
+ if (!chapter) return;
139
+ store.clearFailure();
140
+ store.clearStep();
141
+ store.setPlayhead(chapter.from);
142
+ enterChapter(store, chapter, wants.rate);
143
+ if (!ready) {
144
+ wants.seekAt = chapter.from;
145
+ return;
146
+ }
147
+ send((e)=>({
148
+ ...e,
149
+ type: 'seek',
150
+ at: chapter.from
151
+ }));
152
+ if (store.status === 'ended' || store.status === 'failed') store.setStatus('paused');
153
+ };
154
+ return {
155
+ play () {
156
+ const first = store.manifest?.chapters[0];
157
+ if (store.status === 'ended' && first) seekChapter(first.id);
158
+ else if (store.status === 'failed') seekChapter(store.chapterId ?? first?.id ?? '');
159
+ wants.playing = true;
160
+ if (!ready) return;
161
+ send((e)=>({
162
+ ...e,
163
+ type: 'play'
164
+ }));
165
+ store.setStatus('playing');
166
+ },
167
+ pause () {
168
+ wants.playing = false;
169
+ send((e)=>({
170
+ ...e,
171
+ type: 'pause'
172
+ }));
173
+ if (store.status === 'playing') store.setStatus('paused');
174
+ },
175
+ setRate (rate) {
176
+ if (!Number.isFinite(rate) || rate <= 0 || rate > MAX_RATE) return;
177
+ wants.rate = rate;
178
+ store.setRate(rate);
179
+ if (ready) send((e)=>({
180
+ ...e,
181
+ type: 'rate',
182
+ rate
183
+ }));
184
+ },
185
+ seekChapter,
186
+ setLocale: (locale)=>store.setLocale(locale),
187
+ cursorArrived (mark) {
188
+ const cursor = store.cursor;
189
+ if (!cursor || cursor.mark !== mark) return;
190
+ store.setCursor({
191
+ ...cursor,
192
+ arrived: true
193
+ });
194
+ send((e)=>({
195
+ ...e,
196
+ type: 'cursor-arrived',
197
+ mark
198
+ }));
199
+ },
200
+ dispose () {
201
+ disposed = true;
202
+ listen.removeEventListener('message', onMessage);
203
+ for (const id of [
204
+ ...timers
205
+ ])cancel(id);
206
+ }
207
+ };
208
+ }
@@ -0,0 +1,18 @@
1
+ import type { envelopeFor, FrameMessage, ParentMessage, ReplayChapter } from '../../../../src/Client/Replay';
2
+ import type { ReplayStoreApi } from '../_types';
3
+ export type SendToFrame = (build: (envelope: ReturnType<typeof envelopeFor>) => ParentMessage) => void;
4
+ export interface ReportDeps {
5
+ store: ReplayStoreApi;
6
+ send: SendToFrame;
7
+ /** The frame announced itself for this recording. */
8
+ onReady: (recordingId: string) => void;
9
+ isReady: () => boolean;
10
+ /** The visitor's intent to play ends with the run (failure, end). */
11
+ stopPlaying: () => void;
12
+ /** The rate the visitor chose, or null while the chapter's own rate shows. */
13
+ chosenRate: () => number | null;
14
+ }
15
+ /** Mirrors the chapter into the store; the chapter's rate shows unless the visitor chose one. */
16
+ export declare function enterChapter(store: ReplayStoreApi, chapter: ReplayChapter | null, chosenRate: number | null): void;
17
+ /** The reducer from what the frame reports to what the store shows. */
18
+ export declare function createReportHandler(deps: ReportDeps): (message: FrameMessage) => void;
@@ -0,0 +1,70 @@
1
+ function chapterAt(manifest, at) {
2
+ return manifest.chapters.filter((chapter)=>chapter.from <= at).pop() ?? null;
3
+ }
4
+ /** Mirrors the chapter into the store; the chapter's rate shows unless the visitor chose one. */ export function enterChapter(store, chapter, chosenRate) {
5
+ if (!chapter || chapter.id === store.chapterId) return;
6
+ store.setChapter(chapter.id);
7
+ if (chosenRate === null) store.setRate(chapter.rate);
8
+ }
9
+ /** The reducer from what the frame reports to what the store shows. */ export function createReportHandler(deps) {
10
+ const { store, send } = deps;
11
+ const onTick = (manifest, at, playing)=>{
12
+ store.setPlayhead(at);
13
+ enterChapter(store, chapterAt(manifest, at), deps.chosenRate());
14
+ if (store.status === 'failed') return;
15
+ if (at >= manifest.clock.durationMs && !playing) {
16
+ deps.stopPlaying();
17
+ store.setStatus('ended');
18
+ } else if (playing) store.setStatus('playing');
19
+ else if (store.status === 'playing') store.setStatus('paused');
20
+ };
21
+ const onStepStarted = (manifest, stepId)=>{
22
+ const step = manifest.steps.find((item)=>item.id === stepId);
23
+ if (!step) return;
24
+ store.startStep(step.id, step.caption);
25
+ enterChapter(store, manifest.chapters.find((item)=>item.id === step.chapter) ?? null, deps.chosenRate());
26
+ };
27
+ return (message)=>{
28
+ const manifest = store.manifest;
29
+ if (message.type === 'ready') {
30
+ deps.onReady(message.recordingId);
31
+ return;
32
+ }
33
+ if (!manifest || !deps.isReady()) return;
34
+ switch(message.type){
35
+ case 'step-started':
36
+ onStepStarted(manifest, message.stepId);
37
+ break;
38
+ case 'point':
39
+ store.setCursor({
40
+ stepId: message.stepId,
41
+ mark: message.mark,
42
+ box: message.box,
43
+ arrived: false
44
+ });
45
+ break;
46
+ case 'step-done':
47
+ store.setCursor(null);
48
+ break;
49
+ case 'step-failed':
50
+ deps.stopPlaying();
51
+ send((e)=>({
52
+ ...e,
53
+ type: 'pause'
54
+ }));
55
+ store.fail({
56
+ reason: message.reason,
57
+ detail: null,
58
+ stepId: message.stepId,
59
+ actionIndex: message.actionIndex
60
+ });
61
+ break;
62
+ case 'tick':
63
+ onTick(manifest, message.at, message.playing);
64
+ break;
65
+ case 'unanswered':
66
+ store.reportUnanswered(message.key);
67
+ break;
68
+ }
69
+ };
70
+ }
@@ -0,0 +1,29 @@
1
+ import type { ReplayFailureReason } from '../_types';
2
+ export interface FailureCopy {
3
+ /** What is not working. */
4
+ what: string;
5
+ /** What it means for the visitor. */
6
+ means: string;
7
+ /** What has to happen, and by whom. */
8
+ next: string;
9
+ }
10
+ export declare function failureCopy(reason: ReplayFailureReason): FailureCopy;
11
+ export declare const REPLAY_COPY: {
12
+ watchOnly: string;
13
+ loadingFrame: string;
14
+ stepOf: (index: number, count: number) => string;
15
+ play: string;
16
+ pause: string;
17
+ restart: string;
18
+ speed: string;
19
+ language: string;
20
+ chapters: string;
21
+ chapterPace: (label: string) => string;
22
+ retry: string;
23
+ endedTitle: string;
24
+ endedBody: string;
25
+ watchAgain: string;
26
+ idle: string;
27
+ continue: string;
28
+ };
29
+ export declare const RATE_CHOICES: readonly number[];
@@ -0,0 +1,75 @@
1
+ const RETRY_OR_RERECORD = 'Try again from this chapter. If it repeats, the site owner has to record it again.';
2
+ const STOPPED = 'The walkthrough stopped at this step.';
3
+ const FAILURES = {
4
+ manifest_unreachable: {
5
+ what: 'The recording could not be loaded.',
6
+ means: 'There is nothing to play yet.',
7
+ next: 'Check your connection and try again. If it keeps failing, the site owner has to republish the recording.'
8
+ },
9
+ manifest_invalid: {
10
+ what: 'The recording file is not in a format this player understands.',
11
+ means: 'It cannot be played, and trying again will not change that.',
12
+ next: 'The site owner has to record and publish it again.'
13
+ },
14
+ frame_timeout: {
15
+ what: 'The product screen did not start in time.',
16
+ means: 'The recording is loaded, but nothing can be shown yet.',
17
+ next: 'Try again. If it keeps failing, reload the page.'
18
+ },
19
+ target_timeout: {
20
+ what: 'A screen element in this step never appeared.',
21
+ means: STOPPED,
22
+ next: RETRY_OR_RERECORD
23
+ },
24
+ target_unsupported: {
25
+ what: 'This step points at an element the player cannot operate.',
26
+ means: STOPPED,
27
+ next: 'The site owner has to record this step again.'
28
+ },
29
+ option_not_found: {
30
+ what: 'A choice in this step is missing from the screen.',
31
+ means: STOPPED,
32
+ next: RETRY_OR_RERECORD
33
+ },
34
+ navigate_failed: {
35
+ what: 'The product screen could not open the next page.',
36
+ means: STOPPED,
37
+ next: 'Try again. If it keeps failing, reload the page.'
38
+ },
39
+ action_error: {
40
+ what: 'This step failed while it was running.',
41
+ means: STOPPED,
42
+ next: RETRY_OR_RERECORD
43
+ },
44
+ step_unknown: {
45
+ what: 'The recording refers to a step it does not contain.',
46
+ means: 'It cannot be played to the end.',
47
+ next: 'The site owner has to record and publish it again.'
48
+ }
49
+ };
50
+ export function failureCopy(reason) {
51
+ return FAILURES[reason];
52
+ }
53
+ export const REPLAY_COPY = {
54
+ watchOnly: 'Watch only',
55
+ loadingFrame: 'Opening the product',
56
+ stepOf: (index, count)=>`Step ${index} of ${count}`,
57
+ play: 'Play',
58
+ pause: 'Pause',
59
+ restart: 'Restart',
60
+ speed: 'Speed',
61
+ language: 'Language',
62
+ chapters: 'Chapters',
63
+ chapterPace: (label)=>`Chapter pace ${label}`,
64
+ retry: 'Try again',
65
+ endedTitle: 'That is the whole tour.',
66
+ endedBody: 'Watch it again from the start, or carry on.',
67
+ watchAgain: 'Watch again',
68
+ idle: 'Press play to watch the tour.',
69
+ continue: 'Continue'
70
+ };
71
+ export const RATE_CHOICES = [
72
+ 1,
73
+ 2,
74
+ 4
75
+ ];
@@ -0,0 +1,38 @@
1
+ import type { PointBox } from '../../../../src/Client/Replay';
2
+ export interface CursorElements {
3
+ cursor: HTMLElement | SVGElement;
4
+ ring: HTMLElement;
5
+ ripple: HTMLElement;
6
+ }
7
+ export interface CursorTarget {
8
+ /** Centre of the target in stage pixels. */
9
+ x: number;
10
+ y: number;
11
+ /** The target's box in stage pixels, grown a little so the ring sits around it. */
12
+ box: {
13
+ x: number;
14
+ y: number;
15
+ width: number;
16
+ height: number;
17
+ };
18
+ }
19
+ /** The target's box scaled into the stage's pixels, with its centre. */
20
+ export declare function targetIn(box: PointBox, scale: number): CursorTarget;
21
+ /** How long a glide takes: longer for longer trips, shorter at a higher rate. */
22
+ export declare function glideSeconds(distance: number, rate: number): number;
23
+ export interface CursorMove {
24
+ target: CursorTarget;
25
+ /** Where the cursor is now; null on the first move, which starts at the target. */
26
+ from: {
27
+ x: number;
28
+ y: number;
29
+ } | null;
30
+ rate: number;
31
+ reduced: boolean;
32
+ onArrive: () => void;
33
+ }
34
+ /**
35
+ * Moves the drawn cursor and its ring to the target, presses, and calls `onArrive` once it rested there.
36
+ * Reduced motion jumps and calls `onArrive` at once. Returns the timeline so the caller can kill it.
37
+ */
38
+ export declare function moveCursor(els: CursorElements, move: CursorMove): gsap.core.Timeline;
@@ -0,0 +1,98 @@
1
+ import gsap from 'gsap';
2
+ const RING_GROW = 6;
3
+ const GLIDE_MIN = 0.35;
4
+ const GLIDE_MAX = 1.1;
5
+ const REST = 0.18;
6
+ const MIN_RATE = 0.25;
7
+ /** The target's box scaled into the stage's pixels, with its centre. */ export function targetIn(box, scale) {
8
+ const x = box.x * scale;
9
+ const y = box.y * scale;
10
+ const width = box.width * scale;
11
+ const height = box.height * scale;
12
+ return {
13
+ x: x + width / 2,
14
+ y: y + height / 2,
15
+ box: {
16
+ x: x - RING_GROW,
17
+ y: y - RING_GROW,
18
+ width: width + RING_GROW * 2,
19
+ height: height + RING_GROW * 2
20
+ }
21
+ };
22
+ }
23
+ /** How long a glide takes: longer for longer trips, shorter at a higher rate. */ export function glideSeconds(distance, rate) {
24
+ const base = Math.min(GLIDE_MAX, GLIDE_MIN + distance / 1600);
25
+ return base / Math.max(rate, MIN_RATE);
26
+ }
27
+ /**
28
+ * Moves the drawn cursor and its ring to the target, presses, and calls `onArrive` once it rested there.
29
+ * Reduced motion jumps and calls `onArrive` at once. Returns the timeline so the caller can kill it.
30
+ */ export function moveCursor(els, move) {
31
+ const { target, from, rate, reduced } = move;
32
+ const timeline = gsap.timeline({
33
+ defaults: {
34
+ overwrite: 'auto',
35
+ ease: 'power3.inOut'
36
+ }
37
+ });
38
+ if (reduced) {
39
+ gsap.set(els.cursor, {
40
+ x: target.x,
41
+ y: target.y,
42
+ opacity: 1
43
+ });
44
+ gsap.set(els.ring, {
45
+ ...target.box,
46
+ opacity: 1
47
+ });
48
+ move.onArrive();
49
+ return timeline;
50
+ }
51
+ const start = from ?? target;
52
+ if (from === null) {
53
+ gsap.set(els.cursor, {
54
+ x: start.x,
55
+ y: start.y
56
+ });
57
+ gsap.set(els.ring, {
58
+ ...target.box,
59
+ opacity: 0
60
+ });
61
+ }
62
+ const speed = Math.max(rate, MIN_RATE);
63
+ const seconds = glideSeconds(Math.hypot(target.x - start.x, target.y - start.y), rate);
64
+ timeline.to(els.cursor, {
65
+ x: target.x,
66
+ y: target.y,
67
+ opacity: 1,
68
+ duration: seconds
69
+ }, 0);
70
+ timeline.to(els.ring, {
71
+ ...target.box,
72
+ opacity: 1,
73
+ duration: seconds
74
+ }, 0);
75
+ timeline.call(move.onArrive, [], seconds + REST);
76
+ timeline.to(els.cursor, {
77
+ scale: 0.82,
78
+ duration: 0.09 / speed,
79
+ yoyo: true,
80
+ repeat: 1,
81
+ ease: 'power1.inOut',
82
+ transformOrigin: '0 0'
83
+ }, seconds + REST);
84
+ timeline.fromTo(els.ripple, {
85
+ x: target.x,
86
+ y: target.y,
87
+ scale: 0.2,
88
+ opacity: 0.55
89
+ }, {
90
+ x: target.x,
91
+ y: target.y,
92
+ scale: 1,
93
+ opacity: 0,
94
+ duration: 0.6 / speed,
95
+ ease: 'power2.out'
96
+ }, seconds + REST);
97
+ return timeline;
98
+ }