@hussmartinez/ui 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, t as isThemePair } from "./shared/pair-MeX064R6.js";
3
- import { createMessages, platformOf, sdkCoreMessages } from "@hussmartinez/sdk-core";
4
- import { cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, version } from "react";
3
+ import { createMessages, platformOf, sdkCoreMessages, sequenceOffsets, snap } from "@hussmartinez/sdk-core";
4
+ import { cloneElement, createContext, forwardRef, isValidElement, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore, version } from "react";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { flushSync } from "react-dom";
7
7
  // src/internal/single-copy.ts
@@ -9,7 +9,7 @@ var REGISTRY = /* @__PURE__ */ Symbol.for("@hussmartinez/ui");
9
9
  var THIS_COPY = {};
10
10
  var checked = false;
11
11
  function ownVersion() {
12
- return "0.10.0";
12
+ return "0.12.0";
13
13
  }
14
14
  function checkSingleCopy() {
15
15
  if (checked || !(typeof process !== "undefined" && process.env.NODE_ENV !== "production")) return;
@@ -1169,7 +1169,7 @@ function SegmentedControlImpl({ label, value, onValueChange, options, size = "me
1169
1169
  }
1170
1170
  var SegmentedControl = /* @__PURE__ */ forwardRef(SegmentedControlImpl);
1171
1171
  // src/components/slider/Slider.tsx
1172
- function snap(value, min, max, step) {
1172
+ function snap$1(value, min, max, step) {
1173
1173
  const precision = Math.max(decimals(min), decimals(step));
1174
1174
  const round = (n) => roundTo(n, precision);
1175
1175
  const upper = Math.max(min, max);
@@ -1178,14 +1178,14 @@ function snap(value, min, max, step) {
1178
1178
  return Math.min(Math.max(inRange, min), upper);
1179
1179
  }
1180
1180
  var Slider = /* @__PURE__ */ forwardRef(function Slider({ value: controlled, defaultValue, onValueChange, min = 0, max = 100, step = 1, largeStep, formatValue, label, className, classNames, unstyled, onKeyDown, ...props }, ref) {
1181
- const [uncontrolled, setUncontrolled] = useState(() => snap(defaultValue ?? min, min, max, step));
1182
- const value = snap(controlled ?? uncontrolled, min, max, step);
1181
+ const [uncontrolled, setUncontrolled] = useState(() => snap$1(defaultValue ?? min, min, max, step));
1182
+ const value = snap$1(controlled ?? uncontrolled, min, max, step);
1183
1183
  const fieldProps = useFieldProps(props, label);
1184
1184
  if (label === void 0 && !props["aria-label"] && !props["aria-labelledby"] && fieldProps.id === void 0) {
1185
1185
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("Slider needs an accessible name: pass label, or point a visible <label> at its id. Use text from your message catalogue.");
1186
1186
  }
1187
1187
  const change = (next) => {
1188
- const snapped = snap(next, min, max, step);
1188
+ const snapped = snap$1(next, min, max, step);
1189
1189
  if (snapped === value) return;
1190
1190
  if (controlled === void 0) setUncontrolled(snapped);
1191
1191
  onValueChange?.(snapped);
@@ -1283,30 +1283,867 @@ var TextField = /* @__PURE__ */ forwardRef(function TextField({ type = "text", o
1283
1283
  onChange: handleChange
1284
1284
  });
1285
1285
  });
1286
- // src/components/toggle-button/ToggleButton.tsx
1287
- var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: controlled, defaultPressed = false, onPressedChange, onClick, icon, label, className, ...props }, ref) {
1288
- const [uncontrolled, setUncontrolled] = useState(defaultPressed);
1289
- const pressed = controlled ?? uncontrolled;
1290
- const iconOnly = label !== void 0;
1291
- if (iconOnly && label.trim() === "") {
1292
- if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("ToggleButton needs a label when it shows only an icon: it's the button's only accessible name. Pass text from your message catalogue.");
1286
+ // src/components/timeline/set-style.ts
1287
+ var written = /* @__PURE__ */ new WeakMap();
1288
+ function setStyle(element, property, value) {
1289
+ let last = written.get(element);
1290
+ if (!last) {
1291
+ last = /* @__PURE__ */ new Map();
1292
+ written.set(element, last);
1293
1293
  }
1294
- const handleClick = (event) => {
1295
- onClick?.(event);
1296
- if (event.defaultPrevented) return;
1297
- if (controlled === void 0) setUncontrolled(!pressed);
1298
- onPressedChange?.(!pressed);
1294
+ if ((last.get(property) ?? "") === value) return;
1295
+ last.set(property, value);
1296
+ if (value === "") element.style.removeProperty(property);
1297
+ else element.style.setProperty(property, value);
1298
+ }
1299
+ // src/components/timeline/Timeline.tsx
1300
+ var SNAP_PIXELS = 8;
1301
+ var MAX_TRACK_PIXELS = 8e6;
1302
+ var TimelineLaneContext = /* @__PURE__ */ createContext(void 0);
1303
+ var TimelineContext = /* @__PURE__ */ createContext(void 0);
1304
+ var HEADERS_BESIDE = 720;
1305
+ function useTimelineContext(part) {
1306
+ checkSingleCopy();
1307
+ const context = useContext(TimelineContext);
1308
+ if (!context) {
1309
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`${part} needs a Timeline above it.`);
1310
+ }
1311
+ return context;
1312
+ }
1313
+ var NO_SCALE = {
1314
+ length: 0,
1315
+ extent: 0,
1316
+ pixelsPerUnit: 0,
1317
+ toPixels: () => 0,
1318
+ unitAt: () => 0,
1319
+ snap: (unit) => unit,
1320
+ visibleRange: () => ({
1321
+ start: 0,
1322
+ end: 0
1323
+ })
1324
+ };
1325
+ function useTimelineScale() {
1326
+ return useTimelineContext("useTimelineScale")?.scale ?? NO_SCALE;
1327
+ }
1328
+ var isRtl = (element) => getComputedStyle(element).direction === "rtl";
1329
+ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: rawLength, extent: rawExtent, zoom = 1, maxPixelsPerUnit = 48, onMaxZoomChange, snapping = true, snapTargets, onVisibleRangeChange, className, classNames, unstyled, children, ...props }, ref) {
1330
+ const length = Number.isSafeInteger(rawLength) && rawLength > 0 ? rawLength : 0;
1331
+ const extent = rawExtent !== void 0 && Number.isSafeInteger(rawExtent) ? Math.max(rawExtent, length) : length;
1332
+ const viewport = useRef(null);
1333
+ const track = useRef(null);
1334
+ const [room, setRoom] = useState(0);
1335
+ const lead = useRef(0);
1336
+ const targets = useRef(/* @__PURE__ */ new Set());
1337
+ const laneParts = useRef(/* @__PURE__ */ new Map());
1338
+ const laneClips = useRef(/* @__PURE__ */ new Map());
1339
+ const [lanes, setLanes] = useState([]);
1340
+ const [headerWidth, setHeaderWidth] = useState(0);
1341
+ const [trail, setTrail] = useState(0);
1342
+ const [beside, setBeside] = useState(true);
1343
+ const measure = (element) => {
1344
+ if (laneParts.current.size > 0 || order.current.length > 0) measureLanes(element);
1345
+ const style = getComputedStyle(element);
1346
+ const padding = Number.parseFloat(style.paddingLeft) + Number.parseFloat(style.paddingRight);
1347
+ lead.current = Number.parseFloat(style.paddingInlineStart) || 0;
1348
+ setRoom(Math.max(0, element.clientWidth - padding));
1299
1349
  };
1300
- return /* @__PURE__ */ jsx(Button, {
1350
+ const measureLanes = (element) => {
1351
+ const order = [...laneParts.current.entries()].sort(([, a], [, b]) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
1352
+ const ids = order.map(([id]) => id);
1353
+ setLanes((current) => current.length === ids.length && current.every((id, index) => id === ids[index]) ? current : ids);
1354
+ const wide = element.offsetWidth >= HEADERS_BESIDE;
1355
+ setBeside(wide);
1356
+ const widest = Math.max(0, ...order.map(([, lane]) => lane.toolbar?.offsetWidth ?? 0));
1357
+ const column = wide ? Math.ceil(widest) : 0;
1358
+ setHeaderWidth(column);
1359
+ const after = Number.parseFloat(getComputedStyle(element).paddingInlineEnd) || 0;
1360
+ setTrail(after);
1361
+ setStyle(element, "padding-inline-start", column > 0 ? `${column + after}px` : "");
1362
+ };
1363
+ const remeasure = useRef(measure);
1364
+ remeasure.current = measure;
1365
+ const resized = useRef(null);
1366
+ useEffect(() => {
1367
+ const element = viewport.current;
1368
+ if (!element) return;
1369
+ let frame = 0;
1370
+ const observer = new ResizeObserver(() => {
1371
+ cancelAnimationFrame(frame);
1372
+ frame = requestAnimationFrame(() => remeasure.current(element));
1373
+ });
1374
+ observer.observe(element);
1375
+ resized.current = observer;
1376
+ for (const lane of laneParts.current.values()) if (lane.toolbar) observer.observe(lane.toolbar);
1377
+ return () => {
1378
+ resized.current = null;
1379
+ cancelAnimationFrame(frame);
1380
+ observer.disconnect();
1381
+ };
1382
+ }, []);
1383
+ const fit = extent > 0 && room > 0 ? room / extent : 0;
1384
+ const closest = Math.max(fit, Math.min(maxPixelsPerUnit, MAX_TRACK_PIXELS / Math.max(extent, 1)));
1385
+ const pixelsPerUnit = Math.min(Math.max(fit * zoom, fit), closest);
1386
+ const maxZoom = fit > 0 ? closest / fit : 1;
1387
+ const notifyMaxZoom = useRef(onMaxZoomChange);
1388
+ notifyMaxZoom.current = onMaxZoomChange;
1389
+ useEffect(() => {
1390
+ if (fit > 0) notifyMaxZoom.current?.(maxZoom);
1391
+ }, [fit, maxZoom]);
1392
+ const sizeTrack = (element) => {
1393
+ setStyle(element, "inline-size", pixelsPerUnit > 0 ? `${extent * pixelsPerUnit}px` : "");
1394
+ };
1395
+ const headerColumn = useRef(headerWidth);
1396
+ headerColumn.current = headerWidth;
1397
+ const settings = useRef({
1398
+ snapping,
1399
+ snapTargets
1400
+ });
1401
+ settings.current = {
1402
+ snapping,
1403
+ snapTargets
1404
+ };
1405
+ const snapExceptRef = useRef((unit) => unit);
1406
+ const scale = useMemo(() => {
1407
+ const snap$2 = (unit, except = []) => {
1408
+ if (!settings.current.snapping || pixelsPerUnit <= 0) return unit;
1409
+ const all = [...settings.current.snapTargets ?? []];
1410
+ for (const read of targets.current) all.push(...read());
1411
+ const valid = all.filter((target) => Number.isSafeInteger(target) && target >= 0 && !except.includes(target));
1412
+ return snap(unit, valid, Math.round(SNAP_PIXELS / pixelsPerUnit));
1413
+ };
1414
+ snapExceptRef.current = snap$2;
1415
+ return {
1416
+ length,
1417
+ extent,
1418
+ pixelsPerUnit,
1419
+ toPixels: (unit) => unit * pixelsPerUnit,
1420
+ unitAt: (clientX, options) => {
1421
+ const element = track.current;
1422
+ if (!element || pixelsPerUnit <= 0) return 0;
1423
+ const box = element.getBoundingClientRect();
1424
+ const offset = isRtl(element) ? box.right - clientX : clientX - box.left;
1425
+ const unit = Math.min(Math.max(Math.round(offset / pixelsPerUnit), 0), extent);
1426
+ return options?.snap ? Math.min(snap$2(unit), extent) : unit;
1427
+ },
1428
+ snap: (unit) => snap$2(unit),
1429
+ visibleRange: () => {
1430
+ const element = viewport.current;
1431
+ if (!element || pixelsPerUnit <= 0) return {
1432
+ start: 0,
1433
+ end: extent
1434
+ };
1435
+ const scrolled = Math.abs(element.scrollLeft) - lead.current;
1436
+ const start = (scrolled + headerColumn.current) / pixelsPerUnit;
1437
+ const end = (scrolled + element.clientWidth) / pixelsPerUnit;
1438
+ return {
1439
+ start: Math.min(Math.max(Math.floor(start), 0), extent),
1440
+ end: Math.min(Math.max(Math.ceil(end), 0), extent)
1441
+ };
1442
+ }
1443
+ };
1444
+ }, [
1445
+ length,
1446
+ extent,
1447
+ pixelsPerUnit
1448
+ ]);
1449
+ const addTargets = useCallback((read) => {
1450
+ targets.current.add(read);
1451
+ return () => {
1452
+ targets.current.delete(read);
1453
+ };
1454
+ }, []);
1455
+ const notifyRange = useRef(onVisibleRangeChange);
1456
+ notifyRange.current = onVisibleRangeChange;
1457
+ const lastRange = useRef("");
1458
+ const reportRange = useCallback(() => {
1459
+ const range = scale.visibleRange();
1460
+ const key = `${range.start}:${range.end}`;
1461
+ if (key !== lastRange.current && scale.pixelsPerUnit > 0) {
1462
+ lastRange.current = key;
1463
+ notifyRange.current?.(range);
1464
+ }
1465
+ }, [scale]);
1466
+ useEffect(reportRange, [reportRange, room]);
1467
+ const setLane = useCallback((id, lane) => {
1468
+ const before = laneParts.current.get(id);
1469
+ if (lane) {
1470
+ if (before?.element === lane.element && before.toolbar === lane.toolbar) return;
1471
+ laneParts.current.set(id, lane);
1472
+ if (lane.toolbar) resized.current?.observe(lane.toolbar);
1473
+ } else if (before) {
1474
+ laneParts.current.delete(id);
1475
+ if (before.toolbar) resized.current?.unobserve(before.toolbar);
1476
+ }
1477
+ if (viewport.current) remeasure.current(viewport.current);
1478
+ }, []);
1479
+ const setLaneClips = useCallback((id, clips) => {
1480
+ if (clips) laneClips.current.set(id, clips);
1481
+ else laneClips.current.delete(id);
1482
+ }, []);
1483
+ const order = useRef(lanes);
1484
+ order.current = lanes;
1485
+ const nextLaneClips = useCallback((id, direction) => {
1486
+ const ids = order.current;
1487
+ for (let at = ids.indexOf(id) + direction; at >= 0 && at < ids.length; at += direction) {
1488
+ const clips = laneClips.current.get(ids[at]);
1489
+ if (clips?.any()) return clips;
1490
+ }
1491
+ }, []);
1492
+ const focusOnAnotherLane = useCallback((from, key) => {
1493
+ for (const [id, clips] of laneClips.current) if (id !== from && clips.focus(key)) return true;
1494
+ return false;
1495
+ }, []);
1496
+ const snapExcept = useCallback((unit, except) => snapExceptRef.current(unit, except), []);
1497
+ const context = useMemo(() => ({
1498
+ scale,
1499
+ viewport,
1500
+ track,
1501
+ addTargets,
1502
+ lanes,
1503
+ headerWidth,
1504
+ trail,
1505
+ setLane,
1506
+ setLaneClips,
1507
+ nextLaneClips,
1508
+ focusOnAnotherLane,
1509
+ snapExcept
1510
+ }), [
1511
+ scale,
1512
+ addTargets,
1513
+ lanes,
1514
+ headerWidth,
1515
+ trail,
1516
+ setLane,
1517
+ setLaneClips,
1518
+ nextLaneClips,
1519
+ focusOnAnotherLane,
1520
+ snapExcept
1521
+ ]);
1522
+ const laned = lanes.length > 0;
1523
+ return /* @__PURE__ */ jsx("section", {
1301
1524
  ...props,
1302
1525
  ref,
1303
- ...iconOnly ? {
1304
- "aria-label": label,
1305
- startIcon: icon
1306
- } : {},
1307
- className: cx("hm-toggle-button", iconOnly && "hm-icon-button", className),
1308
- pressed,
1309
- onClick: handleClick
1526
+ "aria-label": label,
1527
+ className: cx("hm-timeline", classNames?.root, className),
1528
+ "data-hm-unstyled": unstyledAttribute(unstyled),
1529
+ "data-hm-lanes": laned ? beside ? "beside" : "above" : void 0,
1530
+ children: /* @__PURE__ */ jsx("div", {
1531
+ ref: (node) => {
1532
+ viewport.current = node;
1533
+ if (node) measure(node);
1534
+ },
1535
+ className: cx("hm-timeline-viewport", classNames?.viewport),
1536
+ onScroll: reportRange,
1537
+ children: /* @__PURE__ */ jsxs("div", {
1538
+ ref: (node) => {
1539
+ track.current = node;
1540
+ if (node) sizeTrack(node);
1541
+ },
1542
+ className: cx("hm-timeline-track", classNames?.track),
1543
+ children: [
1544
+ laned ? /* @__PURE__ */ jsx("div", {
1545
+ className: "hm-timeline-bar",
1546
+ "aria-hidden": "true",
1547
+ ref: (node) => {
1548
+ if (node) setStyle(node, "margin-inline-start", headerWidth > 0 ? `${-(headerWidth + trail)}px` : "");
1549
+ }
1550
+ }) : null,
1551
+ laned && headerWidth > 0 ? /* @__PURE__ */ jsx("div", {
1552
+ className: "hm-timeline-corner",
1553
+ "aria-hidden": "true",
1554
+ ref: (node) => {
1555
+ if (node) {
1556
+ setStyle(node, "margin-inline-start", `${-(headerWidth + trail)}px`);
1557
+ const cover = node.firstElementChild;
1558
+ setStyle(cover, "inline-size", `${headerWidth}px`);
1559
+ setStyle(cover, "inset-inline-start", `${-(headerWidth + trail)}px`);
1560
+ }
1561
+ },
1562
+ children: /* @__PURE__ */ jsx("div", { className: "hm-timeline-corner-cover" })
1563
+ }) : null,
1564
+ /* @__PURE__ */ jsx(TimelineContext.Provider, {
1565
+ value: context,
1566
+ children
1567
+ })
1568
+ ]
1569
+ })
1570
+ })
1571
+ });
1572
+ });
1573
+ var TimelineLayer = /* @__PURE__ */ forwardRef(function TimelineLayer({ className, children, ...props }, ref) {
1574
+ const lanes = useContext(TimelineContext)?.lanes.length ?? 0;
1575
+ const rows = useContext(TimelineLaneContext) !== void 0 ? 0 : lanes;
1576
+ return /* @__PURE__ */ jsx("div", {
1577
+ ...props,
1578
+ ref: (node) => {
1579
+ if (node) setStyle(node, "grid-row", rows > 0 ? `2 / span ${rows}` : "");
1580
+ if (typeof ref === "function") ref(node);
1581
+ else if (ref) ref.current = node;
1582
+ },
1583
+ className: cx("hm-timeline-layer", className),
1584
+ children
1585
+ });
1586
+ });
1587
+ function useTimelineLanes() {
1588
+ const context = useTimelineContext("useTimelineLanes");
1589
+ const lanes = context?.lanes;
1590
+ const track = context?.track;
1591
+ return useMemo(() => ({
1592
+ lanes: lanes ?? [],
1593
+ laneAt: (clientY) => {
1594
+ for (const element of track?.current?.querySelectorAll(":scope > [data-hm-lane]") ?? []) {
1595
+ const box = element.getBoundingClientRect();
1596
+ if (clientY >= box.top && clientY < box.bottom) return element.dataset["hmLane"];
1597
+ }
1598
+ }
1599
+ }), [lanes, track]);
1600
+ }
1601
+ // src/components/timeline/TimelineClips.tsx
1602
+ var DRAG_AFTER = 4;
1603
+ var EDGE = 32;
1604
+ var SCROLL = 12;
1605
+ var Clip = /* @__PURE__ */ memo(function Clip({ clip, selected, tabStop, clipClass, contentClass, edges, dragging, pastEnd, moving }) {
1606
+ return /* @__PURE__ */ jsxs("div", {
1607
+ ...clip.attributes,
1608
+ role: "option",
1609
+ "aria-selected": selected,
1610
+ "aria-label": clip.label,
1611
+ tabIndex: tabStop ? 0 : -1,
1612
+ "data-hm-key": clip.key,
1613
+ "data-hm-dragging": dragging,
1614
+ "data-hm-past-end": pastEnd ? "" : void 0,
1615
+ "data-hm-moving": moving,
1616
+ className: clipClass,
1617
+ children: [clip.content == null ? null : /* @__PURE__ */ jsx("span", {
1618
+ className: contentClass,
1619
+ children: clip.content
1620
+ }), edges ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
1621
+ className: "hm-timeline-clip-edge",
1622
+ "data-hm-edge": "start",
1623
+ "aria-hidden": "true"
1624
+ }), /* @__PURE__ */ jsx("span", {
1625
+ className: "hm-timeline-clip-edge",
1626
+ "data-hm-edge": "end",
1627
+ "aria-hidden": "true"
1628
+ })] }) : null]
1629
+ });
1630
+ });
1631
+ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, clips: given, selectionMode = "single", selectedKeys, onSelectedKeysChange, onMove, onTrim, onTrimToPlayhead, trimStep = 1, trimLimits, onMoveLane, onDrop, canDrop, moveHandle = "clip", className, classNames, unstyled }, ref) {
1632
+ const context = useTimelineContext("TimelineClips");
1633
+ const pixelsPerUnit = context?.scale.pixelsPerUnit ?? 0;
1634
+ const timelineLength = context?.scale.length ?? Number.POSITIVE_INFINITY;
1635
+ const multiple = selectionMode === "multiple";
1636
+ const clips = useMemo(() => {
1637
+ const valid = given.filter((clip) => Number.isSafeInteger(clip.length) && clip.length > 0);
1638
+ if (valid.length !== given.length) {
1639
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("TimelineClips left out a clip whose length isn't a whole number of at least 1.");
1640
+ }
1641
+ return valid;
1642
+ }, [given]);
1643
+ const starts = useMemo(() => {
1644
+ const placed = clips.filter((clip) => clip.at !== void 0).length;
1645
+ if (placed === 0) return sequenceOffsets(clips.map((clip) => clip.length)).slice(0, clips.length);
1646
+ let end = 0;
1647
+ let mistake;
1648
+ if (placed !== clips.length) mistake = "gives some clips `at` and not others: give it to every clip, or to none";
1649
+ const result = clips.map((clip) => {
1650
+ const valid = clip.at !== void 0 && Number.isSafeInteger(clip.at) && clip.at >= 0;
1651
+ const start = valid ? clip.at : end;
1652
+ if (clip.at !== void 0 && !valid) mistake ??= "has a clip whose `at` isn't a whole number of at least 0";
1653
+ else if (start < end) mistake ??= "has clips that overlap or aren't in time order";
1654
+ end = Math.max(end, start + clip.length);
1655
+ return start;
1656
+ });
1657
+ if (mistake) {
1658
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`TimelineClips ${mistake}.`);
1659
+ }
1660
+ return result;
1661
+ }, [clips]);
1662
+ const positioned = clips.some((clip) => clip.at !== void 0);
1663
+ const list = useRef(null);
1664
+ const [focusKey, setFocusKey] = useState(null);
1665
+ const anchor = useRef(null);
1666
+ const held = useRef(null);
1667
+ const moved = useRef(false);
1668
+ const selected = useMemo(() => new Set(selectedKeys), [selectedKeys]);
1669
+ const tabStop = clips.find((clip) => clip.key === focusKey) ?? clips.find((clip) => selected.has(clip.key)) ?? clips[0];
1670
+ const option = (key) => {
1671
+ for (const element of list.current?.children ?? []) if (element.dataset["hmKey"] === key) return element;
1672
+ return null;
1673
+ };
1674
+ const focusClip = (key) => {
1675
+ const element = option(key);
1676
+ if (!element) return false;
1677
+ setFocusKey(key);
1678
+ element.focus({ preventScroll: true });
1679
+ const viewport = context?.viewport.current;
1680
+ if (viewport) {
1681
+ const box = element.getBoundingClientRect();
1682
+ const bounds = viewport.getBoundingClientRect();
1683
+ const header = context?.headerWidth ?? 0;
1684
+ const rtl = getComputedStyle(viewport).direction === "rtl";
1685
+ const view = {
1686
+ left: bounds.left + (rtl ? 0 : header),
1687
+ right: bounds.right - (rtl ? header : 0)
1688
+ };
1689
+ if (box.left < view.left) viewport.scrollLeft -= view.left - box.left;
1690
+ else if (box.right > view.right) viewport.scrollLeft += Math.min(box.right - view.right, box.left - view.left);
1691
+ }
1692
+ return true;
1693
+ };
1694
+ useImperativeHandle(ref, () => ({ focusClip }));
1695
+ const laneId = useContext(TimelineLaneContext);
1696
+ const forLanes = useRef({
1697
+ any: () => false,
1698
+ focus: () => false,
1699
+ focusNearest: () => void 0
1700
+ });
1701
+ forLanes.current = {
1702
+ any: () => clips.length > 0,
1703
+ focus: (key) => clips.some((clip) => clip.key === key) && focusClip(key),
1704
+ focusNearest: (unit, andSelect) => {
1705
+ let nearest;
1706
+ let distance = Number.POSITIVE_INFINITY;
1707
+ clips.forEach((clip, index) => {
1708
+ const start = starts[index] ?? 0;
1709
+ const end = start + clip.length;
1710
+ const away = unit < start ? start - unit : unit >= end ? unit - end + 1 : 0;
1711
+ if (away < distance) {
1712
+ nearest = clip;
1713
+ distance = away;
1714
+ }
1715
+ });
1716
+ if (nearest && focusClip(nearest.key) && andSelect) {
1717
+ anchor.current = nearest.key;
1718
+ select([nearest.key]);
1719
+ }
1720
+ }
1721
+ };
1722
+ const setLaneClips = context?.setLaneClips;
1723
+ useEffect(() => {
1724
+ if (laneId === void 0 || !setLaneClips) return;
1725
+ setLaneClips(laneId, {
1726
+ any: () => forLanes.current.any(),
1727
+ focus: (key) => forLanes.current.focus(key),
1728
+ focusNearest: (unit, andSelect) => forLanes.current.focusNearest(unit, andSelect)
1729
+ });
1730
+ return () => setLaneClips(laneId, null);
1731
+ }, [laneId, setLaneClips]);
1732
+ const addTargets = context?.addTargets;
1733
+ const edges = useMemo(() => [...new Set(clips.flatMap((clip, index) => [starts[index] ?? 0, (starts[index] ?? 0) + clip.length]))], [clips, starts]);
1734
+ const boundaries = useRef(edges);
1735
+ boundaries.current = edges;
1736
+ useEffect(() => addTargets?.(() => boundaries.current), [addTargets]);
1737
+ const [drag, setDrag] = useState(null);
1738
+ const [move, setMove] = useState(null);
1739
+ const sized = useRef(null);
1740
+ const sizeClips = (element) => {
1741
+ if (sized.current?.clips === clips && sized.current.scale === pixelsPerUnit && sized.current.drag === drag && sized.current.move === move) return;
1742
+ sized.current = {
1743
+ clips,
1744
+ scale: pixelsPerUnit,
1745
+ drag,
1746
+ move
1747
+ };
1748
+ const rtl = move ? getComputedStyle(element).direction === "rtl" : false;
1749
+ const elements = element.children;
1750
+ let end = 0;
1751
+ for (let index = 0; index < elements.length; index++) {
1752
+ const clip = clips[index];
1753
+ const node = elements[index];
1754
+ let start = starts[index] ?? end;
1755
+ let length = clip?.length ?? 0;
1756
+ if (clip && drag?.key === clip.key) {
1757
+ length += drag.delta;
1758
+ if (drag.edge === "start" && positioned) start -= drag.delta;
1759
+ }
1760
+ if (!positioned) start = end;
1761
+ const measured = pixelsPerUnit > 0;
1762
+ setStyle(node, "inline-size", measured ? `${length * pixelsPerUnit}px` : "");
1763
+ setStyle(node, "margin-inline-start", measured && start !== end ? `${(start - end) * pixelsPerUnit}px` : "");
1764
+ setStyle(node, "translate", clip && move?.key === clip.key ? `${move.by * pixelsPerUnit * (rtl ? -1 : 1)}px ${move.down}px` : "");
1765
+ end = start + length;
1766
+ }
1767
+ };
1768
+ useEffect(() => {
1769
+ const was = held.current;
1770
+ if (!was) return;
1771
+ if (clips.some((clip) => clip.key === was.key)) {
1772
+ const active = document.activeElement;
1773
+ if (moved.current && (!active || active === document.body)) focusClip(was.key);
1774
+ moved.current = false;
1775
+ return;
1776
+ }
1777
+ moved.current = false;
1778
+ held.current = null;
1779
+ const active = document.activeElement;
1780
+ if (active && active !== document.body) return;
1781
+ if (laneId !== void 0 && context?.focusOnAnotherLane(laneId, was.key)) return;
1782
+ const next = clips[Math.min(was.index, clips.length - 1)];
1783
+ if (next) focusClip(next.key);
1784
+ else context?.track.current?.querySelector(".hm-timeline-playhead-slider")?.focus();
1785
+ });
1786
+ const dragging = useRef(null);
1787
+ const movingWith = (key) => {
1788
+ if (!selected.has(key)) return [key];
1789
+ const own = new Set(clips.map((clip) => clip.key));
1790
+ return [...clips.filter((clip) => selected.has(clip.key)).map((clip) => clip.key), ...selectedKeys.filter((other) => !own.has(other))];
1791
+ };
1792
+ const moving = useRef(null);
1793
+ const dragged = useRef(false);
1794
+ const follow = () => {
1795
+ const at = moving.current;
1796
+ const scale = context?.scale;
1797
+ if (!at || !scale || !list.current) return;
1798
+ let start = Math.max(0, at.start + scale.unitAt(at.lastX) - at.unit);
1799
+ if (!at.alt) {
1800
+ const own = [at.start, at.start + at.length];
1801
+ const byStart = (context?.snapExcept(start, own) ?? start) - start;
1802
+ const end = start + at.length;
1803
+ const byEnd = (context?.snapExcept(end, own) ?? end) - end;
1804
+ start = Math.max(0, start + (byStart !== 0 && (byEnd === 0 || Math.abs(byStart) <= Math.abs(byEnd)) ? byStart : byEnd));
1805
+ }
1806
+ const by = start - at.start;
1807
+ let lane;
1808
+ let down = 0;
1809
+ const ownLane = list.current.closest("[data-hm-lane]");
1810
+ if (ownLane) for (const other of context?.track.current?.querySelectorAll(":scope > [data-hm-lane]") ?? []) {
1811
+ const box = other.getBoundingClientRect();
1812
+ if (at.lastY >= box.top && at.lastY < box.bottom && other !== ownLane) {
1813
+ lane = other.dataset["hmLane"];
1814
+ down = box.top - ownLane.getBoundingClientRect().top;
1815
+ }
1816
+ }
1817
+ const refused = canDrop ? !canDrop(at.keys, {
1818
+ by,
1819
+ lane
1820
+ }) : false;
1821
+ at.by = by;
1822
+ at.lane = lane;
1823
+ at.refused = refused;
1824
+ setMove((current) => current && current.by === by && current.lane === lane && current.down === down && current.refused === refused ? current : {
1825
+ key: at.key,
1826
+ by,
1827
+ lane,
1828
+ down,
1829
+ refused
1830
+ });
1831
+ };
1832
+ const scrollAtEdges = () => {
1833
+ const at = moving.current;
1834
+ const viewport = context?.viewport.current;
1835
+ if (!at?.started || !viewport) return;
1836
+ const box = viewport.getBoundingClientRect();
1837
+ const header = context?.headerWidth ?? 0;
1838
+ const rtl = getComputedStyle(viewport).direction === "rtl";
1839
+ const left = box.left + (rtl ? 0 : header);
1840
+ const right = box.right - (rtl ? header : 0);
1841
+ const step = at.lastX < left + EDGE ? -12 : at.lastX > right - EDGE ? SCROLL : 0;
1842
+ if (step !== 0) {
1843
+ const before = viewport.scrollLeft;
1844
+ viewport.scrollLeft += step;
1845
+ if (viewport.scrollLeft !== before) follow();
1846
+ }
1847
+ at.frame = requestAnimationFrame(scrollAtEdges);
1848
+ };
1849
+ const endMove = (commit) => {
1850
+ const at = moving.current;
1851
+ moving.current = null;
1852
+ if (!at) return;
1853
+ cancelAnimationFrame(at.frame);
1854
+ if (!at.started) return;
1855
+ dragged.current = true;
1856
+ setMove(null);
1857
+ if (commit && !at.refused && (at.by !== 0 || at.lane !== void 0)) {
1858
+ held.current ??= {
1859
+ key: at.key,
1860
+ index: clips.findIndex((clip) => clip.key === at.key)
1861
+ };
1862
+ moved.current = true;
1863
+ onDrop?.(at.keys, {
1864
+ by: at.by,
1865
+ lane: at.lane
1866
+ });
1867
+ }
1868
+ };
1869
+ const handlePointerDown = (event) => {
1870
+ const pressed = event.target.closest("[data-hm-key]");
1871
+ const pressedClip = clips.find((clip) => clip.key === pressed?.dataset["hmKey"]);
1872
+ if (onDrop && pressed && pressedClip && event.button === 0 && event.pointerType !== "touch" && pixelsPerUnit > 0 && !event.target.closest("[data-hm-edge]") && (moveHandle === "clip" || event.target.closest(".hm-timeline-clip-content") !== null)) {
1873
+ const index = clips.indexOf(pressedClip);
1874
+ moving.current = {
1875
+ pointerId: event.pointerId,
1876
+ element: pressed,
1877
+ key: pressedClip.key,
1878
+ keys: movingWith(pressedClip.key),
1879
+ x: event.clientX,
1880
+ y: event.clientY,
1881
+ unit: context?.scale.unitAt(event.clientX) ?? 0,
1882
+ start: starts[index] ?? 0,
1883
+ length: pressedClip.length,
1884
+ started: false,
1885
+ lastX: event.clientX,
1886
+ lastY: event.clientY,
1887
+ alt: event.altKey,
1888
+ by: 0,
1889
+ lane: void 0,
1890
+ refused: false,
1891
+ frame: 0
1892
+ };
1893
+ return;
1894
+ }
1895
+ const handle = event.target.closest("[data-hm-edge]");
1896
+ const key = handle?.closest("[data-hm-key]")?.dataset["hmKey"];
1897
+ const index = clips.findIndex((clip) => clip.key === key);
1898
+ const clip = clips[index];
1899
+ if (!handle || !clip || !onTrim || event.button !== 0 || pixelsPerUnit <= 0) return;
1900
+ const edge = handle.dataset["hmEdge"] === "start" ? "start" : "end";
1901
+ const limits = trimLimits?.(clip.key, edge);
1902
+ dragging.current = {
1903
+ pointerId: event.pointerId,
1904
+ x: event.clientX,
1905
+ key: clip.key,
1906
+ edge,
1907
+ boundary: (starts[index] ?? 0) + (edge === "start" ? 0 : clip.length),
1908
+ min: Math.max(limits?.min ?? Number.NEGATIVE_INFINITY, 1 - clip.length),
1909
+ max: limits?.max ?? Number.POSITIVE_INFINITY,
1910
+ delta: 0
1911
+ };
1912
+ try {
1913
+ handle.setPointerCapture(event.pointerId);
1914
+ } catch {}
1915
+ setDrag({
1916
+ key: clip.key,
1917
+ edge,
1918
+ delta: 0
1919
+ });
1920
+ };
1921
+ const handlePointerMove = (event) => {
1922
+ const at = moving.current;
1923
+ if (at && event.pointerId === at.pointerId) {
1924
+ at.lastX = event.clientX;
1925
+ at.lastY = event.clientY;
1926
+ at.alt = event.altKey;
1927
+ if (!at.started) {
1928
+ if (Math.hypot(event.clientX - at.x, event.clientY - at.y) < DRAG_AFTER) return;
1929
+ at.started = true;
1930
+ try {
1931
+ at.element.setPointerCapture(event.pointerId);
1932
+ } catch {}
1933
+ at.frame = requestAnimationFrame(scrollAtEdges);
1934
+ }
1935
+ follow();
1936
+ return;
1937
+ }
1938
+ const start = dragging.current;
1939
+ if (!start || event.pointerId !== start.pointerId || pixelsPerUnit <= 0) return;
1940
+ const along = getComputedStyle(event.currentTarget).direction === "rtl" ? start.x - event.clientX : event.clientX - start.x;
1941
+ const to = Math.max(0, start.boundary + Math.round(along / pixelsPerUnit));
1942
+ const snapped = event.altKey ? to : context?.scale.snap(to) ?? to;
1943
+ const change = start.edge === "start" ? start.boundary - snapped : snapped - start.boundary;
1944
+ const delta = Math.min(Math.max(change, start.min), start.max);
1945
+ start.delta = delta;
1946
+ setDrag((current) => current && current.delta !== delta ? {
1947
+ ...current,
1948
+ delta
1949
+ } : current);
1950
+ };
1951
+ const endDrag = (commit) => {
1952
+ const start = dragging.current;
1953
+ dragging.current = null;
1954
+ setDrag(null);
1955
+ if (commit && start && start.delta !== 0) onTrim?.(start.key, start.edge, start.delta);
1956
+ };
1957
+ const isDragging = drag !== null || move !== null;
1958
+ useEffect(() => {
1959
+ if (!isDragging) return;
1960
+ const onKeyDown = (event) => {
1961
+ if (event.key === "Escape") {
1962
+ event.preventDefault();
1963
+ dragging.current = null;
1964
+ setDrag(null);
1965
+ if (moving.current) {
1966
+ cancelAnimationFrame(moving.current.frame);
1967
+ moving.current = null;
1968
+ dragged.current = true;
1969
+ setMove(null);
1970
+ }
1971
+ }
1972
+ };
1973
+ document.addEventListener("keydown", onKeyDown, true);
1974
+ return () => document.removeEventListener("keydown", onKeyDown, true);
1975
+ }, [isDragging]);
1976
+ const select = (keys, keepOthers = false) => {
1977
+ const wanted = new Set(keys);
1978
+ const own = new Set(clips.map((clip) => clip.key));
1979
+ const next = clips.filter((clip) => wanted.has(clip.key)).map((clip) => clip.key);
1980
+ if (keepOthers) next.push(...selectedKeys.filter((key) => !own.has(key)));
1981
+ if (next.length !== selectedKeys.length || next.some((key, i) => key !== selectedKeys[i])) onSelectedKeysChange(next);
1982
+ };
1983
+ const range = (to) => {
1984
+ const from = Math.max(0, clips.findIndex((clip) => clip.key === anchor.current));
1985
+ return clips.slice(Math.min(from, to), Math.max(from, to) + 1).map((clip) => clip.key);
1986
+ };
1987
+ const toggle = (key) => {
1988
+ const next = new Set(selected);
1989
+ if (!next.delete(key)) next.add(key);
1990
+ anchor.current = key;
1991
+ select(next, true);
1992
+ };
1993
+ const handleKeyDown = (event) => {
1994
+ if (event.defaultPrevented || event.nativeEvent.isComposing) return;
1995
+ const key = event.target.dataset["hmKey"];
1996
+ const index = clips.findIndex((clip) => clip.key === key);
1997
+ const current = clips[index];
1998
+ if (!current) return;
1999
+ const mod = event.ctrlKey || event.metaKey;
2000
+ const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
2001
+ const forward = rtl ? "ArrowLeft" : "ArrowRight";
2002
+ const backward = rtl ? "ArrowRight" : "ArrowLeft";
2003
+ const edge = event.code === "BracketLeft" ? "start" : event.code === "BracketRight" ? "end" : void 0;
2004
+ if (event.altKey) {
2005
+ if (mod) return;
2006
+ if ((event.key === forward || event.key === backward) && !event.shiftKey) {
2007
+ event.preventDefault();
2008
+ if (onMove) {
2009
+ moved.current = true;
2010
+ onMove(movingWith(current.key), event.key === forward ? 1 : -1);
2011
+ }
2012
+ } else if ((event.key === "ArrowUp" || event.key === "ArrowDown") && !event.shiftKey && laneId !== void 0) {
2013
+ event.preventDefault();
2014
+ if (onMoveLane) {
2015
+ moved.current = true;
2016
+ onMoveLane(movingWith(current.key), event.key === "ArrowDown" ? 1 : -1);
2017
+ }
2018
+ } else if (edge && onTrim) {
2019
+ event.preventDefault();
2020
+ onTrim(current.key, edge, event.shiftKey ? trimStep : -trimStep);
2021
+ }
2022
+ return;
2023
+ }
2024
+ if (edge && !mod && !event.shiftKey) {
2025
+ if (onTrimToPlayhead) {
2026
+ event.preventDefault();
2027
+ onTrimToPlayhead(current.key, edge);
2028
+ }
2029
+ return;
2030
+ }
2031
+ if ((event.key === "ArrowUp" || event.key === "ArrowDown") && laneId !== void 0) {
2032
+ if (event.shiftKey || (context?.lanes.length ?? 0) < 2) return;
2033
+ event.preventDefault();
2034
+ const middle = (starts[index] ?? 0) + current.length / 2;
2035
+ context?.nextLaneClips(laneId, event.key === "ArrowDown" ? 1 : -1)?.focusNearest(middle, !mod);
2036
+ return;
2037
+ }
2038
+ let to;
2039
+ if (event.key === forward) to = Math.min(index + 1, clips.length - 1);
2040
+ else if (event.key === backward) to = Math.max(index - 1, 0);
2041
+ else if (event.key === "Home") to = 0;
2042
+ else if (event.key === "End") to = clips.length - 1;
2043
+ const target = to === void 0 ? void 0 : clips[to];
2044
+ if (to !== void 0 && target) {
2045
+ if (event.shiftKey && (mod || !multiple)) return;
2046
+ event.preventDefault();
2047
+ focusClip(target.key);
2048
+ if (event.shiftKey) select(range(to), true);
2049
+ else if (!mod) {
2050
+ anchor.current = target.key;
2051
+ select([target.key]);
2052
+ }
2053
+ return;
2054
+ }
2055
+ if (event.key === " " || event.key === "Enter" && !mod && !event.shiftKey) {
2056
+ event.preventDefault();
2057
+ if (!multiple) select([current.key]);
2058
+ else if (event.shiftKey) select(range(index), true);
2059
+ else if (event.key === " ") toggle(current.key);
2060
+ else {
2061
+ anchor.current = current.key;
2062
+ select([current.key]);
2063
+ }
2064
+ } else if (multiple && mod && !event.shiftKey && event.key.toLowerCase() === "a") {
2065
+ event.preventDefault();
2066
+ select(clips.map((clip) => clip.key), true);
2067
+ }
2068
+ };
2069
+ const handleClick = (event) => {
2070
+ const key = event.target.closest("[data-hm-key]")?.dataset["hmKey"];
2071
+ const index = clips.findIndex((clip) => clip.key === key);
2072
+ if (key === void 0 || index === -1 || event.defaultPrevented) return;
2073
+ if (dragged.current) {
2074
+ dragged.current = false;
2075
+ return;
2076
+ }
2077
+ setFocusKey(key);
2078
+ if (multiple && event.shiftKey) select(range(index), true);
2079
+ else if (multiple && (event.ctrlKey || event.metaKey)) toggle(key);
2080
+ else {
2081
+ anchor.current = key;
2082
+ select([key]);
2083
+ }
2084
+ };
2085
+ const handleFocus = (event) => {
2086
+ const key = event.target.dataset["hmKey"];
2087
+ const index = clips.findIndex((clip) => clip.key === key);
2088
+ if (key !== void 0 && index !== -1) {
2089
+ held.current = {
2090
+ key,
2091
+ index
2092
+ };
2093
+ setFocusKey(key);
2094
+ anchor.current ??= key;
2095
+ }
2096
+ };
2097
+ const handleBlur = (event) => {
2098
+ if (event.relatedTarget) {
2099
+ if (!event.currentTarget.contains(event.relatedTarget)) held.current = null;
2100
+ return;
2101
+ }
2102
+ const target = event.target;
2103
+ queueMicrotask(() => {
2104
+ if (target.isConnected) held.current = null;
2105
+ });
2106
+ };
2107
+ const clipClass = cx("hm-timeline-clip", classNames?.clip);
2108
+ const contentClass = cx("hm-timeline-clip-content", classNames?.content);
2109
+ return /* @__PURE__ */ jsx("div", {
2110
+ ref: (node) => {
2111
+ list.current = node;
2112
+ if (node) sizeClips(node);
2113
+ },
2114
+ role: "listbox",
2115
+ "aria-label": label,
2116
+ "aria-orientation": "horizontal",
2117
+ "aria-multiselectable": multiple ? true : void 0,
2118
+ className: cx("hm-timeline-clips", classNames?.root, className),
2119
+ "data-hm-unstyled": unstyledAttribute(unstyled),
2120
+ "data-hm-measured": pixelsPerUnit > 0 ? "" : void 0,
2121
+ "data-hm-move-handle": onDrop ? moveHandle : void 0,
2122
+ onKeyDown: handleKeyDown,
2123
+ onClick: handleClick,
2124
+ onPointerDown: handlePointerDown,
2125
+ onPointerMove: handlePointerMove,
2126
+ onPointerUp: () => {
2127
+ endDrag(true);
2128
+ endMove(true);
2129
+ },
2130
+ onPointerCancel: () => {
2131
+ endDrag(false);
2132
+ endMove(false);
2133
+ },
2134
+ onFocus: handleFocus,
2135
+ onBlur: handleBlur,
2136
+ children: clips.map((clip, index) => /* @__PURE__ */ jsx(Clip, {
2137
+ clip,
2138
+ selected: selected.has(clip.key),
2139
+ tabStop: clip === tabStop,
2140
+ clipClass,
2141
+ contentClass,
2142
+ edges: onTrim !== void 0,
2143
+ dragging: drag?.key === clip.key ? drag.edge : void 0,
2144
+ pastEnd: (starts[index] ?? 0) + clip.length > timelineLength,
2145
+ moving: move?.key === clip.key ? move.refused ? "refused" : "allowed" : void 0
2146
+ }, clip.key))
1310
2147
  });
