@cyca/react-timeline-editor 0.2.4-alpha.6 → 0.2.5-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1732 @@
1
+ import { a as parserTimeToPixel, c as PREFIX, i as parserPixelToTime, n as getScaleCountByRows, o as parserTimeToTransform, r as parserActionsToPositions, s as parserTransformToTime, t as getScaleCountByPixel } from "./deal-data-DH3Lh6kA.mjs";
2
+ import { createElement, useCallback, useEffect, useEffectEvent, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { prefixNames } from "framework-utils";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ import { useDrag } from "@use-gesture/react";
6
+ import { ScrollArea, Slot } from "radix-ui";
7
+ import { useVirtualizer } from "@tanstack/react-virtual";
8
+ import { resize } from "motion";
9
+ //#region src/utils/with-defaults.ts
10
+ function withDefaults(props) {
11
+ let { editorData = [], effects = {}, scale = 1, scaleSplitCount = 10, scaleWidth = 160, startLeft = 20, minScaleCount, maxScaleCount = Infinity, rowHeight = 32, collapsedRowHeight, autoScrollSpeed = 1, autoScrollMaxSpeed = 10 } = props;
12
+ if (scale <= 0) {
13
+ console.error("Error: scale must be greater than 0!");
14
+ scale = 1;
15
+ }
16
+ if (scaleSplitCount <= 0) {
17
+ console.warn("Warning: scaleSplitCount cannot be less than 1!");
18
+ scaleSplitCount = 1;
19
+ }
20
+ if (scaleWidth <= 0) {
21
+ console.warn("Warning: scaleWidth must be greater than 0!");
22
+ scaleWidth = 160;
23
+ }
24
+ if (startLeft < 0) {
25
+ console.warn("Warning: startLeft cannot be less than 0!");
26
+ startLeft = 0;
27
+ }
28
+ if (typeof minScaleCount === "number") {
29
+ minScaleCount = parseInt(minScaleCount + "");
30
+ if (minScaleCount < 1) {
31
+ console.warn("Warning: minScaleCount must be greater than 1!");
32
+ minScaleCount = 20;
33
+ }
34
+ }
35
+ maxScaleCount = maxScaleCount === Infinity ? Infinity : parseInt(maxScaleCount + "");
36
+ if (maxScaleCount < 1) {
37
+ console.warn("Warning: maxScaleCount must be greater than 1!");
38
+ maxScaleCount = 20;
39
+ }
40
+ if (typeof minScaleCount === "number" && maxScaleCount < minScaleCount) {
41
+ console.warn("Warning: maxScaleCount cannot be less than minScaleCount!");
42
+ maxScaleCount = minScaleCount;
43
+ }
44
+ if (rowHeight <= 0) {
45
+ console.warn("Warning: rowHeight must be greater than 0!");
46
+ rowHeight = 32;
47
+ }
48
+ if (typeof collapsedRowHeight !== "undefined" && collapsedRowHeight <= 0) {
49
+ console.warn("Warning: collapsedRowHeight must be greater than 0!");
50
+ collapsedRowHeight = rowHeight;
51
+ }
52
+ if (editorData.some((row) => typeof row.collapsed?.height !== "undefined" && row.collapsed.height <= 0)) {
53
+ console.warn("Warning: collapsed row height must be greater than 0!");
54
+ editorData = editorData.map((row) => typeof row.collapsed?.height !== "undefined" && row.collapsed.height <= 0 ? {
55
+ ...row,
56
+ collapsed: {
57
+ ...row.collapsed,
58
+ height: void 0
59
+ }
60
+ } : row);
61
+ }
62
+ const temp = { ...props };
63
+ delete temp["style"];
64
+ return {
65
+ ...temp,
66
+ editorData,
67
+ effects,
68
+ scale,
69
+ scaleSplitCount,
70
+ scaleWidth,
71
+ startLeft,
72
+ minScaleCount,
73
+ maxScaleCount,
74
+ rowHeight,
75
+ collapsedRowHeight,
76
+ autoScrollSpeed,
77
+ autoScrollMaxSpeed
78
+ };
79
+ }
80
+ //#endregion
81
+ //#region src/utils/deal-class-prefix.ts
82
+ function prefix(...classNames) {
83
+ return prefixNames(`${PREFIX}-`, ...classNames);
84
+ }
85
+ //#endregion
86
+ //#region src/components/edit_area/snap-lines.tsx
87
+ /** Drag auxiliary lines */
88
+ const SnapGuideLines = ({ isMoving, movePositions = [], assistPositions = [] }) => {
89
+ return /* @__PURE__ */ jsx("div", {
90
+ className: prefix("snap-line-container"),
91
+ children: isMoving && movePositions.filter((item) => assistPositions.includes(item)).map((linePos, index) => {
92
+ return /* @__PURE__ */ jsx("div", {
93
+ className: prefix("snap-line"),
94
+ style: { left: linePos }
95
+ }, index);
96
+ })
97
+ });
98
+ };
99
+ //#endregion
100
+ //#region src/components/row_rnd/hooks/use-auto-scroll.ts
101
+ const DEFAULT_SPEED = 1;
102
+ const MAX_SPEED = 10;
103
+ const CRITICAL_SIZE = 10;
104
+ function useAutoScroll(target, autoScrollSpeed = DEFAULT_SPEED, autoScrollMaxSpeed = MAX_SPEED) {
105
+ const leftBoundRef = useRef(Number.MIN_SAFE_INTEGER);
106
+ const rightBoundRef = useRef(Number.MAX_SAFE_INTEGER);
107
+ const speed = useRef(autoScrollSpeed);
108
+ const frame = useRef(void 0);
109
+ const initAutoScroll = () => {
110
+ if (target?.current) {
111
+ const { left, width } = target.current.getBoundingClientRect();
112
+ leftBoundRef.current = left;
113
+ rightBoundRef.current = left + width;
114
+ }
115
+ };
116
+ const dealDragAutoScroll = (e, deltaScroll) => {
117
+ if (e.clientX >= rightBoundRef.current || e.clientX <= leftBoundRef.current) {
118
+ if (frame.current !== void 0) cancelAnimationFrame(frame.current);
119
+ const over = Math.abs(e.clientX >= rightBoundRef.current ? e.clientX - rightBoundRef.current : e.clientX - leftBoundRef.current);
120
+ speed.current = Math.min(Math.max(Math.ceil(over / CRITICAL_SIZE) * autoScrollSpeed, autoScrollSpeed), autoScrollMaxSpeed);
121
+ const delta = (e.clientX >= rightBoundRef.current ? 1 : -1) * speed.current;
122
+ const loop = () => {
123
+ deltaScroll && deltaScroll(delta);
124
+ frame.current = requestAnimationFrame(loop);
125
+ };
126
+ frame.current = requestAnimationFrame(loop);
127
+ return false;
128
+ } else if (frame.current !== void 0) cancelAnimationFrame(frame.current);
129
+ return true;
130
+ };
131
+ const dealResizeAutoScroll = (e, _dir, deltaScroll) => {
132
+ if (e.clientX >= rightBoundRef.current || e.clientX < leftBoundRef.current) {
133
+ if (frame.current !== void 0) cancelAnimationFrame(frame.current);
134
+ const over = Math.abs(e.clientX >= rightBoundRef.current ? e.clientX - rightBoundRef.current : e.clientX - leftBoundRef.current);
135
+ speed.current = Math.min(Math.max(Math.ceil(over / CRITICAL_SIZE) * autoScrollSpeed, autoScrollSpeed), autoScrollMaxSpeed);
136
+ const delta = (e.clientX >= rightBoundRef.current ? 1 : -1) * speed.current;
137
+ const loop = () => {
138
+ deltaScroll && deltaScroll(delta);
139
+ frame.current = requestAnimationFrame(loop);
140
+ };
141
+ frame.current = requestAnimationFrame(loop);
142
+ return false;
143
+ } else if (frame.current !== void 0) cancelAnimationFrame(frame.current);
144
+ return true;
145
+ };
146
+ const stopAutoScroll = () => {
147
+ leftBoundRef.current = Number.MIN_SAFE_INTEGER;
148
+ rightBoundRef.current = Number.MAX_SAFE_INTEGER;
149
+ speed.current = autoScrollSpeed;
150
+ if (frame.current !== void 0) cancelAnimationFrame(frame.current);
151
+ };
152
+ return {
153
+ initAutoScroll,
154
+ dealDragAutoScroll,
155
+ dealResizeAutoScroll,
156
+ stopAutoScroll
157
+ };
158
+ }
159
+ //#endregion
160
+ //#region src/components/row_rnd/interactable.tsx
161
+ /**
162
+ * Helper function to create a GestureEvent from gesture state
163
+ */
164
+ const createGestureEvent = (target, delta, xy, edges, deltaRect) => ({
165
+ target,
166
+ dx: delta[0],
167
+ dy: delta[1],
168
+ clientX: xy[0],
169
+ clientY: xy[1],
170
+ ...edges && { edges },
171
+ ...deltaRect && { deltaRect }
172
+ });
173
+ /**
174
+ * Helper function to check if an event target is a resize handle
175
+ */
176
+ const isResizeHandle = (eventTarget, leftHandle, rightHandle) => {
177
+ if (!eventTarget) return false;
178
+ return eventTarget === leftHandle || eventTarget === rightHandle || (leftHandle?.contains(eventTarget) ?? false) || (rightHandle?.contains(eventTarget) ?? false);
179
+ };
180
+ const Interactable = ({ children, style, draggable, resizable, draggableOptions, resizableOptions, ref }) => {
181
+ const draggableOptionsRef = useRef(void 0);
182
+ const resizableOptionsRef = useRef(void 0);
183
+ const leftResizeHandleRef = useRef(null);
184
+ const rightResizeHandleRef = useRef(null);
185
+ useLayoutEffect(() => {
186
+ draggableOptionsRef.current = draggableOptions;
187
+ resizableOptionsRef.current = resizableOptions;
188
+ if (!ref?.current) return;
189
+ const currentLeftSelector = resizableOptions?.edges?.left;
190
+ const currentRightSelector = resizableOptions?.edges?.right;
191
+ const node = ref.current;
192
+ if (currentLeftSelector) leftResizeHandleRef.current = node.querySelector(currentLeftSelector);
193
+ if (currentRightSelector) rightResizeHandleRef.current = node.querySelector(currentRightSelector);
194
+ }, [
195
+ draggableOptions,
196
+ ref,
197
+ resizableOptions
198
+ ]);
199
+ useDrag(({ active, delta, xy, event, first, last }) => {
200
+ const node = ref?.current;
201
+ if (!node) return;
202
+ if (isResizeHandle(event?.target, leftResizeHandleRef.current, rightResizeHandleRef.current)) return;
203
+ const gestureEvent = createGestureEvent(node, delta, xy);
204
+ if (first) draggableOptionsRef.current?.onstart?.(gestureEvent);
205
+ else if (last) draggableOptionsRef.current?.onend?.(gestureEvent);
206
+ else if (active) draggableOptionsRef.current?.onmove?.(gestureEvent);
207
+ }, {
208
+ enabled: draggable,
209
+ axis: draggableOptions?.lockAxis === "x" ? "x" : void 0,
210
+ pointer: { capture: true },
211
+ target: ref,
212
+ threshold: 0
213
+ });
214
+ useDrag(({ active, delta, xy, first, last }) => {
215
+ const node = ref?.current;
216
+ if (!node) return;
217
+ const gestureEvent = createGestureEvent(node, delta, xy, { left: true }, { left: delta[0] });
218
+ if (first) resizableOptionsRef.current?.onstart?.(gestureEvent);
219
+ else if (last) resizableOptionsRef.current?.onend?.(gestureEvent);
220
+ else if (active) resizableOptionsRef.current?.onmove?.(gestureEvent);
221
+ }, {
222
+ enabled: resizable,
223
+ target: leftResizeHandleRef,
224
+ pointer: { capture: true },
225
+ threshold: 0
226
+ });
227
+ useDrag(({ active, delta, xy, first, last }) => {
228
+ const node = ref?.current;
229
+ if (!node) return;
230
+ const gestureEvent = createGestureEvent(node, delta, xy, { right: true }, { right: delta[0] });
231
+ if (first) resizableOptionsRef.current?.onstart?.(gestureEvent);
232
+ else if (last) resizableOptionsRef.current?.onend?.(gestureEvent);
233
+ else if (active) resizableOptionsRef.current?.onmove?.(gestureEvent);
234
+ }, {
235
+ enabled: resizable,
236
+ target: rightResizeHandleRef,
237
+ pointer: { capture: true },
238
+ threshold: 0
239
+ });
240
+ return /* @__PURE__ */ jsx(Slot.Root, {
241
+ ref,
242
+ style: {
243
+ ...draggable ? { touchAction: "none" } : {},
244
+ ...style
245
+ },
246
+ draggable: false,
247
+ children
248
+ });
249
+ };
250
+ //#endregion
251
+ //#region src/components/row_rnd/row-rnd.tsx
252
+ const parseDatasetValue = (value, defaultValue = 0) => {
253
+ return value ? parseFloat(value) : defaultValue;
254
+ };
255
+ const calculateSnap = (position, snapPositions, snapDistance, minDis = Number.MAX_SAFE_INTEGER) => {
256
+ let snap = position;
257
+ let currentMinDis = minDis;
258
+ for (const item of snapPositions) {
259
+ const itemValue = typeof item === "number" ? item : item.value;
260
+ const dis = Math.abs(itemValue - position);
261
+ if (dis < snapDistance && dis < currentMinDis) {
262
+ snap = itemValue;
263
+ currentMinDis = dis;
264
+ }
265
+ }
266
+ return {
267
+ snap,
268
+ minDis: currentMinDis
269
+ };
270
+ };
271
+ function RowDnd({ children, edges, left, width, start = 20, grid = 1, getBounds = () => ({
272
+ left: Number.MIN_SAFE_INTEGER,
273
+ right: Number.MAX_SAFE_INTEGER
274
+ }), enableResizing = true, enableDragging = true, snapDistance = 8, snapPositions = [], snapOrigin = "leading", onResizeStart, onResize, onResizeEnd, onDragStart, onDragEnd, onDrag, parentRef, autoScroll = true, autoScrollSpeed, autoScrollMaxSpeed, ref }) {
275
+ const interactableRef = useRef(null);
276
+ const deltaX = useRef(0);
277
+ const isSnap = useRef(false);
278
+ const { initAutoScroll, stopAutoScroll, dealDragAutoScroll, dealResizeAutoScroll } = useAutoScroll(parentRef, autoScrollSpeed, autoScrollMaxSpeed);
279
+ const handleUpdateLeft = (left, reset = true) => {
280
+ if (!interactableRef.current) return;
281
+ if (reset) deltaX.current = 0;
282
+ const target = interactableRef.current;
283
+ target.style.setProperty("--translate-x", `${left}px`);
284
+ target.dataset.left = String(left);
285
+ };
286
+ const handleUpdateWidth = (width, reset = true) => {
287
+ if (!interactableRef.current) return;
288
+ if (reset) deltaX.current = 0;
289
+ const target = interactableRef.current;
290
+ target.style.width = `${width}px`;
291
+ target.dataset.width = String(width);
292
+ };
293
+ const handleGetLeft = () => {
294
+ if (!interactableRef.current) return 0;
295
+ return parseDatasetValue(interactableRef.current.dataset.left);
296
+ };
297
+ const handleGetWidth = () => {
298
+ if (!interactableRef.current) return 0;
299
+ return parseDatasetValue(interactableRef.current.dataset.width);
300
+ };
301
+ useEffect(() => {
302
+ if (!interactableRef.current) return;
303
+ const target = interactableRef.current;
304
+ handleUpdateWidth(typeof width === "undefined" ? target.offsetWidth : width, false);
305
+ }, [width]);
306
+ useEffect(() => {
307
+ handleUpdateLeft(left || 0, false);
308
+ }, [left]);
309
+ useImperativeHandle(ref, () => ({
310
+ updateLeft: (left) => handleUpdateLeft(left || 0, false),
311
+ updateWidth: (width) => handleUpdateWidth(width, false),
312
+ getLeft: handleGetLeft,
313
+ getWidth: handleGetWidth
314
+ }));
315
+ const handleMoveStart = () => {
316
+ deltaX.current = 0;
317
+ isSnap.current = false;
318
+ initAutoScroll();
319
+ onDragStart?.();
320
+ };
321
+ const move = (param) => {
322
+ const { preLeft, preWidth, scrollDelta } = param;
323
+ if (scrollDelta) deltaX.current += scrollDelta;
324
+ const distance = isSnap.current ? snapDistance : grid;
325
+ if (Math.abs(deltaX.current) < distance) return;
326
+ let curLeft = preLeft + Math.trunc(deltaX.current / distance) * distance;
327
+ const movingRight = deltaX.current > 0;
328
+ let checkPosition = curLeft;
329
+ if (snapOrigin === "leading") checkPosition = movingRight ? curLeft + preWidth : curLeft;
330
+ else if (snapOrigin === "right") checkPosition = curLeft + preWidth;
331
+ else if (snapOrigin === "center") checkPosition = curLeft + preWidth / 2;
332
+ const { snap: snapPosition } = calculateSnap(checkPosition, snapPositions, snapDistance);
333
+ if (snapPosition !== checkPosition) {
334
+ isSnap.current = true;
335
+ if (snapOrigin === "leading") curLeft = movingRight ? snapPosition - preWidth : snapPosition;
336
+ else if (snapOrigin === "right") curLeft = snapPosition - preWidth;
337
+ else if (snapOrigin === "center") curLeft = snapPosition - preWidth / 2;
338
+ else curLeft = snapPosition;
339
+ } else {
340
+ const offset = curLeft - start;
341
+ if (offset % grid !== 0) curLeft = start + grid * Math.round(offset / grid);
342
+ isSnap.current = false;
343
+ }
344
+ deltaX.current = deltaX.current % distance;
345
+ const bounds = getBounds();
346
+ if (curLeft < bounds.left) curLeft = bounds.left;
347
+ else if (curLeft + preWidth > bounds.right) curLeft = bounds.right - preWidth;
348
+ if (onDrag) {
349
+ if (onDrag({
350
+ lastLeft: preLeft,
351
+ left: curLeft,
352
+ lastWidth: preWidth,
353
+ width: preWidth
354
+ }, scrollDelta) === false) return;
355
+ }
356
+ handleUpdateLeft(curLeft, false);
357
+ };
358
+ const handleMove = (e) => {
359
+ const target = e.target;
360
+ const preLeft = parseDatasetValue(target.dataset.left);
361
+ const preWidth = parseDatasetValue(target.dataset.width);
362
+ deltaX.current += e.dx;
363
+ if (autoScroll && parentRef?.current) {
364
+ const deltaScroll = (delta) => {
365
+ if (!parentRef?.current || !interactableRef.current) return;
366
+ parentRef.current.scrollLeft += delta;
367
+ const currentTarget = interactableRef.current;
368
+ move({
369
+ preLeft: parseDatasetValue(currentTarget.dataset.left),
370
+ preWidth: parseDatasetValue(currentTarget.dataset.width),
371
+ scrollDelta: delta
372
+ });
373
+ };
374
+ if (!dealDragAutoScroll(e, deltaScroll)) return;
375
+ }
376
+ move({
377
+ preLeft,
378
+ preWidth
379
+ });
380
+ };
381
+ const handleMoveStop = (e) => {
382
+ deltaX.current = 0;
383
+ isSnap.current = false;
384
+ stopAutoScroll();
385
+ const target = e.target;
386
+ onDragEnd?.({
387
+ left: parseDatasetValue(target.dataset.left),
388
+ width: parseDatasetValue(target.dataset.width)
389
+ });
390
+ };
391
+ const handleResizeStart = (e) => {
392
+ deltaX.current = 0;
393
+ isSnap.current = false;
394
+ initAutoScroll();
395
+ const dir = e.edges?.right ? "right" : "left";
396
+ onResizeStart?.(dir);
397
+ };
398
+ const resize = (param) => {
399
+ const { dir, preWidth, preLeft, scrollDelta } = param;
400
+ if (scrollDelta) deltaX.current += scrollDelta;
401
+ const distance = isSnap.current ? snapDistance : grid;
402
+ if (Math.abs(deltaX.current) < distance) return;
403
+ const bounds = getBounds();
404
+ if (dir === "left") {
405
+ let curLeft = preLeft + Math.trunc(deltaX.current / distance) * distance;
406
+ const { snap } = calculateSnap(curLeft, snapPositions, snapDistance);
407
+ if (snap !== curLeft) {
408
+ isSnap.current = true;
409
+ curLeft = snap;
410
+ } else {
411
+ const offset = curLeft - start;
412
+ if (offset % grid !== 0) curLeft = start + grid * Math.round(offset / grid);
413
+ isSnap.current = false;
414
+ }
415
+ deltaX.current = deltaX.current % distance;
416
+ if (curLeft < bounds.left) curLeft = bounds.left;
417
+ const tempRight = preLeft + preWidth;
418
+ const curWidth = tempRight - curLeft;
419
+ if (curLeft >= tempRight) return;
420
+ if (onResize) {
421
+ if (onResize("left", {
422
+ lastLeft: preLeft,
423
+ lastWidth: preWidth,
424
+ left: curLeft,
425
+ width: curWidth
426
+ }) === false) return;
427
+ }
428
+ handleUpdateLeft(curLeft, false);
429
+ handleUpdateWidth(curWidth, false);
430
+ } else {
431
+ let curWidth = preWidth + Math.trunc(deltaX.current / distance) * distance;
432
+ const rightEdge = preLeft + curWidth;
433
+ const { snap } = calculateSnap(rightEdge, snapPositions, snapDistance);
434
+ if (snap !== rightEdge) {
435
+ isSnap.current = true;
436
+ curWidth = snap - preLeft;
437
+ } else {
438
+ let tempRight = preLeft + curWidth;
439
+ const offset = tempRight - start;
440
+ if (offset % grid !== 0) {
441
+ tempRight = start + grid * Math.round(offset / grid);
442
+ curWidth = tempRight - preLeft;
443
+ }
444
+ isSnap.current = false;
445
+ }
446
+ deltaX.current = deltaX.current % distance;
447
+ if (preLeft + curWidth > bounds.right) curWidth = bounds.right - preLeft;
448
+ if (curWidth <= 0) return;
449
+ if (onResize) {
450
+ if (onResize("right", {
451
+ lastLeft: preLeft,
452
+ lastWidth: preWidth,
453
+ left: preLeft,
454
+ width: curWidth
455
+ }) === false) return;
456
+ }
457
+ handleUpdateWidth(curWidth, false);
458
+ }
459
+ };
460
+ const handleResize = (e) => {
461
+ const target = e.target;
462
+ const dir = e.edges?.left ? "left" : "right";
463
+ const preLeft = parseDatasetValue(target.dataset.left);
464
+ const preWidth = parseDatasetValue(target.dataset.width);
465
+ deltaX.current += dir === "left" ? e.deltaRect?.left || 0 : e.deltaRect?.right || 0;
466
+ if (autoScroll && parentRef?.current) {
467
+ const deltaScroll = (delta) => {
468
+ if (!parentRef?.current || !interactableRef.current) return;
469
+ parentRef.current.scrollLeft += delta;
470
+ const currentTarget = interactableRef.current;
471
+ resize({
472
+ preLeft: parseDatasetValue(currentTarget.dataset.left),
473
+ preWidth: parseDatasetValue(currentTarget.dataset.width),
474
+ dir,
475
+ scrollDelta: delta
476
+ });
477
+ };
478
+ if (!dealResizeAutoScroll(e, dir, deltaScroll)) return;
479
+ }
480
+ resize({
481
+ preLeft,
482
+ preWidth,
483
+ dir
484
+ });
485
+ };
486
+ const handleResizeStop = (e) => {
487
+ deltaX.current = 0;
488
+ isSnap.current = false;
489
+ stopAutoScroll();
490
+ const target = e.target;
491
+ const dir = e.edges?.right ? "right" : "left";
492
+ onResizeEnd?.(dir, {
493
+ left: parseDatasetValue(target.dataset.left),
494
+ width: parseDatasetValue(target.dataset.width)
495
+ });
496
+ };
497
+ return /* @__PURE__ */ jsx(Interactable, {
498
+ "data-left": left || 0,
499
+ style: {
500
+ "--translate-x": `${left || 0}px`,
501
+ transform: `translateX(var(--translate-x)) scaleX(var(--scale-x,1))`,
502
+ width
503
+ },
504
+ ref: interactableRef,
505
+ draggable: enableDragging,
506
+ resizable: enableResizing,
507
+ draggableOptions: {
508
+ lockAxis: "x",
509
+ onmove: handleMove,
510
+ onstart: handleMoveStart,
511
+ onend: handleMoveStop,
512
+ cursorChecker: () => ""
513
+ },
514
+ resizableOptions: {
515
+ axis: "x",
516
+ invert: "none",
517
+ edges,
518
+ onmove: handleResize,
519
+ onstart: handleResizeStart,
520
+ onend: handleResizeStop
521
+ },
522
+ children
523
+ });
524
+ }
525
+ //#endregion
526
+ //#region src/utils/clsx.ts
527
+ function clsx() {
528
+ let i = 0, tmp, str = "", len = arguments.length;
529
+ for (; i < len; i++) if (tmp = arguments[i]) {
530
+ if (typeof tmp === "string") str += (str && " ") + tmp;
531
+ }
532
+ return str;
533
+ }
534
+ //#endregion
535
+ //#region src/components/edit_area/edit-action.tsx
536
+ const EditAction = ({ editorData, row, rowRenderHeight, action, effects, scale, scaleWidth, scaleSplitCount, startLeft, gridSnap, disableDrag, autoScroll, autoScrollSpeed, autoScrollMaxSpeed, scaleCount, maxScaleCount, setScaleCount, onActionMoveStart, onActionMoving, onActionMoveEnd, onActionResizeStart, onActionResizeEnd, onActionResizing, snapData, setEditorData, onClickAction, onClickActionOnly, onDoubleClickAction, onContextMenuAction, getActionRender, handleTime, scrollContainerRef }) => {
537
+ const rowRnd = useRef(null);
538
+ const isDragWhenClick = useRef(false);
539
+ const { id, maxEnd, minStart, end, start, selected, flexible = true, movable = true, effectId } = action;
540
+ const safeScale = scale ?? 1;
541
+ const safeScaleWidth = scaleWidth ?? 160;
542
+ const safeStartLeft = startLeft ?? 20;
543
+ const safeScaleSplitCount = scaleSplitCount ?? 10;
544
+ const safeMaxScaleCount = maxScaleCount ?? Number.MAX_SAFE_INTEGER;
545
+ const leftLimit = parserTimeToPixel(minStart || 0, {
546
+ startLeft: safeStartLeft,
547
+ scale: safeScale,
548
+ scaleWidth: safeScaleWidth
549
+ });
550
+ const rightLimit = Math.min(safeMaxScaleCount * safeScaleWidth + safeStartLeft, parserTimeToPixel(maxEnd || Number.MAX_VALUE, {
551
+ startLeft: safeStartLeft,
552
+ scale: safeScale,
553
+ scaleWidth: safeScaleWidth
554
+ }));
555
+ const baseTransform = useMemo(() => {
556
+ return parserTimeToTransform({
557
+ start,
558
+ end
559
+ }, {
560
+ startLeft: safeStartLeft,
561
+ scale: safeScale,
562
+ scaleWidth: safeScaleWidth
563
+ });
564
+ }, [
565
+ end,
566
+ start,
567
+ safeStartLeft,
568
+ safeScaleWidth,
569
+ safeScale
570
+ ]);
571
+ const [dragTransform, setDragTransform] = useState(null);
572
+ const transform = dragTransform ?? baseTransform;
573
+ const gridSize = safeScaleWidth / safeScaleSplitCount;
574
+ const classNames = prefix(clsx("action", movable && "action-movable", selected && "action-selected", flexible && "action-flexible", effects[effectId] && `action-effect-${effectId}`));
575
+ /** Calculate scale count */
576
+ const handleScaleCount = (left, width) => {
577
+ const curScaleCount = getScaleCountByPixel(left + width, {
578
+ startLeft: safeStartLeft,
579
+ scaleCount,
580
+ scaleWidth: safeScaleWidth
581
+ });
582
+ if (curScaleCount !== scaleCount) setScaleCount(curScaleCount);
583
+ };
584
+ const handleDragStart = () => {
585
+ onActionMoveStart && onActionMoveStart({
586
+ action,
587
+ row
588
+ });
589
+ };
590
+ const handleDrag = ({ left, width }) => {
591
+ isDragWhenClick.current = true;
592
+ if (onActionMoving) {
593
+ const { start, end } = parserTransformToTime({
594
+ left,
595
+ width
596
+ }, {
597
+ scaleWidth: safeScaleWidth,
598
+ scale: safeScale,
599
+ startLeft: safeStartLeft
600
+ });
601
+ if (onActionMoving({
602
+ action,
603
+ row,
604
+ start,
605
+ end
606
+ }) === false) return false;
607
+ }
608
+ setDragTransform({
609
+ left,
610
+ width
611
+ });
612
+ handleScaleCount(left, width);
613
+ };
614
+ const handleDragEnd = ({ left, width }) => {
615
+ const { start, end } = parserTransformToTime({
616
+ left,
617
+ width
618
+ }, {
619
+ scaleWidth: safeScaleWidth,
620
+ scale: safeScale,
621
+ startLeft: safeStartLeft
622
+ });
623
+ const rowItem = editorData.find((item) => item.id === row.id);
624
+ if (!rowItem) return;
625
+ const actionItem = rowItem.actions.find((item) => item.id === id);
626
+ if (!actionItem) return;
627
+ actionItem.start = start;
628
+ actionItem.end = end;
629
+ setEditorData([...editorData]);
630
+ if (onActionMoveEnd) onActionMoveEnd({
631
+ action: actionItem,
632
+ row,
633
+ start,
634
+ end
635
+ });
636
+ setDragTransform(null);
637
+ };
638
+ const handleResizeStart = (dir) => {
639
+ onActionResizeStart && onActionResizeStart({
640
+ action,
641
+ row,
642
+ dir
643
+ });
644
+ };
645
+ const handleResizing = (dir, { left, width }) => {
646
+ isDragWhenClick.current = true;
647
+ if (onActionResizing) {
648
+ const { start, end } = parserTransformToTime({
649
+ left,
650
+ width
651
+ }, {
652
+ scaleWidth: safeScaleWidth,
653
+ scale: safeScale,
654
+ startLeft: safeStartLeft
655
+ });
656
+ if (onActionResizing({
657
+ action,
658
+ row,
659
+ start,
660
+ end,
661
+ dir
662
+ }) === false) return false;
663
+ }
664
+ setDragTransform({
665
+ left,
666
+ width
667
+ });
668
+ handleScaleCount(left, width);
669
+ };
670
+ const handleResizeEnd = (dir, { left, width }) => {
671
+ const { start, end } = parserTransformToTime({
672
+ left,
673
+ width
674
+ }, {
675
+ scaleWidth: safeScaleWidth,
676
+ scale: safeScale,
677
+ startLeft: safeStartLeft
678
+ });
679
+ const rowItem = editorData.find((item) => item.id === row.id);
680
+ if (!rowItem) return;
681
+ const actionItem = rowItem.actions.find((item) => item.id === id);
682
+ if (!actionItem) return;
683
+ actionItem.start = start;
684
+ actionItem.end = end;
685
+ setEditorData([...editorData]);
686
+ if (onActionResizeEnd) onActionResizeEnd({
687
+ action: actionItem,
688
+ row,
689
+ start,
690
+ end,
691
+ dir
692
+ });
693
+ setDragTransform(null);
694
+ };
695
+ const nowAction = {
696
+ ...action,
697
+ ...parserTransformToTime({
698
+ left: transform.left,
699
+ width: transform.width
700
+ }, {
701
+ startLeft: safeStartLeft,
702
+ scaleWidth: safeScaleWidth,
703
+ scale: safeScale
704
+ })
705
+ };
706
+ const nowRow = {
707
+ ...row,
708
+ actions: [...row.actions]
709
+ };
710
+ if (row.actions.includes(action)) nowRow.actions[row.actions.indexOf(action)] = nowAction;
711
+ return /* @__PURE__ */ jsx(RowDnd, {
712
+ ref: rowRnd,
713
+ parentRef: scrollContainerRef,
714
+ start: safeStartLeft,
715
+ left: transform.left,
716
+ width: transform.width,
717
+ grid: gridSnap && gridSize || 1,
718
+ snapDistance: gridSnap ? Math.max((gridSize || 1) / 2, 8) : 8,
719
+ snapPositions: snapData.assistPositions,
720
+ getBounds: () => {
721
+ return {
722
+ left: leftLimit,
723
+ right: rightLimit
724
+ };
725
+ },
726
+ edges: {
727
+ left: !disableDrag && flexible && `.${prefix("action-left-stretch")}`,
728
+ right: !disableDrag && flexible && `.${prefix("action-right-stretch")}`
729
+ },
730
+ enableDragging: !disableDrag && movable,
731
+ enableResizing: !disableDrag && flexible,
732
+ onDragStart: handleDragStart,
733
+ onDrag: handleDrag,
734
+ onDragEnd: handleDragEnd,
735
+ onResizeStart: handleResizeStart,
736
+ onResize: handleResizing,
737
+ onResizeEnd: handleResizeEnd,
738
+ autoScroll,
739
+ autoScrollSpeed,
740
+ autoScrollMaxSpeed,
741
+ children: /* @__PURE__ */ jsxs("div", {
742
+ onMouseDown: () => {
743
+ isDragWhenClick.current = false;
744
+ },
745
+ onClick: (e) => {
746
+ let time;
747
+ if (onClickAction) {
748
+ time = handleTime(e);
749
+ onClickAction(e, {
750
+ row,
751
+ action,
752
+ time
753
+ });
754
+ }
755
+ if (isDragWhenClick.current) {
756
+ e.stopPropagation();
757
+ return;
758
+ }
759
+ if (onClickActionOnly) {
760
+ if (time === void 0) time = handleTime(e);
761
+ onClickActionOnly(e, {
762
+ row,
763
+ action,
764
+ time
765
+ });
766
+ }
767
+ },
768
+ onDoubleClick: (e) => {
769
+ if (onDoubleClickAction) onDoubleClickAction(e, {
770
+ row,
771
+ action,
772
+ time: handleTime(e)
773
+ });
774
+ },
775
+ onContextMenu: (e) => {
776
+ if (onContextMenuAction) onContextMenuAction(e, {
777
+ row,
778
+ action,
779
+ time: handleTime(e)
780
+ });
781
+ },
782
+ className: classNames,
783
+ style: { height: rowRenderHeight },
784
+ children: [
785
+ getActionRender && getActionRender(nowAction, nowRow),
786
+ /* @__PURE__ */ jsx("div", {
787
+ className: clsx(prefix("action-left-stretch")),
788
+ style: {
789
+ touchAction: "none",
790
+ visibility: flexible ? "visible" : "hidden",
791
+ pointerEvents: flexible ? "auto" : "none"
792
+ }
793
+ }),
794
+ /* @__PURE__ */ jsx("div", {
795
+ className: prefix("action-right-stretch"),
796
+ style: {
797
+ touchAction: "none",
798
+ visibility: flexible ? "visible" : "hidden",
799
+ pointerEvents: flexible ? "auto" : "none"
800
+ }
801
+ })
802
+ ]
803
+ })
804
+ });
805
+ };
806
+ //#endregion
807
+ //#region src/components/edit_area/edit-row.tsx
808
+ const EditRow = (props) => {
809
+ const { rowData, rowRenderHeight, isCollapsed = false, style = {}, onClickRow, onPointerMoveRow, onDoubleClickRow, onContextMenuRow, scrollContainerRef, startLeft, scale, scaleWidth, unstable_rowActionsOverscan, getEmptyRowRender, getCollapsedRowLabelRender, getActionPreviewRender, actionPreview } = props;
810
+ const classNames = ["edit-row"];
811
+ if (rowData?.selected) classNames.push("edit-row-selected");
812
+ const safeScale = scale ?? 1;
813
+ const safeScaleWidth = scaleWidth ?? 160;
814
+ const safeStartLeft = startLeft ?? 20;
815
+ const handleTime = (e) => {
816
+ if (!scrollContainerRef.current) return 0;
817
+ const rect = e.currentTarget.getBoundingClientRect();
818
+ return parserPixelToTime(e.clientX - rect.x, {
819
+ startLeft: safeStartLeft,
820
+ scale: safeScale,
821
+ scaleWidth: safeScaleWidth
822
+ });
823
+ };
824
+ const handleTimelineCursorPreviewPointerMove = (e) => {
825
+ if (!rowData) return;
826
+ const position = e.clientX - e.currentTarget.getBoundingClientRect().x;
827
+ const maxCount = props.maxScaleCount ?? Infinity;
828
+ const maxLeft = Number.isFinite(maxCount) ? maxCount * safeScaleWidth + safeStartLeft : e.currentTarget.offsetWidth;
829
+ if (position < safeStartLeft || position > maxLeft) {
830
+ props.onTimelineCursorPreviewPointerLeave?.();
831
+ return;
832
+ }
833
+ props.onTimelineCursorPreviewPointerMove?.({
834
+ surface: "edit-row",
835
+ row: rowData,
836
+ time: parserPixelToTime(position, {
837
+ startLeft: safeStartLeft,
838
+ scale: safeScale,
839
+ scaleWidth: safeScaleWidth
840
+ })
841
+ });
842
+ };
843
+ const actions = useMemo(() => (rowData?.actions ? [...rowData.actions] : []).sort((a, b) => a.start - b.start), [rowData]);
844
+ const getItemKey = useCallback((index) => actions[index]?.id ?? index, [actions]);
845
+ const previewAction = rowData && actionPreview?.rowId === rowData.id ? actionPreview.action : null;
846
+ const previewTransform = previewAction ? parserTimeToTransform({
847
+ start: previewAction.start,
848
+ end: previewAction.end
849
+ }, {
850
+ startLeft: safeStartLeft,
851
+ scale: safeScale,
852
+ scaleWidth: safeScaleWidth
853
+ }) : null;
854
+ const virtualizer = useVirtualizer({
855
+ horizontal: true,
856
+ count: actions.length,
857
+ getItemKey,
858
+ getScrollElement: () => scrollContainerRef.current,
859
+ estimateSize: (index) => {
860
+ if (!actions[index]) return 0;
861
+ let start = index > 0 ? actions[index - 1].end : 0;
862
+ let end = actions[index].end;
863
+ if (start > end) return 0;
864
+ let { width } = parserTimeToTransform({
865
+ start,
866
+ end
867
+ }, {
868
+ startLeft: safeStartLeft,
869
+ scale: safeScale,
870
+ scaleWidth: safeScaleWidth
871
+ });
872
+ return width;
873
+ },
874
+ overscan: unstable_rowActionsOverscan ?? 5
875
+ });
876
+ useEffect(() => virtualizer.measure(), [
877
+ safeScale,
878
+ safeScaleWidth,
879
+ safeStartLeft,
880
+ virtualizer
881
+ ]);
882
+ return /* @__PURE__ */ jsxs("div", {
883
+ className: `${prefix(...classNames)} ${(rowData?.classNames || []).join(" ")}`,
884
+ style,
885
+ onPointerEnter: props.onPointerEnter,
886
+ onPointerLeave: props.onPointerLeave,
887
+ onPointerMove: (e) => {
888
+ handleTimelineCursorPreviewPointerMove(e);
889
+ if (rowData && onPointerMoveRow) onPointerMoveRow(e, {
890
+ row: rowData,
891
+ time: handleTime(e)
892
+ });
893
+ },
894
+ onClick: (e) => {
895
+ if (rowData && onClickRow) onClickRow(e, {
896
+ row: rowData,
897
+ time: handleTime(e)
898
+ });
899
+ },
900
+ onDoubleClick: (e) => {
901
+ if (rowData && onDoubleClickRow) onDoubleClickRow(e, {
902
+ row: rowData,
903
+ time: handleTime(e)
904
+ });
905
+ },
906
+ onContextMenu: (e) => {
907
+ if (rowData && onContextMenuRow) onContextMenuRow(e, {
908
+ row: rowData,
909
+ time: handleTime(e)
910
+ });
911
+ },
912
+ children: [
913
+ rowData && isCollapsed && getCollapsedRowLabelRender && /* @__PURE__ */ jsx("div", {
914
+ className: prefix("collapsed-row-label"),
915
+ "aria-hidden": "true",
916
+ children: getCollapsedRowLabelRender({
917
+ row: rowData,
918
+ height: rowRenderHeight
919
+ })
920
+ }),
921
+ rowData && actions.length === 0 && getEmptyRowRender && /* @__PURE__ */ jsx("div", {
922
+ className: prefix("empty-row"),
923
+ children: getEmptyRowRender({
924
+ row: rowData,
925
+ height: rowRenderHeight
926
+ })
927
+ }),
928
+ rowData && previewAction && previewTransform && /* @__PURE__ */ jsx("div", {
929
+ className: prefix("action-preview"),
930
+ style: {
931
+ height: rowRenderHeight,
932
+ transform: `translateX(${previewTransform.left}px)`,
933
+ width: previewTransform.width
934
+ },
935
+ "aria-hidden": "true",
936
+ children: getActionPreviewRender?.({
937
+ action: previewAction,
938
+ row: rowData,
939
+ height: rowRenderHeight
940
+ })
941
+ }),
942
+ rowData && virtualizer.getVirtualItems().map((virtualEntry) => {
943
+ const action = actions[virtualEntry.index];
944
+ if (!action) throw new Error("Action not found");
945
+ return /* @__PURE__ */ jsx(EditAction, {
946
+ ...props,
947
+ handleTime,
948
+ row: rowData,
949
+ rowRenderHeight,
950
+ action
951
+ }, action.id);
952
+ })
953
+ ]
954
+ });
955
+ };
956
+ //#endregion
957
+ //#region src/components/edit_area/hooks/use-snap.ts
958
+ const useSnap = (props) => {
959
+ const [snapData, setSnapData] = useState({
960
+ isMoving: false,
961
+ movePositions: [],
962
+ assistPositions: []
963
+ });
964
+ const activeDragStateRef = useRef(null);
965
+ const snapDataRef = useEffectEvent(() => ({
966
+ ...props,
967
+ snapData
968
+ }));
969
+ useEffect(() => {
970
+ const activeDragState = activeDragStateRef.current;
971
+ const currentProps = snapDataRef();
972
+ if (currentProps.snap && activeDragState && currentProps.snapData.isMoving && currentProps.snapPositions) {
973
+ const assistActionIds = activeDragState.assistActionIds;
974
+ const assistPositions = currentProps.snapPositions.filter((pos) => {
975
+ if (pos.actionId === activeDragState.action.id) return false;
976
+ if (assistActionIds && !assistActionIds.includes(pos.actionId)) return false;
977
+ return true;
978
+ }).map((pos) => pos.value);
979
+ if (!currentProps.hideCursor) {
980
+ const cursorLeft = parserTimeToPixel(currentProps.cursorTime, {
981
+ scaleWidth: currentProps.scaleWidth ?? 160,
982
+ scale: currentProps.scale ?? 1,
983
+ startLeft: currentProps.startLeft ?? 20
984
+ });
985
+ assistPositions.push(cursorLeft);
986
+ }
987
+ setSnapData((pre) => ({
988
+ ...pre,
989
+ assistPositions
990
+ }));
991
+ } else if (!currentProps.snap && currentProps.snapData.isMoving) setSnapData((pre) => ({
992
+ ...pre,
993
+ assistPositions: []
994
+ }));
995
+ }, [props.snap]);
996
+ const handleInitSnap = (data) => {
997
+ const assistActionIds = props.getAssistDragLineActionIds && props.getAssistDragLineActionIds({
998
+ action: data.action,
999
+ row: data.row,
1000
+ editorData: props.editorData
1001
+ });
1002
+ activeDragStateRef.current = {
1003
+ action: data.action,
1004
+ row: data.row,
1005
+ assistActionIds
1006
+ };
1007
+ if (props.snap && props.snapPositions) {
1008
+ const assistPositions = props.snapPositions.filter((pos) => {
1009
+ if (pos.actionId === data.action.id) return false;
1010
+ if (assistActionIds && !assistActionIds.includes(pos.actionId)) return false;
1011
+ return true;
1012
+ }).map((pos) => pos.value);
1013
+ if (!props.hideCursor) {
1014
+ const cursorLeft = parserTimeToPixel(props.cursorTime, {
1015
+ scaleWidth: props.scaleWidth ?? 160,
1016
+ scale: props.scale ?? 1,
1017
+ startLeft: props.startLeft ?? 20
1018
+ });
1019
+ assistPositions.push(cursorLeft);
1020
+ }
1021
+ setSnapData({
1022
+ isMoving: true,
1023
+ movePositions: [],
1024
+ assistPositions
1025
+ });
1026
+ } else setSnapData({
1027
+ isMoving: true,
1028
+ movePositions: [],
1029
+ assistPositions: []
1030
+ });
1031
+ };
1032
+ const handleUpdateSnap = (data) => {
1033
+ if (props.snap) {
1034
+ const currentScaleWidth = props.scaleWidth ?? 160;
1035
+ const currentScale = props.scale ?? 1;
1036
+ const currentStartLeft = props.startLeft ?? 20;
1037
+ const { left, width } = parserTimeToTransform({
1038
+ start: data.start,
1039
+ end: data.end
1040
+ }, {
1041
+ startLeft: currentStartLeft,
1042
+ scaleWidth: currentScaleWidth,
1043
+ scale: currentScale
1044
+ });
1045
+ const movePositions = data.dir ? data.dir === "right" ? [left + width] : [left] : [left, left + width];
1046
+ setSnapData((pre) => ({
1047
+ ...pre,
1048
+ movePositions
1049
+ }));
1050
+ }
1051
+ };
1052
+ const disposeSnap = () => {
1053
+ activeDragStateRef.current = null;
1054
+ setSnapData({
1055
+ isMoving: false,
1056
+ movePositions: [],
1057
+ assistPositions: []
1058
+ });
1059
+ };
1060
+ return {
1061
+ snapData,
1062
+ handleInitSnap,
1063
+ handleUpdateSnap,
1064
+ disposeSnap
1065
+ };
1066
+ };
1067
+ //#endregion
1068
+ //#region src/utils/row-layout.ts
1069
+ function getTimelineRowPresentation(params) {
1070
+ const layouts = [];
1071
+ let totalHeight = 0;
1072
+ const collapsibleRowIds = new Set(params.editorData.filter((row) => row.collapsed).map((row) => row.id));
1073
+ const defaultExpandedRowIds = params.editorData.filter((row) => row.collapsed?.expandedByDefault).map((row) => row.id);
1074
+ const focusedRowId = (params.lockedRowId && collapsibleRowIds.has(params.lockedRowId) ? params.lockedRowId : null) ?? (params.hoveredRowId && collapsibleRowIds.has(params.hoveredRowId) ? params.hoveredRowId : null) ?? defaultExpandedRowIds[0] ?? null;
1075
+ for (const row of params.editorData) {
1076
+ const expandedHeight = row.rowHeight || params.rowHeight;
1077
+ const collapsedHeight = row.collapsed?.height ?? params.collapsedRowHeight;
1078
+ const isCollapsed = Boolean(row.collapsed && row.id !== focusedRowId);
1079
+ const height = isCollapsed ? collapsedHeight : expandedHeight;
1080
+ layouts.push({
1081
+ row,
1082
+ top: totalHeight,
1083
+ height,
1084
+ isCollapsed
1085
+ });
1086
+ totalHeight += height;
1087
+ }
1088
+ return {
1089
+ layouts,
1090
+ totalHeight,
1091
+ defaultExpandedRowIds
1092
+ };
1093
+ }
1094
+ //#endregion
1095
+ //#region src/components/edit_area/edit-area.tsx
1096
+ const EditArea = ({ ref, ...props }) => {
1097
+ const { snapData, handleInitSnap, handleUpdateSnap, disposeSnap } = useSnap({
1098
+ snap: props.snap,
1099
+ hideCursor: props.hideCursor,
1100
+ cursorTime: props.cursorTime,
1101
+ scaleWidth: props.scaleWidth,
1102
+ scale: props.scale,
1103
+ startLeft: props.startLeft,
1104
+ getAssistDragLineActionIds: props.getAssistDragLineActionIds,
1105
+ editorData: props.editorData,
1106
+ snapPositions: props.snapPositions
1107
+ });
1108
+ const currentScaleWidth = props.scaleWidth ?? 160;
1109
+ const currentStartLeft = props.startLeft ?? 20;
1110
+ const contentWidth = Math.max(props.scaleCount * currentScaleWidth + currentStartLeft, props.timelineWidth);
1111
+ const rows = (() => {
1112
+ let result = [];
1113
+ for (const { row, top, height, isCollapsed } of props.rowLayouts) result.push(/* @__PURE__ */ createElement(EditRow, {
1114
+ ...props,
1115
+ key: row.id,
1116
+ rowData: row,
1117
+ rowRenderHeight: height,
1118
+ isCollapsed,
1119
+ snapData,
1120
+ scrollContainerRef: props.scrollElementRef,
1121
+ style: {
1122
+ position: "absolute",
1123
+ top: 0,
1124
+ left: 0,
1125
+ width: contentWidth,
1126
+ height: `${height}px`,
1127
+ transform: `translateY(${top}px)`
1128
+ },
1129
+ onPointerEnter: () => {
1130
+ if (row.collapsed) props.setHoveredRowId(row.id);
1131
+ },
1132
+ onPointerLeave: () => {
1133
+ props.clearHoveredRowId(row.id);
1134
+ props.onTimelineCursorPreviewPointerLeave?.();
1135
+ },
1136
+ onTimelineCursorPreviewPointerMove: props.onTimelineCursorPreviewPointerMove,
1137
+ onTimelineCursorPreviewPointerLeave: props.onTimelineCursorPreviewPointerLeave,
1138
+ onActionMoveStart: (data) => {
1139
+ if (row.collapsed) props.setLockedRowId(row.id);
1140
+ handleInitSnap(data);
1141
+ return props.onActionMoveStart && props.onActionMoveStart(data);
1142
+ },
1143
+ onActionResizeStart: (data) => {
1144
+ if (row.collapsed) props.setLockedRowId(row.id);
1145
+ handleInitSnap(data);
1146
+ return props.onActionResizeStart && props.onActionResizeStart(data);
1147
+ },
1148
+ onActionMoving: (data) => {
1149
+ handleUpdateSnap(data);
1150
+ return props.onActionMoving && props.onActionMoving(data);
1151
+ },
1152
+ onActionResizing: (data) => {
1153
+ handleUpdateSnap(data);
1154
+ return props.onActionResizing && props.onActionResizing(data);
1155
+ },
1156
+ onActionResizeEnd: (data) => {
1157
+ props.setLockedRowId(null);
1158
+ disposeSnap();
1159
+ return props.onActionResizeEnd && props.onActionResizeEnd(data);
1160
+ },
1161
+ onActionMoveEnd: (data) => {
1162
+ props.setLockedRowId(null);
1163
+ disposeSnap();
1164
+ return props.onActionMoveEnd && props.onActionMoveEnd(data);
1165
+ }
1166
+ }));
1167
+ return result;
1168
+ })();
1169
+ return /* @__PURE__ */ jsxs("div", {
1170
+ ref,
1171
+ style: {
1172
+ width: contentWidth,
1173
+ height: props.rowLayoutsTotalHeight,
1174
+ position: "relative",
1175
+ backgroundPositionX: `0, ${props.startLeft ?? 20}px`,
1176
+ backgroundSize: `${props.startLeft ?? 20}px, ${props.scaleWidth ?? 160}px`
1177
+ },
1178
+ className: "timeline-editor-edit-area",
1179
+ children: [rows, props.snap && /* @__PURE__ */ jsx(SnapGuideLines, { ...snapData })]
1180
+ });
1181
+ };
1182
+ //#endregion
1183
+ //#region src/components/time_area/time-area.tsx
1184
+ function TimeArea({ scaleSplitCount, scaleWidth, startLeft, scaleCount, maxScaleCount, scale, scrollElementRef, onClickTimeArea, setCursor, getScaleRender, onTimelineCursorPreviewPointerMove, onTimelineCursorPreviewPointerLeave }) {
1185
+ const splitCount = scaleSplitCount ?? 1;
1186
+ const width = scaleWidth ?? 160;
1187
+ const left = startLeft ?? 20;
1188
+ /** Whether to show sub-scale marks */
1189
+ const showUnit = (scaleSplitCount ?? 0) > 0;
1190
+ const columnCount = showUnit ? scaleCount * (scaleSplitCount ?? 1) + 1 : scaleCount;
1191
+ const totalWidth = (showUnit ? width / splitCount : width) * (columnCount - 1) + left;
1192
+ const getTimeFromPointerX = (currentTarget, clientX) => {
1193
+ const leftStart = startLeft ?? 20;
1194
+ const widthValue = scaleWidth ?? 160;
1195
+ const scaleValue = scale ?? 1;
1196
+ const maxCount = maxScaleCount ?? Infinity;
1197
+ const position = clientX - currentTarget.getBoundingClientRect().x;
1198
+ const maxLeft = Number.isFinite(maxCount) ? maxCount * widthValue + leftStart : totalWidth;
1199
+ if (position < leftStart || position > maxLeft) return null;
1200
+ return parserPixelToTime(position, {
1201
+ startLeft: leftStart,
1202
+ scale: scaleValue,
1203
+ scaleWidth: widthValue
1204
+ });
1205
+ };
1206
+ const getColumnWidth = (index) => {
1207
+ switch (index) {
1208
+ case 0: return left;
1209
+ default: return showUnit ? width / splitCount : width;
1210
+ }
1211
+ };
1212
+ const virtualizer = useVirtualizer({
1213
+ horizontal: true,
1214
+ count: columnCount,
1215
+ getScrollElement: () => scrollElementRef.current,
1216
+ estimateSize: getColumnWidth,
1217
+ overscan: 10
1218
+ });
1219
+ useEffect(() => virtualizer.measure(), [
1220
+ scale,
1221
+ scaleWidth,
1222
+ startLeft,
1223
+ virtualizer
1224
+ ]);
1225
+ return /* @__PURE__ */ jsx("div", {
1226
+ style: { width: `${totalWidth}px` },
1227
+ className: prefix("time-area"),
1228
+ onPointerMove: (e) => {
1229
+ const time = getTimeFromPointerX(e.currentTarget, e.clientX);
1230
+ if (time === null) {
1231
+ onTimelineCursorPreviewPointerLeave?.();
1232
+ return;
1233
+ }
1234
+ onTimelineCursorPreviewPointerMove?.({
1235
+ surface: "time-area",
1236
+ time
1237
+ });
1238
+ },
1239
+ onPointerLeave: () => {
1240
+ onTimelineCursorPreviewPointerLeave?.();
1241
+ },
1242
+ onClick: (e) => {
1243
+ const leftStart = startLeft ?? 20;
1244
+ const widthValue = scaleWidth ?? 160;
1245
+ const scaleValue = scale ?? 1;
1246
+ const maxCount = maxScaleCount ?? Infinity;
1247
+ const rect = e.currentTarget.getBoundingClientRect();
1248
+ const position = e.clientX - rect.x;
1249
+ const left = Math.max(position, leftStart);
1250
+ if (left > maxCount * widthValue + leftStart) return;
1251
+ const time = parserPixelToTime(left, {
1252
+ startLeft: leftStart,
1253
+ scale: scaleValue,
1254
+ scaleWidth: widthValue
1255
+ });
1256
+ onClickTimeArea && onClickTimeArea(time, e);
1257
+ if (e.defaultPrevented) return;
1258
+ setCursor({ time });
1259
+ },
1260
+ children: virtualizer.getVirtualItems().map((virtualColumn) => {
1261
+ const columnIndex = virtualColumn.index;
1262
+ const splitCount = scaleSplitCount ?? 1;
1263
+ const scaleValue = scale ?? 1;
1264
+ const isShowScale = showUnit ? columnIndex % splitCount === 0 : true;
1265
+ const classNames = [prefix("time-unit"), isShowScale ? prefix("time-unit-big") : prefix("time-unit-small")];
1266
+ const item = (showUnit ? columnIndex / splitCount : columnIndex) * scaleValue;
1267
+ return /* @__PURE__ */ jsx("div", {
1268
+ "data-index": virtualColumn.index,
1269
+ style: {
1270
+ width: `${virtualColumn.size}px`,
1271
+ transform: `translateX(${virtualColumn.start}px)`
1272
+ },
1273
+ className: classNames.join(" "),
1274
+ children: isShowScale && /* @__PURE__ */ jsx("div", {
1275
+ className: prefix("time-unit-scale"),
1276
+ children: getScaleRender?.(item) ?? item
1277
+ })
1278
+ }, virtualColumn.key);
1279
+ })
1280
+ });
1281
+ }
1282
+ //#endregion
1283
+ //#region src/utils/with-hook.tsx
1284
+ function withHooks(hook) {
1285
+ const Component = ({ children, ...params }) => {
1286
+ return children(hook(params));
1287
+ };
1288
+ Component.displayName = `withHooks(${hook.name || "Hook"})`;
1289
+ return Component;
1290
+ }
1291
+ //#endregion
1292
+ //#region src/utils/measured.tsx
1293
+ function useMeasure({ elementRef }) {
1294
+ const [size, setSize] = useState({
1295
+ width: 0,
1296
+ height: 0
1297
+ });
1298
+ useLayoutEffect(() => {
1299
+ if (!elementRef.current) return;
1300
+ resize(elementRef.current, (_el, size) => {
1301
+ setSize({
1302
+ width: size.width,
1303
+ height: size.height
1304
+ });
1305
+ });
1306
+ }, [elementRef]);
1307
+ return size;
1308
+ }
1309
+ withHooks(useMeasure);
1310
+ //#endregion
1311
+ //#region src/components/cursor/cursor.tsx
1312
+ const Cursor = ({ disableDrag, height, cursorTime, setCursor, startLeft, scaleWidth, scale, scaleCount, scaleSplitCount, scrollElementRef, maxScaleCount, onCursorDragStart, onCursorDrag, onCursorDragEnd, cursorSnap, autoScrollSpeed, autoScrollMaxSpeed, snapPositions = [] }) => {
1313
+ const rowRnd = useRef(null);
1314
+ const leftStart = startLeft ?? 20;
1315
+ const width = scaleWidth ?? 160;
1316
+ const scaleValue = scale ?? 1;
1317
+ const activeSnapPositions = !cursorSnap ? [] : snapPositions;
1318
+ useEffect(() => {
1319
+ if (rowRnd.current) {
1320
+ const left = startLeft ?? 20;
1321
+ const width = scaleWidth ?? 160;
1322
+ const scaleValue = scale ?? 1;
1323
+ rowRnd.current.updateLeft(parserTimeToPixel(cursorTime, {
1324
+ startLeft: left,
1325
+ scaleWidth: width,
1326
+ scale: scaleValue
1327
+ }));
1328
+ }
1329
+ }, [
1330
+ cursorTime,
1331
+ startLeft,
1332
+ scaleWidth,
1333
+ scale
1334
+ ]);
1335
+ const maxCount = maxScaleCount ?? Infinity;
1336
+ const showUnit = (scaleSplitCount ?? 0) > 0;
1337
+ const splitCount = scaleSplitCount ?? 1;
1338
+ const columnCount = showUnit ? scaleCount * (scaleSplitCount ?? 1) + 1 : scaleCount;
1339
+ const left = startLeft ?? 20;
1340
+ const totalWidth = (showUnit ? width / splitCount : width) * (columnCount - 1) + left;
1341
+ return /* @__PURE__ */ jsx(RowDnd, {
1342
+ start: leftStart,
1343
+ ref: rowRnd,
1344
+ parentRef: scrollElementRef,
1345
+ getBounds: () => {
1346
+ return {
1347
+ left: 0,
1348
+ right: Math.min(totalWidth, maxCount * width + leftStart - (scrollElementRef.current?.scrollLeft ?? 0))
1349
+ };
1350
+ },
1351
+ autoScroll: true,
1352
+ autoScrollSpeed,
1353
+ autoScrollMaxSpeed,
1354
+ enableDragging: !disableDrag,
1355
+ enableResizing: false,
1356
+ snapPositions: activeSnapPositions,
1357
+ snapDistance: 8,
1358
+ snapOrigin: "left",
1359
+ onDragStart: () => {
1360
+ const time = parserPixelToTime(rowRnd.current?.getLeft() ?? parserTimeToPixel(cursorTime, {
1361
+ startLeft: leftStart,
1362
+ scaleWidth: width,
1363
+ scale: scaleValue
1364
+ }), {
1365
+ startLeft: leftStart,
1366
+ scale: scaleValue,
1367
+ scaleWidth: width
1368
+ });
1369
+ onCursorDragStart && onCursorDragStart(time);
1370
+ },
1371
+ onDragEnd: ({ left }) => {
1372
+ const time = parserPixelToTime(left, {
1373
+ startLeft: leftStart,
1374
+ scale: scaleValue,
1375
+ scaleWidth: width
1376
+ });
1377
+ setCursor({ time });
1378
+ onCursorDragEnd && onCursorDragEnd(time);
1379
+ },
1380
+ onDrag: ({ left }) => {
1381
+ const time = parserPixelToTime(left, {
1382
+ startLeft: leftStart,
1383
+ scale: scaleValue,
1384
+ scaleWidth: width
1385
+ });
1386
+ setCursor({ time });
1387
+ onCursorDrag && onCursorDrag(time);
1388
+ },
1389
+ children: /* @__PURE__ */ jsxs("div", {
1390
+ className: prefix("cursor"),
1391
+ style: { height },
1392
+ children: [/* @__PURE__ */ jsx("svg", {
1393
+ className: prefix("cursor-top"),
1394
+ width: "8",
1395
+ height: "12",
1396
+ viewBox: "0 0 8 12",
1397
+ fill: "none",
1398
+ children: /* @__PURE__ */ jsx("path", {
1399
+ d: "M0 1C0 0.447715 0.447715 0 1 0H7C7.55228 0 8 0.447715 8 1V9.38197C8 9.76074 7.786 10.107 7.44721 10.2764L4.44721 11.7764C4.16569 11.9172 3.83431 11.9172 3.55279 11.7764L0.552786 10.2764C0.214002 10.107 0 9.76074 0 9.38197V1Z",
1400
+ fill: "currentColor"
1401
+ })
1402
+ }), /* @__PURE__ */ jsx("div", { className: prefix("cursor-area") })]
1403
+ })
1404
+ });
1405
+ };
1406
+ //#endregion
1407
+ //#region src/components/cursor/timeline-cursor-preview.tsx
1408
+ const HIDDEN_DISTANCE = 2;
1409
+ const VISIBLE_DISTANCE = 16;
1410
+ const MAX_OPACITY = 1;
1411
+ const TimelineCursorPreview = ({ cursorTime, height, preview, startLeft, scaleWidth, scale, getTimelineCursorPreviewHeadRender }) => {
1412
+ const transformOptions = {
1413
+ startLeft: startLeft ?? 20,
1414
+ scaleWidth: scaleWidth ?? 160,
1415
+ scale: scale ?? 1
1416
+ };
1417
+ const previewLeft = parserTimeToPixel(preview.time, transformOptions);
1418
+ const cursorLeft = parserTimeToPixel(cursorTime, transformOptions);
1419
+ const distance = Math.abs(previewLeft - cursorLeft);
1420
+ const opacity = distance <= HIDDEN_DISTANCE ? 0 : Math.min(MAX_OPACITY, (distance - HIDDEN_DISTANCE) / (VISIBLE_DISTANCE - HIDDEN_DISTANCE) * MAX_OPACITY);
1421
+ return /* @__PURE__ */ jsxs("div", {
1422
+ className: prefix("cursor-preview"),
1423
+ style: {
1424
+ height,
1425
+ opacity,
1426
+ transform: `translateX(${previewLeft}px) scaleX(0.5)`
1427
+ },
1428
+ "aria-hidden": "true",
1429
+ children: [getTimelineCursorPreviewHeadRender ? /* @__PURE__ */ jsx("div", {
1430
+ className: prefix("cursor-preview-head"),
1431
+ children: getTimelineCursorPreviewHeadRender(preview)
1432
+ }) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("svg", {
1433
+ className: prefix("cursor-top"),
1434
+ width: "8",
1435
+ height: "12",
1436
+ viewBox: "0 0 8 12",
1437
+ fill: "none",
1438
+ "aria-hidden": "true",
1439
+ children: /* @__PURE__ */ jsx("path", {
1440
+ d: "M0 1C0 0.447715 0.447715 0 1 0H7C7.55228 0 8 0.447715 8 1V9.38197C8 9.76074 7.786 10.107 7.44721 10.2764L4.44721 11.7764C4.16569 11.9172 3.83431 11.9172 3.55279 11.7764L0.552786 10.2764C0.214002 10.107 0 9.76074 0 9.38197V1Z",
1441
+ fill: "currentColor"
1442
+ })
1443
+ }) }), /* @__PURE__ */ jsx("div", { className: prefix("cursor-area") })]
1444
+ });
1445
+ };
1446
+ //#endregion
1447
+ //#region src/components/scroll-area.tsx
1448
+ function ScrollBar({ className, orientation = "vertical", ...props }) {
1449
+ return /* @__PURE__ */ jsx(ScrollArea.ScrollAreaScrollbar, {
1450
+ "data-slot": "scroll-area-scrollbar",
1451
+ orientation,
1452
+ className,
1453
+ ...props,
1454
+ children: /* @__PURE__ */ jsx(ScrollArea.ScrollAreaThumb, { "data-slot": "scroll-area-thumb" })
1455
+ });
1456
+ }
1457
+ //#endregion
1458
+ //#region src/components/hooks/use-stable-scroll.ts
1459
+ /**
1460
+ * Hook to maintain scroll position stability when scale or scaleWidth changes.
1461
+ * Uses the cursor time as a reference point to keep it visually stable.
1462
+ */
1463
+ function useStableScroll({ scrollElementRef, scale, scaleWidth, startLeft, cursorTimeRef }) {
1464
+ const prevScaleRef = useRef(null);
1465
+ const prevScaleWidthRef = useRef(null);
1466
+ useLayoutEffect(() => {
1467
+ const scrollElement = scrollElementRef.current;
1468
+ if (prevScaleRef.current !== null && prevScaleWidthRef.current !== null && scrollElement && (prevScaleRef.current !== scale || prevScaleWidthRef.current !== scaleWidth)) {
1469
+ const currentScrollLeft = scrollElement.scrollLeft;
1470
+ const cursorTime = cursorTimeRef.current;
1471
+ const oldCursorPixelPosition = parserTimeToPixel(cursorTime, {
1472
+ startLeft,
1473
+ scale: prevScaleRef.current,
1474
+ scaleWidth: prevScaleWidthRef.current
1475
+ });
1476
+ scrollElement.scrollLeft = parserTimeToPixel(cursorTime, {
1477
+ startLeft,
1478
+ scale,
1479
+ scaleWidth
1480
+ }) - (oldCursorPixelPosition - currentScrollLeft);
1481
+ }
1482
+ prevScaleRef.current = scale;
1483
+ prevScaleWidthRef.current = scaleWidth;
1484
+ }, [
1485
+ scale,
1486
+ scaleWidth,
1487
+ startLeft,
1488
+ scrollElementRef,
1489
+ cursorTimeRef
1490
+ ]);
1491
+ }
1492
+ //#endregion
1493
+ //#region src/components/timeline.tsx
1494
+ function Timeline({ ref, ...props }) {
1495
+ const timelineProps = withDefaults(props);
1496
+ const domRef = useRef(null);
1497
+ const warnedDefaultRowsRef = useRef("");
1498
+ const warnedMissingActionPreviewRowRef = useRef("");
1499
+ const { width, height } = useMeasure({ elementRef: domRef });
1500
+ const [hoveredRowId, setHoveredRowId] = useState(null);
1501
+ const [lockedRowId, setLockedRowId] = useState(null);
1502
+ const [timelineCursorPreview, setTimelineCursorPreview] = useState(null);
1503
+ const [isCursorDragging, setIsCursorDragging] = useState(false);
1504
+ const editorAreaKey = props.unstable_forceRemountEditorArea ?? 0;
1505
+ const minScaleCount = timelineProps.minScaleCount ?? Math.max(getScaleCountByRows(timelineProps.editorData, {
1506
+ scale: timelineProps.scale,
1507
+ pad: .1
1508
+ }), Math.ceil((width - timelineProps.startLeft) / timelineProps.scaleWidth));
1509
+ const derivedScaleCount = Math.min(timelineProps.maxScaleCount, minScaleCount);
1510
+ const snapPositions = !timelineProps.editorData ? [] : parserActionsToPositions(timelineProps.editorData.flatMap((row) => row.actions), {
1511
+ startLeft: timelineProps.startLeft,
1512
+ scale: timelineProps.scale,
1513
+ scaleWidth: timelineProps.scaleWidth
1514
+ });
1515
+ const [overrideScaleCount, setOverrideScaleCount] = useState(null);
1516
+ useLayoutEffect(() => {
1517
+ setOverrideScaleCount(null);
1518
+ }, [derivedScaleCount]);
1519
+ const scaleCount = overrideScaleCount ?? derivedScaleCount;
1520
+ const rowPresentation = getTimelineRowPresentation({
1521
+ editorData: timelineProps.editorData,
1522
+ rowHeight: timelineProps.rowHeight,
1523
+ collapsedRowHeight: timelineProps.collapsedRowHeight ?? timelineProps.rowHeight,
1524
+ hoveredRowId,
1525
+ lockedRowId
1526
+ });
1527
+ const duplicateDefaultRowsKey = rowPresentation.defaultExpandedRowIds.join("\n");
1528
+ if (rowPresentation.defaultExpandedRowIds.length > 1 && warnedDefaultRowsRef.current !== duplicateDefaultRowsKey) {
1529
+ warnedDefaultRowsRef.current = duplicateDefaultRowsKey;
1530
+ console.warn("Warning: multiple collapsible rows set expandedByDefault. The first row in editorData wins.");
1531
+ }
1532
+ if (timelineProps.actionPreview && !timelineProps.editorData.some((row) => row.id === timelineProps.actionPreview?.rowId) && warnedMissingActionPreviewRowRef.current !== timelineProps.actionPreview.rowId) {
1533
+ warnedMissingActionPreviewRowRef.current = timelineProps.actionPreview.rowId;
1534
+ console.warn(`Warning: actionPreview rowId "${timelineProps.actionPreview.rowId}" does not match any timeline row.`);
1535
+ }
1536
+ /** Dynamically set scale count - overrides the derived value */
1537
+ const handleSetScaleCount = (value) => {
1538
+ setOverrideScaleCount(Math.min(timelineProps.maxScaleCount, value));
1539
+ };
1540
+ const [cursorTime, setCursorTime] = useState(0);
1541
+ const cursorTimeRef = useRef(0);
1542
+ useStableScroll({
1543
+ scrollElementRef: domRef,
1544
+ scale: timelineProps.scale,
1545
+ scaleWidth: timelineProps.scaleWidth,
1546
+ startLeft: timelineProps.startLeft,
1547
+ cursorTimeRef
1548
+ });
1549
+ /** Handle editor data changes */
1550
+ const handleEditorDataChange = (editorData) => {
1551
+ timelineProps.onChange?.(editorData);
1552
+ };
1553
+ /** Handle cursor */
1554
+ const handleSetCursor = (param) => {
1555
+ let { left, time } = param;
1556
+ if (typeof time !== "undefined") {
1557
+ setCursorTime(time);
1558
+ cursorTimeRef.current = time;
1559
+ return true;
1560
+ }
1561
+ if (typeof left !== "undefined") {
1562
+ setCursorTime(cursorTimeRef.current = parserPixelToTime(left, {
1563
+ startLeft: timelineProps.startLeft,
1564
+ scale: timelineProps.scale,
1565
+ scaleWidth: timelineProps.scaleWidth
1566
+ }));
1567
+ return true;
1568
+ }
1569
+ return false;
1570
+ };
1571
+ const handleTimelineCursorPreviewPointerMove = useCallback((preview) => {
1572
+ setTimelineCursorPreview(preview);
1573
+ }, []);
1574
+ const handleTimelineCursorPreviewPointerLeave = useCallback(() => {
1575
+ setTimelineCursorPreview(null);
1576
+ }, []);
1577
+ const timelineCursorHeight = Math.max(height, rowPresentation.totalHeight + 42);
1578
+ const showTimelineCursorPreview = timelineProps.showTimelineCursorPreview !== false && (timelineProps.showTimelineCursorPreview === true || Boolean(timelineProps.getTimelineCursorPreviewHeadRender));
1579
+ const handleScrollToTime = (time, options = {}) => {
1580
+ const element = domRef.current;
1581
+ if (!element) return;
1582
+ const { block = "start", offset = 0, onlyIfNotVisible = false } = options;
1583
+ const target = parserTimeToPixel(time, {
1584
+ startLeft: timelineProps.startLeft,
1585
+ scale: timelineProps.scale,
1586
+ scaleWidth: timelineProps.scaleWidth
1587
+ });
1588
+ const viewportWidth = element.clientWidth;
1589
+ if (onlyIfNotVisible) {
1590
+ const currentScrollLeft = element.scrollLeft;
1591
+ if (target >= currentScrollLeft && target <= currentScrollLeft + viewportWidth) return;
1592
+ }
1593
+ let targetScrollLeft;
1594
+ if (block === "end") targetScrollLeft = target - viewportWidth + offset;
1595
+ else if (block === "center") targetScrollLeft = target - viewportWidth / 2;
1596
+ else targetScrollLeft = target - offset;
1597
+ const maxScrollLeft = Math.max(0, element.scrollWidth - viewportWidth);
1598
+ element.scrollTo({
1599
+ left: Math.min(Math.max(targetScrollLeft, 0), maxScrollLeft),
1600
+ behavior: options.behavior ?? "instant"
1601
+ });
1602
+ };
1603
+ useImperativeHandle(ref, () => ({
1604
+ get target() {
1605
+ return domRef.current;
1606
+ },
1607
+ set time(time) {
1608
+ handleSetCursor({ time });
1609
+ },
1610
+ get time() {
1611
+ return cursorTimeRef.current;
1612
+ },
1613
+ getTime() {
1614
+ return cursorTimeRef.current;
1615
+ },
1616
+ setTime(time) {
1617
+ handleSetCursor({ time });
1618
+ },
1619
+ getTimePixelPosition(time) {
1620
+ return parserTimeToPixel(time ?? cursorTimeRef.current, {
1621
+ startLeft: timelineProps.startLeft,
1622
+ scale: timelineProps.scale,
1623
+ scaleWidth: timelineProps.scaleWidth
1624
+ });
1625
+ },
1626
+ setScrollLeft: (val) => {
1627
+ if (!domRef.current) return;
1628
+ domRef.current.scrollLeft = val;
1629
+ },
1630
+ setScrollTop: (val) => {
1631
+ if (!domRef.current) return;
1632
+ domRef.current.scrollTop = val;
1633
+ },
1634
+ get scrollLeft() {
1635
+ if (!domRef.current) return 0;
1636
+ return domRef.current.scrollLeft;
1637
+ },
1638
+ get scrollTop() {
1639
+ if (!domRef.current) return 0;
1640
+ return domRef.current.scrollTop;
1641
+ },
1642
+ set scrollLeft(val) {
1643
+ if (!domRef.current) return;
1644
+ domRef.current.scrollLeft = val;
1645
+ },
1646
+ set scrollTop(val) {
1647
+ if (!domRef.current) return;
1648
+ domRef.current.scrollTop = val;
1649
+ },
1650
+ scrollToTime: handleScrollToTime
1651
+ }));
1652
+ return /* @__PURE__ */ jsxs(ScrollArea.Root, {
1653
+ style: timelineProps.style,
1654
+ className: `${PREFIX} ${timelineProps.disableDrag ? PREFIX + "-disable" : ""}`,
1655
+ "data-slot": "scroll-area",
1656
+ children: [
1657
+ /* @__PURE__ */ jsxs(ScrollArea.Viewport, {
1658
+ "data-slot": "scroll-area-viewport",
1659
+ ref: domRef,
1660
+ onScroll: (e) => {
1661
+ timelineProps.onScroll?.(e.currentTarget);
1662
+ },
1663
+ children: [
1664
+ /* @__PURE__ */ jsx(TimeArea, {
1665
+ ...timelineProps,
1666
+ setCursor: handleSetCursor,
1667
+ scaleCount,
1668
+ scrollElementRef: domRef,
1669
+ onTimelineCursorPreviewPointerMove: showTimelineCursorPreview ? handleTimelineCursorPreviewPointerMove : void 0,
1670
+ onTimelineCursorPreviewPointerLeave: showTimelineCursorPreview ? handleTimelineCursorPreviewPointerLeave : void 0
1671
+ }),
1672
+ /* @__PURE__ */ jsx(EditArea, {
1673
+ ...timelineProps,
1674
+ scrollElementRef: domRef,
1675
+ timelineWidth: width,
1676
+ timelineHeight: height,
1677
+ disableDrag: timelineProps.disableDrag,
1678
+ editorData: timelineProps.editorData,
1679
+ cursorTime,
1680
+ scaleCount,
1681
+ setScaleCount: handleSetScaleCount,
1682
+ setEditorData: handleEditorDataChange,
1683
+ snapPositions,
1684
+ rowLayouts: rowPresentation.layouts,
1685
+ rowLayoutsTotalHeight: rowPresentation.totalHeight,
1686
+ setHoveredRowId,
1687
+ clearHoveredRowId: (rowId) => {
1688
+ setHoveredRowId((currentRowId) => currentRowId === rowId ? null : currentRowId);
1689
+ },
1690
+ setLockedRowId,
1691
+ onTimelineCursorPreviewPointerMove: showTimelineCursorPreview ? handleTimelineCursorPreviewPointerMove : void 0,
1692
+ onTimelineCursorPreviewPointerLeave: showTimelineCursorPreview ? handleTimelineCursorPreviewPointerLeave : void 0
1693
+ }, `__editor_area_${editorAreaKey}__`),
1694
+ showTimelineCursorPreview && timelineCursorPreview && !isCursorDragging && /* @__PURE__ */ jsx(TimelineCursorPreview, {
1695
+ cursorTime,
1696
+ height: timelineCursorHeight,
1697
+ preview: timelineCursorPreview,
1698
+ startLeft: timelineProps.startLeft,
1699
+ scaleWidth: timelineProps.scaleWidth,
1700
+ scale: timelineProps.scale,
1701
+ getTimelineCursorPreviewHeadRender: timelineProps.getTimelineCursorPreviewHeadRender
1702
+ }),
1703
+ !timelineProps.hideCursor && /* @__PURE__ */ jsx(Cursor, {
1704
+ ...timelineProps,
1705
+ timelineWidth: width,
1706
+ height: timelineCursorHeight,
1707
+ scaleCount,
1708
+ setScaleCount: handleSetScaleCount,
1709
+ setCursor: handleSetCursor,
1710
+ cursorTime,
1711
+ editorData: timelineProps.editorData,
1712
+ scrollElementRef: domRef,
1713
+ snapPositions,
1714
+ onCursorDragStart: (time) => {
1715
+ setIsCursorDragging(true);
1716
+ timelineProps.onCursorDragStart?.(time);
1717
+ },
1718
+ onCursorDragEnd: (time) => {
1719
+ setIsCursorDragging(false);
1720
+ timelineProps.onCursorDragEnd?.(time);
1721
+ }
1722
+ })
1723
+ ]
1724
+ }),
1725
+ /* @__PURE__ */ jsx(ScrollBar, { orientation: "horizontal" }),
1726
+ /* @__PURE__ */ jsx(ScrollBar, { orientation: "vertical" }),
1727
+ /* @__PURE__ */ jsx(ScrollArea.Corner, {})
1728
+ ]
1729
+ });
1730
+ }
1731
+ //#endregion
1732
+ export { Timeline };