@hussmartinez/ui 0.9.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/README.md +12 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +493 -1
- package/dist/react.js +849 -68
- package/dist/react.js.map +1 -1
- package/dist/shared/{pair-pt-vUVwu.js → pair-MeX064R6.js} +2 -1
- package/dist/shared/pair-MeX064R6.js.map +1 -0
- package/dist/styles.css +262 -0
- package/dist/ui.d.ts +493 -1
- package/package.json +1 -1
- package/dist/shared/pair-pt-vUVwu.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, t as isThemePair } from "./shared/pair-
|
|
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";
|
|
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, 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.
|
|
12
|
+
return "0.11.0";
|
|
13
13
|
}
|
|
14
14
|
function checkSingleCopy() {
|
|
15
15
|
if (checked || !(typeof process !== "undefined" && process.env.NODE_ENV !== "production")) return;
|
|
@@ -838,6 +838,274 @@ var ProgressBar = /* @__PURE__ */ forwardRef(function ProgressBar({ value, max =
|
|
|
838
838
|
"data-hm-unstyled": unstyledAttribute(unstyled)
|
|
839
839
|
});
|
|
840
840
|
});
|
|
841
|
+
// src/components/toolbar/roving-focus.ts
|
|
842
|
+
var FOCUSABLE = "button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex^=\"-\"]):not(button, a, input, select, textarea), [data-hm-roving]:not(:disabled)";
|
|
843
|
+
function items(toolbar) {
|
|
844
|
+
return [...toolbar.querySelectorAll(FOCUSABLE)].filter((element) => !element.closest("[hidden], [inert]") && element.getClientRects().length > 0);
|
|
845
|
+
}
|
|
846
|
+
function syncTabStop$1(toolbar, active) {
|
|
847
|
+
const list = items(toolbar);
|
|
848
|
+
const current = list.find((item) => item === active) ?? list.find((item) => item.tabIndex === 0 && item.dataset["hmTabStop"] !== void 0) ?? list[0];
|
|
849
|
+
for (const item of list) {
|
|
850
|
+
const isStop = item === current;
|
|
851
|
+
item.dataset["hmRoving"] = "";
|
|
852
|
+
item.tabIndex = isStop ? 0 : -1;
|
|
853
|
+
if (isStop) item.dataset["hmTabStop"] = "";
|
|
854
|
+
else delete item.dataset["hmTabStop"];
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function editsText$1(target) {
|
|
858
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
859
|
+
return target.isContentEditable || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLInputElement && ![
|
|
860
|
+
"button",
|
|
861
|
+
"checkbox",
|
|
862
|
+
"radio",
|
|
863
|
+
"reset",
|
|
864
|
+
"submit"
|
|
865
|
+
].includes(target.type);
|
|
866
|
+
}
|
|
867
|
+
function moveFocus(toolbar, event, orientation) {
|
|
868
|
+
if (editsText$1(event.target)) return false;
|
|
869
|
+
const rtl = getComputedStyle(toolbar).direction === "rtl";
|
|
870
|
+
const next = orientation === "vertical" ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
|
|
871
|
+
const previous = orientation === "vertical" ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
|
|
872
|
+
const list = items(toolbar);
|
|
873
|
+
if (list.length === 0) return false;
|
|
874
|
+
const index = list.indexOf(event.target);
|
|
875
|
+
let target;
|
|
876
|
+
switch (event.key) {
|
|
877
|
+
case next:
|
|
878
|
+
target = list[(index + 1) % list.length];
|
|
879
|
+
break;
|
|
880
|
+
case previous:
|
|
881
|
+
target = list[(index - 1 + list.length) % list.length];
|
|
882
|
+
break;
|
|
883
|
+
case "Home":
|
|
884
|
+
target = list[0];
|
|
885
|
+
break;
|
|
886
|
+
case "End":
|
|
887
|
+
target = list[list.length - 1];
|
|
888
|
+
break;
|
|
889
|
+
default: return false;
|
|
890
|
+
}
|
|
891
|
+
if (target) {
|
|
892
|
+
syncTabStop$1(toolbar, target);
|
|
893
|
+
target.focus();
|
|
894
|
+
}
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
// src/components/reorderable-list/ReorderableList.tsx
|
|
898
|
+
var ReorderableListContext = /* @__PURE__ */ createContext(void 0);
|
|
899
|
+
function editsText(target) {
|
|
900
|
+
return target instanceof HTMLElement && (target.isContentEditable || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLInputElement && ![
|
|
901
|
+
"button",
|
|
902
|
+
"checkbox",
|
|
903
|
+
"radio",
|
|
904
|
+
"reset",
|
|
905
|
+
"submit"
|
|
906
|
+
].includes(target.type));
|
|
907
|
+
}
|
|
908
|
+
function rowsOf(list) {
|
|
909
|
+
return [...list.children].filter((child) => child instanceof HTMLElement && child.getAttribute("role") === "row");
|
|
910
|
+
}
|
|
911
|
+
function cellsOf(row) {
|
|
912
|
+
const targets = [];
|
|
913
|
+
for (const cell of row.children) {
|
|
914
|
+
if (!(cell instanceof HTMLElement)) continue;
|
|
915
|
+
if (cell.dataset["hmCell"] === "item") targets.push(cell);
|
|
916
|
+
else {
|
|
917
|
+
const control = items(cell)[0];
|
|
918
|
+
if (control) targets.push(control);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return targets;
|
|
922
|
+
}
|
|
923
|
+
var idOf = (row) => row?.dataset["hmId"] ?? "";
|
|
924
|
+
var orderOf = (rows) => JSON.stringify(rows.map(idOf));
|
|
925
|
+
var selectedRow = (rows) => rows.find((row) => row.getAttribute("aria-selected") === "true");
|
|
926
|
+
function syncTabStop(list, active) {
|
|
927
|
+
const rows = rowsOf(list);
|
|
928
|
+
const all = rows.flatMap(cellsOf);
|
|
929
|
+
const current = all.find((cell) => cell === active) ?? all.find((cell) => cell.dataset["hmTabStop"] !== void 0) ?? cellsOf(selectedRow(rows) ?? rows[0] ?? list)[0];
|
|
930
|
+
for (const cell of all) {
|
|
931
|
+
const isStop = cell === current;
|
|
932
|
+
cell.dataset["hmRoving"] = "";
|
|
933
|
+
cell.tabIndex = isStop ? 0 : -1;
|
|
934
|
+
if (isStop) cell.dataset["hmTabStop"] = "";
|
|
935
|
+
else delete cell.dataset["hmTabStop"];
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
var ReorderableList = /* @__PURE__ */ forwardRef(function ReorderableList({ label, selectedId, onSelectedChange, onMove, onRemove, announceMoves = true, className, classNames, unstyled, onKeyDown, onClick, onFocus, onBlur, children, ...props }, ref) {
|
|
939
|
+
const list = useRef(null);
|
|
940
|
+
const pending = useRef(void 0);
|
|
941
|
+
const lastSelected = useRef(selectedId);
|
|
942
|
+
const announce = useAnnounce();
|
|
943
|
+
const messages = useUiMessages();
|
|
944
|
+
useEffect(() => {
|
|
945
|
+
const element = list.current;
|
|
946
|
+
if (!element) return;
|
|
947
|
+
const change = pending.current;
|
|
948
|
+
const rows = rowsOf(element);
|
|
949
|
+
if (change && orderOf(rows) !== change.order) {
|
|
950
|
+
pending.current = void 0;
|
|
951
|
+
const index = change.kind === "move" ? rows.findIndex((row) => idOf(row) === change.id) : Math.min(change.index, rows.length - 1);
|
|
952
|
+
const row = rows[index];
|
|
953
|
+
const active = document.activeElement;
|
|
954
|
+
const free = !active || active === document.body || element.contains(active);
|
|
955
|
+
if (row && free) {
|
|
956
|
+
const cells = cellsOf(row);
|
|
957
|
+
const target = cells[change.cell] ?? cells[0];
|
|
958
|
+
syncTabStop(element, target);
|
|
959
|
+
target?.focus();
|
|
960
|
+
}
|
|
961
|
+
if (row && change.kind === "move" && announceMoves) announce(messages.t("reorderableList.moved", {
|
|
962
|
+
label: cellsOf(row)[0]?.getAttribute("aria-label") ?? "",
|
|
963
|
+
position: index + 1,
|
|
964
|
+
count: rows.length
|
|
965
|
+
}));
|
|
966
|
+
}
|
|
967
|
+
const inside = element.contains(document.activeElement);
|
|
968
|
+
const reselected = lastSelected.current !== selectedId;
|
|
969
|
+
lastSelected.current = selectedId;
|
|
970
|
+
syncTabStop(element, inside ? document.activeElement : reselected ? cellsOf(selectedRow(rowsOf(element)) ?? element)[0] : null);
|
|
971
|
+
});
|
|
972
|
+
const select = (id) => {
|
|
973
|
+
if (id !== "" && id !== selectedId) onSelectedChange?.(id);
|
|
974
|
+
};
|
|
975
|
+
const focusCell = (row, cell) => {
|
|
976
|
+
if (!row || !list.current) return;
|
|
977
|
+
const cells = cellsOf(row);
|
|
978
|
+
const target = cells[cell] ?? cells[0];
|
|
979
|
+
syncTabStop(list.current, target);
|
|
980
|
+
target?.focus();
|
|
981
|
+
};
|
|
982
|
+
const handleKeyDown = (event) => {
|
|
983
|
+
onKeyDown?.(event);
|
|
984
|
+
pending.current = void 0;
|
|
985
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing || event.shiftKey || editsText(event.target)) return;
|
|
986
|
+
const element = event.currentTarget;
|
|
987
|
+
const rows = rowsOf(element);
|
|
988
|
+
const index = rows.findIndex((row) => row.contains(event.target));
|
|
989
|
+
const row = rows[index];
|
|
990
|
+
if (!row) return;
|
|
991
|
+
const cells = cellsOf(row);
|
|
992
|
+
const cell = cells.indexOf(event.target);
|
|
993
|
+
if (cell === -1) return;
|
|
994
|
+
const quiet = event.ctrlKey || event.metaKey;
|
|
995
|
+
const vertical = event.key === "ArrowUp" ? -1 : event.key === "ArrowDown" ? 1 : 0;
|
|
996
|
+
if (event.altKey) {
|
|
997
|
+
if (vertical !== 0 && !quiet && onMove) {
|
|
998
|
+
event.preventDefault();
|
|
999
|
+
const toIndex = index + vertical;
|
|
1000
|
+
if (toIndex >= 0 && toIndex < rows.length) {
|
|
1001
|
+
pending.current = {
|
|
1002
|
+
kind: "move",
|
|
1003
|
+
id: idOf(row),
|
|
1004
|
+
index,
|
|
1005
|
+
cell,
|
|
1006
|
+
order: orderOf(rows)
|
|
1007
|
+
};
|
|
1008
|
+
onMove(idOf(row), toIndex);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (vertical !== 0) {
|
|
1014
|
+
event.preventDefault();
|
|
1015
|
+
const next = rows[index + vertical];
|
|
1016
|
+
if (next) {
|
|
1017
|
+
focusCell(next, cell);
|
|
1018
|
+
if (!quiet) select(idOf(next));
|
|
1019
|
+
}
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
if (event.key === "Home" || event.key === "End") {
|
|
1023
|
+
event.preventDefault();
|
|
1024
|
+
if (quiet) focusCell(event.key === "Home" ? rows[0] : rows[rows.length - 1], cell);
|
|
1025
|
+
else focusCell(row, event.key === "Home" ? 0 : cells.length - 1);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (quiet) return;
|
|
1029
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
1030
|
+
event.preventDefault();
|
|
1031
|
+
const rtl = getComputedStyle(element).direction === "rtl";
|
|
1032
|
+
const step = event.key === "ArrowRight" === rtl ? -1 : 1;
|
|
1033
|
+
if (cells[cell + step]) focusCell(row, cell + step);
|
|
1034
|
+
} else if ((event.key === "Delete" || event.key === "Backspace") && onRemove) {
|
|
1035
|
+
event.preventDefault();
|
|
1036
|
+
pending.current = {
|
|
1037
|
+
kind: "remove",
|
|
1038
|
+
id: idOf(row),
|
|
1039
|
+
index,
|
|
1040
|
+
cell,
|
|
1041
|
+
order: orderOf(rows)
|
|
1042
|
+
};
|
|
1043
|
+
onRemove(idOf(row));
|
|
1044
|
+
} else if ((event.key === " " || event.key === "Enter") && cell === 0) {
|
|
1045
|
+
event.preventDefault();
|
|
1046
|
+
select(idOf(row));
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
const handleClick = (event) => {
|
|
1050
|
+
onClick?.(event);
|
|
1051
|
+
const target = event.target;
|
|
1052
|
+
const row = rowsOf(event.currentTarget).find((candidate) => candidate.contains(target));
|
|
1053
|
+
if (row && !event.defaultPrevented && target.closest("[data-hm-cell=\"control\"]") === null) select(idOf(row));
|
|
1054
|
+
};
|
|
1055
|
+
const handleFocus = (event) => {
|
|
1056
|
+
onFocus?.(event);
|
|
1057
|
+
syncTabStop(event.currentTarget, event.target);
|
|
1058
|
+
};
|
|
1059
|
+
const handleBlur = (event) => {
|
|
1060
|
+
onBlur?.(event);
|
|
1061
|
+
if (event.relatedTarget && !event.currentTarget.contains(event.relatedTarget)) pending.current = void 0;
|
|
1062
|
+
};
|
|
1063
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1064
|
+
...props,
|
|
1065
|
+
ref: (node) => {
|
|
1066
|
+
list.current = node;
|
|
1067
|
+
if (typeof ref === "function") ref(node);
|
|
1068
|
+
else if (ref) ref.current = node;
|
|
1069
|
+
},
|
|
1070
|
+
role: "grid",
|
|
1071
|
+
"aria-label": label,
|
|
1072
|
+
className: cx("hm-reorderable-list", classNames?.root, className),
|
|
1073
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1074
|
+
onKeyDown: handleKeyDown,
|
|
1075
|
+
onClick: handleClick,
|
|
1076
|
+
onFocus: handleFocus,
|
|
1077
|
+
onBlur: handleBlur,
|
|
1078
|
+
children: /* @__PURE__ */ jsx(ReorderableListContext.Provider, {
|
|
1079
|
+
value: { selectedId },
|
|
1080
|
+
children
|
|
1081
|
+
})
|
|
1082
|
+
});
|
|
1083
|
+
});
|
|
1084
|
+
var ReorderableListItem = /* @__PURE__ */ forwardRef(function ReorderableListItem({ id, label, controls, className, classNames, unstyled, children, ...props }, ref) {
|
|
1085
|
+
const selected = useContext(ReorderableListContext)?.selectedId === id;
|
|
1086
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1087
|
+
...props,
|
|
1088
|
+
ref,
|
|
1089
|
+
role: "row",
|
|
1090
|
+
"aria-selected": selected,
|
|
1091
|
+
"data-hm-id": id,
|
|
1092
|
+
className: cx("hm-reorderable-list-row", classNames?.root, className),
|
|
1093
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1094
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
1095
|
+
role: "gridcell",
|
|
1096
|
+
"aria-label": label,
|
|
1097
|
+
tabIndex: selected ? 0 : -1,
|
|
1098
|
+
"data-hm-cell": "item",
|
|
1099
|
+
className: cx("hm-reorderable-list-item", classNames?.item),
|
|
1100
|
+
children
|
|
1101
|
+
}), controls?.map((control, index) => /* @__PURE__ */ jsx("div", {
|
|
1102
|
+
role: "gridcell",
|
|
1103
|
+
"data-hm-cell": "control",
|
|
1104
|
+
className: cx("hm-reorderable-list-control", classNames?.control),
|
|
1105
|
+
children: control
|
|
1106
|
+
}, index))]
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
841
1109
|
// src/components/toolbar/toolbar-context.ts
|
|
842
1110
|
var ToolbarContext = /* @__PURE__ */ createContext(void 0);
|
|
843
1111
|
function useToolbar() {
|
|
@@ -901,7 +1169,7 @@ function SegmentedControlImpl({ label, value, onValueChange, options, size = "me
|
|
|
901
1169
|
}
|
|
902
1170
|
var SegmentedControl = /* @__PURE__ */ forwardRef(SegmentedControlImpl);
|
|
903
1171
|
// src/components/slider/Slider.tsx
|
|
904
|
-
function snap(value, min, max, step) {
|
|
1172
|
+
function snap$1(value, min, max, step) {
|
|
905
1173
|
const precision = Math.max(decimals(min), decimals(step));
|
|
906
1174
|
const round = (n) => roundTo(n, precision);
|
|
907
1175
|
const upper = Math.max(min, max);
|
|
@@ -910,14 +1178,14 @@ function snap(value, min, max, step) {
|
|
|
910
1178
|
return Math.min(Math.max(inRange, min), upper);
|
|
911
1179
|
}
|
|
912
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) {
|
|
913
|
-
const [uncontrolled, setUncontrolled] = useState(() => snap(defaultValue ?? min, min, max, step));
|
|
914
|
-
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);
|
|
915
1183
|
const fieldProps = useFieldProps(props, label);
|
|
916
1184
|
if (label === void 0 && !props["aria-label"] && !props["aria-labelledby"] && fieldProps.id === void 0) {
|
|
917
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.");
|
|
918
1186
|
}
|
|
919
1187
|
const change = (next) => {
|
|
920
|
-
const snapped = snap(next, min, max, step);
|
|
1188
|
+
const snapped = snap$1(next, min, max, step);
|
|
921
1189
|
if (snapped === value) return;
|
|
922
1190
|
if (controlled === void 0) setUncontrolled(snapped);
|
|
923
1191
|
onValueChange?.(snapped);
|
|
@@ -1015,6 +1283,557 @@ var TextField = /* @__PURE__ */ forwardRef(function TextField({ type = "text", o
|
|
|
1015
1283
|
onChange: handleChange
|
|
1016
1284
|
});
|
|
1017
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
|
+
});
|
|
1018
1837
|
// src/components/toggle-button/ToggleButton.tsx
|
|
1019
1838
|
var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: controlled, defaultPressed = false, onPressedChange, onClick, icon, label, className, ...props }, ref) {
|
|
1020
1839
|
const [uncontrolled, setUncontrolled] = useState(defaultPressed);
|
|
@@ -1041,62 +1860,6 @@ var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: c
|
|
|
1041
1860
|
onClick: handleClick
|
|
1042
1861
|
});
|
|
1043
1862
|
});
|
|
1044
|
-
// src/components/toolbar/roving-focus.ts
|
|
1045
|
-
var FOCUSABLE = "button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex^=\"-\"]):not(button, a, input, select, textarea), [data-hm-roving]:not(:disabled)";
|
|
1046
|
-
function items(toolbar) {
|
|
1047
|
-
return [...toolbar.querySelectorAll(FOCUSABLE)].filter((element) => !element.closest("[hidden], [inert]") && element.getClientRects().length > 0);
|
|
1048
|
-
}
|
|
1049
|
-
function syncTabStop(toolbar, active) {
|
|
1050
|
-
const list = items(toolbar);
|
|
1051
|
-
const current = list.find((item) => item === active) ?? list.find((item) => item.tabIndex === 0 && item.dataset["hmTabStop"] !== void 0) ?? list[0];
|
|
1052
|
-
for (const item of list) {
|
|
1053
|
-
const isStop = item === current;
|
|
1054
|
-
item.dataset["hmRoving"] = "";
|
|
1055
|
-
item.tabIndex = isStop ? 0 : -1;
|
|
1056
|
-
if (isStop) item.dataset["hmTabStop"] = "";
|
|
1057
|
-
else delete item.dataset["hmTabStop"];
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
function editsText(target) {
|
|
1061
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
1062
|
-
return target.isContentEditable || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || target instanceof HTMLInputElement && ![
|
|
1063
|
-
"button",
|
|
1064
|
-
"checkbox",
|
|
1065
|
-
"radio",
|
|
1066
|
-
"reset",
|
|
1067
|
-
"submit"
|
|
1068
|
-
].includes(target.type);
|
|
1069
|
-
}
|
|
1070
|
-
function moveFocus(toolbar, event, orientation) {
|
|
1071
|
-
if (editsText(event.target)) return false;
|
|
1072
|
-
const rtl = getComputedStyle(toolbar).direction === "rtl";
|
|
1073
|
-
const next = orientation === "vertical" ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
|
|
1074
|
-
const previous = orientation === "vertical" ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
|
|
1075
|
-
const list = items(toolbar);
|
|
1076
|
-
if (list.length === 0) return false;
|
|
1077
|
-
const index = list.indexOf(event.target);
|
|
1078
|
-
let target;
|
|
1079
|
-
switch (event.key) {
|
|
1080
|
-
case next:
|
|
1081
|
-
target = list[(index + 1) % list.length];
|
|
1082
|
-
break;
|
|
1083
|
-
case previous:
|
|
1084
|
-
target = list[(index - 1 + list.length) % list.length];
|
|
1085
|
-
break;
|
|
1086
|
-
case "Home":
|
|
1087
|
-
target = list[0];
|
|
1088
|
-
break;
|
|
1089
|
-
case "End":
|
|
1090
|
-
target = list[list.length - 1];
|
|
1091
|
-
break;
|
|
1092
|
-
default: return false;
|
|
1093
|
-
}
|
|
1094
|
-
if (target) {
|
|
1095
|
-
syncTabStop(toolbar, target);
|
|
1096
|
-
target.focus();
|
|
1097
|
-
}
|
|
1098
|
-
return true;
|
|
1099
|
-
}
|
|
1100
1863
|
// src/components/toolbar/Toolbar.tsx
|
|
1101
1864
|
function useMergedRef(forwarded) {
|
|
1102
1865
|
const local = useRef(null);
|
|
@@ -1111,8 +1874,8 @@ var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation =
|
|
|
1111
1874
|
useEffect(() => {
|
|
1112
1875
|
const toolbar = ref.current;
|
|
1113
1876
|
if (!toolbar) return;
|
|
1114
|
-
syncTabStop(toolbar);
|
|
1115
|
-
const observer = new MutationObserver(() => syncTabStop(toolbar, document.activeElement));
|
|
1877
|
+
syncTabStop$1(toolbar);
|
|
1878
|
+
const observer = new MutationObserver(() => syncTabStop$1(toolbar, document.activeElement));
|
|
1116
1879
|
observer.observe(toolbar, {
|
|
1117
1880
|
childList: true,
|
|
1118
1881
|
subtree: true,
|
|
@@ -1127,7 +1890,7 @@ var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation =
|
|
|
1127
1890
|
};
|
|
1128
1891
|
const handleFocus = (event) => {
|
|
1129
1892
|
onFocus?.(event);
|
|
1130
|
-
if (ref.current && event.target !== ref.current) syncTabStop(ref.current, event.target);
|
|
1893
|
+
if (ref.current && event.target !== ref.current) syncTabStop$1(ref.current, event.target);
|
|
1131
1894
|
};
|
|
1132
1895
|
return /* @__PURE__ */ jsx(ToolbarContext.Provider, {
|
|
1133
1896
|
value: { orientation },
|
|
@@ -1456,6 +2219,24 @@ function HiddenIcon(props) {
|
|
|
1456
2219
|
function HighlighterIcon(props) {
|
|
1457
2220
|
return renderIcon("highlighter", [["path", { d: "m9 11-6 6v3h9l3-3" }], ["path", { d: "m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" }]], false, props);
|
|
1458
2221
|
}
|
|
2222
|
+
function ImageIcon(props) {
|
|
2223
|
+
return renderIcon("image", [
|
|
2224
|
+
["rect", {
|
|
2225
|
+
width: "18",
|
|
2226
|
+
height: "18",
|
|
2227
|
+
x: "3",
|
|
2228
|
+
y: "3",
|
|
2229
|
+
rx: "2",
|
|
2230
|
+
ry: "2"
|
|
2231
|
+
}],
|
|
2232
|
+
["circle", {
|
|
2233
|
+
cx: "9",
|
|
2234
|
+
cy: "9",
|
|
2235
|
+
r: "2"
|
|
2236
|
+
}],
|
|
2237
|
+
["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" }]
|
|
2238
|
+
], false, props);
|
|
2239
|
+
}
|
|
1459
2240
|
function InfoIcon(props) {
|
|
1460
2241
|
return renderIcon("info", [
|
|
1461
2242
|
["circle", {
|
|
@@ -1799,6 +2580,6 @@ function ThemeProvider(props) {
|
|
|
1799
2580
|
}), children]
|
|
1800
2581
|
});
|
|
1801
2582
|
}
|
|
1802
|
-
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, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, 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 };
|
|
1803
2584
|
|
|
1804
2585
|
//# sourceMappingURL=react.js.map
|