@hussmartinez/ui 0.10.0 → 0.11.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.11.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,6 +1283,557 @@ var TextField = /* @__PURE__ */ forwardRef(function TextField({ type = "text", o
1283
1283
  onChange: handleChange
1284
1284
  });
1285
1285
  });
1286
+ // src/components/timeline/Timeline.tsx
1287
+ var SNAP_PIXELS = 8;
1288
+ var MAX_TRACK_PIXELS = 8e6;
1289
+ var TimelineContext = /* @__PURE__ */ createContext(void 0);
1290
+ function useTimelineContext(part) {
1291
+ checkSingleCopy();
1292
+ const context = useContext(TimelineContext);
1293
+ if (!context) {
1294
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`${part} needs a Timeline above it.`);
1295
+ }
1296
+ return context;
1297
+ }
1298
+ var NO_SCALE = {
1299
+ length: 0,
1300
+ pixelsPerUnit: 0,
1301
+ toPixels: () => 0,
1302
+ unitAt: () => 0,
1303
+ snap: (unit) => unit,
1304
+ visibleRange: () => ({
1305
+ start: 0,
1306
+ end: 0
1307
+ })
1308
+ };
1309
+ function useTimelineScale() {
1310
+ return useTimelineContext("useTimelineScale")?.scale ?? NO_SCALE;
1311
+ }
1312
+ var isRtl = (element) => getComputedStyle(element).direction === "rtl";
1313
+ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: rawLength, zoom = 1, maxPixelsPerUnit = 48, onMaxZoomChange, snapping = true, snapTargets, onVisibleRangeChange, className, classNames, unstyled, children, ...props }, ref) {
1314
+ const length = Number.isSafeInteger(rawLength) && rawLength > 0 ? rawLength : 0;
1315
+ const viewport = useRef(null);
1316
+ const track = useRef(null);
1317
+ const [room, setRoom] = useState(0);
1318
+ const lead = useRef(0);
1319
+ const targets = useRef(/* @__PURE__ */ new Set());
1320
+ const measure = (element) => {
1321
+ const style = getComputedStyle(element);
1322
+ const padding = Number.parseFloat(style.paddingLeft) + Number.parseFloat(style.paddingRight);
1323
+ lead.current = Number.parseFloat(style.paddingInlineStart) || 0;
1324
+ setRoom(Math.max(0, element.clientWidth - padding));
1325
+ };
1326
+ const remeasure = useRef(measure);
1327
+ remeasure.current = measure;
1328
+ useEffect(() => {
1329
+ const element = viewport.current;
1330
+ if (!element) return;
1331
+ const observer = new ResizeObserver(() => remeasure.current(element));
1332
+ observer.observe(element);
1333
+ return () => observer.disconnect();
1334
+ }, []);
1335
+ const fit = length > 0 && room > 0 ? room / length : 0;
1336
+ const closest = Math.max(fit, Math.min(maxPixelsPerUnit, MAX_TRACK_PIXELS / Math.max(length, 1)));
1337
+ const pixelsPerUnit = Math.min(Math.max(fit * zoom, fit), closest);
1338
+ const maxZoom = fit > 0 ? closest / fit : 1;
1339
+ const notifyMaxZoom = useRef(onMaxZoomChange);
1340
+ notifyMaxZoom.current = onMaxZoomChange;
1341
+ useEffect(() => {
1342
+ if (fit > 0) notifyMaxZoom.current?.(maxZoom);
1343
+ }, [fit, maxZoom]);
1344
+ const sizeTrack = (element) => {
1345
+ element.style.inlineSize = pixelsPerUnit > 0 ? `${length * pixelsPerUnit}px` : "";
1346
+ };
1347
+ const settings = useRef({
1348
+ snapping,
1349
+ snapTargets
1350
+ });
1351
+ settings.current = {
1352
+ snapping,
1353
+ snapTargets
1354
+ };
1355
+ const scale = useMemo(() => {
1356
+ const snap$2 = (unit) => {
1357
+ if (!settings.current.snapping || pixelsPerUnit <= 0) return unit;
1358
+ const all = [...settings.current.snapTargets ?? []];
1359
+ for (const read of targets.current) all.push(...read());
1360
+ const valid = all.filter((target) => Number.isSafeInteger(target) && target >= 0);
1361
+ return snap(unit, valid, Math.round(SNAP_PIXELS / pixelsPerUnit));
1362
+ };
1363
+ return {
1364
+ length,
1365
+ pixelsPerUnit,
1366
+ toPixels: (unit) => unit * pixelsPerUnit,
1367
+ unitAt: (clientX, options) => {
1368
+ const element = track.current;
1369
+ if (!element || pixelsPerUnit <= 0) return 0;
1370
+ const box = element.getBoundingClientRect();
1371
+ const offset = isRtl(element) ? box.right - clientX : clientX - box.left;
1372
+ const unit = Math.min(Math.max(Math.round(offset / pixelsPerUnit), 0), length);
1373
+ return options?.snap ? Math.min(snap$2(unit), length) : unit;
1374
+ },
1375
+ snap: snap$2,
1376
+ visibleRange: () => {
1377
+ const element = viewport.current;
1378
+ if (!element || pixelsPerUnit <= 0) return {
1379
+ start: 0,
1380
+ end: length
1381
+ };
1382
+ const start = (Math.abs(element.scrollLeft) - lead.current) / pixelsPerUnit;
1383
+ return {
1384
+ start: Math.min(Math.max(Math.floor(start), 0), length),
1385
+ end: Math.min(Math.max(Math.ceil(start + element.clientWidth / pixelsPerUnit), 0), length)
1386
+ };
1387
+ }
1388
+ };
1389
+ }, [length, pixelsPerUnit]);
1390
+ const addTargets = useCallback((read) => {
1391
+ targets.current.add(read);
1392
+ return () => {
1393
+ targets.current.delete(read);
1394
+ };
1395
+ }, []);
1396
+ const notifyRange = useRef(onVisibleRangeChange);
1397
+ notifyRange.current = onVisibleRangeChange;
1398
+ const lastRange = useRef("");
1399
+ const reportRange = useCallback(() => {
1400
+ const range = scale.visibleRange();
1401
+ const key = `${range.start}:${range.end}`;
1402
+ if (key !== lastRange.current && scale.pixelsPerUnit > 0) {
1403
+ lastRange.current = key;
1404
+ notifyRange.current?.(range);
1405
+ }
1406
+ }, [scale]);
1407
+ useEffect(reportRange, [reportRange, room]);
1408
+ const context = useMemo(() => ({
1409
+ scale,
1410
+ viewport,
1411
+ track,
1412
+ addTargets
1413
+ }), [scale, addTargets]);
1414
+ return /* @__PURE__ */ jsx("section", {
1415
+ ...props,
1416
+ ref,
1417
+ "aria-label": label,
1418
+ className: cx("hm-timeline", classNames?.root, className),
1419
+ "data-hm-unstyled": unstyledAttribute(unstyled),
1420
+ children: /* @__PURE__ */ jsx("div", {
1421
+ ref: (node) => {
1422
+ viewport.current = node;
1423
+ if (node) measure(node);
1424
+ },
1425
+ className: cx("hm-timeline-viewport", classNames?.viewport),
1426
+ onScroll: reportRange,
1427
+ children: /* @__PURE__ */ jsx("div", {
1428
+ ref: (node) => {
1429
+ track.current = node;
1430
+ if (node) sizeTrack(node);
1431
+ },
1432
+ className: cx("hm-timeline-track", classNames?.track),
1433
+ children: /* @__PURE__ */ jsx(TimelineContext.Provider, {
1434
+ value: context,
1435
+ children
1436
+ })
1437
+ })
1438
+ })
1439
+ });
1440
+ });
1441
+ var TimelineLayer = /* @__PURE__ */ forwardRef(function TimelineLayer({ className, children, ...props }, ref) {
1442
+ return /* @__PURE__ */ jsx("div", {
1443
+ ...props,
1444
+ ref,
1445
+ className: cx("hm-timeline-layer", className),
1446
+ children
1447
+ });
1448
+ });
1449
+ // src/components/timeline/TimelineClips.tsx
1450
+ var Clip = /* @__PURE__ */ memo(function Clip({ clip, selected, tabStop, clipClass, contentClass, edges, dragging }) {
1451
+ return /* @__PURE__ */ jsxs("div", {
1452
+ ...clip.attributes,
1453
+ role: "option",
1454
+ "aria-selected": selected,
1455
+ "aria-label": clip.label,
1456
+ tabIndex: tabStop ? 0 : -1,
1457
+ "data-hm-key": clip.key,
1458
+ "data-hm-dragging": dragging,
1459
+ className: clipClass,
1460
+ children: [clip.content == null ? null : /* @__PURE__ */ jsx("span", {
1461
+ className: contentClass,
1462
+ children: clip.content
1463
+ }), edges ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
1464
+ className: "hm-timeline-clip-edge",
1465
+ "data-hm-edge": "start",
1466
+ "aria-hidden": "true"
1467
+ }), /* @__PURE__ */ jsx("span", {
1468
+ className: "hm-timeline-clip-edge",
1469
+ "data-hm-edge": "end",
1470
+ "aria-hidden": "true"
1471
+ })] }) : null]
1472
+ });
1473
+ });
1474
+ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, clips: given, selectionMode = "single", selectedKeys, onSelectedKeysChange, onMove, onTrim, onTrimToPlayhead, trimStep = 1, trimLimits, className, classNames, unstyled }, ref) {
1475
+ const context = useTimelineContext("TimelineClips");
1476
+ const pixelsPerUnit = context?.scale.pixelsPerUnit ?? 0;
1477
+ const multiple = selectionMode === "multiple";
1478
+ const clips = useMemo(() => {
1479
+ const valid = given.filter((clip) => Number.isSafeInteger(clip.length) && clip.length > 0);
1480
+ if (valid.length !== given.length) {
1481
+ 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.");
1482
+ }
1483
+ return valid;
1484
+ }, [given]);
1485
+ const offsets = useMemo(() => sequenceOffsets(clips.map((clip) => clip.length)), [clips]);
1486
+ const list = useRef(null);
1487
+ const [focusKey, setFocusKey] = useState(null);
1488
+ const anchor = useRef(null);
1489
+ const held = useRef(null);
1490
+ const moved = useRef(false);
1491
+ const selected = useMemo(() => new Set(selectedKeys), [selectedKeys]);
1492
+ const tabStop = clips.find((clip) => clip.key === focusKey) ?? clips.find((clip) => selected.has(clip.key)) ?? clips[0];
1493
+ const option = (key) => {
1494
+ for (const element of list.current?.children ?? []) if (element.dataset["hmKey"] === key) return element;
1495
+ return null;
1496
+ };
1497
+ const focusClip = (key) => {
1498
+ const element = option(key);
1499
+ if (!element) return false;
1500
+ setFocusKey(key);
1501
+ element.focus({ preventScroll: true });
1502
+ const viewport = context?.viewport.current;
1503
+ if (viewport) {
1504
+ const box = element.getBoundingClientRect();
1505
+ const view = viewport.getBoundingClientRect();
1506
+ if (box.left < view.left) viewport.scrollLeft -= view.left - box.left;
1507
+ else if (box.right > view.right) viewport.scrollLeft += Math.min(box.right - view.right, box.left - view.left);
1508
+ }
1509
+ return true;
1510
+ };
1511
+ useImperativeHandle(ref, () => ({ focusClip }));
1512
+ const addTargets = context?.addTargets;
1513
+ const boundaries = useRef(offsets);
1514
+ boundaries.current = offsets;
1515
+ useEffect(() => addTargets?.(() => boundaries.current), [addTargets]);
1516
+ const [drag, setDrag] = useState(null);
1517
+ const sized = useRef(null);
1518
+ const sizeClips = (element) => {
1519
+ if (sized.current?.clips === clips && sized.current.scale === pixelsPerUnit && sized.current.drag === drag) return;
1520
+ sized.current = {
1521
+ clips,
1522
+ scale: pixelsPerUnit,
1523
+ drag
1524
+ };
1525
+ const elements = element.children;
1526
+ for (let index = 0; index < elements.length; index++) {
1527
+ const clip = clips[index];
1528
+ const length = (clip?.length ?? 0) + (clip && drag?.key === clip.key ? drag.delta : 0);
1529
+ elements[index].style.inlineSize = pixelsPerUnit > 0 ? `${length * pixelsPerUnit}px` : "";
1530
+ }
1531
+ };
1532
+ useEffect(() => {
1533
+ const was = held.current;
1534
+ if (!was) return;
1535
+ if (clips.some((clip) => clip.key === was.key)) {
1536
+ const active = document.activeElement;
1537
+ if (moved.current && (!active || active === document.body)) focusClip(was.key);
1538
+ moved.current = false;
1539
+ return;
1540
+ }
1541
+ moved.current = false;
1542
+ held.current = null;
1543
+ const active = document.activeElement;
1544
+ if (active && active !== document.body) return;
1545
+ const next = clips[Math.min(was.index, clips.length - 1)];
1546
+ if (next) focusClip(next.key);
1547
+ else context?.track.current?.querySelector(".hm-timeline-playhead-slider")?.focus();
1548
+ });
1549
+ const dragging = useRef(null);
1550
+ const handlePointerDown = (event) => {
1551
+ const handle = event.target.closest("[data-hm-edge]");
1552
+ const key = handle?.closest("[data-hm-key]")?.dataset["hmKey"];
1553
+ const index = clips.findIndex((clip) => clip.key === key);
1554
+ const clip = clips[index];
1555
+ if (!handle || !clip || !onTrim || event.button !== 0 || pixelsPerUnit <= 0) return;
1556
+ const edge = handle.dataset["hmEdge"] === "start" ? "start" : "end";
1557
+ const limits = trimLimits?.(clip.key, edge);
1558
+ dragging.current = {
1559
+ pointerId: event.pointerId,
1560
+ x: event.clientX,
1561
+ key: clip.key,
1562
+ edge,
1563
+ boundary: offsets[edge === "start" ? index : index + 1] ?? 0,
1564
+ min: Math.max(limits?.min ?? Number.NEGATIVE_INFINITY, 1 - clip.length),
1565
+ max: limits?.max ?? Number.POSITIVE_INFINITY,
1566
+ delta: 0
1567
+ };
1568
+ try {
1569
+ handle.setPointerCapture(event.pointerId);
1570
+ } catch {}
1571
+ setDrag({
1572
+ key: clip.key,
1573
+ edge,
1574
+ delta: 0
1575
+ });
1576
+ };
1577
+ const handlePointerMove = (event) => {
1578
+ const start = dragging.current;
1579
+ if (!start || event.pointerId !== start.pointerId || pixelsPerUnit <= 0) return;
1580
+ const along = getComputedStyle(event.currentTarget).direction === "rtl" ? start.x - event.clientX : event.clientX - start.x;
1581
+ const to = Math.max(0, start.boundary + Math.round(along / pixelsPerUnit));
1582
+ const snapped = event.altKey ? to : context?.scale.snap(to) ?? to;
1583
+ const change = start.edge === "start" ? start.boundary - snapped : snapped - start.boundary;
1584
+ const delta = Math.min(Math.max(change, start.min), start.max);
1585
+ start.delta = delta;
1586
+ setDrag((current) => current && current.delta !== delta ? {
1587
+ ...current,
1588
+ delta
1589
+ } : current);
1590
+ };
1591
+ const endDrag = (commit) => {
1592
+ const start = dragging.current;
1593
+ dragging.current = null;
1594
+ setDrag(null);
1595
+ if (commit && start && start.delta !== 0) onTrim?.(start.key, start.edge, start.delta);
1596
+ };
1597
+ const isDragging = drag !== null;
1598
+ useEffect(() => {
1599
+ if (!isDragging) return;
1600
+ const onKeyDown = (event) => {
1601
+ if (event.key === "Escape") {
1602
+ event.preventDefault();
1603
+ dragging.current = null;
1604
+ setDrag(null);
1605
+ }
1606
+ };
1607
+ document.addEventListener("keydown", onKeyDown, true);
1608
+ return () => document.removeEventListener("keydown", onKeyDown, true);
1609
+ }, [isDragging]);
1610
+ const select = (keys) => {
1611
+ const wanted = new Set(keys);
1612
+ const next = clips.filter((clip) => wanted.has(clip.key)).map((clip) => clip.key);
1613
+ if (next.length !== selectedKeys.length || next.some((key, i) => key !== selectedKeys[i])) onSelectedKeysChange(next);
1614
+ };
1615
+ const range = (to) => {
1616
+ const from = Math.max(0, clips.findIndex((clip) => clip.key === anchor.current));
1617
+ return clips.slice(Math.min(from, to), Math.max(from, to) + 1).map((clip) => clip.key);
1618
+ };
1619
+ const toggle = (key) => {
1620
+ const next = new Set(selected);
1621
+ if (!next.delete(key)) next.add(key);
1622
+ anchor.current = key;
1623
+ select(next);
1624
+ };
1625
+ const handleKeyDown = (event) => {
1626
+ if (event.defaultPrevented || event.nativeEvent.isComposing) return;
1627
+ const key = event.target.dataset["hmKey"];
1628
+ const index = clips.findIndex((clip) => clip.key === key);
1629
+ const current = clips[index];
1630
+ if (!current) return;
1631
+ const mod = event.ctrlKey || event.metaKey;
1632
+ const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
1633
+ const forward = rtl ? "ArrowLeft" : "ArrowRight";
1634
+ const backward = rtl ? "ArrowRight" : "ArrowLeft";
1635
+ const edge = event.code === "BracketLeft" ? "start" : event.code === "BracketRight" ? "end" : void 0;
1636
+ if (event.altKey) {
1637
+ if (mod) return;
1638
+ if ((event.key === forward || event.key === backward) && !event.shiftKey) {
1639
+ event.preventDefault();
1640
+ if (onMove) {
1641
+ moved.current = true;
1642
+ onMove(selected.has(current.key) ? clips.filter((clip) => selected.has(clip.key)).map((clip) => clip.key) : [current.key], event.key === forward ? 1 : -1);
1643
+ }
1644
+ } else if (edge && onTrim) {
1645
+ event.preventDefault();
1646
+ onTrim(current.key, edge, event.shiftKey ? trimStep : -trimStep);
1647
+ }
1648
+ return;
1649
+ }
1650
+ if (edge && !mod && !event.shiftKey) {
1651
+ if (onTrimToPlayhead) {
1652
+ event.preventDefault();
1653
+ onTrimToPlayhead(current.key, edge);
1654
+ }
1655
+ return;
1656
+ }
1657
+ let to;
1658
+ if (event.key === forward) to = Math.min(index + 1, clips.length - 1);
1659
+ else if (event.key === backward) to = Math.max(index - 1, 0);
1660
+ else if (event.key === "Home") to = 0;
1661
+ else if (event.key === "End") to = clips.length - 1;
1662
+ const target = to === void 0 ? void 0 : clips[to];
1663
+ if (to !== void 0 && target) {
1664
+ if (event.shiftKey && (mod || !multiple)) return;
1665
+ event.preventDefault();
1666
+ focusClip(target.key);
1667
+ if (event.shiftKey) select(range(to));
1668
+ else if (!mod) {
1669
+ anchor.current = target.key;
1670
+ select([target.key]);
1671
+ }
1672
+ return;
1673
+ }
1674
+ if (event.key === " " || event.key === "Enter" && !mod && !event.shiftKey) {
1675
+ event.preventDefault();
1676
+ if (!multiple) select([current.key]);
1677
+ else if (event.shiftKey) select(range(index));
1678
+ else if (event.key === " ") toggle(current.key);
1679
+ else {
1680
+ anchor.current = current.key;
1681
+ select([current.key]);
1682
+ }
1683
+ } else if (multiple && mod && !event.shiftKey && event.key.toLowerCase() === "a") {
1684
+ event.preventDefault();
1685
+ select(clips.map((clip) => clip.key));
1686
+ }
1687
+ };
1688
+ const handleClick = (event) => {
1689
+ const key = event.target.closest("[data-hm-key]")?.dataset["hmKey"];
1690
+ const index = clips.findIndex((clip) => clip.key === key);
1691
+ if (key === void 0 || index === -1 || event.defaultPrevented) return;
1692
+ setFocusKey(key);
1693
+ if (multiple && event.shiftKey) select(range(index));
1694
+ else if (multiple && (event.ctrlKey || event.metaKey)) toggle(key);
1695
+ else {
1696
+ anchor.current = key;
1697
+ select([key]);
1698
+ }
1699
+ };
1700
+ const handleFocus = (event) => {
1701
+ const key = event.target.dataset["hmKey"];
1702
+ const index = clips.findIndex((clip) => clip.key === key);
1703
+ if (key !== void 0 && index !== -1) {
1704
+ held.current = {
1705
+ key,
1706
+ index
1707
+ };
1708
+ setFocusKey(key);
1709
+ anchor.current ??= key;
1710
+ }
1711
+ };
1712
+ const handleBlur = (event) => {
1713
+ if (event.relatedTarget) {
1714
+ if (!event.currentTarget.contains(event.relatedTarget)) held.current = null;
1715
+ return;
1716
+ }
1717
+ const target = event.target;
1718
+ queueMicrotask(() => {
1719
+ if (target.isConnected) held.current = null;
1720
+ });
1721
+ };
1722
+ const clipClass = cx("hm-timeline-clip", classNames?.clip);
1723
+ const contentClass = cx("hm-timeline-clip-content", classNames?.content);
1724
+ return /* @__PURE__ */ jsx("div", {
1725
+ ref: (node) => {
1726
+ list.current = node;
1727
+ if (node) sizeClips(node);
1728
+ },
1729
+ role: "listbox",
1730
+ "aria-label": label,
1731
+ "aria-orientation": "horizontal",
1732
+ "aria-multiselectable": multiple ? true : void 0,
1733
+ className: cx("hm-timeline-clips", classNames?.root, className),
1734
+ "data-hm-unstyled": unstyledAttribute(unstyled),
1735
+ "data-hm-measured": pixelsPerUnit > 0 ? "" : void 0,
1736
+ onKeyDown: handleKeyDown,
1737
+ onClick: handleClick,
1738
+ onPointerDown: handlePointerDown,
1739
+ onPointerMove: handlePointerMove,
1740
+ onPointerUp: () => endDrag(true),
1741
+ onPointerCancel: () => endDrag(false),
1742
+ onFocus: handleFocus,
1743
+ onBlur: handleBlur,
1744
+ children: clips.map((clip) => /* @__PURE__ */ jsx(Clip, {
1745
+ clip,
1746
+ selected: selected.has(clip.key),
1747
+ tabStop: clip === tabStop,
1748
+ clipClass,
1749
+ contentClass,
1750
+ edges: onTrim !== void 0,
1751
+ dragging: drag?.key === clip.key ? drag.edge : void 0
1752
+ }, clip.key))
1753
+ });
1754
+ });
1755
+ // src/components/timeline/TimelinePlayhead.tsx
1756
+ var OWN_PRESS = "input, button, a[href], select, textarea, [role=\"option\"], [tabindex]";
1757
+ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ label, position: rawPosition, onPositionChange, step = 1, largeStep, formatValue, seekOnPress = true, following = false, className, classNames, unstyled }, ref) {
1758
+ const context = useTimelineContext("TimelinePlayhead");
1759
+ const scale = context?.scale;
1760
+ const length = scale?.length ?? 0;
1761
+ const pixelsPerUnit = scale?.pixelsPerUnit ?? 0;
1762
+ const position = Math.min(Math.max(Math.round(rawPosition) || 0, 0), length);
1763
+ const latest = useRef({
1764
+ position,
1765
+ onPositionChange
1766
+ });
1767
+ latest.current = {
1768
+ position,
1769
+ onPositionChange
1770
+ };
1771
+ const addTargets = context?.addTargets;
1772
+ useEffect(() => addTargets?.(() => [latest.current.position]), [addTargets]);
1773
+ const placeLine = (element) => {
1774
+ element.style.insetInlineStart = `${position * pixelsPerUnit}px`;
1775
+ };
1776
+ const viewport = context?.viewport;
1777
+ const lastScale = useRef(0);
1778
+ useEffect(() => {
1779
+ const element = viewport?.current;
1780
+ const first = lastScale.current === 0 && pixelsPerUnit > 0;
1781
+ const zoomed = lastScale.current !== pixelsPerUnit && lastScale.current > 0;
1782
+ lastScale.current = pixelsPerUnit;
1783
+ if (!element || pixelsPerUnit <= 0 || !(following || zoomed || first)) return;
1784
+ const at = position * pixelsPerUnit;
1785
+ const start = Math.abs(element.scrollLeft);
1786
+ const width = element.clientWidth;
1787
+ if (zoomed || at < start || at > start + width) {
1788
+ const to = Math.max(0, at - (zoomed || first ? width / 2 : width / 10));
1789
+ element.scrollLeft = getComputedStyle(element).direction === "rtl" ? -to : to;
1790
+ }
1791
+ }, [
1792
+ viewport,
1793
+ position,
1794
+ pixelsPerUnit,
1795
+ following
1796
+ ]);
1797
+ const track = context?.track;
1798
+ useEffect(() => {
1799
+ const element = track?.current;
1800
+ if (!element || !seekOnPress || !scale) return;
1801
+ const onPointerDown = (event) => {
1802
+ if (event.button !== 0 || event.defaultPrevented || event.target.closest(OWN_PRESS)) return;
1803
+ const next = scale.unitAt(event.clientX, { snap: !event.altKey });
1804
+ if (next !== latest.current.position) latest.current.onPositionChange(next);
1805
+ };
1806
+ element.addEventListener("pointerdown", onPointerDown);
1807
+ return () => element.removeEventListener("pointerdown", onPointerDown);
1808
+ }, [
1809
+ track,
1810
+ scale,
1811
+ seekOnPress
1812
+ ]);
1813
+ return /* @__PURE__ */ jsxs("div", {
1814
+ className: cx("hm-timeline-playhead", classNames?.root, className),
1815
+ "data-hm-unstyled": unstyledAttribute(unstyled),
1816
+ children: [/* @__PURE__ */ jsx(Slider, {
1817
+ ref,
1818
+ label,
1819
+ min: 0,
1820
+ max: length,
1821
+ step,
1822
+ largeStep,
1823
+ value: position,
1824
+ onValueChange: onPositionChange,
1825
+ formatValue,
1826
+ unstyled,
1827
+ className: cx("hm-timeline-playhead-slider", classNames?.slider)
1828
+ }), /* @__PURE__ */ jsx("div", {
1829
+ ref: (node) => {
1830
+ if (node) placeLine(node);
1831
+ },
1832
+ className: cx("hm-timeline-playhead-line", classNames?.line),
1833
+ "aria-hidden": "true"
1834
+ })]
1835
+ });
1836
+ });
1286
1837
  // src/components/toggle-button/ToggleButton.tsx
1287
1838
  var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: controlled, defaultPressed = false, onPressedChange, onClick, icon, label, className, ...props }, ref) {
1288
1839
  const [uncontrolled, setUncontrolled] = useState(defaultPressed);
@@ -2029,6 +2580,6 @@ function ThemeProvider(props) {
2029
2580
  }), children]
2030
2581
  });
2031
2582
  }
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 };
2583
+ 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, TimelineLayer, TimelinePlayhead, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useTimelineScale, useUiMessages };
2033
2584
 
2034
2585
  //# sourceMappingURL=react.js.map