saccade 0.0.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/README.md +135 -0
- package/dist/core.cjs +1736 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +276 -0
- package/dist/core.d.ts +276 -0
- package/dist/core.mjs +1703 -0
- package/dist/core.mjs.map +1 -0
- package/dist/index.cjs +2822 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.mjs +2791 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2822 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
Lapse: () => Lapse,
|
|
25
|
+
LapseEngine: () => LapseEngine,
|
|
26
|
+
LapseProvider: () => LapseProvider,
|
|
27
|
+
useLapseEngine: () => useLapseEngine,
|
|
28
|
+
useSpeed: () => useSpeed,
|
|
29
|
+
useTimeline: () => useTimeline
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/react/Lapse.tsx
|
|
34
|
+
var import_react7 = require("react");
|
|
35
|
+
var import_react_dom = require("react-dom");
|
|
36
|
+
|
|
37
|
+
// src/react/LapseContext.tsx
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
|
|
40
|
+
// src/core/timing.ts
|
|
41
|
+
var TimingController = class {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.speed = 1;
|
|
44
|
+
this.virtualBaseline = 0;
|
|
45
|
+
this.intervalMap = /* @__PURE__ */ new Map();
|
|
46
|
+
this.nextIntervalId = 1e6;
|
|
47
|
+
this.mediaObserver = null;
|
|
48
|
+
this.animObserver = null;
|
|
49
|
+
this._origAnimate = null;
|
|
50
|
+
this.installed = false;
|
|
51
|
+
this._raf = requestAnimationFrame.bind(window);
|
|
52
|
+
this._caf = cancelAnimationFrame.bind(window);
|
|
53
|
+
this._setTimeout = setTimeout.bind(window);
|
|
54
|
+
this._clearTimeout = clearTimeout.bind(window);
|
|
55
|
+
this._setInterval = setInterval.bind(window);
|
|
56
|
+
this._clearInterval = clearInterval.bind(window);
|
|
57
|
+
this._perfNow = performance.now.bind(performance);
|
|
58
|
+
this._dateNow = Date.now;
|
|
59
|
+
this.realBaseline = this._perfNow();
|
|
60
|
+
}
|
|
61
|
+
getVirtualTime() {
|
|
62
|
+
const realElapsed = this._perfNow() - this.realBaseline;
|
|
63
|
+
return this.virtualBaseline + realElapsed * this.speed;
|
|
64
|
+
}
|
|
65
|
+
reanchor() {
|
|
66
|
+
const virtualNow = this.getVirtualTime();
|
|
67
|
+
this.realBaseline = this._perfNow();
|
|
68
|
+
this.virtualBaseline = virtualNow;
|
|
69
|
+
}
|
|
70
|
+
/** Install timing patches. Safe to call multiple times. */
|
|
71
|
+
install() {
|
|
72
|
+
if (this.installed) return;
|
|
73
|
+
this.installed = true;
|
|
74
|
+
const self = this;
|
|
75
|
+
window.__LAPSE_ORIGINAL_RAF__ = this._raf;
|
|
76
|
+
const origAnimate = Element.prototype.animate;
|
|
77
|
+
this._origAnimate = origAnimate;
|
|
78
|
+
Element.prototype.animate = function(...args) {
|
|
79
|
+
const anim = origAnimate.apply(this, args);
|
|
80
|
+
if (self.speed !== 1) {
|
|
81
|
+
anim.playbackRate = self.speed || 1e-3;
|
|
82
|
+
}
|
|
83
|
+
return anim;
|
|
84
|
+
};
|
|
85
|
+
performance.now = () => self.getVirtualTime();
|
|
86
|
+
const dateBaseline = this._dateNow();
|
|
87
|
+
Date.now = () => dateBaseline + self.getVirtualTime();
|
|
88
|
+
window.requestAnimationFrame = (callback) => {
|
|
89
|
+
return self._raf(() => {
|
|
90
|
+
callback(self.getVirtualTime());
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
window.cancelAnimationFrame = this._caf;
|
|
94
|
+
window.setTimeout = ((handler, delay, ...args) => {
|
|
95
|
+
const scaledDelay = (delay ?? 0) / (self.speed || 1);
|
|
96
|
+
return self._setTimeout(handler, scaledDelay, ...args);
|
|
97
|
+
});
|
|
98
|
+
window.clearTimeout = this._clearTimeout;
|
|
99
|
+
window.setInterval = ((handler, delay, ...args) => {
|
|
100
|
+
const id = self.nextIntervalId++;
|
|
101
|
+
const baseDelay = delay ?? 0;
|
|
102
|
+
function tick() {
|
|
103
|
+
const scaledDelay = baseDelay / (self.speed || 1);
|
|
104
|
+
const realId = self._setTimeout(() => {
|
|
105
|
+
if (typeof handler === "function") {
|
|
106
|
+
;
|
|
107
|
+
handler(...args);
|
|
108
|
+
}
|
|
109
|
+
if (self.intervalMap.has(id)) tick();
|
|
110
|
+
}, scaledDelay);
|
|
111
|
+
const entry = self.intervalMap.get(id);
|
|
112
|
+
if (entry) entry.realId = realId;
|
|
113
|
+
}
|
|
114
|
+
self.intervalMap.set(id, { handler, delay: baseDelay, realId: 0 });
|
|
115
|
+
tick();
|
|
116
|
+
return id;
|
|
117
|
+
});
|
|
118
|
+
window.clearInterval = ((id) => {
|
|
119
|
+
if (id == null) return;
|
|
120
|
+
const entry = self.intervalMap.get(id);
|
|
121
|
+
if (entry) {
|
|
122
|
+
self._clearTimeout(entry.realId);
|
|
123
|
+
self.intervalMap.delete(id);
|
|
124
|
+
} else {
|
|
125
|
+
self._clearInterval(id);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
this.mediaObserver = new MutationObserver((mutations) => {
|
|
129
|
+
for (const mutation of mutations) {
|
|
130
|
+
for (const node of mutation.addedNodes) {
|
|
131
|
+
if (node instanceof HTMLVideoElement || node instanceof HTMLAudioElement) {
|
|
132
|
+
node.playbackRate = self.speed;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
if (document.body) {
|
|
138
|
+
this.mediaObserver.observe(document.body, { childList: true, subtree: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** Set playback speed. Requires install() first. */
|
|
142
|
+
setSpeed(newSpeed) {
|
|
143
|
+
if (!this.installed) this.install();
|
|
144
|
+
this.reanchor();
|
|
145
|
+
this.speed = newSpeed;
|
|
146
|
+
document.querySelectorAll("video, audio").forEach((el) => {
|
|
147
|
+
;
|
|
148
|
+
el.playbackRate = newSpeed;
|
|
149
|
+
});
|
|
150
|
+
this.patchAnimations();
|
|
151
|
+
}
|
|
152
|
+
/** Patch playbackRate on all active CSS transitions/animations via WAAPI. */
|
|
153
|
+
patchAnimations() {
|
|
154
|
+
try {
|
|
155
|
+
const anims = document.getAnimations();
|
|
156
|
+
for (const anim of anims) {
|
|
157
|
+
const target = anim.effect?.target;
|
|
158
|
+
if (target?.closest?.("[data-lapse-panel]")) continue;
|
|
159
|
+
anim.playbackRate = this.speed || 1e-3;
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
if (!this.animObserver) {
|
|
164
|
+
this.animObserver = this._setInterval(() => {
|
|
165
|
+
if (!this.installed) return;
|
|
166
|
+
try {
|
|
167
|
+
const anims = document.getAnimations();
|
|
168
|
+
for (const anim of anims) {
|
|
169
|
+
const target = anim.effect?.target;
|
|
170
|
+
if (target?.closest?.("[data-lapse-panel]")) continue;
|
|
171
|
+
if (anim.playbackRate !== this.speed) {
|
|
172
|
+
anim.playbackRate = this.speed || 1e-3;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
}, 100);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
getSpeed() {
|
|
181
|
+
return this.speed;
|
|
182
|
+
}
|
|
183
|
+
/** Restore all patched APIs to originals. */
|
|
184
|
+
destroy() {
|
|
185
|
+
if (!this.installed) return;
|
|
186
|
+
performance.now = this._perfNow;
|
|
187
|
+
Date.now = this._dateNow;
|
|
188
|
+
window.requestAnimationFrame = this._raf;
|
|
189
|
+
window.cancelAnimationFrame = this._caf;
|
|
190
|
+
window.setTimeout = this._setTimeout;
|
|
191
|
+
window.clearTimeout = this._clearTimeout;
|
|
192
|
+
window.setInterval = this._setInterval;
|
|
193
|
+
window.clearInterval = this._clearInterval;
|
|
194
|
+
for (const [, entry] of this.intervalMap) {
|
|
195
|
+
this._clearTimeout(entry.realId);
|
|
196
|
+
}
|
|
197
|
+
this.intervalMap.clear();
|
|
198
|
+
if (this._origAnimate) {
|
|
199
|
+
Element.prototype.animate = this._origAnimate;
|
|
200
|
+
this._origAnimate = null;
|
|
201
|
+
}
|
|
202
|
+
this.mediaObserver?.disconnect();
|
|
203
|
+
this.mediaObserver = null;
|
|
204
|
+
if (this.animObserver != null) {
|
|
205
|
+
this._clearInterval(this.animObserver);
|
|
206
|
+
this.animObserver = null;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
for (const anim of document.getAnimations()) {
|
|
210
|
+
anim.playbackRate = 1;
|
|
211
|
+
}
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
214
|
+
delete window.__LAPSE_ORIGINAL_RAF__;
|
|
215
|
+
this.installed = false;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// src/core/recorder.ts
|
|
220
|
+
var SAFE_PROPS = [
|
|
221
|
+
"opacity",
|
|
222
|
+
"transform",
|
|
223
|
+
"background-color",
|
|
224
|
+
"color",
|
|
225
|
+
"border-color",
|
|
226
|
+
"box-shadow",
|
|
227
|
+
"border-radius",
|
|
228
|
+
"filter",
|
|
229
|
+
"clip-path",
|
|
230
|
+
"scale",
|
|
231
|
+
"rotate",
|
|
232
|
+
"translate",
|
|
233
|
+
"outline-color",
|
|
234
|
+
"outline-width",
|
|
235
|
+
"outline-offset",
|
|
236
|
+
"outline-style",
|
|
237
|
+
"text-decoration-color",
|
|
238
|
+
"fill",
|
|
239
|
+
"stroke",
|
|
240
|
+
"stroke-dasharray",
|
|
241
|
+
"stroke-dashoffset",
|
|
242
|
+
"visibility",
|
|
243
|
+
"pointer-events"
|
|
244
|
+
];
|
|
245
|
+
var LAYOUT_PROPS = [
|
|
246
|
+
"width",
|
|
247
|
+
"height",
|
|
248
|
+
"top",
|
|
249
|
+
"left",
|
|
250
|
+
"right",
|
|
251
|
+
"bottom",
|
|
252
|
+
"margin-top",
|
|
253
|
+
"margin-right",
|
|
254
|
+
"margin-bottom",
|
|
255
|
+
"margin-left",
|
|
256
|
+
"padding-top",
|
|
257
|
+
"padding-right",
|
|
258
|
+
"padding-bottom",
|
|
259
|
+
"padding-left",
|
|
260
|
+
"max-height",
|
|
261
|
+
"max-width",
|
|
262
|
+
"min-height",
|
|
263
|
+
"min-width",
|
|
264
|
+
"display"
|
|
265
|
+
];
|
|
266
|
+
var SNAPSHOT_PROPS = [...SAFE_PROPS, ...LAYOUT_PROPS];
|
|
267
|
+
var SAFE_PROPS_SET = new Set(SAFE_PROPS);
|
|
268
|
+
var SNAPSHOT_ATTRS = [
|
|
269
|
+
"data-state",
|
|
270
|
+
"data-checked",
|
|
271
|
+
"data-disabled",
|
|
272
|
+
"data-highlighted",
|
|
273
|
+
"data-orientation",
|
|
274
|
+
"data-active",
|
|
275
|
+
"data-selected",
|
|
276
|
+
"data-open",
|
|
277
|
+
"data-closed",
|
|
278
|
+
"data-side",
|
|
279
|
+
"data-align",
|
|
280
|
+
"data-focus",
|
|
281
|
+
"data-hover",
|
|
282
|
+
"data-at-boundary",
|
|
283
|
+
"data-scrubbing",
|
|
284
|
+
"aria-checked",
|
|
285
|
+
"aria-selected",
|
|
286
|
+
"aria-expanded",
|
|
287
|
+
"aria-pressed",
|
|
288
|
+
"aria-hidden",
|
|
289
|
+
"aria-disabled",
|
|
290
|
+
"aria-valuenow",
|
|
291
|
+
"aria-valuemin",
|
|
292
|
+
"aria-valuemax",
|
|
293
|
+
"aria-invalid",
|
|
294
|
+
"checked",
|
|
295
|
+
"disabled",
|
|
296
|
+
"hidden",
|
|
297
|
+
"value",
|
|
298
|
+
"class",
|
|
299
|
+
"style"
|
|
300
|
+
];
|
|
301
|
+
var STATE_SELECTORS = [
|
|
302
|
+
"[data-state]",
|
|
303
|
+
"[aria-checked]",
|
|
304
|
+
"[aria-selected]",
|
|
305
|
+
"[aria-expanded]",
|
|
306
|
+
"[aria-pressed]",
|
|
307
|
+
'[role="radio"]',
|
|
308
|
+
'[role="checkbox"]',
|
|
309
|
+
'[role="switch"]',
|
|
310
|
+
'[role="tab"]',
|
|
311
|
+
'[role="tabpanel"]',
|
|
312
|
+
'[role="option"]',
|
|
313
|
+
'[role="slider"]',
|
|
314
|
+
'[role="menuitem"]',
|
|
315
|
+
'[role="menuitemcheckbox"]',
|
|
316
|
+
'[role="menuitemradio"]',
|
|
317
|
+
'[type="radio"]',
|
|
318
|
+
'[type="checkbox"]',
|
|
319
|
+
'[type="range"]',
|
|
320
|
+
"input",
|
|
321
|
+
"button",
|
|
322
|
+
"select",
|
|
323
|
+
"textarea",
|
|
324
|
+
"[data-radix-collection-item]",
|
|
325
|
+
'[data-slot="slider-thumb"]',
|
|
326
|
+
'[data-slot="slider-track"]'
|
|
327
|
+
].join(",");
|
|
328
|
+
function getSelector(el) {
|
|
329
|
+
if (!el || !el.tagName) return null;
|
|
330
|
+
const parts = [];
|
|
331
|
+
let current = el;
|
|
332
|
+
for (let i = 0; i < 5 && current && current.tagName && current.tagName !== "HTML"; i++) {
|
|
333
|
+
const tag = current.tagName.toLowerCase();
|
|
334
|
+
const parent = current.parentElement;
|
|
335
|
+
if (parent) {
|
|
336
|
+
const siblings = Array.from(parent.children);
|
|
337
|
+
const idx = siblings.indexOf(current) + 1;
|
|
338
|
+
parts.unshift(tag + ":nth-child(" + idx + ")");
|
|
339
|
+
} else {
|
|
340
|
+
parts.unshift(tag);
|
|
341
|
+
}
|
|
342
|
+
current = parent;
|
|
343
|
+
}
|
|
344
|
+
return parts.join(" > ");
|
|
345
|
+
}
|
|
346
|
+
function getReadableSelector(el) {
|
|
347
|
+
if (!el || !el.tagName) return "unknown";
|
|
348
|
+
if (el.id) return "#" + el.id;
|
|
349
|
+
const tag = el.tagName.toLowerCase();
|
|
350
|
+
const classes = Array.from(el.classList || []).slice(0, 3).map((c) => "." + c).join("");
|
|
351
|
+
return tag + classes;
|
|
352
|
+
}
|
|
353
|
+
function getElementLabel(el) {
|
|
354
|
+
if (!el) return "unknown";
|
|
355
|
+
const ariaLabel = el.getAttribute("aria-label");
|
|
356
|
+
if (ariaLabel) return ariaLabel;
|
|
357
|
+
const text = (el.textContent || "").trim();
|
|
358
|
+
if (text && text.length < 40 && text.length > 0) return text;
|
|
359
|
+
const label = el.closest("label") || el.closest("[aria-label]");
|
|
360
|
+
if (label) {
|
|
361
|
+
const lt = label.getAttribute("aria-label") || (label.textContent || "").trim();
|
|
362
|
+
if (lt && lt.length < 40) return lt;
|
|
363
|
+
}
|
|
364
|
+
const state = el.getAttribute("data-state");
|
|
365
|
+
const role = el.getAttribute("role");
|
|
366
|
+
if (role && state) return role + " (" + state + ")";
|
|
367
|
+
if (role) return role;
|
|
368
|
+
return getReadableSelector(el);
|
|
369
|
+
}
|
|
370
|
+
function cssSplit(str) {
|
|
371
|
+
const parts = [];
|
|
372
|
+
let depth = 0;
|
|
373
|
+
let start = 0;
|
|
374
|
+
for (let i = 0; i < str.length; i++) {
|
|
375
|
+
if (str[i] === "(") depth++;
|
|
376
|
+
else if (str[i] === ")") depth--;
|
|
377
|
+
else if (str[i] === "," && depth === 0) {
|
|
378
|
+
parts.push(str.slice(start, i).trim());
|
|
379
|
+
start = i + 1;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
parts.push(str.slice(start).trim());
|
|
383
|
+
return parts;
|
|
384
|
+
}
|
|
385
|
+
var _TimelineRecorder = class _TimelineRecorder {
|
|
386
|
+
constructor() {
|
|
387
|
+
// ---- Recording state ----------------------------------------------------
|
|
388
|
+
this.recording = false;
|
|
389
|
+
this.startTime = 0;
|
|
390
|
+
this.boundingBox = null;
|
|
391
|
+
/** Structural-selector -> live DOM element. */
|
|
392
|
+
this.elements = /* @__PURE__ */ new Map();
|
|
393
|
+
/** Animation id -> info. */
|
|
394
|
+
this.animations = /* @__PURE__ */ new Map();
|
|
395
|
+
/** Original inline style per element (captured on first encounter). */
|
|
396
|
+
this.originalStyles = /* @__PURE__ */ new Map();
|
|
397
|
+
/** Captured frames. */
|
|
398
|
+
this.frames = [];
|
|
399
|
+
// ---- Portal management --------------------------------------------------
|
|
400
|
+
this.activePortals = /* @__PURE__ */ new Map();
|
|
401
|
+
this.portalIdCounter = 0;
|
|
402
|
+
this.currentPortalIds = /* @__PURE__ */ new Set();
|
|
403
|
+
this.capturedPortals = /* @__PURE__ */ new Set();
|
|
404
|
+
// ---- JS animation detection (Phase 2) -----------------------------------
|
|
405
|
+
this.prevInlineStyles = /* @__PURE__ */ new Map();
|
|
406
|
+
this.jsAnimStartTimes = /* @__PURE__ */ new Map();
|
|
407
|
+
this.jsAnimLastSeen = /* @__PURE__ */ new Map();
|
|
408
|
+
this.jsAnimFromValues = /* @__PURE__ */ new Map();
|
|
409
|
+
this.jsAnimChangeCount = /* @__PURE__ */ new Map();
|
|
410
|
+
// ---- Interaction state --------------------------------------------------
|
|
411
|
+
this.currentHoverEls = /* @__PURE__ */ new Set();
|
|
412
|
+
this.currentFocusSel = null;
|
|
413
|
+
this.currentPointer = { x: 0, y: 0, buttons: 0 };
|
|
414
|
+
// ---- Observers & listeners ----------------------------------------------
|
|
415
|
+
this.attrObserver = null;
|
|
416
|
+
this.portalObserver = null;
|
|
417
|
+
this.exitObserver = null;
|
|
418
|
+
this.onMouseOver = null;
|
|
419
|
+
this.onMouseOut = null;
|
|
420
|
+
this.onFocusIn = null;
|
|
421
|
+
this.onFocusOut = null;
|
|
422
|
+
this.onPointerMove = null;
|
|
423
|
+
this.onPointerDown = null;
|
|
424
|
+
this.onPointerUp = null;
|
|
425
|
+
// ---- WAAPI interception --------------------------------------------------
|
|
426
|
+
/** Animations captured via Element.prototype.animate monkey-patch. */
|
|
427
|
+
this.interceptedAnimations = [];
|
|
428
|
+
this.hiddenSince = null;
|
|
429
|
+
this.onVisibilityChange = null;
|
|
430
|
+
/** Set to true when the capture loop self-terminates due to limits. */
|
|
431
|
+
this.autoStopped = false;
|
|
432
|
+
/** Called when recording auto-stops. Set by the engine. */
|
|
433
|
+
this.onAutoStop = null;
|
|
434
|
+
// ---- Saved originals (for restoration) ----------------------------------
|
|
435
|
+
this._removeChild = null;
|
|
436
|
+
this._remove = null;
|
|
437
|
+
this._elementAnimate = null;
|
|
438
|
+
// ---- DOM elements injected during stop ----------------------------------
|
|
439
|
+
/** `<style>` that disables all transitions/animations after recording. */
|
|
440
|
+
this.noTransitionsEl = null;
|
|
441
|
+
/** Full-screen overlay blocking interaction during scrub. */
|
|
442
|
+
this.blockerEl = null;
|
|
443
|
+
/** `<style>` with cloned :hover / :focus rules rewritten as `[data-lapse-*]`. */
|
|
444
|
+
this.lapseStyleEl = null;
|
|
445
|
+
// =========================================================================
|
|
446
|
+
// Public API — helpers exposed for the scrubber
|
|
447
|
+
// =========================================================================
|
|
448
|
+
this.getSelector = getSelector;
|
|
449
|
+
}
|
|
450
|
+
// ---- Unpatched rAF reference --------------------------------------------
|
|
451
|
+
get _raf() {
|
|
452
|
+
return window.__LAPSE_ORIGINAL_RAF__ || requestAnimationFrame;
|
|
453
|
+
}
|
|
454
|
+
get SAFE_PROPS_SET() {
|
|
455
|
+
return SAFE_PROPS_SET;
|
|
456
|
+
}
|
|
457
|
+
get capturedPortalIds() {
|
|
458
|
+
return this.capturedPortals;
|
|
459
|
+
}
|
|
460
|
+
// =========================================================================
|
|
461
|
+
// startRecording
|
|
462
|
+
// =========================================================================
|
|
463
|
+
startRecording(boundingBox) {
|
|
464
|
+
if (this.recording) return;
|
|
465
|
+
this.recording = true;
|
|
466
|
+
this.autoStopped = false;
|
|
467
|
+
this.hiddenSince = null;
|
|
468
|
+
this.startTime = performance.now();
|
|
469
|
+
this.frames = [];
|
|
470
|
+
this.animations.clear();
|
|
471
|
+
this.elements.clear();
|
|
472
|
+
this.originalStyles.clear();
|
|
473
|
+
this.boundingBox = boundingBox || null;
|
|
474
|
+
this.activePortals.clear();
|
|
475
|
+
this.portalIdCounter = 0;
|
|
476
|
+
this.currentPortalIds.clear();
|
|
477
|
+
this.capturedPortals.clear();
|
|
478
|
+
this.prevInlineStyles.clear();
|
|
479
|
+
this.jsAnimStartTimes.clear();
|
|
480
|
+
this.jsAnimLastSeen.clear();
|
|
481
|
+
this.jsAnimFromValues.clear();
|
|
482
|
+
this.jsAnimChangeCount.clear();
|
|
483
|
+
this.currentHoverEls.clear();
|
|
484
|
+
this.currentFocusSel = null;
|
|
485
|
+
this.currentPointer = { x: 0, y: 0, buttons: 0 };
|
|
486
|
+
this.onVisibilityChange = () => {
|
|
487
|
+
if (!this.recording) return;
|
|
488
|
+
if (document.hidden) {
|
|
489
|
+
this.hiddenSince = performance.now();
|
|
490
|
+
} else {
|
|
491
|
+
this.hiddenSince = null;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
document.addEventListener("visibilitychange", this.onVisibilityChange);
|
|
495
|
+
const trackElement = (el) => {
|
|
496
|
+
if (!el || !el.tagName) return;
|
|
497
|
+
if (el.closest?.("[data-lapse-panel]")) return;
|
|
498
|
+
const sel = getSelector(el);
|
|
499
|
+
if (!sel) return;
|
|
500
|
+
const isNew = !this.elements.has(sel);
|
|
501
|
+
this.elements.set(sel, el);
|
|
502
|
+
if (isNew) {
|
|
503
|
+
this.originalStyles.set(sel, el.getAttribute("style") || "");
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const trackTree = (root) => {
|
|
507
|
+
if (!root || !root.querySelectorAll) return;
|
|
508
|
+
trackElement(root);
|
|
509
|
+
for (const child of root.querySelectorAll("*")) {
|
|
510
|
+
trackElement(child);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
const isInBounds = (el) => {
|
|
514
|
+
if (el.closest?.("[data-lapse-panel]")) return false;
|
|
515
|
+
if (!this.boundingBox) return true;
|
|
516
|
+
const r = el.getBoundingClientRect();
|
|
517
|
+
const bb = this.boundingBox;
|
|
518
|
+
return r.x < bb.x + bb.width && r.x + r.width > bb.x && r.y < bb.y + bb.height && r.y + r.height > bb.y;
|
|
519
|
+
};
|
|
520
|
+
try {
|
|
521
|
+
const stateEls = document.querySelectorAll(STATE_SELECTORS);
|
|
522
|
+
for (const el of stateEls) {
|
|
523
|
+
if (!isInBounds(el)) continue;
|
|
524
|
+
trackElement(el);
|
|
525
|
+
for (const child of el.querySelectorAll("*")) {
|
|
526
|
+
trackElement(child);
|
|
527
|
+
}
|
|
528
|
+
const parent = el.parentElement;
|
|
529
|
+
if (parent) {
|
|
530
|
+
trackElement(parent);
|
|
531
|
+
for (const sibling of parent.children) {
|
|
532
|
+
trackElement(sibling);
|
|
533
|
+
for (const child of sibling.querySelectorAll("*")) {
|
|
534
|
+
trackElement(child);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
} catch (_) {
|
|
540
|
+
}
|
|
541
|
+
this.attrObserver = new MutationObserver((mutations) => {
|
|
542
|
+
for (const m of mutations) {
|
|
543
|
+
if (m.target instanceof HTMLElement) {
|
|
544
|
+
trackElement(m.target);
|
|
545
|
+
const parent = m.target.parentElement;
|
|
546
|
+
if (parent) {
|
|
547
|
+
for (const sibling of parent.children) {
|
|
548
|
+
trackElement(sibling);
|
|
549
|
+
for (const child of sibling.querySelectorAll("*")) {
|
|
550
|
+
trackElement(child);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
this.attrObserver.observe(document.body, {
|
|
558
|
+
attributes: true,
|
|
559
|
+
attributeFilter: [
|
|
560
|
+
"data-state",
|
|
561
|
+
"data-highlighted",
|
|
562
|
+
"data-hover",
|
|
563
|
+
"data-focus",
|
|
564
|
+
"data-active",
|
|
565
|
+
"data-selected",
|
|
566
|
+
"data-open",
|
|
567
|
+
"data-closed",
|
|
568
|
+
"data-at-boundary",
|
|
569
|
+
"data-scrubbing",
|
|
570
|
+
"aria-checked",
|
|
571
|
+
"aria-selected",
|
|
572
|
+
"aria-expanded",
|
|
573
|
+
"aria-valuenow",
|
|
574
|
+
"aria-invalid",
|
|
575
|
+
"class",
|
|
576
|
+
"style"
|
|
577
|
+
],
|
|
578
|
+
subtree: true
|
|
579
|
+
});
|
|
580
|
+
this._removeChild = Node.prototype.removeChild;
|
|
581
|
+
const savedRemoveChild = this._removeChild;
|
|
582
|
+
const self = this;
|
|
583
|
+
Node.prototype.removeChild = function(child) {
|
|
584
|
+
if (self.recording && child instanceof HTMLElement && child.hasAttribute("data-lapse-portal-id")) {
|
|
585
|
+
child.style.display = "none";
|
|
586
|
+
child.setAttribute("data-lapse-portal-hidden", "");
|
|
587
|
+
const id = child.getAttribute("data-lapse-portal-id");
|
|
588
|
+
if (id) self.currentPortalIds.delete(id);
|
|
589
|
+
return child;
|
|
590
|
+
}
|
|
591
|
+
return savedRemoveChild.call(this, child);
|
|
592
|
+
};
|
|
593
|
+
this._remove = Element.prototype.remove;
|
|
594
|
+
const savedRemove = this._remove;
|
|
595
|
+
Element.prototype.remove = function() {
|
|
596
|
+
if (self.recording && this instanceof HTMLElement && this.hasAttribute("data-lapse-portal-id")) {
|
|
597
|
+
this.style.display = "none";
|
|
598
|
+
this.setAttribute("data-lapse-portal-hidden", "");
|
|
599
|
+
const id = this.getAttribute("data-lapse-portal-id");
|
|
600
|
+
if (id) self.currentPortalIds.delete(id);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
return savedRemove.call(this);
|
|
604
|
+
};
|
|
605
|
+
this._elementAnimate = Element.prototype.animate;
|
|
606
|
+
const savedAnimate = this._elementAnimate;
|
|
607
|
+
Element.prototype.animate = function(keyframes, options) {
|
|
608
|
+
const anim = savedAnimate.call(this, keyframes, options);
|
|
609
|
+
if (self.recording && this instanceof HTMLElement && isInBounds(this)) {
|
|
610
|
+
trackElement(this);
|
|
611
|
+
self.interceptedAnimations.push({ animation: anim, target: this });
|
|
612
|
+
}
|
|
613
|
+
return anim;
|
|
614
|
+
};
|
|
615
|
+
this.portalObserver = new MutationObserver((mutations) => {
|
|
616
|
+
for (const m of mutations) {
|
|
617
|
+
for (const node of m.addedNodes) {
|
|
618
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
619
|
+
if (node.parentElement !== document.body) continue;
|
|
620
|
+
if (node.hasAttribute("data-lapse-portal-id")) continue;
|
|
621
|
+
const isPortal = node.hasAttribute("data-radix-popper-content-wrapper") || node.hasAttribute("data-radix-portal") || node.getAttribute("role") === "dialog" || node.getAttribute("role") === "alertdialog" || node.querySelector(
|
|
622
|
+
'[role="menu"], [role="dialog"], [role="alertdialog"], [role="listbox"], [role="tooltip"], [data-radix-popper-content-wrapper]'
|
|
623
|
+
) || node.hasAttribute("data-state") || node.style && (node.style.position === "fixed" || node.style.position === "absolute") || getComputedStyle(node).position === "fixed";
|
|
624
|
+
if (!isPortal) continue;
|
|
625
|
+
const id = "__lapse_portal_" + this.portalIdCounter++;
|
|
626
|
+
node.setAttribute("data-lapse-portal-id", id);
|
|
627
|
+
this.activePortals.set(id, { element: node });
|
|
628
|
+
this.currentPortalIds.add(id);
|
|
629
|
+
this.capturedPortals.add(id);
|
|
630
|
+
trackTree(node);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
this.portalObserver.observe(document.body, { childList: true });
|
|
635
|
+
this.exitObserver = new MutationObserver((mutations) => {
|
|
636
|
+
if (!this.recording) return;
|
|
637
|
+
for (const m of mutations) {
|
|
638
|
+
for (const node of m.removedNodes) {
|
|
639
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
640
|
+
const sel = getSelector(node);
|
|
641
|
+
if (sel && this.elements.has(sel)) {
|
|
642
|
+
if (!node.isConnected) {
|
|
643
|
+
node.style.display = "none";
|
|
644
|
+
node.setAttribute("data-lapse-exit-captured", "");
|
|
645
|
+
(m.target || document.body).appendChild(node);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
this.exitObserver.observe(document.body, { childList: true, subtree: true });
|
|
652
|
+
this.onMouseOver = (e) => {
|
|
653
|
+
if (!this.recording) return;
|
|
654
|
+
this.currentHoverEls.clear();
|
|
655
|
+
let el = e.target;
|
|
656
|
+
while (el && el !== document.body) {
|
|
657
|
+
const sel = getSelector(el);
|
|
658
|
+
if (sel) {
|
|
659
|
+
this.currentHoverEls.add(sel);
|
|
660
|
+
trackElement(el);
|
|
661
|
+
}
|
|
662
|
+
el = el.parentElement;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
this.onMouseOut = (e) => {
|
|
666
|
+
if (!this.recording) return;
|
|
667
|
+
if (!e.relatedTarget || !document.body.contains(e.relatedTarget)) {
|
|
668
|
+
this.currentHoverEls.clear();
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
document.addEventListener("mouseover", this.onMouseOver, true);
|
|
672
|
+
document.addEventListener("mouseout", this.onMouseOut, true);
|
|
673
|
+
this.onFocusIn = (e) => {
|
|
674
|
+
if (!this.recording) return;
|
|
675
|
+
const el = e.target;
|
|
676
|
+
if (el && el !== document.body) {
|
|
677
|
+
const sel = getSelector(el);
|
|
678
|
+
this.currentFocusSel = sel;
|
|
679
|
+
trackElement(el);
|
|
680
|
+
let parent = el.parentElement;
|
|
681
|
+
while (parent && parent !== document.body) {
|
|
682
|
+
trackElement(parent);
|
|
683
|
+
parent = parent.parentElement;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
this.onFocusOut = () => {
|
|
688
|
+
if (!this.recording) return;
|
|
689
|
+
this.currentFocusSel = null;
|
|
690
|
+
};
|
|
691
|
+
document.addEventListener("focusin", this.onFocusIn, true);
|
|
692
|
+
document.addEventListener("focusout", this.onFocusOut, true);
|
|
693
|
+
this.onPointerMove = (e) => {
|
|
694
|
+
if (!this.recording) return;
|
|
695
|
+
this.currentPointer = { x: e.clientX, y: e.clientY, buttons: e.buttons };
|
|
696
|
+
};
|
|
697
|
+
this.onPointerDown = (e) => {
|
|
698
|
+
if (!this.recording) return;
|
|
699
|
+
this.currentPointer = { x: e.clientX, y: e.clientY, buttons: e.buttons };
|
|
700
|
+
};
|
|
701
|
+
this.onPointerUp = (e) => {
|
|
702
|
+
if (!this.recording) return;
|
|
703
|
+
this.currentPointer = { x: e.clientX, y: e.clientY, buttons: 0 };
|
|
704
|
+
};
|
|
705
|
+
document.addEventListener("pointermove", this.onPointerMove, true);
|
|
706
|
+
document.addEventListener("pointerdown", this.onPointerDown, true);
|
|
707
|
+
document.addEventListener("pointerup", this.onPointerUp, true);
|
|
708
|
+
const captureFrame = () => {
|
|
709
|
+
if (!this.recording) return;
|
|
710
|
+
const time = performance.now() - this.startTime;
|
|
711
|
+
if (time >= _TimelineRecorder.MAX_DURATION_MS || this.frames.length >= _TimelineRecorder.MAX_FRAMES || this.hiddenSince && performance.now() - this.hiddenSince > 5e3) {
|
|
712
|
+
this.recording = false;
|
|
713
|
+
this.autoStopped = true;
|
|
714
|
+
this.onAutoStop?.();
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
const anims = document.getAnimations();
|
|
718
|
+
const frameAnims = [];
|
|
719
|
+
for (const a of anims) {
|
|
720
|
+
const target = a.effect?.target;
|
|
721
|
+
if (!target) continue;
|
|
722
|
+
if (!isInBounds(target)) continue;
|
|
723
|
+
const uniqueSelector = getSelector(target);
|
|
724
|
+
if (!uniqueSelector) continue;
|
|
725
|
+
const readableSelector = getReadableSelector(target);
|
|
726
|
+
trackElement(target);
|
|
727
|
+
const timing = a.effect?.getTiming?.() || {};
|
|
728
|
+
const duration = typeof timing.duration === "number" ? timing.duration : 0;
|
|
729
|
+
const delay = timing.delay || 0;
|
|
730
|
+
const easing = timing.easing || "linear";
|
|
731
|
+
let name = "";
|
|
732
|
+
let type = "WebAnimation";
|
|
733
|
+
if (a.constructor.name === "CSSTransition" || a.transitionProperty) {
|
|
734
|
+
name = a.transitionProperty || "";
|
|
735
|
+
type = "CSSTransition";
|
|
736
|
+
} else if (a.constructor.name === "CSSAnimation" || a.animationName) {
|
|
737
|
+
name = a.animationName || "";
|
|
738
|
+
type = "CSSAnimation";
|
|
739
|
+
}
|
|
740
|
+
const id = type + ":" + name + ":" + uniqueSelector;
|
|
741
|
+
if (!this.animations.has(id)) {
|
|
742
|
+
const keyframes2 = a.effect?.getKeyframes?.() || [];
|
|
743
|
+
let source = null;
|
|
744
|
+
if (type === "CSSAnimation" && keyframes2.length > 0) {
|
|
745
|
+
const kfLines = keyframes2.map((kf) => {
|
|
746
|
+
const offset = Math.round((kf.offset ?? 0) * 100) + "%";
|
|
747
|
+
const props = Object.entries(kf).filter(
|
|
748
|
+
([k]) => !["offset", "easing", "composite", "computedOffset"].includes(k)
|
|
749
|
+
).map(
|
|
750
|
+
([k, v]) => k.replace(/([A-Z])/g, "-$1").toLowerCase() + ": " + v
|
|
751
|
+
).join("; ");
|
|
752
|
+
return " " + offset + " { " + props + " }";
|
|
753
|
+
}).join("\n");
|
|
754
|
+
source = "@keyframes " + (name || "anonymous") + " {\n" + kfLines + "\n}";
|
|
755
|
+
} else if (type === "CSSTransition") {
|
|
756
|
+
source = "transition: " + name + " " + duration + "ms " + easing;
|
|
757
|
+
}
|
|
758
|
+
const resolvedVars = {};
|
|
759
|
+
try {
|
|
760
|
+
const cs = getComputedStyle(target);
|
|
761
|
+
const style = target.getAttribute("style") || "";
|
|
762
|
+
const allRules = [];
|
|
763
|
+
for (const sheet of document.styleSheets) {
|
|
764
|
+
try {
|
|
765
|
+
for (const rule of sheet.cssRules) {
|
|
766
|
+
if (rule.selectorText && target.matches(rule.selectorText)) {
|
|
767
|
+
allRules.push(rule.cssText);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
} catch (_) {
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const allCssText = allRules.join(" ") + " " + style;
|
|
774
|
+
const varRegex = /var\(\s*(--[a-zA-Z0-9-]+)/g;
|
|
775
|
+
let varMatch;
|
|
776
|
+
while ((varMatch = varRegex.exec(allCssText)) !== null) {
|
|
777
|
+
const varName = varMatch[1];
|
|
778
|
+
const resolved = cs.getPropertyValue(varName).trim();
|
|
779
|
+
if (resolved) {
|
|
780
|
+
resolvedVars[varName] = resolved;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
} catch (_) {
|
|
784
|
+
}
|
|
785
|
+
let conflicts = null;
|
|
786
|
+
if (type === "CSSTransition") {
|
|
787
|
+
try {
|
|
788
|
+
const cs = getComputedStyle(target);
|
|
789
|
+
const tProps = cssSplit(cs.transitionProperty);
|
|
790
|
+
const tDurations = cssSplit(cs.transitionDuration).map(
|
|
791
|
+
(s) => parseFloat(s) * 1e3
|
|
792
|
+
);
|
|
793
|
+
const tEasings = cssSplit(cs.transitionTimingFunction);
|
|
794
|
+
const tDelays = cssSplit(cs.transitionDelay).map(
|
|
795
|
+
(s) => parseFloat(s) * 1e3
|
|
796
|
+
);
|
|
797
|
+
let idx = tProps.indexOf(name);
|
|
798
|
+
if (idx === -1 && tProps.includes("all"))
|
|
799
|
+
idx = tProps.indexOf("all");
|
|
800
|
+
if (idx >= 0) {
|
|
801
|
+
const declaredDuration = tDurations[idx % tDurations.length] || 0;
|
|
802
|
+
const declaredEasing = tEasings[idx % tEasings.length] || "ease";
|
|
803
|
+
const declaredDelay = tDelays[idx % tDelays.length] || 0;
|
|
804
|
+
const diffs = [];
|
|
805
|
+
if (Math.abs(declaredDuration - duration) > 1) {
|
|
806
|
+
diffs.push(
|
|
807
|
+
"duration: declared " + declaredDuration + "ms, actual " + duration + "ms"
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
if (declaredEasing !== easing) {
|
|
811
|
+
const normDeclared = declaredEasing.replace(/\s/g, "");
|
|
812
|
+
const normActual = easing.replace(/\s/g, "");
|
|
813
|
+
if (normDeclared !== normActual) {
|
|
814
|
+
diffs.push(
|
|
815
|
+
"easing: declared " + declaredEasing + ", actual " + easing
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (Math.abs(declaredDelay - delay) > 1) {
|
|
820
|
+
diffs.push(
|
|
821
|
+
"delay: declared " + declaredDelay + "ms, actual " + delay + "ms"
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
if (diffs.length > 0) {
|
|
825
|
+
conflicts = diffs;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
} catch (_) {
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
this.animations.set(id, {
|
|
832
|
+
id,
|
|
833
|
+
name,
|
|
834
|
+
selector: readableSelector,
|
|
835
|
+
elementLabel: getElementLabel(target),
|
|
836
|
+
duration,
|
|
837
|
+
delay,
|
|
838
|
+
easing,
|
|
839
|
+
type,
|
|
840
|
+
source,
|
|
841
|
+
resolvedVars: Object.keys(resolvedVars).length > 0 ? resolvedVars : null,
|
|
842
|
+
conflicts
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
const keyframes = a.effect?.getKeyframes?.() || [];
|
|
846
|
+
const animatedProps = /* @__PURE__ */ new Set();
|
|
847
|
+
for (const kf of keyframes) {
|
|
848
|
+
for (const key of Object.keys(kf)) {
|
|
849
|
+
if (!["offset", "easing", "composite", "computedOffset"].includes(key)) {
|
|
850
|
+
animatedProps.add(key);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
const computedStyle = getComputedStyle(target);
|
|
855
|
+
const properties = [];
|
|
856
|
+
for (const prop of animatedProps) {
|
|
857
|
+
const kebab = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
858
|
+
const value = computedStyle.getPropertyValue(kebab) || "";
|
|
859
|
+
if (value) {
|
|
860
|
+
const from = keyframes[0]?.[prop] || null;
|
|
861
|
+
const to = keyframes[keyframes.length - 1]?.[prop] || null;
|
|
862
|
+
properties.push({ property: kebab, value, from, to });
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
const currentTime = a.currentTime ?? 0;
|
|
866
|
+
const progress = duration > 0 ? Math.max(0, Math.min(1, currentTime / duration)) : 0;
|
|
867
|
+
frameAnims.push({ animationId: id, currentTime, progress, properties });
|
|
868
|
+
}
|
|
869
|
+
const waapiAnimatedIds = /* @__PURE__ */ new Set();
|
|
870
|
+
for (const fa of frameAnims) {
|
|
871
|
+
const parts = fa.animationId.split(":");
|
|
872
|
+
waapiAnimatedIds.add(parts[parts.length - 1]);
|
|
873
|
+
}
|
|
874
|
+
const JS_TRACK_PROPS = ["transform", "opacity", "left", "top", "right", "bottom", "background"];
|
|
875
|
+
const waapiAnimatedProps = /* @__PURE__ */ new Map();
|
|
876
|
+
for (const fa of frameAnims) {
|
|
877
|
+
const parts = fa.animationId.split(":");
|
|
878
|
+
const elKey = parts[parts.length - 1];
|
|
879
|
+
if (!waapiAnimatedProps.has(elKey)) waapiAnimatedProps.set(elKey, /* @__PURE__ */ new Set());
|
|
880
|
+
const propName = parts[1];
|
|
881
|
+
if (propName) waapiAnimatedProps.get(elKey).add(propName);
|
|
882
|
+
}
|
|
883
|
+
for (const [elId, el] of this.elements) {
|
|
884
|
+
if (!el.isConnected) continue;
|
|
885
|
+
const hasWaapi = waapiAnimatedIds.has(elId);
|
|
886
|
+
const waapiProps = waapiAnimatedProps.get(elId);
|
|
887
|
+
const currentInline = {};
|
|
888
|
+
let hasAnyInline = false;
|
|
889
|
+
for (const prop of JS_TRACK_PROPS) {
|
|
890
|
+
const camel = prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
891
|
+
const val = el.style[camel];
|
|
892
|
+
if (val) {
|
|
893
|
+
currentInline[prop] = val;
|
|
894
|
+
hasAnyInline = true;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (!hasAnyInline) {
|
|
898
|
+
this.prevInlineStyles.set(elId, currentInline);
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
const prevInline = this.prevInlineStyles.get(elId) || {};
|
|
902
|
+
this.prevInlineStyles.set(elId, currentInline);
|
|
903
|
+
for (const p of JS_TRACK_PROPS) {
|
|
904
|
+
const cur = currentInline[p] || "";
|
|
905
|
+
const prev = prevInline[p] || "";
|
|
906
|
+
const propCoveredByWaapi = waapiProps?.has(p) || waapiProps?.has(p.replace(/-([a-z])/g, (_, c) => c.toUpperCase()));
|
|
907
|
+
if (cur && cur !== prev && !propCoveredByWaapi) {
|
|
908
|
+
const jsId = "JSAnimation:" + p + ":" + elId;
|
|
909
|
+
this.jsAnimChangeCount.set(jsId, (this.jsAnimChangeCount.get(jsId) || 0) + 1);
|
|
910
|
+
if (!this.jsAnimStartTimes.has(jsId)) {
|
|
911
|
+
this.jsAnimStartTimes.set(jsId, time);
|
|
912
|
+
this.jsAnimFromValues.set(jsId, prev || cur);
|
|
913
|
+
}
|
|
914
|
+
this.jsAnimLastSeen.set(jsId, time);
|
|
915
|
+
if (this.jsAnimChangeCount.get(jsId) < 3) continue;
|
|
916
|
+
if (!this.animations.has(jsId)) {
|
|
917
|
+
const readableSel = getReadableSelector(el);
|
|
918
|
+
this.animations.set(jsId, {
|
|
919
|
+
id: jsId,
|
|
920
|
+
name: p,
|
|
921
|
+
selector: readableSel,
|
|
922
|
+
elementLabel: getElementLabel(el),
|
|
923
|
+
duration: 0,
|
|
924
|
+
delay: 0,
|
|
925
|
+
easing: "JS-driven",
|
|
926
|
+
type: "JSAnimation",
|
|
927
|
+
source: "Detected: inline style animation (JS library or requestAnimationFrame)",
|
|
928
|
+
resolvedVars: null,
|
|
929
|
+
conflicts: null
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
const startT = this.jsAnimStartTimes.get(jsId);
|
|
933
|
+
const anim = this.animations.get(jsId);
|
|
934
|
+
anim.duration = time - startT;
|
|
935
|
+
const fromVal = this.jsAnimFromValues.get(jsId) || "";
|
|
936
|
+
const elapsed = time - startT;
|
|
937
|
+
const estimatedDuration = Math.max(anim.duration, 300);
|
|
938
|
+
const prog = Math.min(1, elapsed / estimatedDuration);
|
|
939
|
+
frameAnims.push({
|
|
940
|
+
animationId: jsId,
|
|
941
|
+
currentTime: elapsed,
|
|
942
|
+
progress: prog,
|
|
943
|
+
properties: [{
|
|
944
|
+
property: p,
|
|
945
|
+
value: cur,
|
|
946
|
+
from: fromVal,
|
|
947
|
+
to: cur
|
|
948
|
+
}]
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
const elementSnapshots = {};
|
|
954
|
+
for (const [sel, el] of this.elements) {
|
|
955
|
+
if (!el.isConnected) continue;
|
|
956
|
+
const cs = getComputedStyle(el);
|
|
957
|
+
const snap = { __styles: {}, __attrs: {} };
|
|
958
|
+
for (const prop of SNAPSHOT_PROPS) {
|
|
959
|
+
snap.__styles[prop] = cs.getPropertyValue(prop);
|
|
960
|
+
}
|
|
961
|
+
for (const attr of SNAPSHOT_ATTRS) {
|
|
962
|
+
if (attr === "checked") {
|
|
963
|
+
snap.__attrs[attr] = el.checked ? "true" : null;
|
|
964
|
+
} else if (attr === "class") {
|
|
965
|
+
snap.__attrs[attr] = el.className;
|
|
966
|
+
} else if (attr === "style") {
|
|
967
|
+
snap.__attrs[attr] = el.getAttribute("style") || "";
|
|
968
|
+
} else if (attr === "value") {
|
|
969
|
+
snap.__attrs[attr] = el.value !== void 0 ? String(el.value) : null;
|
|
970
|
+
} else {
|
|
971
|
+
snap.__attrs[attr] = el.getAttribute(attr);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
try {
|
|
975
|
+
snap.__afterOpacity = getComputedStyle(el, "::after").getPropertyValue(
|
|
976
|
+
"opacity"
|
|
977
|
+
);
|
|
978
|
+
snap.__beforeOpacity = getComputedStyle(
|
|
979
|
+
el,
|
|
980
|
+
"::before"
|
|
981
|
+
).getPropertyValue("opacity");
|
|
982
|
+
} catch (_) {
|
|
983
|
+
}
|
|
984
|
+
elementSnapshots[sel] = snap;
|
|
985
|
+
}
|
|
986
|
+
for (const [id, portal] of this.activePortals) {
|
|
987
|
+
if (portal.element?.isConnected && !portal.element.hasAttribute("data-lapse-portal-hidden")) {
|
|
988
|
+
this.currentPortalIds.add(id);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
this.frames.push({
|
|
992
|
+
time,
|
|
993
|
+
animations: frameAnims,
|
|
994
|
+
elementSnapshots,
|
|
995
|
+
activePortalIds: [...this.currentPortalIds],
|
|
996
|
+
hoveredSels: [...this.currentHoverEls],
|
|
997
|
+
focusSel: this.currentFocusSel,
|
|
998
|
+
pointer: { ...this.currentPointer },
|
|
999
|
+
scrollPositions: {}
|
|
1000
|
+
});
|
|
1001
|
+
this._raf(captureFrame);
|
|
1002
|
+
};
|
|
1003
|
+
this._raf(captureFrame);
|
|
1004
|
+
}
|
|
1005
|
+
// =========================================================================
|
|
1006
|
+
// stopRecording
|
|
1007
|
+
// =========================================================================
|
|
1008
|
+
stopRecording() {
|
|
1009
|
+
if (!this.recording) {
|
|
1010
|
+
return {
|
|
1011
|
+
startTime: 0,
|
|
1012
|
+
endTime: 0,
|
|
1013
|
+
duration: 0,
|
|
1014
|
+
animations: [],
|
|
1015
|
+
frames: [],
|
|
1016
|
+
boundingBox: null
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
this.recording = false;
|
|
1020
|
+
if (this._removeChild) Node.prototype.removeChild = this._removeChild;
|
|
1021
|
+
if (this._remove) Element.prototype.remove = this._remove;
|
|
1022
|
+
if (this._elementAnimate) Element.prototype.animate = this._elementAnimate;
|
|
1023
|
+
this.attrObserver?.disconnect();
|
|
1024
|
+
this.portalObserver?.disconnect();
|
|
1025
|
+
this.exitObserver?.disconnect();
|
|
1026
|
+
if (this.onVisibilityChange) {
|
|
1027
|
+
document.removeEventListener("visibilitychange", this.onVisibilityChange);
|
|
1028
|
+
this.onVisibilityChange = null;
|
|
1029
|
+
}
|
|
1030
|
+
if (this.onMouseOver)
|
|
1031
|
+
document.removeEventListener("mouseover", this.onMouseOver, true);
|
|
1032
|
+
if (this.onMouseOut)
|
|
1033
|
+
document.removeEventListener("mouseout", this.onMouseOut, true);
|
|
1034
|
+
if (this.onFocusIn)
|
|
1035
|
+
document.removeEventListener("focusin", this.onFocusIn, true);
|
|
1036
|
+
if (this.onFocusOut)
|
|
1037
|
+
document.removeEventListener("focusout", this.onFocusOut, true);
|
|
1038
|
+
if (this.onPointerMove)
|
|
1039
|
+
document.removeEventListener("pointermove", this.onPointerMove, true);
|
|
1040
|
+
if (this.onPointerDown)
|
|
1041
|
+
document.removeEventListener("pointerdown", this.onPointerDown, true);
|
|
1042
|
+
if (this.onPointerUp)
|
|
1043
|
+
document.removeEventListener("pointerup", this.onPointerUp, true);
|
|
1044
|
+
try {
|
|
1045
|
+
for (const anim of document.getAnimations()) {
|
|
1046
|
+
anim.cancel();
|
|
1047
|
+
}
|
|
1048
|
+
} catch (_) {
|
|
1049
|
+
}
|
|
1050
|
+
window.requestAnimationFrame = () => 0;
|
|
1051
|
+
const noTransitions = document.createElement("style");
|
|
1052
|
+
noTransitions.id = "__lapse-no-transitions";
|
|
1053
|
+
noTransitions.textContent = "*, *::before, *::after { transition: none !important; animation: none !important; }";
|
|
1054
|
+
document.head.appendChild(noTransitions);
|
|
1055
|
+
this.noTransitionsEl = noTransitions;
|
|
1056
|
+
const blocker = document.createElement("div");
|
|
1057
|
+
blocker.id = "__lapse-scrub-blocker";
|
|
1058
|
+
blocker.style.cssText = "position:fixed;inset:0;z-index:999999;cursor:not-allowed;background:transparent;";
|
|
1059
|
+
blocker.title = "Clear the timeline to interact with the page";
|
|
1060
|
+
document.body.appendChild(blocker);
|
|
1061
|
+
this.blockerEl = blocker;
|
|
1062
|
+
try {
|
|
1063
|
+
const lapseStyle = document.createElement("style");
|
|
1064
|
+
lapseStyle.id = "__lapse-state-rules";
|
|
1065
|
+
let allCss = "";
|
|
1066
|
+
for (const style of document.querySelectorAll("style")) {
|
|
1067
|
+
if (style.id === "__lapse-state-rules") continue;
|
|
1068
|
+
allCss += style.textContent + "\n";
|
|
1069
|
+
}
|
|
1070
|
+
for (const sheet of document.styleSheets) {
|
|
1071
|
+
try {
|
|
1072
|
+
let walk2 = function(rules) {
|
|
1073
|
+
for (const rule of rules) {
|
|
1074
|
+
if (rule.cssRules) {
|
|
1075
|
+
walk2(rule.cssRules);
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
const t = rule.cssText;
|
|
1079
|
+
if (t && (t.includes(":hover") || t.includes(":focus"))) {
|
|
1080
|
+
allCss += t + "\n";
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
var walk = walk2;
|
|
1085
|
+
walk2(sheet.cssRules);
|
|
1086
|
+
} catch (_) {
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
const stateRegex = /([^{}]*(?::hover|:focus-visible|:focus-within|:focus(?!-))[^{}]*)\{([^{}]*)\}/g;
|
|
1090
|
+
let match;
|
|
1091
|
+
while ((match = stateRegex.exec(allCss)) !== null) {
|
|
1092
|
+
const selector = match[1].trim();
|
|
1093
|
+
const body = match[2].trim();
|
|
1094
|
+
if (!body) continue;
|
|
1095
|
+
const newBody = body.replace(
|
|
1096
|
+
/([^;:]+):\s*([^;]+)(;|$)/g,
|
|
1097
|
+
(m, prop, val, end) => {
|
|
1098
|
+
if (val.includes("!important")) return m;
|
|
1099
|
+
return prop + ": " + val.trim() + " !important" + end;
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
if (selector.includes(":hover")) {
|
|
1103
|
+
lapseStyle.textContent += selector.replace(/:hover/g, "[data-lapse-hover]") + " { " + newBody + " }\n";
|
|
1104
|
+
}
|
|
1105
|
+
if (selector.includes(":focus-visible")) {
|
|
1106
|
+
lapseStyle.textContent += selector.replace(/:focus-visible/g, "[data-lapse-focus]") + " { " + newBody + " }\n";
|
|
1107
|
+
} else if (selector.includes(":focus-within")) {
|
|
1108
|
+
lapseStyle.textContent += selector.replace(
|
|
1109
|
+
/:focus-within/g,
|
|
1110
|
+
":has([data-lapse-focus])"
|
|
1111
|
+
) + " { " + newBody + " }\n";
|
|
1112
|
+
} else if (selector.includes(":focus")) {
|
|
1113
|
+
lapseStyle.textContent += selector.replace(/:focus(?!-)/g, "[data-lapse-focus]") + " { " + newBody + " }\n";
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
document.head.appendChild(lapseStyle);
|
|
1117
|
+
this.lapseStyleEl = lapseStyle;
|
|
1118
|
+
} catch (_) {
|
|
1119
|
+
}
|
|
1120
|
+
if (this.frames.length > 0) {
|
|
1121
|
+
const frame0 = this.frames[0];
|
|
1122
|
+
if (frame0.elementSnapshots) {
|
|
1123
|
+
for (const [sel, snap] of Object.entries(frame0.elementSnapshots)) {
|
|
1124
|
+
const el = this.elements.get(sel);
|
|
1125
|
+
if (!el || !el.isConnected) continue;
|
|
1126
|
+
if (snap.__styles) {
|
|
1127
|
+
for (const [prop, value] of Object.entries(snap.__styles)) {
|
|
1128
|
+
if (SAFE_PROPS_SET.has(prop)) {
|
|
1129
|
+
el.style.setProperty(prop, value, "important");
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
if (snap.__attrs) {
|
|
1134
|
+
for (const [attr, value] of Object.entries(snap.__attrs)) {
|
|
1135
|
+
if (attr === "checked") {
|
|
1136
|
+
;
|
|
1137
|
+
el.checked = value === "true";
|
|
1138
|
+
} else if (attr === "class" && value != null) {
|
|
1139
|
+
el.className = value;
|
|
1140
|
+
} else if (attr === "style") {
|
|
1141
|
+
} else if (attr === "value" && value != null) {
|
|
1142
|
+
;
|
|
1143
|
+
el.value = value;
|
|
1144
|
+
} else if (value == null) {
|
|
1145
|
+
el.removeAttribute(attr);
|
|
1146
|
+
} else {
|
|
1147
|
+
el.setAttribute(attr, value);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
const duration = this.frames.length > 0 ? this.frames[this.frames.length - 1].time : 0;
|
|
1155
|
+
const capture = {
|
|
1156
|
+
startTime: this.startTime,
|
|
1157
|
+
endTime: performance.now(),
|
|
1158
|
+
duration,
|
|
1159
|
+
animations: Array.from(this.animations.values()),
|
|
1160
|
+
frames: this.frames,
|
|
1161
|
+
boundingBox: this.boundingBox
|
|
1162
|
+
};
|
|
1163
|
+
return capture;
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
// ---- Recording limits ---------------------------------------------------
|
|
1167
|
+
_TimelineRecorder.MAX_DURATION_MS = 6e4;
|
|
1168
|
+
_TimelineRecorder.MAX_FRAMES = 3600;
|
|
1169
|
+
var TimelineRecorder = _TimelineRecorder;
|
|
1170
|
+
|
|
1171
|
+
// src/core/scrubber.ts
|
|
1172
|
+
var TimelineScrubber = class {
|
|
1173
|
+
constructor(state) {
|
|
1174
|
+
/** Saved originals for restore on release */
|
|
1175
|
+
this._originalAnimate = null;
|
|
1176
|
+
this._originalRaf = null;
|
|
1177
|
+
this._originalRemoveChild = null;
|
|
1178
|
+
this._originalRemove = null;
|
|
1179
|
+
this.elements = state.elements;
|
|
1180
|
+
this.frames = state.frames;
|
|
1181
|
+
this.capturedPortals = state.capturedPortals;
|
|
1182
|
+
this.interceptedAnimations = state.interceptedAnimations;
|
|
1183
|
+
this.SAFE_PROPS_SET = state.SAFE_PROPS_SET;
|
|
1184
|
+
this._originalAnimate = window.__LAPSE_ORIGINAL_ANIMATE__ ?? null;
|
|
1185
|
+
this._originalRaf = window.__LAPSE_ORIGINAL_RAF__ ?? null;
|
|
1186
|
+
this._originalRemoveChild = window.__LAPSE_TIMELINE__?._removeChild ?? null;
|
|
1187
|
+
this._originalRemove = window.__LAPSE_TIMELINE__?._remove ?? null;
|
|
1188
|
+
}
|
|
1189
|
+
// ---------------------------------------------------------------------------
|
|
1190
|
+
// Selector helper — mirrors the recorder's getSelector so we can look up
|
|
1191
|
+
// elements by the same key the recorder used in frame.animations[].animationId
|
|
1192
|
+
// ---------------------------------------------------------------------------
|
|
1193
|
+
getSelector(el) {
|
|
1194
|
+
if (!el || !el.tagName) return null;
|
|
1195
|
+
const parts = [];
|
|
1196
|
+
let current = el;
|
|
1197
|
+
for (let i = 0; i < 5 && current && current.tagName && current.tagName !== "HTML"; i++) {
|
|
1198
|
+
const tag = current.tagName.toLowerCase();
|
|
1199
|
+
const parent = current.parentElement;
|
|
1200
|
+
if (parent) {
|
|
1201
|
+
const siblings = Array.from(parent.children);
|
|
1202
|
+
const idx = siblings.indexOf(current) + 1;
|
|
1203
|
+
parts.unshift(`${tag}:nth-child(${idx})`);
|
|
1204
|
+
} else {
|
|
1205
|
+
parts.unshift(tag);
|
|
1206
|
+
}
|
|
1207
|
+
current = parent;
|
|
1208
|
+
}
|
|
1209
|
+
return parts.join(" > ");
|
|
1210
|
+
}
|
|
1211
|
+
// ---------------------------------------------------------------------------
|
|
1212
|
+
// seekTo — scrub the DOM to match a specific timestamp
|
|
1213
|
+
// ---------------------------------------------------------------------------
|
|
1214
|
+
seekTo(timeMs) {
|
|
1215
|
+
if (!this.frames.length) return;
|
|
1216
|
+
let lo = 0;
|
|
1217
|
+
let hi = this.frames.length - 1;
|
|
1218
|
+
while (lo < hi) {
|
|
1219
|
+
const mid = lo + hi >> 1;
|
|
1220
|
+
if (this.frames[mid].time < timeMs) lo = mid + 1;
|
|
1221
|
+
else hi = mid;
|
|
1222
|
+
}
|
|
1223
|
+
const frame = this.frames[lo];
|
|
1224
|
+
if (!frame || !frame.elementSnapshots) return;
|
|
1225
|
+
document.querySelectorAll("[data-lapse-hover]").forEach((el) => {
|
|
1226
|
+
el.removeAttribute("data-lapse-hover");
|
|
1227
|
+
});
|
|
1228
|
+
document.querySelectorAll("[data-lapse-focus]").forEach((el) => {
|
|
1229
|
+
el.removeAttribute("data-lapse-focus");
|
|
1230
|
+
});
|
|
1231
|
+
const activeIds = new Set(frame.activePortalIds || []);
|
|
1232
|
+
for (const id of this.capturedPortals) {
|
|
1233
|
+
const portalEl = document.querySelector(
|
|
1234
|
+
`[data-lapse-portal-id="${id}"]`
|
|
1235
|
+
);
|
|
1236
|
+
if (!portalEl) continue;
|
|
1237
|
+
if (activeIds.has(id)) {
|
|
1238
|
+
portalEl.style.removeProperty("display");
|
|
1239
|
+
portalEl.removeAttribute("data-lapse-portal-hidden");
|
|
1240
|
+
} else {
|
|
1241
|
+
portalEl.style.setProperty("display", "none", "important");
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
const hoveredSels = frame.hoveredSels || [];
|
|
1245
|
+
for (const sel of hoveredSels) {
|
|
1246
|
+
const el = this.elements.get(sel);
|
|
1247
|
+
if (el && el.isConnected) el.setAttribute("data-lapse-hover", "");
|
|
1248
|
+
}
|
|
1249
|
+
if (frame.focusSel) {
|
|
1250
|
+
const focusEl = this.elements.get(frame.focusSel);
|
|
1251
|
+
if (focusEl && focusEl.isConnected) {
|
|
1252
|
+
focusEl.setAttribute("data-lapse-focus", "");
|
|
1253
|
+
let parent = focusEl.parentElement;
|
|
1254
|
+
while (parent && parent !== document.body) {
|
|
1255
|
+
parent.setAttribute("data-lapse-focus", "");
|
|
1256
|
+
parent = parent.parentElement;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
for (const entry of this.interceptedAnimations) {
|
|
1261
|
+
try {
|
|
1262
|
+
const anim = entry.animation;
|
|
1263
|
+
if (anim.playState !== "finished") {
|
|
1264
|
+
anim.pause();
|
|
1265
|
+
}
|
|
1266
|
+
anim.currentTime = timeMs;
|
|
1267
|
+
} catch {
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
for (const [sel, snap] of Object.entries(frame.elementSnapshots)) {
|
|
1271
|
+
const el = this.elements.get(sel);
|
|
1272
|
+
if (!el || !el.isConnected) continue;
|
|
1273
|
+
if (el.closest?.("[data-lapse-panel]")) continue;
|
|
1274
|
+
const hasAnimation = (frame.animations || []).some(
|
|
1275
|
+
(a) => a.animationId.endsWith(":" + sel) || a.animationId.includes(":" + sel.split(" > ").pop())
|
|
1276
|
+
);
|
|
1277
|
+
const snapTyped = snap;
|
|
1278
|
+
if (snapTyped.__styles) {
|
|
1279
|
+
for (const [prop, value] of Object.entries(snapTyped.__styles)) {
|
|
1280
|
+
if (this.SAFE_PROPS_SET.has(prop) || hasAnimation) {
|
|
1281
|
+
el.style.setProperty(prop, value, "important");
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if (snapTyped.__attrs) {
|
|
1286
|
+
for (const [attr, value] of Object.entries(snapTyped.__attrs)) {
|
|
1287
|
+
if (attr === "checked") {
|
|
1288
|
+
;
|
|
1289
|
+
el.checked = value === "true";
|
|
1290
|
+
} else if (attr === "class") {
|
|
1291
|
+
if (value != null) el.className = value;
|
|
1292
|
+
} else if (attr === "style") {
|
|
1293
|
+
if (value) {
|
|
1294
|
+
el.setAttribute("style", value);
|
|
1295
|
+
el.style.transition = "none";
|
|
1296
|
+
if (snapTyped.__styles) {
|
|
1297
|
+
for (const [prop, val] of Object.entries(snapTyped.__styles)) {
|
|
1298
|
+
el.style.setProperty(prop, val, "important");
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
} else if (attr === "value") {
|
|
1303
|
+
if (value != null) el.value = value;
|
|
1304
|
+
} else if (value == null) {
|
|
1305
|
+
el.removeAttribute(attr);
|
|
1306
|
+
} else {
|
|
1307
|
+
el.setAttribute(attr, value);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
for (const anim of frame.animations || []) {
|
|
1313
|
+
const firstColon = anim.animationId.indexOf(":");
|
|
1314
|
+
const secondColon = anim.animationId.indexOf(":", firstColon + 1);
|
|
1315
|
+
const animSel = secondColon >= 0 ? anim.animationId.substring(secondColon + 1) : "";
|
|
1316
|
+
const animEl = this.elements.get(animSel);
|
|
1317
|
+
if (!animEl || !animEl.isConnected) continue;
|
|
1318
|
+
for (const prop of anim.properties || []) {
|
|
1319
|
+
if (prop.value) {
|
|
1320
|
+
animEl.style.setProperty(prop.property, prop.value, "important");
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
const animatedSels = /* @__PURE__ */ new Set();
|
|
1325
|
+
for (const anim of frame.animations || []) {
|
|
1326
|
+
const fc = anim.animationId.indexOf(":");
|
|
1327
|
+
const sc = anim.animationId.indexOf(":", fc + 1);
|
|
1328
|
+
if (sc >= 0) animatedSels.add(anim.animationId.substring(sc + 1));
|
|
1329
|
+
}
|
|
1330
|
+
document.querySelectorAll(".checkbox-indicator, .radio-indicator").forEach((rawEl) => {
|
|
1331
|
+
const el = rawEl;
|
|
1332
|
+
const sel = this.getSelector(el);
|
|
1333
|
+
if (sel && !animatedSels.has(sel)) {
|
|
1334
|
+
el.style.removeProperty("opacity");
|
|
1335
|
+
el.style.removeProperty("transform");
|
|
1336
|
+
el.style.removeProperty("filter");
|
|
1337
|
+
el.style.removeProperty("stroke-dashoffset");
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
// ---------------------------------------------------------------------------
|
|
1342
|
+
// release — tear down all scrub state and restore the page to normal
|
|
1343
|
+
// ---------------------------------------------------------------------------
|
|
1344
|
+
release() {
|
|
1345
|
+
for (const entry of this.interceptedAnimations) {
|
|
1346
|
+
try {
|
|
1347
|
+
entry.animation.cancel();
|
|
1348
|
+
} catch {
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
this.interceptedAnimations.length = 0;
|
|
1352
|
+
if (this._originalAnimate) {
|
|
1353
|
+
Element.prototype.animate = this._originalAnimate;
|
|
1354
|
+
this._originalAnimate = null;
|
|
1355
|
+
delete window.__LAPSE_ORIGINAL_ANIMATE__;
|
|
1356
|
+
}
|
|
1357
|
+
if (this._originalRaf) {
|
|
1358
|
+
window.requestAnimationFrame = this._originalRaf;
|
|
1359
|
+
this._originalRaf = null;
|
|
1360
|
+
delete window.__LAPSE_ORIGINAL_RAF__;
|
|
1361
|
+
}
|
|
1362
|
+
const tl = window.__LAPSE_TIMELINE__;
|
|
1363
|
+
if (tl?.noTransitionsEl) {
|
|
1364
|
+
tl.noTransitionsEl.remove();
|
|
1365
|
+
}
|
|
1366
|
+
const noTrans = document.getElementById("__lapse-no-transitions");
|
|
1367
|
+
if (noTrans) noTrans.remove();
|
|
1368
|
+
const blocker = document.getElementById("__lapse-scrub-blocker");
|
|
1369
|
+
if (blocker) blocker.remove();
|
|
1370
|
+
if (tl?.blockerEl) tl.blockerEl.remove();
|
|
1371
|
+
const stateRules = document.getElementById("__lapse-state-rules");
|
|
1372
|
+
if (stateRules) stateRules.remove();
|
|
1373
|
+
if (tl?.lapseStyleEl) tl.lapseStyleEl.remove();
|
|
1374
|
+
if (this._originalRemoveChild) {
|
|
1375
|
+
Node.prototype.removeChild = this._originalRemoveChild;
|
|
1376
|
+
this._originalRemoveChild = null;
|
|
1377
|
+
} else if (tl?._removeChild) {
|
|
1378
|
+
Node.prototype.removeChild = tl._removeChild;
|
|
1379
|
+
}
|
|
1380
|
+
if (this._originalRemove) {
|
|
1381
|
+
Element.prototype.remove = this._originalRemove;
|
|
1382
|
+
this._originalRemove = null;
|
|
1383
|
+
} else if (tl?._remove) {
|
|
1384
|
+
Element.prototype.remove = tl._remove;
|
|
1385
|
+
}
|
|
1386
|
+
document.querySelectorAll("[data-lapse-exit-captured]").forEach((el) => {
|
|
1387
|
+
el.remove();
|
|
1388
|
+
});
|
|
1389
|
+
document.querySelectorAll("[data-lapse-id]").forEach((el) => {
|
|
1390
|
+
el.removeAttribute("data-lapse-id");
|
|
1391
|
+
});
|
|
1392
|
+
document.querySelectorAll("[data-lapse-hover]").forEach((el) => {
|
|
1393
|
+
el.removeAttribute("data-lapse-hover");
|
|
1394
|
+
});
|
|
1395
|
+
document.querySelectorAll("[data-lapse-focus]").forEach((el) => {
|
|
1396
|
+
el.removeAttribute("data-lapse-focus");
|
|
1397
|
+
});
|
|
1398
|
+
document.querySelectorAll("[data-lapse-portal-id]").forEach((el) => {
|
|
1399
|
+
el.removeAttribute("data-lapse-portal-id");
|
|
1400
|
+
el.removeAttribute("data-lapse-portal-hidden");
|
|
1401
|
+
});
|
|
1402
|
+
delete window.__LAPSE_TIMELINE__;
|
|
1403
|
+
this.elements.clear();
|
|
1404
|
+
this.frames.length = 0;
|
|
1405
|
+
this.capturedPortals.clear();
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
|
|
1409
|
+
// src/core/export.ts
|
|
1410
|
+
function getFrameAtTime(frames, timeMs) {
|
|
1411
|
+
if (frames.length === 0) return null;
|
|
1412
|
+
let lo = 0;
|
|
1413
|
+
let hi = frames.length - 1;
|
|
1414
|
+
while (lo < hi) {
|
|
1415
|
+
const mid = lo + hi >> 1;
|
|
1416
|
+
if (frames[mid].time < timeMs) lo = mid + 1;
|
|
1417
|
+
else hi = mid;
|
|
1418
|
+
}
|
|
1419
|
+
return frames[lo];
|
|
1420
|
+
}
|
|
1421
|
+
function generateExport(animations, frames, timeMs, filter = "active") {
|
|
1422
|
+
const frame = getFrameAtTime(frames, timeMs);
|
|
1423
|
+
const duration = frames.at(-1)?.time ?? 0;
|
|
1424
|
+
const filteredAnims = animations.filter((anim) => {
|
|
1425
|
+
if (filter === "all-animations") return true;
|
|
1426
|
+
if (filter === "active") {
|
|
1427
|
+
const frameAnim = frame?.animations.find((a) => a.animationId === anim.id);
|
|
1428
|
+
if (!frameAnim || frameAnim.progress <= 0 || frameAnim.progress >= 1) return false;
|
|
1429
|
+
if (frameAnim.properties.length > 0) {
|
|
1430
|
+
const hasRealChange = frameAnim.properties.some(
|
|
1431
|
+
(p) => p.from && p.to && p.from !== p.to
|
|
1432
|
+
);
|
|
1433
|
+
if (!hasRealChange) return false;
|
|
1434
|
+
}
|
|
1435
|
+
return true;
|
|
1436
|
+
}
|
|
1437
|
+
return true;
|
|
1438
|
+
});
|
|
1439
|
+
const animExports = filteredAnims.map((anim) => {
|
|
1440
|
+
let frameAnim = frame?.animations.find((a) => a.animationId === anim.id);
|
|
1441
|
+
let status = frameAnim ? "active" : "completed";
|
|
1442
|
+
if (!frameAnim) {
|
|
1443
|
+
for (let i = frames.length - 1; i >= 0; i--) {
|
|
1444
|
+
if (frames[i].time > timeMs) continue;
|
|
1445
|
+
const found = frames[i].animations.find((a) => a.animationId === anim.id);
|
|
1446
|
+
if (found) {
|
|
1447
|
+
frameAnim = found;
|
|
1448
|
+
break;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
if (!frameAnim) {
|
|
1452
|
+
for (let i = 0; i < frames.length; i++) {
|
|
1453
|
+
if (frames[i].time < timeMs) continue;
|
|
1454
|
+
const found = frames[i].animations.find((a) => a.animationId === anim.id);
|
|
1455
|
+
if (found) {
|
|
1456
|
+
frameAnim = found;
|
|
1457
|
+
status = "upcoming";
|
|
1458
|
+
break;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
const progressLabel = status === "active" ? `${Math.round((frameAnim?.progress ?? 0) * 100)}%` : status === "completed" ? "done" : "upcoming";
|
|
1464
|
+
return {
|
|
1465
|
+
element: anim.selector,
|
|
1466
|
+
elementLabel: anim.elementLabel || anim.selector,
|
|
1467
|
+
name: anim.name || anim.type,
|
|
1468
|
+
type: anim.type,
|
|
1469
|
+
timing: `${Math.round(anim.duration)}ms ${anim.easing}${anim.delay ? ` (delay: ${Math.round(anim.delay)}ms)` : ""}`,
|
|
1470
|
+
progress: progressLabel,
|
|
1471
|
+
properties: (frameAnim?.properties ?? []).map((p) => ({
|
|
1472
|
+
property: p.property,
|
|
1473
|
+
value: p.value,
|
|
1474
|
+
range: p.from && p.to ? `${p.from} \u2192 ${p.to}` : ""
|
|
1475
|
+
})),
|
|
1476
|
+
source: anim.source,
|
|
1477
|
+
resolvedVars: anim.resolvedVars,
|
|
1478
|
+
conflicts: anim.conflicts
|
|
1479
|
+
};
|
|
1480
|
+
});
|
|
1481
|
+
const hoveredElements = Array.isArray(frame?.hoveredSels) ? frame.hoveredSels.map(String) : [];
|
|
1482
|
+
const focusedElement = frame?.focusSel ? String(frame.focusSel) : null;
|
|
1483
|
+
return {
|
|
1484
|
+
timestamp: `${Math.round(timeMs)}ms into ${Math.round(duration)}ms recording`,
|
|
1485
|
+
duration: `${Math.round(duration)}ms`,
|
|
1486
|
+
scrubPosition: timeMs,
|
|
1487
|
+
hoveredElements,
|
|
1488
|
+
focusedElement,
|
|
1489
|
+
animations: animExports
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
function formatExportForLLM(exp, detail = "standard") {
|
|
1493
|
+
const lines = [];
|
|
1494
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
1495
|
+
for (const anim of exp.animations) {
|
|
1496
|
+
const key = (anim.elementLabel || "") + "|||" + anim.element;
|
|
1497
|
+
if (!grouped.has(key)) {
|
|
1498
|
+
grouped.set(key, { label: anim.elementLabel || "", selector: anim.element, anims: [] });
|
|
1499
|
+
}
|
|
1500
|
+
grouped.get(key).anims.push(anim);
|
|
1501
|
+
}
|
|
1502
|
+
function isRealChange(prop) {
|
|
1503
|
+
if (!prop.range) return true;
|
|
1504
|
+
const [from, to] = prop.range.split(" \u2192 ");
|
|
1505
|
+
return !(from && to && from.trim() === to.trim());
|
|
1506
|
+
}
|
|
1507
|
+
if (detail === "compact") {
|
|
1508
|
+
lines.push(`# Animation State at ${exp.timestamp}`);
|
|
1509
|
+
lines.push("");
|
|
1510
|
+
for (const [, group] of grouped) {
|
|
1511
|
+
const label = group.label && group.label !== group.selector ? `**${group.label}** \`${group.selector}\`` : `\`${group.selector}\``;
|
|
1512
|
+
const cssAnims = group.anims.filter((a) => a.type !== "JSAnimation");
|
|
1513
|
+
const jsAnims = group.anims.filter((a) => a.type === "JSAnimation");
|
|
1514
|
+
if (cssAnims.length > 0) {
|
|
1515
|
+
const props = /* @__PURE__ */ new Set();
|
|
1516
|
+
for (const a of cssAnims) a.properties.filter(isRealChange).forEach((p) => props.add(p.property));
|
|
1517
|
+
const timing = cssAnims[0]?.timing || "";
|
|
1518
|
+
const progress = cssAnims[0]?.progress || "";
|
|
1519
|
+
const progressStr = progress && progress !== "unknown" ? ` @ ${progress}` : "";
|
|
1520
|
+
lines.push(`- ${label}: ${[...props].join(", ")} (${timing}${progressStr})`);
|
|
1521
|
+
}
|
|
1522
|
+
if (jsAnims.length > 0) {
|
|
1523
|
+
const props = /* @__PURE__ */ new Set();
|
|
1524
|
+
for (const a of jsAnims) a.properties.filter(isRealChange).forEach((p) => props.add(p.property));
|
|
1525
|
+
if (props.size > 0) lines.push(`- ${label}: ${[...props].join(", ")} (JS)`);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return lines.join("\n");
|
|
1529
|
+
}
|
|
1530
|
+
lines.push(`# Animation State at ${exp.timestamp}`);
|
|
1531
|
+
lines.push("");
|
|
1532
|
+
if (detail === "forensic") {
|
|
1533
|
+
lines.push("**Environment:**");
|
|
1534
|
+
lines.push(`- Viewport: ${window.innerWidth}\xD7${window.innerHeight}`);
|
|
1535
|
+
lines.push(`- URL: ${window.location.href}`);
|
|
1536
|
+
lines.push(`- User Agent: ${navigator.userAgent}`);
|
|
1537
|
+
lines.push(`- Timestamp: ${(/* @__PURE__ */ new Date()).toISOString()}`);
|
|
1538
|
+
lines.push(`- Device Pixel Ratio: ${window.devicePixelRatio}`);
|
|
1539
|
+
lines.push("");
|
|
1540
|
+
}
|
|
1541
|
+
if (exp.hoveredElements.length > 0 || exp.focusedElement) {
|
|
1542
|
+
lines.push("**Interaction state:**");
|
|
1543
|
+
if (exp.hoveredElements.length > 0) {
|
|
1544
|
+
const deepest = exp.hoveredElements[exp.hoveredElements.length - 1] || exp.hoveredElements[0];
|
|
1545
|
+
lines.push(`- Hovered: \`${deepest}\``);
|
|
1546
|
+
}
|
|
1547
|
+
if (exp.focusedElement) {
|
|
1548
|
+
lines.push(`- Focused: \`${exp.focusedElement}\``);
|
|
1549
|
+
}
|
|
1550
|
+
lines.push("");
|
|
1551
|
+
}
|
|
1552
|
+
if (exp.animations.length === 0 && exp.hoveredElements.length === 0 && !exp.focusedElement) {
|
|
1553
|
+
lines.push("No active animations or interactions at this position.");
|
|
1554
|
+
return lines.join("\n");
|
|
1555
|
+
}
|
|
1556
|
+
if (exp.animations.length === 0) {
|
|
1557
|
+
return lines.join("\n");
|
|
1558
|
+
}
|
|
1559
|
+
for (const [, group] of grouped) {
|
|
1560
|
+
const label = group.label && group.label !== group.selector ? `"${group.label}" ` : "";
|
|
1561
|
+
const cssAnims = group.anims.filter((a) => a.type !== "JSAnimation");
|
|
1562
|
+
const jsAnims = group.anims.filter((a) => a.type === "JSAnimation");
|
|
1563
|
+
const cssPropLines = [];
|
|
1564
|
+
if (cssAnims.length > 0) {
|
|
1565
|
+
const seenProps = /* @__PURE__ */ new Set();
|
|
1566
|
+
for (const anim of cssAnims) {
|
|
1567
|
+
const progressStr = anim.progress !== "unknown" ? ` @ ${anim.progress}` : "";
|
|
1568
|
+
for (const prop of anim.properties) {
|
|
1569
|
+
if (seenProps.has(prop.property)) continue;
|
|
1570
|
+
if (!isRealChange(prop)) continue;
|
|
1571
|
+
seenProps.add(prop.property);
|
|
1572
|
+
let line = `- \`${prop.property}\`: ${prop.value}`;
|
|
1573
|
+
if (prop.range) line += ` [${prop.range}]`;
|
|
1574
|
+
line += ` (${anim.timing}${progressStr})`;
|
|
1575
|
+
cssPropLines.push(line);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
const jsPropLines = [];
|
|
1580
|
+
if (jsAnims.length > 0) {
|
|
1581
|
+
const seenProps = /* @__PURE__ */ new Set();
|
|
1582
|
+
for (const anim of jsAnims) {
|
|
1583
|
+
for (const prop of anim.properties) {
|
|
1584
|
+
if (seenProps.has(prop.property)) continue;
|
|
1585
|
+
if (!isRealChange(prop)) continue;
|
|
1586
|
+
seenProps.add(prop.property);
|
|
1587
|
+
jsPropLines.push(`- \`${prop.property}\`: ${prop.value}`);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
if (cssPropLines.length === 0 && jsPropLines.length === 0) continue;
|
|
1592
|
+
lines.push(`## ${label}\`${group.selector}\``);
|
|
1593
|
+
lines.push("");
|
|
1594
|
+
if (cssPropLines.length > 0) {
|
|
1595
|
+
const transitionSet = new Set(cssAnims.map((a) => `${a.name} ${a.timing}`));
|
|
1596
|
+
lines.push(`Transitions: ${[...transitionSet].join(", ")}`);
|
|
1597
|
+
lines.push("");
|
|
1598
|
+
for (const line of cssPropLines) lines.push(line);
|
|
1599
|
+
if (detail === "detailed" || detail === "forensic") {
|
|
1600
|
+
const allVars = {};
|
|
1601
|
+
for (const anim of cssAnims) {
|
|
1602
|
+
if (anim.resolvedVars) Object.assign(allVars, anim.resolvedVars);
|
|
1603
|
+
}
|
|
1604
|
+
if (Object.keys(allVars).length > 0) {
|
|
1605
|
+
lines.push("");
|
|
1606
|
+
lines.push("CSS variables:");
|
|
1607
|
+
for (const [name, value] of Object.entries(allVars)) {
|
|
1608
|
+
lines.push(`- \`${name}\`: ${value}`);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
for (const anim of cssAnims) {
|
|
1612
|
+
if (anim.source) {
|
|
1613
|
+
lines.push("");
|
|
1614
|
+
lines.push("```css");
|
|
1615
|
+
lines.push(anim.source);
|
|
1616
|
+
lines.push("```");
|
|
1617
|
+
break;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
if (jsPropLines.length > 0) {
|
|
1623
|
+
if (cssPropLines.length > 0) lines.push("");
|
|
1624
|
+
for (const line of jsPropLines) lines.push(line);
|
|
1625
|
+
}
|
|
1626
|
+
lines.push("");
|
|
1627
|
+
}
|
|
1628
|
+
return lines.join("\n");
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// src/core/engine.ts
|
|
1632
|
+
var LapseEngine = class {
|
|
1633
|
+
constructor() {
|
|
1634
|
+
this.timing = new TimingController();
|
|
1635
|
+
this.recorder = new TimelineRecorder();
|
|
1636
|
+
this.scrubber = null;
|
|
1637
|
+
this.capture = null;
|
|
1638
|
+
this._state = "idle";
|
|
1639
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
1640
|
+
}
|
|
1641
|
+
get state() {
|
|
1642
|
+
return this._state;
|
|
1643
|
+
}
|
|
1644
|
+
getCapture() {
|
|
1645
|
+
return this.capture;
|
|
1646
|
+
}
|
|
1647
|
+
// -- Speed control --------------------------------------------------------
|
|
1648
|
+
setSpeed(speed) {
|
|
1649
|
+
this.timing.setSpeed(speed);
|
|
1650
|
+
}
|
|
1651
|
+
getSpeed() {
|
|
1652
|
+
return this.timing.getSpeed();
|
|
1653
|
+
}
|
|
1654
|
+
// -- Timeline recording ---------------------------------------------------
|
|
1655
|
+
startRecording(boundingBox) {
|
|
1656
|
+
if (this._state !== "idle") return;
|
|
1657
|
+
this.timing.install();
|
|
1658
|
+
this.recorder.onAutoStop = () => this.stopRecording();
|
|
1659
|
+
this.recorder.startRecording(boundingBox);
|
|
1660
|
+
this._state = "recording";
|
|
1661
|
+
this.notify();
|
|
1662
|
+
}
|
|
1663
|
+
stopRecording() {
|
|
1664
|
+
if (this._state !== "recording") {
|
|
1665
|
+
return {
|
|
1666
|
+
startTime: 0,
|
|
1667
|
+
endTime: 0,
|
|
1668
|
+
duration: 0,
|
|
1669
|
+
animations: [],
|
|
1670
|
+
frames: [],
|
|
1671
|
+
boundingBox: null
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
const capture = this.recorder.stopRecording();
|
|
1675
|
+
this.capture = capture;
|
|
1676
|
+
const scrubberState = {
|
|
1677
|
+
elements: this.recorder.elements,
|
|
1678
|
+
frames: capture.frames,
|
|
1679
|
+
capturedPortals: this.recorder.capturedPortalIds,
|
|
1680
|
+
interceptedAnimations: this.recorder.interceptedAnimations,
|
|
1681
|
+
SAFE_PROPS_SET: this.recorder.SAFE_PROPS_SET
|
|
1682
|
+
};
|
|
1683
|
+
this.scrubber = new TimelineScrubber(scrubberState);
|
|
1684
|
+
this._state = "scrubbing";
|
|
1685
|
+
this.notify();
|
|
1686
|
+
return capture;
|
|
1687
|
+
}
|
|
1688
|
+
// -- Scrubbing ------------------------------------------------------------
|
|
1689
|
+
seekTo(timeMs) {
|
|
1690
|
+
this.scrubber?.seekTo(timeMs);
|
|
1691
|
+
}
|
|
1692
|
+
release() {
|
|
1693
|
+
this.scrubber?.release();
|
|
1694
|
+
this.scrubber = null;
|
|
1695
|
+
this.capture = null;
|
|
1696
|
+
this._state = "idle";
|
|
1697
|
+
this.notify();
|
|
1698
|
+
}
|
|
1699
|
+
// -- Export ---------------------------------------------------------------
|
|
1700
|
+
generateExport(timeMs, filter = "active") {
|
|
1701
|
+
if (!this.capture) return null;
|
|
1702
|
+
return generateExport(
|
|
1703
|
+
this.capture.animations,
|
|
1704
|
+
this.capture.frames,
|
|
1705
|
+
timeMs,
|
|
1706
|
+
filter
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1709
|
+
exportForLLM(timeMs, filter = "active", detail = "standard") {
|
|
1710
|
+
const exp = this.generateExport(timeMs, filter);
|
|
1711
|
+
if (!exp) return "";
|
|
1712
|
+
return formatExportForLLM(exp, detail);
|
|
1713
|
+
}
|
|
1714
|
+
// -- State subscription ---------------------------------------------------
|
|
1715
|
+
subscribe(listener) {
|
|
1716
|
+
this.listeners.add(listener);
|
|
1717
|
+
return () => this.listeners.delete(listener);
|
|
1718
|
+
}
|
|
1719
|
+
notify() {
|
|
1720
|
+
for (const listener of this.listeners) {
|
|
1721
|
+
listener();
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
// -- Cleanup --------------------------------------------------------------
|
|
1725
|
+
destroy() {
|
|
1726
|
+
this.scrubber?.release();
|
|
1727
|
+
this.scrubber = null;
|
|
1728
|
+
this.capture = null;
|
|
1729
|
+
this.timing.destroy();
|
|
1730
|
+
this._state = "idle";
|
|
1731
|
+
}
|
|
1732
|
+
};
|
|
1733
|
+
|
|
1734
|
+
// src/react/LapseContext.tsx
|
|
1735
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1736
|
+
var LapseContext = (0, import_react.createContext)(null);
|
|
1737
|
+
function LapseProvider({ children }) {
|
|
1738
|
+
const engineRef = (0, import_react.useRef)(null);
|
|
1739
|
+
if (!engineRef.current) {
|
|
1740
|
+
engineRef.current = new LapseEngine();
|
|
1741
|
+
}
|
|
1742
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LapseContext.Provider, { value: engineRef.current, children });
|
|
1743
|
+
}
|
|
1744
|
+
function useLapseEngine() {
|
|
1745
|
+
const engine = (0, import_react.useContext)(LapseContext);
|
|
1746
|
+
if (!engine) throw new Error("useLapseEngine must be used within <LapseProvider>");
|
|
1747
|
+
return engine;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// src/react/LapsePanel.tsx
|
|
1751
|
+
var import_react6 = require("react");
|
|
1752
|
+
|
|
1753
|
+
// src/react/Timeline.tsx
|
|
1754
|
+
var import_react2 = require("react");
|
|
1755
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1756
|
+
var DETAIL_LABELS = {
|
|
1757
|
+
compact: "Compact",
|
|
1758
|
+
standard: "Standard",
|
|
1759
|
+
detailed: "Detailed",
|
|
1760
|
+
forensic: "Forensic"
|
|
1761
|
+
};
|
|
1762
|
+
function CopyCheckIcon({ copied }) {
|
|
1763
|
+
const spring = "cubic-bezier(0.34, 1.15, 0.64, 1)";
|
|
1764
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: [
|
|
1765
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1766
|
+
"path",
|
|
1767
|
+
{
|
|
1768
|
+
stroke: "currentColor",
|
|
1769
|
+
strokeWidth: "2",
|
|
1770
|
+
d: "M7 4v-.5A1.5 1.5 0 0 1 8.5 2h4A1.5 1.5 0 0 1 14 3.5v4A1.5 1.5 0 0 1 12.5 9H12",
|
|
1771
|
+
style: {
|
|
1772
|
+
opacity: copied ? 0 : 1,
|
|
1773
|
+
transition: copied ? "opacity 0.1s ease-out" : "opacity 0.15s ease-out 0.18s"
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
),
|
|
1777
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1778
|
+
"rect",
|
|
1779
|
+
{
|
|
1780
|
+
stroke: copied ? "#33C664" : "currentColor",
|
|
1781
|
+
fill: "none",
|
|
1782
|
+
style: {
|
|
1783
|
+
x: copied ? 1.5 : 2,
|
|
1784
|
+
y: copied ? 1.5 : 7,
|
|
1785
|
+
width: copied ? 13 : 7,
|
|
1786
|
+
height: copied ? 13 : 7,
|
|
1787
|
+
rx: copied ? 6.5 : 1.5,
|
|
1788
|
+
ry: copied ? 6.5 : 1.5,
|
|
1789
|
+
strokeWidth: 2,
|
|
1790
|
+
transition: copied ? `x 0.28s ${spring}, y 0.28s ${spring}, width 0.28s ${spring}, height 0.28s ${spring}, rx 0.28s ${spring}, ry 0.28s ${spring}` : "x 0.22s ease-in-out, y 0.22s ease-in-out, width 0.22s ease-in-out, height 0.22s ease-in-out, rx 0.22s ease-in-out, ry 0.22s ease-in-out"
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
),
|
|
1794
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1795
|
+
"path",
|
|
1796
|
+
{
|
|
1797
|
+
d: "m5.5 8.5 2 1.5 2.75-3.75",
|
|
1798
|
+
stroke: copied ? "#33C664" : "currentColor",
|
|
1799
|
+
strokeWidth: "2",
|
|
1800
|
+
strokeLinecap: "round",
|
|
1801
|
+
strokeLinejoin: "round",
|
|
1802
|
+
fill: "none",
|
|
1803
|
+
style: {
|
|
1804
|
+
strokeDasharray: 12,
|
|
1805
|
+
strokeDashoffset: copied ? 0 : 12,
|
|
1806
|
+
opacity: copied ? 1 : 0,
|
|
1807
|
+
transition: copied ? "stroke-dashoffset 0.25s ease-out 0.1s, opacity 0.08s ease-out 0.08s" : "stroke-dashoffset 0.12s ease-in, opacity 0.08s ease-in"
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
)
|
|
1811
|
+
] });
|
|
1812
|
+
}
|
|
1813
|
+
var DETAIL_BRIGHT_COUNT = {
|
|
1814
|
+
compact: 1,
|
|
1815
|
+
standard: 2,
|
|
1816
|
+
detailed: 3,
|
|
1817
|
+
forensic: 4
|
|
1818
|
+
};
|
|
1819
|
+
function DetailIcon({ level }) {
|
|
1820
|
+
const bright = DETAIL_BRIGHT_COUNT[level];
|
|
1821
|
+
const ys = [2, 6, 10, 14];
|
|
1822
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: ys.map((y, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1823
|
+
"path",
|
|
1824
|
+
{
|
|
1825
|
+
stroke: "currentColor",
|
|
1826
|
+
strokeLinecap: "round",
|
|
1827
|
+
strokeWidth: "2",
|
|
1828
|
+
d: "M2 0h12",
|
|
1829
|
+
transform: `translate(0, ${y})`,
|
|
1830
|
+
style: {
|
|
1831
|
+
opacity: i < bright ? 1 : 0.4,
|
|
1832
|
+
transition: "opacity 0.2s ease-out"
|
|
1833
|
+
}
|
|
1834
|
+
},
|
|
1835
|
+
y
|
|
1836
|
+
)) });
|
|
1837
|
+
}
|
|
1838
|
+
function Timeline({
|
|
1839
|
+
state,
|
|
1840
|
+
capture,
|
|
1841
|
+
scrubTime,
|
|
1842
|
+
copied,
|
|
1843
|
+
onStartRecording,
|
|
1844
|
+
onStopRecording,
|
|
1845
|
+
onSeek,
|
|
1846
|
+
onRelease,
|
|
1847
|
+
onExportLLM,
|
|
1848
|
+
detailLevel,
|
|
1849
|
+
onCycleDetailLevel
|
|
1850
|
+
}) {
|
|
1851
|
+
const scrubberRef = (0, import_react2.useRef)(null);
|
|
1852
|
+
const isDragging = (0, import_react2.useRef)(false);
|
|
1853
|
+
const [hasLeftRecord, setHasLeftRecord] = (0, import_react2.useState)(false);
|
|
1854
|
+
(0, import_react2.useEffect)(() => {
|
|
1855
|
+
if (state === "recording") setHasLeftRecord(false);
|
|
1856
|
+
}, [state]);
|
|
1857
|
+
const handleScrub = (0, import_react2.useCallback)(
|
|
1858
|
+
(e) => {
|
|
1859
|
+
if (!capture || !scrubberRef.current) return;
|
|
1860
|
+
const rect = scrubberRef.current.getBoundingClientRect();
|
|
1861
|
+
const x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
1862
|
+
onSeek(x * capture.duration);
|
|
1863
|
+
},
|
|
1864
|
+
[capture, onSeek]
|
|
1865
|
+
);
|
|
1866
|
+
const handleMouseDown = (0, import_react2.useCallback)(
|
|
1867
|
+
(e) => {
|
|
1868
|
+
isDragging.current = true;
|
|
1869
|
+
handleScrub(e);
|
|
1870
|
+
const handleMouseMove = (e2) => {
|
|
1871
|
+
if (!isDragging.current || !capture || !scrubberRef.current) return;
|
|
1872
|
+
const rect = scrubberRef.current.getBoundingClientRect();
|
|
1873
|
+
const x = Math.max(0, Math.min(1, (e2.clientX - rect.left) / rect.width));
|
|
1874
|
+
onSeek(x * capture.duration);
|
|
1875
|
+
};
|
|
1876
|
+
const handleMouseUp = () => {
|
|
1877
|
+
isDragging.current = false;
|
|
1878
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
1879
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
1880
|
+
};
|
|
1881
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
1882
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
1883
|
+
},
|
|
1884
|
+
[capture, handleScrub, onSeek]
|
|
1885
|
+
);
|
|
1886
|
+
const progress = capture && capture.duration > 0 ? scrubTime / capture.duration : 0;
|
|
1887
|
+
const isScrubbing = state === "scrubbing";
|
|
1888
|
+
const isRecording = state === "recording";
|
|
1889
|
+
function handleMainClick() {
|
|
1890
|
+
if (state === "idle") onStartRecording();
|
|
1891
|
+
else if (state === "recording") onStopRecording();
|
|
1892
|
+
else if (state === "scrubbing") onRelease();
|
|
1893
|
+
}
|
|
1894
|
+
const tooltip = state === "idle" ? "Record" : state === "recording" ? "Stop" : "Clear";
|
|
1895
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1896
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1897
|
+
"button",
|
|
1898
|
+
{
|
|
1899
|
+
onClick: handleMainClick,
|
|
1900
|
+
className: `lapse-btn lapse-btn-icon lapse-main-btn ${isRecording ? "lapse-record-btn--active" : ""}`,
|
|
1901
|
+
"data-tooltip": tooltip,
|
|
1902
|
+
onMouseLeave: isRecording ? () => setHasLeftRecord(true) : void 0,
|
|
1903
|
+
children: [
|
|
1904
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1905
|
+
"svg",
|
|
1906
|
+
{
|
|
1907
|
+
width: "16",
|
|
1908
|
+
height: "16",
|
|
1909
|
+
viewBox: "0 0 16 16",
|
|
1910
|
+
fill: "none",
|
|
1911
|
+
className: `lapse-morph-icon ${state === "idle" ? "lapse-morph-icon--active" : ""}`,
|
|
1912
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { fill: "currentColor", d: "M8 .5a7.5 7.5 0 1 1 0 15 7.5 7.5 0 0 1 0-15Zm0 2a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11Z" })
|
|
1913
|
+
}
|
|
1914
|
+
),
|
|
1915
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1916
|
+
"svg",
|
|
1917
|
+
{
|
|
1918
|
+
width: "16",
|
|
1919
|
+
height: "16",
|
|
1920
|
+
viewBox: "0 0 16 16",
|
|
1921
|
+
fill: "none",
|
|
1922
|
+
className: `lapse-morph-icon ${isRecording ? "lapse-morph-icon--active" : ""}`,
|
|
1923
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1924
|
+
"rect",
|
|
1925
|
+
{
|
|
1926
|
+
x: hasLeftRecord ? "1.5" : "0.5",
|
|
1927
|
+
y: hasLeftRecord ? "1.5" : "0.5",
|
|
1928
|
+
width: hasLeftRecord ? "13" : "15",
|
|
1929
|
+
height: hasLeftRecord ? "13" : "15",
|
|
1930
|
+
rx: hasLeftRecord ? "3" : "7.5",
|
|
1931
|
+
fill: "currentColor",
|
|
1932
|
+
className: "lapse-record-shape"
|
|
1933
|
+
}
|
|
1934
|
+
)
|
|
1935
|
+
}
|
|
1936
|
+
),
|
|
1937
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1938
|
+
"svg",
|
|
1939
|
+
{
|
|
1940
|
+
width: "16",
|
|
1941
|
+
height: "16",
|
|
1942
|
+
viewBox: "0 0 16 16",
|
|
1943
|
+
fill: "none",
|
|
1944
|
+
className: `lapse-morph-icon ${isScrubbing ? "lapse-morph-icon--active" : ""}`,
|
|
1945
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "m5.5 3-3 3m0 0h7a3.5 3.5 0 1 1 0 7h-2m-5-7 3 3" })
|
|
1946
|
+
}
|
|
1947
|
+
)
|
|
1948
|
+
]
|
|
1949
|
+
}
|
|
1950
|
+
),
|
|
1951
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: `lapse-scrub-wrap ${isScrubbing ? "lapse-scrub-wrap--visible" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "lapse-scrub-inner", children: [
|
|
1952
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1953
|
+
"div",
|
|
1954
|
+
{
|
|
1955
|
+
ref: scrubberRef,
|
|
1956
|
+
onMouseDown: handleMouseDown,
|
|
1957
|
+
className: "lapse-scrub-track",
|
|
1958
|
+
children: [
|
|
1959
|
+
capture && capture.duration > 0 && (() => {
|
|
1960
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1961
|
+
const times = [];
|
|
1962
|
+
for (const frame of capture.frames) {
|
|
1963
|
+
if (!frame.animations) continue;
|
|
1964
|
+
for (const fa of frame.animations) {
|
|
1965
|
+
if (!seen.has(fa.animationId)) {
|
|
1966
|
+
seen.add(fa.animationId);
|
|
1967
|
+
times.push(frame.time);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
times.sort((a, b) => a - b);
|
|
1972
|
+
const clusters = [];
|
|
1973
|
+
for (const t of times) {
|
|
1974
|
+
const last = clusters[clusters.length - 1];
|
|
1975
|
+
if (last && t - last.time < 200) {
|
|
1976
|
+
last.count++;
|
|
1977
|
+
} else {
|
|
1978
|
+
clusters.push({ time: t, count: 1 });
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
return clusters.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1982
|
+
"div",
|
|
1983
|
+
{
|
|
1984
|
+
className: "lapse-scrub-marker",
|
|
1985
|
+
style: { left: `${c.time / capture.duration * 100}%` }
|
|
1986
|
+
},
|
|
1987
|
+
i
|
|
1988
|
+
));
|
|
1989
|
+
})(),
|
|
1990
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "lapse-scrub-fill", style: { width: `calc(${progress * 100}% + 4px)` } }),
|
|
1991
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "lapse-scrub-playhead", style: { left: `clamp(4px, ${progress * 100}%, calc(100% - 4px))` } }),
|
|
1992
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "lapse-scrub-label", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
1993
|
+
Math.round(scrubTime),
|
|
1994
|
+
"ms / ",
|
|
1995
|
+
Math.round(capture?.duration ?? 0),
|
|
1996
|
+
"ms"
|
|
1997
|
+
] }) })
|
|
1998
|
+
]
|
|
1999
|
+
}
|
|
2000
|
+
),
|
|
2001
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2002
|
+
"button",
|
|
2003
|
+
{
|
|
2004
|
+
onClick: onCycleDetailLevel,
|
|
2005
|
+
className: "lapse-btn lapse-btn-icon",
|
|
2006
|
+
"data-tooltip": DETAIL_LABELS[detailLevel],
|
|
2007
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DetailIcon, { level: detailLevel })
|
|
2008
|
+
}
|
|
2009
|
+
),
|
|
2010
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { onClick: onExportLLM, className: "lapse-btn lapse-btn-icon", "data-tooltip": copied ? "Copied!" : "Copy", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopyCheckIcon, { copied }) })
|
|
2011
|
+
] }) })
|
|
2012
|
+
] });
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
// src/react/SpeedControl.tsx
|
|
2016
|
+
var import_react3 = require("react");
|
|
2017
|
+
|
|
2018
|
+
// src/react/constants.ts
|
|
2019
|
+
var SPEED_PRESETS = [0.1, 0.25, 0.5, 0.75, 1];
|
|
2020
|
+
var SPEED_MIN = 0.05;
|
|
2021
|
+
var SPEED_MAX = 5;
|
|
2022
|
+
function formatSpeed(speed) {
|
|
2023
|
+
if (speed >= 0.1) return `${speed}\xD7`;
|
|
2024
|
+
return `${speed.toFixed(2)}\xD7`;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
// src/react/SpeedControl.tsx
|
|
2028
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2029
|
+
var SPEEDS = [1, 0.75, 0.5, 0.25, 0.1];
|
|
2030
|
+
var SPEED_ANGLES = {
|
|
2031
|
+
0.1: 225,
|
|
2032
|
+
// 7 o'clock
|
|
2033
|
+
0.25: 315,
|
|
2034
|
+
// 10 o'clock
|
|
2035
|
+
0.5: 0,
|
|
2036
|
+
// 12 o'clock
|
|
2037
|
+
0.75: 45,
|
|
2038
|
+
// 2 o'clock
|
|
2039
|
+
1: 135
|
|
2040
|
+
// 4 o'clock
|
|
2041
|
+
};
|
|
2042
|
+
var HAND_PATHS = {
|
|
2043
|
+
0.1: "M7.293 5.293a1 1 0 1 1 1.414 1.414l-1.5 1.5a1 1 0 1 1-1.414-1.414l1.5-1.5Z",
|
|
2044
|
+
0.25: "M5.793 5.794a1 1 0 0 1 1.414 0l1.5 1.499a1 1 0 0 1-1.414 1.414l-1.5-1.499a1 1 0 0 1 0-1.414Z",
|
|
2045
|
+
0.5: "M8 5a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0V6a1 1 0 0 1 1-1Z",
|
|
2046
|
+
0.75: "M8.793 5.293a1 1 0 0 1 1.414 1.414l-1.5 1.5a1 1 0 0 1-1.414-1.414l1.5-1.5Z",
|
|
2047
|
+
1: "M7.293 8.293a1 1 0 0 1 1.414 0l1.5 1.5a1 1 0 1 1-1.414 1.414l-1.5-1.5a1 1 0 0 1 0-1.414Z"
|
|
2048
|
+
};
|
|
2049
|
+
function SpeedControl({ speed, isPaused, onSetSpeed, onTogglePause }) {
|
|
2050
|
+
const currentIndex = SPEEDS.findIndex((s) => Math.abs(speed - s) < 1e-3);
|
|
2051
|
+
const activeIndex = currentIndex >= 0 ? currentIndex : 0;
|
|
2052
|
+
const prevAngleRef = (0, import_react3.useRef)(SPEED_ANGLES[SPEEDS[activeIndex]]);
|
|
2053
|
+
const cumulativeRef = (0, import_react3.useRef)(SPEED_ANGLES[SPEEDS[activeIndex]]);
|
|
2054
|
+
const directionRef = (0, import_react3.useRef)(1);
|
|
2055
|
+
const forceClockwiseRef = (0, import_react3.useRef)(false);
|
|
2056
|
+
function cycle() {
|
|
2057
|
+
if (isPaused) {
|
|
2058
|
+
onTogglePause();
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
let next = activeIndex + directionRef.current;
|
|
2062
|
+
if (next >= SPEEDS.length) {
|
|
2063
|
+
directionRef.current = -1;
|
|
2064
|
+
next = activeIndex - 1;
|
|
2065
|
+
} else if (next < 0) {
|
|
2066
|
+
directionRef.current = 1;
|
|
2067
|
+
next = activeIndex + 1;
|
|
2068
|
+
}
|
|
2069
|
+
onSetSpeed(SPEEDS[next]);
|
|
2070
|
+
}
|
|
2071
|
+
const targetAngle = isPaused ? 180 : SPEED_ANGLES[SPEEDS[activeIndex]] ?? 135;
|
|
2072
|
+
if (targetAngle !== prevAngleRef.current) {
|
|
2073
|
+
let delta = targetAngle - prevAngleRef.current;
|
|
2074
|
+
if (isPaused) {
|
|
2075
|
+
while (delta >= 0) delta -= 360;
|
|
2076
|
+
} else if (forceClockwiseRef.current) {
|
|
2077
|
+
while (delta <= 0) delta += 360;
|
|
2078
|
+
forceClockwiseRef.current = false;
|
|
2079
|
+
} else {
|
|
2080
|
+
while (delta > 180) delta -= 360;
|
|
2081
|
+
while (delta < -180) delta += 360;
|
|
2082
|
+
}
|
|
2083
|
+
cumulativeRef.current += delta;
|
|
2084
|
+
prevAngleRef.current = targetAngle;
|
|
2085
|
+
}
|
|
2086
|
+
const holdTimerRef = (0, import_react3.useRef)(null);
|
|
2087
|
+
const didHoldRef = (0, import_react3.useRef)(false);
|
|
2088
|
+
const startHold = (0, import_react3.useCallback)(() => {
|
|
2089
|
+
didHoldRef.current = false;
|
|
2090
|
+
holdTimerRef.current = setTimeout(() => {
|
|
2091
|
+
didHoldRef.current = true;
|
|
2092
|
+
forceClockwiseRef.current = true;
|
|
2093
|
+
directionRef.current = 1;
|
|
2094
|
+
onSetSpeed(1);
|
|
2095
|
+
}, 240);
|
|
2096
|
+
}, [onSetSpeed]);
|
|
2097
|
+
const endHold = (0, import_react3.useCallback)(() => {
|
|
2098
|
+
if (holdTimerRef.current) clearTimeout(holdTimerRef.current);
|
|
2099
|
+
holdTimerRef.current = null;
|
|
2100
|
+
}, []);
|
|
2101
|
+
const handleClick = (0, import_react3.useCallback)(() => {
|
|
2102
|
+
if (didHoldRef.current) {
|
|
2103
|
+
didHoldRef.current = false;
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
cycle();
|
|
2107
|
+
}, [cycle]);
|
|
2108
|
+
const currentSpeed = SPEEDS[activeIndex];
|
|
2109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "lapse-speed", children: [
|
|
2110
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2111
|
+
"button",
|
|
2112
|
+
{
|
|
2113
|
+
onClick: onTogglePause,
|
|
2114
|
+
className: "lapse-btn lapse-btn-icon lapse-playpause",
|
|
2115
|
+
"data-tooltip": isPaused ? "Play" : "Pause",
|
|
2116
|
+
children: [
|
|
2117
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", className: `lapse-playpause-icon ${isPaused ? "lapse-playpause-icon--active" : ""}`, style: { marginLeft: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2", d: "M3 12.821V3.18a1 1 0 0 1 1.476-.88l8.9 4.822a1 1 0 0 1 0 1.758l-8.9 4.821A1 1 0 0 1 3 12.821Z" }) }),
|
|
2118
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", className: `lapse-playpause-icon ${!isPaused ? "lapse-playpause-icon--active" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { stroke: "currentColor", strokeLinecap: "round", strokeWidth: "2", d: "M3.5 2.5v11m9-11v11" }) })
|
|
2119
|
+
]
|
|
2120
|
+
}
|
|
2121
|
+
),
|
|
2122
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2123
|
+
"button",
|
|
2124
|
+
{
|
|
2125
|
+
onClick: handleClick,
|
|
2126
|
+
onMouseDown: startHold,
|
|
2127
|
+
onMouseUp: endHold,
|
|
2128
|
+
onMouseLeave: endHold,
|
|
2129
|
+
className: "lapse-speed-cycle",
|
|
2130
|
+
"data-tooltip": formatSpeed(speed),
|
|
2131
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", className: "lapse-speed-clock", children: [
|
|
2132
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { fill: "currentColor", d: "M8 .5a7.5 7.5 0 1 1 0 15 7.5 7.5 0 0 1 0-15Zm0 2a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11Z" }),
|
|
2133
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("g", { style: { transform: `rotate(${cumulativeRef.current}deg)`, transformOrigin: "8px 8px", transition: "transform 0.4s cubic-bezier(0, 0.55, 0.45, 1)" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { fill: "currentColor", d: HAND_PATHS[0.5] }) })
|
|
2134
|
+
] })
|
|
2135
|
+
}
|
|
2136
|
+
)
|
|
2137
|
+
] });
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
// src/react/useTimeline.ts
|
|
2141
|
+
var import_react4 = require("react");
|
|
2142
|
+
var DETAIL_LEVELS = ["compact", "standard", "detailed", "forensic"];
|
|
2143
|
+
function useTimeline() {
|
|
2144
|
+
const engine = useLapseEngine();
|
|
2145
|
+
const state = (0, import_react4.useSyncExternalStore)(
|
|
2146
|
+
(cb) => engine.subscribe(cb),
|
|
2147
|
+
() => engine.state
|
|
2148
|
+
);
|
|
2149
|
+
const [capture, setCapture] = (0, import_react4.useState)(null);
|
|
2150
|
+
const [scrubTime, setScrubTime] = (0, import_react4.useState)(0);
|
|
2151
|
+
const [copied, setCopied] = (0, import_react4.useState)(false);
|
|
2152
|
+
const [exportFilter, setExportFilter] = (0, import_react4.useState)("all-animations");
|
|
2153
|
+
const [detailLevel, setDetailLevel] = (0, import_react4.useState)("standard");
|
|
2154
|
+
const copiedTimeout = (0, import_react4.useRef)(null);
|
|
2155
|
+
const pendingSeek = (0, import_react4.useRef)(null);
|
|
2156
|
+
const rafId = (0, import_react4.useRef)(0);
|
|
2157
|
+
(0, import_react4.useEffect)(() => {
|
|
2158
|
+
if (state === "scrubbing" && !capture) {
|
|
2159
|
+
const engineCapture = engine.getCapture();
|
|
2160
|
+
if (engineCapture) {
|
|
2161
|
+
setCapture(engineCapture);
|
|
2162
|
+
setScrubTime(0);
|
|
2163
|
+
}
|
|
2164
|
+
} else if (state === "idle") {
|
|
2165
|
+
setCapture(null);
|
|
2166
|
+
setScrubTime(0);
|
|
2167
|
+
}
|
|
2168
|
+
}, [state, capture, engine]);
|
|
2169
|
+
const startRecording = (0, import_react4.useCallback)(
|
|
2170
|
+
(boundingBox) => {
|
|
2171
|
+
setCapture(null);
|
|
2172
|
+
setScrubTime(0);
|
|
2173
|
+
engine.startRecording(boundingBox);
|
|
2174
|
+
},
|
|
2175
|
+
[engine]
|
|
2176
|
+
);
|
|
2177
|
+
const stopRecording = (0, import_react4.useCallback)(() => {
|
|
2178
|
+
const result = engine.stopRecording();
|
|
2179
|
+
setCapture(result);
|
|
2180
|
+
setScrubTime(0);
|
|
2181
|
+
}, [engine]);
|
|
2182
|
+
const seek = (0, import_react4.useCallback)(
|
|
2183
|
+
(timeMs) => {
|
|
2184
|
+
setScrubTime(timeMs);
|
|
2185
|
+
pendingSeek.current = timeMs;
|
|
2186
|
+
if (!rafId.current) {
|
|
2187
|
+
rafId.current = requestAnimationFrame(() => {
|
|
2188
|
+
rafId.current = 0;
|
|
2189
|
+
if (pendingSeek.current !== null) {
|
|
2190
|
+
engine.seekTo(pendingSeek.current);
|
|
2191
|
+
pendingSeek.current = null;
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
},
|
|
2196
|
+
[engine]
|
|
2197
|
+
);
|
|
2198
|
+
const release = (0, import_react4.useCallback)(() => {
|
|
2199
|
+
if (rafId.current) {
|
|
2200
|
+
cancelAnimationFrame(rafId.current);
|
|
2201
|
+
rafId.current = 0;
|
|
2202
|
+
}
|
|
2203
|
+
pendingSeek.current = null;
|
|
2204
|
+
engine.release();
|
|
2205
|
+
setCapture(null);
|
|
2206
|
+
setScrubTime(0);
|
|
2207
|
+
}, [engine]);
|
|
2208
|
+
const cycleDetailLevel = (0, import_react4.useCallback)(() => {
|
|
2209
|
+
setDetailLevel((prev) => {
|
|
2210
|
+
const idx = DETAIL_LEVELS.indexOf(prev);
|
|
2211
|
+
return DETAIL_LEVELS[(idx + 1) % DETAIL_LEVELS.length];
|
|
2212
|
+
});
|
|
2213
|
+
}, []);
|
|
2214
|
+
const exportLLM = (0, import_react4.useCallback)(
|
|
2215
|
+
(filter) => {
|
|
2216
|
+
if (!capture) return "";
|
|
2217
|
+
const f = filter || exportFilter || "active";
|
|
2218
|
+
const t = Number(scrubTime) || 0;
|
|
2219
|
+
const text = engine.exportForLLM(t, f, detailLevel);
|
|
2220
|
+
navigator.clipboard.writeText(text).catch(() => {
|
|
2221
|
+
});
|
|
2222
|
+
setCopied(true);
|
|
2223
|
+
if (copiedTimeout.current) clearTimeout(copiedTimeout.current);
|
|
2224
|
+
copiedTimeout.current = setTimeout(() => setCopied(false), 2e3);
|
|
2225
|
+
return text;
|
|
2226
|
+
},
|
|
2227
|
+
[engine, capture, scrubTime, exportFilter, detailLevel]
|
|
2228
|
+
);
|
|
2229
|
+
return {
|
|
2230
|
+
state,
|
|
2231
|
+
capture,
|
|
2232
|
+
scrubTime,
|
|
2233
|
+
copied,
|
|
2234
|
+
exportFilter,
|
|
2235
|
+
setExportFilter,
|
|
2236
|
+
detailLevel,
|
|
2237
|
+
cycleDetailLevel,
|
|
2238
|
+
startRecording,
|
|
2239
|
+
stopRecording,
|
|
2240
|
+
seek,
|
|
2241
|
+
release,
|
|
2242
|
+
exportLLM
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
// src/react/useSpeed.ts
|
|
2247
|
+
var import_react5 = require("react");
|
|
2248
|
+
function useSpeed() {
|
|
2249
|
+
const engine = useLapseEngine();
|
|
2250
|
+
const [speed, setSpeedState] = (0, import_react5.useState)(1);
|
|
2251
|
+
const [previousSpeed, setPreviousSpeed] = (0, import_react5.useState)(1);
|
|
2252
|
+
const [isPaused, setIsPaused] = (0, import_react5.useState)(false);
|
|
2253
|
+
const setSpeed = (0, import_react5.useCallback)(
|
|
2254
|
+
(value) => {
|
|
2255
|
+
const clamped = Math.max(SPEED_MIN, Math.min(SPEED_MAX, value));
|
|
2256
|
+
setSpeedState(clamped);
|
|
2257
|
+
setIsPaused(false);
|
|
2258
|
+
setPreviousSpeed(clamped);
|
|
2259
|
+
engine.setSpeed(clamped);
|
|
2260
|
+
},
|
|
2261
|
+
[engine]
|
|
2262
|
+
);
|
|
2263
|
+
const togglePause = (0, import_react5.useCallback)(() => {
|
|
2264
|
+
if (isPaused) {
|
|
2265
|
+
setSpeedState(previousSpeed);
|
|
2266
|
+
setIsPaused(false);
|
|
2267
|
+
engine.setSpeed(previousSpeed);
|
|
2268
|
+
} else {
|
|
2269
|
+
setPreviousSpeed(speed);
|
|
2270
|
+
setSpeedState(0);
|
|
2271
|
+
setIsPaused(true);
|
|
2272
|
+
engine.setSpeed(0);
|
|
2273
|
+
}
|
|
2274
|
+
}, [engine, isPaused, previousSpeed, speed]);
|
|
2275
|
+
const stepDown = (0, import_react5.useCallback)(() => {
|
|
2276
|
+
const currentIndex = SPEED_PRESETS.findIndex((p) => p >= speed);
|
|
2277
|
+
const nextIndex = Math.max(0, (currentIndex <= 0 ? 1 : currentIndex) - 1);
|
|
2278
|
+
setSpeed(SPEED_PRESETS[nextIndex]);
|
|
2279
|
+
}, [speed, setSpeed]);
|
|
2280
|
+
const stepUp = (0, import_react5.useCallback)(() => {
|
|
2281
|
+
const currentIndex = SPEED_PRESETS.findIndex((p) => p > speed);
|
|
2282
|
+
const nextIndex = Math.min(
|
|
2283
|
+
SPEED_PRESETS.length - 1,
|
|
2284
|
+
currentIndex < 0 ? SPEED_PRESETS.length - 1 : currentIndex
|
|
2285
|
+
);
|
|
2286
|
+
setSpeed(SPEED_PRESETS[nextIndex]);
|
|
2287
|
+
}, [speed, setSpeed]);
|
|
2288
|
+
(0, import_react5.useEffect)(() => {
|
|
2289
|
+
function handleKeyDown(e) {
|
|
2290
|
+
if (e.target instanceof HTMLInputElement) return;
|
|
2291
|
+
switch (e.key) {
|
|
2292
|
+
case "[":
|
|
2293
|
+
stepDown();
|
|
2294
|
+
break;
|
|
2295
|
+
case "]":
|
|
2296
|
+
stepUp();
|
|
2297
|
+
break;
|
|
2298
|
+
case "\\":
|
|
2299
|
+
setSpeed(1);
|
|
2300
|
+
break;
|
|
2301
|
+
case "s":
|
|
2302
|
+
togglePause();
|
|
2303
|
+
break;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
2307
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2308
|
+
}, [stepDown, stepUp, setSpeed, togglePause]);
|
|
2309
|
+
return { speed, isPaused, setSpeed, togglePause };
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// src/react/LapsePanel.tsx
|
|
2313
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
2314
|
+
function LapsePanel() {
|
|
2315
|
+
const timeline = useTimeline();
|
|
2316
|
+
const { speed, isPaused, setSpeed, togglePause } = useSpeed();
|
|
2317
|
+
const panelRef = (0, import_react6.useRef)(null);
|
|
2318
|
+
const warmTimeout = (0, import_react6.useRef)(null);
|
|
2319
|
+
const handleMouseOver = (0, import_react6.useCallback)((e) => {
|
|
2320
|
+
const target = e.target.closest?.("[data-tooltip]");
|
|
2321
|
+
if (target && panelRef.current) {
|
|
2322
|
+
panelRef.current.classList.add("lapse-tooltip-warm");
|
|
2323
|
+
if (warmTimeout.current) clearTimeout(warmTimeout.current);
|
|
2324
|
+
}
|
|
2325
|
+
}, []);
|
|
2326
|
+
const handleMouseOut = (0, import_react6.useCallback)((e) => {
|
|
2327
|
+
const related = e.relatedTarget;
|
|
2328
|
+
const stillOnTooltip = related?.closest?.("[data-tooltip]");
|
|
2329
|
+
if (!stillOnTooltip) {
|
|
2330
|
+
warmTimeout.current = setTimeout(() => {
|
|
2331
|
+
panelRef.current?.classList.remove("lapse-tooltip-warm");
|
|
2332
|
+
}, 300);
|
|
2333
|
+
}
|
|
2334
|
+
}, []);
|
|
2335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2336
|
+
"div",
|
|
2337
|
+
{
|
|
2338
|
+
ref: panelRef,
|
|
2339
|
+
className: "lapse-panel",
|
|
2340
|
+
onMouseOver: handleMouseOver,
|
|
2341
|
+
onMouseOut: handleMouseOut,
|
|
2342
|
+
children: [
|
|
2343
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2344
|
+
Timeline,
|
|
2345
|
+
{
|
|
2346
|
+
state: timeline.state,
|
|
2347
|
+
capture: timeline.capture,
|
|
2348
|
+
scrubTime: timeline.scrubTime,
|
|
2349
|
+
copied: timeline.copied,
|
|
2350
|
+
exportFilter: timeline.exportFilter,
|
|
2351
|
+
onSetExportFilter: timeline.setExportFilter,
|
|
2352
|
+
onStartRecording: () => timeline.startRecording(),
|
|
2353
|
+
onStopRecording: timeline.stopRecording,
|
|
2354
|
+
onSeek: timeline.seek,
|
|
2355
|
+
onRelease: timeline.release,
|
|
2356
|
+
onExportLLM: () => timeline.exportLLM(),
|
|
2357
|
+
detailLevel: timeline.detailLevel,
|
|
2358
|
+
onCycleDetailLevel: timeline.cycleDetailLevel
|
|
2359
|
+
}
|
|
2360
|
+
),
|
|
2361
|
+
timeline.state !== "scrubbing" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `lapse-speed-wrap ${timeline.state === "recording" ? "lapse-speed-wrap--hidden" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2362
|
+
SpeedControl,
|
|
2363
|
+
{
|
|
2364
|
+
speed,
|
|
2365
|
+
isPaused,
|
|
2366
|
+
onSetSpeed: setSpeed,
|
|
2367
|
+
onTogglePause: togglePause
|
|
2368
|
+
}
|
|
2369
|
+
) })
|
|
2370
|
+
]
|
|
2371
|
+
}
|
|
2372
|
+
);
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
// src/react/styles.ts
|
|
2376
|
+
var PANEL_STYLES = (
|
|
2377
|
+
/* css */
|
|
2378
|
+
`
|
|
2379
|
+
:host {
|
|
2380
|
+
--lapse-bg: #1a1a1a;
|
|
2381
|
+
--lapse-surface: #2a2a2a;
|
|
2382
|
+
--lapse-border: #3a3a3a;
|
|
2383
|
+
--lapse-text: #e5e5e5;
|
|
2384
|
+
--lapse-text-muted: #888;
|
|
2385
|
+
--lapse-accent: #6d9fff;
|
|
2386
|
+
--lapse-speed-active: #5b8def;
|
|
2387
|
+
--lapse-danger: #ff6b6b;
|
|
2388
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
2389
|
+
font-size: 13px;
|
|
2390
|
+
line-height: 1.4;
|
|
2391
|
+
color: var(--lapse-text);
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
*, *::before, *::after {
|
|
2395
|
+
box-sizing: border-box;
|
|
2396
|
+
margin: 0;
|
|
2397
|
+
padding: 0;
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
/* Tooltips */
|
|
2401
|
+
[data-tooltip] {
|
|
2402
|
+
position: relative;
|
|
2403
|
+
}
|
|
2404
|
+
[data-tooltip]::after {
|
|
2405
|
+
content: attr(data-tooltip);
|
|
2406
|
+
position: absolute;
|
|
2407
|
+
bottom: calc(100% + 8px);
|
|
2408
|
+
left: 50%;
|
|
2409
|
+
transform: translateX(-50%) translateY(2px) scale(0.96);
|
|
2410
|
+
padding: 4px 10px;
|
|
2411
|
+
border-radius: 6px;
|
|
2412
|
+
background: #0d0d0d;
|
|
2413
|
+
border: 0.5px solid var(--lapse-border);
|
|
2414
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
2415
|
+
color: var(--lapse-text);
|
|
2416
|
+
font-size: 11px;
|
|
2417
|
+
font-weight: 500;
|
|
2418
|
+
white-space: nowrap;
|
|
2419
|
+
pointer-events: none;
|
|
2420
|
+
opacity: 0;
|
|
2421
|
+
transition: opacity 0.15s ease-out 0.65s, transform 0.15s ease-out 0.65s;
|
|
2422
|
+
}
|
|
2423
|
+
[data-tooltip]:hover::after {
|
|
2424
|
+
opacity: 1;
|
|
2425
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
2426
|
+
}
|
|
2427
|
+
/* Warm: when panel already has a tooltip showing, new ones appear instantly */
|
|
2428
|
+
.lapse-panel.lapse-tooltip-warm [data-tooltip]::after {
|
|
2429
|
+
transition-duration: 0s;
|
|
2430
|
+
transition-delay: 0s;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
/* Panel container */
|
|
2434
|
+
.lapse-panel {
|
|
2435
|
+
display: flex;
|
|
2436
|
+
align-items: center;
|
|
2437
|
+
gap: 0;
|
|
2438
|
+
background: var(--lapse-bg);
|
|
2439
|
+
border: 0.5px solid var(--lapse-border);
|
|
2440
|
+
border-radius: 999px;
|
|
2441
|
+
padding: 4px;
|
|
2442
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.1);
|
|
2443
|
+
overflow: visible;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
/* Buttons */
|
|
2447
|
+
.lapse-btn {
|
|
2448
|
+
display: flex;
|
|
2449
|
+
align-items: center;
|
|
2450
|
+
gap: 6px;
|
|
2451
|
+
height: 32px;
|
|
2452
|
+
padding: 0 12px;
|
|
2453
|
+
border: none;
|
|
2454
|
+
border-radius: 999px;
|
|
2455
|
+
font-size: 13px;
|
|
2456
|
+
font-weight: 500;
|
|
2457
|
+
cursor: pointer;
|
|
2458
|
+
white-space: nowrap;
|
|
2459
|
+
transition: background 0.15s, color 0.15s;
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
.lapse-btn-surface {
|
|
2463
|
+
background: transparent;
|
|
2464
|
+
color: var(--lapse-text-muted);
|
|
2465
|
+
}
|
|
2466
|
+
.lapse-btn-surface:hover {
|
|
2467
|
+
background: var(--lapse-surface);
|
|
2468
|
+
color: var(--lapse-text);
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
.lapse-btn-recording {
|
|
2472
|
+
background: rgba(239, 68, 68, 0.1);
|
|
2473
|
+
color: #f87171;
|
|
2474
|
+
}
|
|
2475
|
+
.lapse-btn-recording:hover { background: rgba(239, 68, 68, 0.2); }
|
|
2476
|
+
|
|
2477
|
+
.lapse-btn-accent {
|
|
2478
|
+
background: rgba(109, 159, 255, 0.2);
|
|
2479
|
+
color: var(--lapse-accent);
|
|
2480
|
+
font-size: 13px;
|
|
2481
|
+
}
|
|
2482
|
+
.lapse-btn-accent:hover { background: rgba(109, 159, 255, 0.3); }
|
|
2483
|
+
|
|
2484
|
+
.lapse-btn-icon {
|
|
2485
|
+
width: 32px;
|
|
2486
|
+
height: 32px;
|
|
2487
|
+
padding: 0;
|
|
2488
|
+
justify-content: center;
|
|
2489
|
+
background: transparent;
|
|
2490
|
+
color: var(--lapse-text-muted);
|
|
2491
|
+
border: none;
|
|
2492
|
+
border-radius: 999px;
|
|
2493
|
+
cursor: pointer;
|
|
2494
|
+
transition: background 0.15s, color 0.15s;
|
|
2495
|
+
}
|
|
2496
|
+
.lapse-btn-icon:hover {
|
|
2497
|
+
background: var(--lapse-surface);
|
|
2498
|
+
color: var(--lapse-text);
|
|
2499
|
+
}
|
|
2500
|
+
.lapse-record-btn--active:hover {
|
|
2501
|
+
color: #ef4444;
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
/* Main button \u2014 icon morphing (record / recording / close) */
|
|
2505
|
+
.lapse-main-btn {
|
|
2506
|
+
position: relative;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
.lapse-morph-icon {
|
|
2510
|
+
position: absolute;
|
|
2511
|
+
opacity: 0;
|
|
2512
|
+
scale: 0.4;
|
|
2513
|
+
filter: blur(6px);
|
|
2514
|
+
transition: opacity 0.2s ease, scale 0.2s ease, filter 0.2s ease;
|
|
2515
|
+
display: block;
|
|
2516
|
+
}
|
|
2517
|
+
.lapse-morph-icon--active {
|
|
2518
|
+
opacity: 1;
|
|
2519
|
+
scale: 1;
|
|
2520
|
+
filter: blur(0);
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
.lapse-record-shape {
|
|
2524
|
+
animation: lapse-pulse 1.5s ease-in-out infinite;
|
|
2525
|
+
transition: x 0.4s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2526
|
+
y 0.4s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2527
|
+
width 0.4s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2528
|
+
height 0.4s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2529
|
+
rx 0.4s cubic-bezier(0.19, 1, 0.22, 1);
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
.lapse-record-btn--active {
|
|
2533
|
+
color: #ef4444;
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
@keyframes lapse-pulse {
|
|
2537
|
+
0%, 100% { opacity: 1; }
|
|
2538
|
+
50% { opacity: 0.5; }
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
/* Scrub content \u2014 expands when entering scrubbing state */
|
|
2542
|
+
.lapse-scrub-wrap {
|
|
2543
|
+
display: grid;
|
|
2544
|
+
grid-template-columns: 0fr;
|
|
2545
|
+
margin-left: 0;
|
|
2546
|
+
transition: grid-template-columns 0.4s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2547
|
+
margin-left 0.4s cubic-bezier(0.19, 1, 0.22, 1);
|
|
2548
|
+
}
|
|
2549
|
+
.lapse-scrub-wrap > * {
|
|
2550
|
+
min-width: 0;
|
|
2551
|
+
}
|
|
2552
|
+
.lapse-scrub-wrap--visible {
|
|
2553
|
+
grid-template-columns: 1fr;
|
|
2554
|
+
margin-left: 6px;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
.lapse-scrub-inner {
|
|
2558
|
+
display: flex;
|
|
2559
|
+
align-items: center;
|
|
2560
|
+
gap: 6px;
|
|
2561
|
+
}
|
|
2562
|
+
.lapse-scrub-inner > * {
|
|
2563
|
+
transform-origin: left center;
|
|
2564
|
+
transition: opacity 0.6s cubic-bezier(0.19, 1, 0.22, 1) 0.05s,
|
|
2565
|
+
transform 0.6s cubic-bezier(0.19, 1, 0.22, 1) 0.05s,
|
|
2566
|
+
filter 0.8s cubic-bezier(0.19, 1, 0.22, 1) 0.05s;
|
|
2567
|
+
}
|
|
2568
|
+
.lapse-scrub-wrap:not(.lapse-scrub-wrap--visible) .lapse-scrub-inner > * {
|
|
2569
|
+
opacity: 0;
|
|
2570
|
+
transform: scale(0.85);
|
|
2571
|
+
filter: blur(10px);
|
|
2572
|
+
transition-delay: 0ms;
|
|
2573
|
+
transition-duration: 0.15s;
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
/* Spinner */
|
|
2577
|
+
.lapse-spinner {
|
|
2578
|
+
width: 10px;
|
|
2579
|
+
height: 10px;
|
|
2580
|
+
animation: lapse-spin 1s linear infinite;
|
|
2581
|
+
}
|
|
2582
|
+
.lapse-spinner-track { opacity: 0.25; }
|
|
2583
|
+
.lapse-spinner-head { opacity: 0.75; }
|
|
2584
|
+
|
|
2585
|
+
@keyframes lapse-spin {
|
|
2586
|
+
from { transform: rotate(0deg); }
|
|
2587
|
+
to { transform: rotate(360deg); }
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
/* Scrubber */
|
|
2591
|
+
.lapse-scrub-track {
|
|
2592
|
+
position: relative;
|
|
2593
|
+
height: 32px;
|
|
2594
|
+
width: 200px;
|
|
2595
|
+
cursor: pointer;
|
|
2596
|
+
border-radius: 6px;
|
|
2597
|
+
background: var(--lapse-surface);
|
|
2598
|
+
user-select: none;
|
|
2599
|
+
overflow: hidden;
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
.lapse-scrub-marker {
|
|
2603
|
+
position: absolute;
|
|
2604
|
+
top: 0;
|
|
2605
|
+
height: 100%;
|
|
2606
|
+
width: 1px;
|
|
2607
|
+
background: rgba(109, 159, 255, 0.5);
|
|
2608
|
+
pointer-events: none;
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
.lapse-scrub-fill {
|
|
2612
|
+
position: absolute;
|
|
2613
|
+
inset: 0;
|
|
2614
|
+
right: auto;
|
|
2615
|
+
background: rgba(109, 159, 255, 0.1);
|
|
2616
|
+
pointer-events: none;
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
.lapse-scrub-playhead {
|
|
2620
|
+
position: absolute;
|
|
2621
|
+
top: 4px;
|
|
2622
|
+
bottom: 4px;
|
|
2623
|
+
width: 2px;
|
|
2624
|
+
border-radius: 1px;
|
|
2625
|
+
background: var(--lapse-accent);
|
|
2626
|
+
transform: translateX(-50%);
|
|
2627
|
+
pointer-events: none;
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
.lapse-scrub-label {
|
|
2631
|
+
position: absolute;
|
|
2632
|
+
inset: 0;
|
|
2633
|
+
display: flex;
|
|
2634
|
+
align-items: flex-end;
|
|
2635
|
+
justify-content: center;
|
|
2636
|
+
padding-bottom: 2px;
|
|
2637
|
+
pointer-events: none;
|
|
2638
|
+
}
|
|
2639
|
+
.lapse-scrub-label span {
|
|
2640
|
+
font-size: 13px;
|
|
2641
|
+
font-variant-numeric: tabular-nums;
|
|
2642
|
+
color: var(--lapse-text-muted);
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
/* Filter buttons */
|
|
2646
|
+
.lapse-filter-group {
|
|
2647
|
+
display: flex;
|
|
2648
|
+
border-radius: 6px;
|
|
2649
|
+
background: var(--lapse-surface);
|
|
2650
|
+
overflow: hidden;
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
.lapse-filter-btn {
|
|
2654
|
+
height: 32px;
|
|
2655
|
+
padding: 0 8px;
|
|
2656
|
+
border: none;
|
|
2657
|
+
background: transparent;
|
|
2658
|
+
font-size: 13px;
|
|
2659
|
+
font-weight: 500;
|
|
2660
|
+
color: var(--lapse-text-muted);
|
|
2661
|
+
cursor: pointer;
|
|
2662
|
+
transition: background 0.15s, color 0.15s;
|
|
2663
|
+
}
|
|
2664
|
+
.lapse-filter-btn:hover { color: var(--lapse-text); }
|
|
2665
|
+
.lapse-filter-btn--active {
|
|
2666
|
+
background: rgba(109, 159, 255, 0.2);
|
|
2667
|
+
color: var(--lapse-accent);
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2670
|
+
/* Chevron */
|
|
2671
|
+
.lapse-chevron {
|
|
2672
|
+
transition: transform 0.2s;
|
|
2673
|
+
}
|
|
2674
|
+
.lapse-chevron--open {
|
|
2675
|
+
transform: rotate(90deg);
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
/* Animation tags */
|
|
2679
|
+
.lapse-anim-tags {
|
|
2680
|
+
display: flex;
|
|
2681
|
+
flex-wrap: wrap;
|
|
2682
|
+
gap: 6px;
|
|
2683
|
+
}
|
|
2684
|
+
.lapse-anim-tag {
|
|
2685
|
+
background: rgba(109, 159, 255, 0.1);
|
|
2686
|
+
color: var(--lapse-accent);
|
|
2687
|
+
padding: 2px 6px;
|
|
2688
|
+
border-radius: 4px;
|
|
2689
|
+
font-size: 13px;
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
/* Speed control wrapper \u2014 collapses when recording */
|
|
2693
|
+
.lapse-speed-wrap {
|
|
2694
|
+
display: grid;
|
|
2695
|
+
grid-template-columns: 1fr;
|
|
2696
|
+
margin-left: 6px;
|
|
2697
|
+
transition: grid-template-columns 0.4s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2698
|
+
margin-left 0.4s cubic-bezier(0.19, 1, 0.22, 1);
|
|
2699
|
+
}
|
|
2700
|
+
.lapse-speed-wrap > * {
|
|
2701
|
+
min-width: 0;
|
|
2702
|
+
}
|
|
2703
|
+
.lapse-speed-wrap--hidden {
|
|
2704
|
+
grid-template-columns: 0fr;
|
|
2705
|
+
margin-left: 0;
|
|
2706
|
+
pointer-events: none;
|
|
2707
|
+
}
|
|
2708
|
+
.lapse-speed-wrap .lapse-speed {
|
|
2709
|
+
transition: transform 0.6s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2710
|
+
filter 0.8s cubic-bezier(0.19, 1, 0.22, 1),
|
|
2711
|
+
opacity 0.6s cubic-bezier(0.19, 1, 0.22, 1);
|
|
2712
|
+
}
|
|
2713
|
+
.lapse-speed-wrap--hidden .lapse-speed {
|
|
2714
|
+
transform: translateX(-8px) scale(0.4);
|
|
2715
|
+
filter: blur(10px);
|
|
2716
|
+
opacity: 0;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
/* Speed control */
|
|
2720
|
+
.lapse-speed {
|
|
2721
|
+
display: flex;
|
|
2722
|
+
align-items: center;
|
|
2723
|
+
gap: 6px;
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
/* Speed cycle button */
|
|
2727
|
+
.lapse-speed-cycle {
|
|
2728
|
+
display: flex;
|
|
2729
|
+
align-items: center;
|
|
2730
|
+
gap: 6px;
|
|
2731
|
+
height: 32px;
|
|
2732
|
+
padding: 0 8px;
|
|
2733
|
+
border: none;
|
|
2734
|
+
border-radius: 999px;
|
|
2735
|
+
background: transparent;
|
|
2736
|
+
color: var(--lapse-text-muted);
|
|
2737
|
+
font-size: 13px;
|
|
2738
|
+
font-weight: 500;
|
|
2739
|
+
cursor: pointer;
|
|
2740
|
+
transition: background 0.15s, color 0.15s;
|
|
2741
|
+
white-space: nowrap;
|
|
2742
|
+
}
|
|
2743
|
+
.lapse-speed-cycle:hover {
|
|
2744
|
+
background: var(--lapse-surface);
|
|
2745
|
+
color: var(--lapse-text);
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
/* Play/pause transition */
|
|
2749
|
+
.lapse-playpause {
|
|
2750
|
+
position: relative;
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
.lapse-playpause-icon {
|
|
2754
|
+
position: absolute;
|
|
2755
|
+
opacity: 0;
|
|
2756
|
+
scale: 0.4;
|
|
2757
|
+
filter: blur(6px);
|
|
2758
|
+
transition: opacity 0.2s ease, scale 0.2s ease, filter 0.2s ease;
|
|
2759
|
+
display: block;
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
.lapse-playpause-icon--active {
|
|
2763
|
+
opacity: 1;
|
|
2764
|
+
scale: 1;
|
|
2765
|
+
filter: blur(0);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
.lapse-speed-cycle svg {
|
|
2769
|
+
display: block;
|
|
2770
|
+
}
|
|
2771
|
+
`
|
|
2772
|
+
);
|
|
2773
|
+
|
|
2774
|
+
// src/react/Lapse.tsx
|
|
2775
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
2776
|
+
function Lapse({ position = "bottom-left" }) {
|
|
2777
|
+
const hostRef = (0, import_react7.useRef)(null);
|
|
2778
|
+
const [shadowRoot, setShadowRoot] = (0, import_react7.useState)(null);
|
|
2779
|
+
(0, import_react7.useEffect)(() => {
|
|
2780
|
+
const host = hostRef.current;
|
|
2781
|
+
if (!host || host.shadowRoot) {
|
|
2782
|
+
if (host?.shadowRoot) setShadowRoot(host.shadowRoot);
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
2786
|
+
const style = document.createElement("style");
|
|
2787
|
+
style.textContent = PANEL_STYLES;
|
|
2788
|
+
shadow.appendChild(style);
|
|
2789
|
+
const mount = document.createElement("div");
|
|
2790
|
+
shadow.appendChild(mount);
|
|
2791
|
+
setShadowRoot(shadow);
|
|
2792
|
+
}, []);
|
|
2793
|
+
const positionOffset = position === "top-left" ? { top: 20, left: 20 } : position === "top-right" ? { top: 20, right: 20 } : position === "bottom-left" ? { bottom: 20, left: 20 } : { bottom: 20, right: 20 };
|
|
2794
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2795
|
+
"div",
|
|
2796
|
+
{
|
|
2797
|
+
ref: hostRef,
|
|
2798
|
+
"data-lapse-panel": "",
|
|
2799
|
+
style: {
|
|
2800
|
+
position: "fixed",
|
|
2801
|
+
zIndex: 2147483647,
|
|
2802
|
+
// max int — must sit above the scrub blocker (z-index: 999999)
|
|
2803
|
+
pointerEvents: "auto",
|
|
2804
|
+
...positionOffset
|
|
2805
|
+
},
|
|
2806
|
+
children: shadowRoot && (0, import_react_dom.createPortal)(
|
|
2807
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LapseProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LapsePanel, {}) }),
|
|
2808
|
+
shadowRoot.lastElementChild || shadowRoot
|
|
2809
|
+
)
|
|
2810
|
+
}
|
|
2811
|
+
);
|
|
2812
|
+
}
|
|
2813
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2814
|
+
0 && (module.exports = {
|
|
2815
|
+
Lapse,
|
|
2816
|
+
LapseEngine,
|
|
2817
|
+
LapseProvider,
|
|
2818
|
+
useLapseEngine,
|
|
2819
|
+
useSpeed,
|
|
2820
|
+
useTimeline
|
|
2821
|
+
});
|
|
2822
|
+
//# sourceMappingURL=index.cjs.map
|