1311
2148
  });
1312
2149
  // src/components/toolbar/Toolbar.tsx
@@ -1357,6 +2194,177 @@ var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation =
1357
2194
  })
1358
2195
  });
1359
2196
  });
2197
+ // src/components/timeline/TimelineLane.tsx
2198
+ var TimelineLane = /* @__PURE__ */ forwardRef(function TimelineLane({ id, label, header, className, classNames, unstyled, children, ...props }, ref) {
2199
+ const context = useTimelineContext("TimelineLane");
2200
+ useContext(TimelineLaneContext);
2201
+ const toolbar = useRef(null);
2202
+ const index = context?.lanes.indexOf(id) ?? -1;
2203
+ const column = context?.headerWidth ?? 0;
2204
+ const trail = context?.trail ?? 0;
2205
+ const setLane = context?.setLane;
2206
+ const hasHeader = header != null && header !== false;
2207
+ useEffect(() => () => setLane?.(id, null), [id, setLane]);
2208
+ return /* @__PURE__ */ jsx("div", {
2209
+ ...props,
2210
+ ref: (node) => {
2211
+ if (node) {
2212
+ setStyle(node, "grid-row", index >= 0 ? String(index + 2) : "");
2213
+ setStyle(node, "margin-inline-start", column > 0 ? `${-(column + trail)}px` : "");
2214
+ setLane?.(id, {
2215
+ element: node,
2216
+ toolbar: toolbar.current
2217
+ });
2218
+ }
2219
+ if (typeof ref === "function") ref(node);
2220
+ else if (ref) ref.current = node;
2221
+ },
2222
+ role: "group",
2223
+ "aria-label": label,
2224
+ "data-hm-lane": id,
2225
+ className: cx("hm-timeline-lane", classNames?.root, className),
2226
+ "data-hm-unstyled": unstyledAttribute(unstyled),
2227
+ children: /* @__PURE__ */ jsxs(TimelineLaneContext.Provider, {
2228
+ value: id,
2229
+ children: [hasHeader ? /* @__PURE__ */ jsx("div", {
2230
+ className: cx("hm-timeline-lane-header", classNames?.header),
2231
+ ref: (node) => {
2232
+ if (node) {
2233
+ setStyle(node, "inline-size", column > 0 ? `${column}px` : "");
2234
+ setStyle(node, "margin-inline-end", column > 0 ? `${trail}px` : "");
2235
+ setStyle(node, "inset-inline-start", column > 0 ? `${-(column + trail)}px` : "");
2236
+ }
2237
+ },
2238
+ children: /* @__PURE__ */ jsx(Toolbar, {
2239
+ ref: toolbar,
2240
+ label,
2241
+ className: "hm-timeline-lane-toolbar",
2242
+ children: header
2243
+ })
2244
+ }) : null, children]
2245
+ })
2246
+ });
2247
+ });
2248
+ // src/components/timeline/TimelinePlayhead.tsx
2249
+ var OWN_PRESS = "input, button, a[href], select, textarea, [role=\"option\"], [tabindex]";
2250
+ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ label, position: rawPosition, onPositionChange, step = 1, largeStep, formatValue, seekOnPress = true, following = false, className, classNames, unstyled }, ref) {
2251
+ const context = useTimelineContext("TimelinePlayhead");
2252
+ const scale = context?.scale;
2253
+ const length = scale?.length ?? 0;
2254
+ const pixelsPerUnit = scale?.pixelsPerUnit ?? 0;
2255
+ const extent = scale?.extent ?? 0;
2256
+ const position = Math.min(Math.max(Math.round(rawPosition) || 0, 0), length);
2257
+ const latest = useRef({
2258
+ position,
2259
+ onPositionChange
2260
+ });
2261
+ latest.current = {
2262
+ position,
2263
+ onPositionChange
2264
+ };
2265
+ const addTargets = context?.addTargets;
2266
+ useEffect(() => addTargets?.(() => [latest.current.position]), [addTargets]);
2267
+ const placeLine = (element) => {
2268
+ setStyle(element, "inset-inline-start", `${position * pixelsPerUnit}px`);
2269
+ };
2270
+ const viewport = context?.viewport;
2271
+ const header = context?.headerWidth ?? 0;
2272
+ const lanes = context?.lanes.length ?? 0;
2273
+ const lastScale = useRef(0);
2274
+ useEffect(() => {
2275
+ const element = viewport?.current;
2276
+ const first = lastScale.current === 0 && pixelsPerUnit > 0;
2277
+ const zoomed = lastScale.current !== pixelsPerUnit && lastScale.current > 0;
2278
+ lastScale.current = pixelsPerUnit;
2279
+ if (!element || pixelsPerUnit <= 0 || !(following || zoomed || first)) return;
2280
+ const at = position * pixelsPerUnit;
2281
+ const start = Math.abs(element.scrollLeft);
2282
+ const width = element.clientWidth - header;
2283
+ if (zoomed || at < start || at > start + width) {
2284
+ const to = Math.max(0, at - (zoomed || first ? width / 2 : width / 10));
2285
+ element.scrollLeft = getComputedStyle(element).direction === "rtl" ? -to : to;
2286
+ }
2287
+ }, [
2288
+ viewport,
2289
+ position,
2290
+ pixelsPerUnit,
2291
+ following,
2292
+ header
2293
+ ]);
2294
+ const track = context?.track;
2295
+ useEffect(() => {
2296
+ const element = track?.current;
2297
+ if (!element || !seekOnPress || !scale) return;
2298
+ const onPointerDown = (event) => {
2299
+ if (event.button !== 0 || event.defaultPrevented || event.target.closest(OWN_PRESS)) return;
2300
+ const next = scale.unitAt(event.clientX, { snap: !event.altKey });
2301
+ if (next !== latest.current.position) latest.current.onPositionChange(next);
2302
+ };
2303
+ element.addEventListener("pointerdown", onPointerDown);
2304
+ return () => element.removeEventListener("pointerdown", onPointerDown);
2305
+ }, [
2306
+ track,
2307
+ scale,
2308
+ seekOnPress
2309
+ ]);
2310
+ return /* @__PURE__ */ jsxs("div", {
2311
+ ref: (node) => {
2312
+ if (node) {
2313
+ setStyle(node, "grid-row", lanes > 0 ? `1 / span ${lanes + 1}` : "");
2314
+ const shorter = extent > length && pixelsPerUnit > 0;
2315
+ setStyle(node, "justify-self", shorter ? "start" : "");
2316
+ setStyle(node, "inline-size", shorter ? `${length * pixelsPerUnit}px` : "");
2317
+ }
2318
+ },
2319
+ className: cx("hm-timeline-playhead", classNames?.root, className),
2320
+ "data-hm-unstyled": unstyledAttribute(unstyled),
2321
+ children: [/* @__PURE__ */ jsx(Slider, {
2322
+ ref,
2323
+ label,
2324
+ min: 0,
2325
+ max: length,
2326
+ step,
2327
+ largeStep,
2328
+ value: position,
2329
+ onValueChange: onPositionChange,
2330
+ formatValue,
2331
+ unstyled,
2332
+ className: cx("hm-timeline-playhead-slider", classNames?.slider)
2333
+ }), /* @__PURE__ */ jsx("div", {
2334
+ ref: (node) => {
2335
+ if (node) placeLine(node);
2336
+ },
2337
+ className: cx("hm-timeline-playhead-line", classNames?.line),
2338
+ "aria-hidden": "true"
2339
+ })]
2340
+ });
2341
+ });
2342
+ // src/components/toggle-button/ToggleButton.tsx
2343
+ var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: controlled, defaultPressed = false, onPressedChange, onClick, icon, label, className, ...props }, ref) {
2344
+ const [uncontrolled, setUncontrolled] = useState(defaultPressed);
2345
+ const pressed = controlled ?? uncontrolled;
2346
+ const iconOnly = label !== void 0;
2347
+ if (iconOnly && label.trim() === "") {
2348
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment("ToggleButton needs a label when it shows only an icon: it's the button's only accessible name. Pass text from your message catalogue.");
2349
+ }
2350
+ const handleClick = (event) => {
2351
+ onClick?.(event);
2352
+ if (event.defaultPrevented) return;
2353
+ if (controlled === void 0) setUncontrolled(!pressed);
2354
+ onPressedChange?.(!pressed);
2355
+ };
2356
+ return /* @__PURE__ */ jsx(Button, {
2357
+ ...props,
2358
+ ref,
2359
+ ...iconOnly ? {
2360
+ "aria-label": label,
2361
+ startIcon: icon
2362
+ } : {},
2363
+ className: cx("hm-toggle-button", iconOnly && "hm-icon-button", className),
2364
+ pressed,
2365
+ onClick: handleClick
2366
+ });
2367
+ });
1360
2368
  // src/components/toolbar/ToolbarGroup.tsx
1361
2369
  var ToolbarGroup = /* @__PURE__ */ forwardRef(function ToolbarGroup({ label, className, ...props }, ref) {
1362
2370
  return /* @__PURE__ */ jsx("div", {
@@ -2029,6 +3037,6 @@ function ThemeProvider(props) {
2029
3037
  }), children]
2030
3038
  });
2031
3039
  }
2032
- export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, ImageIcon, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextArea, TextField, TextIcon, ThemeProvider, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useUiMessages };
3040
+ export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, ImageIcon, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextArea, TextField, TextIcon, ThemeProvider, Timeline, TimelineClips, TimelineLane, TimelineLayer, TimelinePlayhead, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useTimelineLanes, useTimelineScale, useUiMessages };
2033
3041
 
2034
3042
  //# sourceMappingURL=react.js.map