strata-react 1.0.33 → 1.0.35
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 -2
- package/UPGRADING.md +1 -0
- package/dist/components/conversation.d.ts +67 -0
- package/dist/components/dialog.d.ts +1 -1
- package/dist/components/folder-picker.d.ts +42 -0
- package/dist/components/lightbox.d.ts +34 -0
- package/dist/components/markable-text.d.ts +56 -0
- package/dist/components/media-group.d.ts +25 -0
- package/dist/components/media-player.d.ts +80 -2
- package/dist/components/region-editor.d.ts +55 -0
- package/dist/components/sequence-timeline.d.ts +50 -0
- package/dist/components/transcript-view.d.ts +36 -0
- package/dist/components/tree.d.ts +41 -0
- package/dist/components/waveform.d.ts +66 -0
- package/dist/{cursor-DplHNzj3.js → cursor-DDGBPiTJ.js} +2 -200
- package/dist/cursor-DDGBPiTJ.js.map +1 -0
- package/dist/field-7Z4N5r5g.js +178 -0
- package/dist/field-7Z4N5r5g.js.map +1 -0
- package/dist/format-B32-PVi2.js +201 -0
- package/dist/format-B32-PVi2.js.map +1 -0
- package/dist/hls/index.d.ts +19 -0
- package/dist/hls.js +84 -0
- package/dist/hls.js.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +3454 -568
- package/dist/index.js.map +1 -1
- package/dist/lib/marks.d.ts +6 -0
- package/dist/lib/region.d.ts +46 -0
- package/dist/lib/rich-text.d.ts +44 -0
- package/dist/lib/sequence.d.ts +34 -0
- package/dist/lib/transcript.d.ts +28 -0
- package/dist/lib/waveform.d.ts +36 -0
- package/dist/map.js +4 -2
- package/dist/map.js.map +1 -1
- package/dist/panorama/gl.d.ts +16 -0
- package/dist/panorama/index.d.ts +2 -0
- package/dist/panorama/panorama-viewer.d.ts +56 -0
- package/dist/panorama/projection.d.ts +45 -0
- package/dist/panorama.js +657 -0
- package/dist/panorama.js.map +1 -0
- package/dist/{query-DgJMyXTT.js → query-BJcxJLhh.js} +3 -2
- package/dist/{query-DgJMyXTT.js.map → query-BJcxJLhh.js.map} +1 -1
- package/dist/{run-BqZGKhW9.js → run-DzyLrZlA.js} +23 -5
- package/dist/run-DzyLrZlA.js.map +1 -0
- package/dist/testing.js +2 -2
- package/dist/{theme-BgTOESmN.js → theme-CFNi6WUO.js} +5 -175
- package/dist/theme-CFNi6WUO.js.map +1 -0
- package/dist/value-controls-D6O9TsM6.js +356 -0
- package/dist/value-controls-D6O9TsM6.js.map +1 -0
- package/dist/visual-cli.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +19 -4
- package/dist/cursor-DplHNzj3.js.map +0 -1
- package/dist/run-BqZGKhW9.js.map +0 -1
- package/dist/theme-BgTOESmN.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
1
|
+
import { a as Textarea, c as cn, i as NativeSelect, l as typeSteps, n as Field, r as Input, t as ChoiceGroup } from "./field-7Z4N5r5g.js";
|
|
2
|
+
import { a as toDate, i as format, n as NBSP, r as createFormat, t as MISSING } from "./format-B32-PVi2.js";
|
|
3
|
+
import { i as useInView, n as NumberField, r as Slider, t as ColorField } from "./value-controls-D6O9TsM6.js";
|
|
4
|
+
import { _ as IconButton, a as toLoad, c as toast, d as describeActionError, f as describeHttpError, g as Button, h as overlaySurface, i as staleOf, l as toastTimeout, m as readErrorBody, n as createQueryClient, o as useLoad, p as fieldErrorsOf, r as fetchJson, s as StrataToastRegion, t as StrataQueryProvider, u as HttpError, v as RowAction, y as buttonVariants } from "./query-BJcxJLhh.js";
|
|
5
|
+
import { a as useColorScheme, c as Tooltip, i as colorSchemeScript, l as KeyText, n as ColorSchemeChoice, o as useSystemColorScheme, r as ThemeProvider, s as Density, t as COLOR_SCHEME_STORAGE_KEY } from "./theme-CFNi6WUO.js";
|
|
6
|
+
import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-DDGBPiTJ.js";
|
|
4
7
|
import * as React from "react";
|
|
5
|
-
import { Autocomplete, Button as Button$1, Cell, Checkbox as Checkbox$1, Collection, Column, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridLayout, GridList, GridListItem, Header, Heading,
|
|
6
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, Flag, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, Play, Redo2, RotateCcw, Scan, Search, SkipBack, SkipForward, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
8
|
+
import { Autocomplete, Button as Button$1, Cell, Checkbox as Checkbox$1, Collection, Column, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridLayout, GridList, GridListItem, Header, Heading, Input as Input$1, Keyboard, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, Row, SearchField, Separator, Slider as Slider$1, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Table, TableBody, TableHeader, TableLayout, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, Tree as Tree$1, TreeItem, TreeItemContent, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
|
|
9
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronLeft, ChevronRight, CircleAlert, CircleCheck, FileQuestion, Flag, Folder, FolderOpen, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, Pencil, Play, Redo2, RotateCcw, Scan, Search, Send, SkipBack, SkipForward, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
7
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
11
|
import { Link, NavLink, useSearchParams } from "react-router";
|
|
9
12
|
import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
@@ -11,45 +14,6 @@ import { VisuallyHidden, mergeProps, useDrop, useFocusRing, useMove, useSlider,
|
|
|
11
14
|
import { Size, useSliderState } from "react-stately";
|
|
12
15
|
import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
13
16
|
import pixelmatch from "pixelmatch";
|
|
14
|
-
// src/lib/in-view.ts
|
|
15
|
-
/**
|
|
16
|
-
* Whether an element is within `rootMargin` of its scroll region (the nearest
|
|
17
|
-
* `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the
|
|
18
|
-
* element as it mounts and unmounts.
|
|
19
|
-
*/
|
|
20
|
-
function useInView({ active = true, rootMargin = "0px", once = false, unsupported = false } = {}) {
|
|
21
|
-
const [inView, setInView] = React.useState(false);
|
|
22
|
-
const [el, setEl] = React.useState(null);
|
|
23
|
-
const seen = once && inView;
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
if (seen) return;
|
|
26
|
-
if (!active || !el) {
|
|
27
|
-
setInView(false);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (typeof IntersectionObserver === "undefined") {
|
|
31
|
-
setInView(unsupported);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
|
|
35
|
-
const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
|
|
36
|
-
root,
|
|
37
|
-
rootMargin
|
|
38
|
-
});
|
|
39
|
-
observer.observe(el);
|
|
40
|
-
return () => observer.disconnect();
|
|
41
|
-
}, [
|
|
42
|
-
active,
|
|
43
|
-
el,
|
|
44
|
-
rootMargin,
|
|
45
|
-
seen,
|
|
46
|
-
unsupported
|
|
47
|
-
]);
|
|
48
|
-
return {
|
|
49
|
-
ref: setEl,
|
|
50
|
-
inView
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
17
|
// src/lib/chords.ts
|
|
54
18
|
/** The platform this page runs on, read from the browser (`mac` for macOS and iOS). Server and test default: `other`. */
|
|
55
19
|
function detectPlatform() {
|
|
@@ -679,7 +643,8 @@ function Switch({ label, detail, on, defaultOn, onChange, disabled, className })
|
|
|
679
643
|
var sizes = {
|
|
680
644
|
sm: "max-w-sm",
|
|
681
645
|
md: "max-w-lg",
|
|
682
|
-
lg: "max-w-3xl"
|
|
646
|
+
lg: "max-w-3xl",
|
|
647
|
+
full: "h-full max-w-none"
|
|
683
648
|
};
|
|
684
649
|
function Overlay({ trigger, open, onOpenChange, children }) {
|
|
685
650
|
if (trigger) return /* @__PURE__ */ jsxs(DialogTrigger, {
|
|
@@ -724,7 +689,7 @@ function Dialog({ title, description, trigger, open, onOpenChange, className, ch
|
|
|
724
689
|
children: /* @__PURE__ */ jsx(ModalOverlay, {
|
|
725
690
|
isDismissable: closable,
|
|
726
691
|
isKeyboardDismissDisabled: !closable,
|
|
727
|
-
className: cn(overlayClass, placement === "end" ? "justify-items-end" : "place-items-center p-4"),
|
|
692
|
+
className: cn(overlayClass, placement === "end" ? "justify-items-end" : size === "full" ? "grid-cols-1 grid-rows-1 p-4" : "place-items-center p-4"),
|
|
728
693
|
children: /* @__PURE__ */ jsx(Modal, {
|
|
729
694
|
className: cn("flex max-h-full min-h-0 w-full flex-col outline-none", overlaySurface, placement === "end" ? "h-full max-w-md rounded-r-none" : sizes[size], className),
|
|
730
695
|
children: /* @__PURE__ */ jsx(Dialog$1, {
|
|
@@ -1500,315 +1465,6 @@ function Skeleton({ className }) {
|
|
|
1500
1465
|
className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
|
|
1501
1466
|
});
|
|
1502
1467
|
}
|
|
1503
|
-
// src/lib/number-input.ts
|
|
1504
|
-
/** Reads `#rgb`, `#rrggbb` (with or without the #) as lower-case `#rrggbb`, or null. */
|
|
1505
|
-
function parseHex(text) {
|
|
1506
|
-
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(text.trim());
|
|
1507
|
-
if (!m) return null;
|
|
1508
|
-
const h = m[1].toLowerCase();
|
|
1509
|
-
return "#" + (h.length === 3 ? [...h].map((c) => c + c).join("") : h);
|
|
1510
|
-
}
|
|
1511
|
-
function luminance(hex) {
|
|
1512
|
-
const v = [
|
|
1513
|
-
1,
|
|
1514
|
-
3,
|
|
1515
|
-
5
|
|
1516
|
-
].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((c) => c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4);
|
|
1517
|
-
return .2126 * v[0] + .7152 * v[1] + .0722 * v[2];
|
|
1518
|
-
}
|
|
1519
|
-
/** WCAG contrast ratio between two `#rrggbb` colours, 1 to 21. */
|
|
1520
|
-
function contrastRatio(a, b) {
|
|
1521
|
-
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
1522
|
-
return (hi + .05) / (lo + .05);
|
|
1523
|
-
}
|
|
1524
|
-
// src/components/value-controls.tsx
|
|
1525
|
-
var box = "flex w-full min-w-0 items-center rounded-control border border-input bg-background px-3 type-body text-foreground transition-state disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:bg-muted has-[input:disabled]:opacity-70 aria-invalid:border-danger has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-ring";
|
|
1526
|
-
/** A number with its unit joined by a non-breaking space; `%` and `°` stay attached. */
|
|
1527
|
-
function withUnit(text, unit) {
|
|
1528
|
-
if (!unit) return text;
|
|
1529
|
-
return unit === "%" || unit === "°" ? text + unit : text + "\xA0" + unit;
|
|
1530
|
-
}
|
|
1531
|
-
var intlUnits = {
|
|
1532
|
-
"%": "percent",
|
|
1533
|
-
"°": "degree",
|
|
1534
|
-
ms: "millisecond",
|
|
1535
|
-
s: "second",
|
|
1536
|
-
kB: "kilobyte",
|
|
1537
|
-
MB: "megabyte",
|
|
1538
|
-
GB: "gigabyte",
|
|
1539
|
-
kbps: "kilobit-per-second",
|
|
1540
|
-
Mbps: "megabit-per-second"
|
|
1541
|
-
};
|
|
1542
|
-
function decimalsOf(n) {
|
|
1543
|
-
const s = String(n);
|
|
1544
|
-
if (s.includes("e-")) return Number(s.split("e-")[1]) + (s.split("e-")[0].split(".")[1]?.length ?? 0);
|
|
1545
|
-
return s.split(".")[1]?.length ?? 0;
|
|
1546
|
-
}
|
|
1547
|
-
function useNumberText(locale, places) {
|
|
1548
|
-
return React.useMemo(() => {
|
|
1549
|
-
const f = new Intl.NumberFormat(locale, {
|
|
1550
|
-
maximumFractionDigits: places,
|
|
1551
|
-
minimumFractionDigits: 0
|
|
1552
|
-
});
|
|
1553
|
-
return (n) => f.format(n);
|
|
1554
|
-
}, [locale, places]);
|
|
1555
|
-
}
|
|
1556
|
-
function formatOptionsFor(places, unit) {
|
|
1557
|
-
const base = {
|
|
1558
|
-
maximumFractionDigits: places,
|
|
1559
|
-
minimumFractionDigits: 0
|
|
1560
|
-
};
|
|
1561
|
-
const known = unit ? intlUnits[unit] : void 0;
|
|
1562
|
-
return known ? {
|
|
1563
|
-
...base,
|
|
1564
|
-
style: "unit",
|
|
1565
|
-
unit: known,
|
|
1566
|
-
unitDisplay: "narrow"
|
|
1567
|
-
} : base;
|
|
1568
|
-
}
|
|
1569
|
-
function describeRange(min, max, show, unit) {
|
|
1570
|
-
const a = min === void 0 ? "" : withUnit(show(min), unit);
|
|
1571
|
-
const b = max === void 0 ? "" : withUnit(show(max), unit);
|
|
1572
|
-
if (min !== void 0 && max !== void 0) return `Enter a value from ${a} to ${b}.`;
|
|
1573
|
-
if (min !== void 0) return `Enter ${a} or more.`;
|
|
1574
|
-
if (max !== void 0) return `Enter ${b} or less.`;
|
|
1575
|
-
return "Enter a number.";
|
|
1576
|
-
}
|
|
1577
|
-
/** A number with a unit on React Aria's number field: typed input is validated, not clamped, so an out-of-range value is explained in the surrounding `Field` and never passed on; empty stays `null`. */
|
|
1578
|
-
function NumberField({ value, onChange, min, max, step = 1, places, unit, locale = format.locale, required = false, disabled, id: idProp, name, size = "default", className, "aria-label": ariaLabel }) {
|
|
1579
|
-
const { field, report } = useFieldControl();
|
|
1580
|
-
const digits = places ?? Math.max(decimalsOf(step), min === void 0 ? 0 : decimalsOf(min));
|
|
1581
|
-
const show = useNumberText(locale, digits);
|
|
1582
|
-
const [own, setOwn] = React.useState(false);
|
|
1583
|
-
const unitId = React.useId();
|
|
1584
|
-
const [local, setLocal] = React.useState(value ?? NaN);
|
|
1585
|
-
const [seen, setSeen] = React.useState(value);
|
|
1586
|
-
if (seen !== value) {
|
|
1587
|
-
setSeen(value);
|
|
1588
|
-
setLocal(value ?? NaN);
|
|
1589
|
-
}
|
|
1590
|
-
const fail = (message) => {
|
|
1591
|
-
setOwn(true);
|
|
1592
|
-
report(message);
|
|
1593
|
-
};
|
|
1594
|
-
const ok = () => {
|
|
1595
|
-
setOwn(false);
|
|
1596
|
-
report(void 0);
|
|
1597
|
-
};
|
|
1598
|
-
const handle = (n) => {
|
|
1599
|
-
setLocal(n);
|
|
1600
|
-
if (Number.isNaN(n)) {
|
|
1601
|
-
if (required) return fail("Enter a value.");
|
|
1602
|
-
ok();
|
|
1603
|
-
if (value !== null) onChange(null);
|
|
1604
|
-
return;
|
|
1605
|
-
}
|
|
1606
|
-
if (min !== void 0 && n < min || max !== void 0 && n > max) return fail(describeRange(min, max, show, unit));
|
|
1607
|
-
ok();
|
|
1608
|
-
if (n !== value) onChange(n);
|
|
1609
|
-
};
|
|
1610
|
-
const invalid = field?.invalid || own;
|
|
1611
|
-
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
1612
|
-
locale,
|
|
1613
|
-
children: /* @__PURE__ */ jsxs(NumberField$1, {
|
|
1614
|
-
value: local,
|
|
1615
|
-
onChange: handle,
|
|
1616
|
-
minValue: min,
|
|
1617
|
-
maxValue: max,
|
|
1618
|
-
step,
|
|
1619
|
-
formatOptions: {
|
|
1620
|
-
maximumFractionDigits: digits,
|
|
1621
|
-
minimumFractionDigits: 0
|
|
1622
|
-
},
|
|
1623
|
-
commitBehavior: "validate",
|
|
1624
|
-
isDisabled: disabled,
|
|
1625
|
-
isInvalid: invalid || void 0,
|
|
1626
|
-
name,
|
|
1627
|
-
"aria-label": ariaLabel ?? field?.label,
|
|
1628
|
-
className: cn(box, controlHeight[size], className),
|
|
1629
|
-
children: [/* @__PURE__ */ jsx(Input$1, {
|
|
1630
|
-
id: idProp ?? field?.id,
|
|
1631
|
-
placeholder: format.missing,
|
|
1632
|
-
"aria-describedby": [field?.describedBy, unit ? unitId : void 0].filter(Boolean).join(" ") || void 0,
|
|
1633
|
-
className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
1634
|
-
}), unit && /* @__PURE__ */ jsxs("span", {
|
|
1635
|
-
id: unitId,
|
|
1636
|
-
className: "ml-2 shrink-0 type-body-sm text-muted-foreground",
|
|
1637
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
1638
|
-
"aria-hidden": true,
|
|
1639
|
-
children: unit
|
|
1640
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1641
|
-
className: "sr-only",
|
|
1642
|
-
children: intlUnits[unit] ? intlUnits[unit].replace(/-/g, " ") : unit
|
|
1643
|
-
})]
|
|
1644
|
-
})]
|
|
1645
|
-
})
|
|
1646
|
-
});
|
|
1647
|
-
}
|
|
1648
|
-
/** A slider on React Aria with its current value always printed beside the track (and spoken with the unit when `Intl` knows it); `editable` adds a number field to type an exact value. */
|
|
1649
|
-
function Slider({ value, onChange, min, max, step = 1, unit, locale = format.locale, editable = false, hideValue = false, places, disabled, className, "aria-label": ariaLabel }) {
|
|
1650
|
-
const { field } = useFieldControl();
|
|
1651
|
-
const digits = places ?? Math.max(decimalsOf(step), decimalsOf(min));
|
|
1652
|
-
const show = useNumberText(locale, digits);
|
|
1653
|
-
const name = ariaLabel ?? field?.label ?? "Value";
|
|
1654
|
-
const text = withUnit(show(value), unit);
|
|
1655
|
-
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
1656
|
-
locale,
|
|
1657
|
-
children: /* @__PURE__ */ jsxs(Slider$1, {
|
|
1658
|
-
value,
|
|
1659
|
-
onChange: (v) => onChange(v),
|
|
1660
|
-
minValue: min,
|
|
1661
|
-
maxValue: max,
|
|
1662
|
-
step,
|
|
1663
|
-
formatOptions: formatOptionsFor(digits, unit),
|
|
1664
|
-
isDisabled: disabled,
|
|
1665
|
-
"aria-label": name,
|
|
1666
|
-
"aria-describedby": field?.describedBy,
|
|
1667
|
-
className: cn("flex min-w-0 items-center gap-3", className),
|
|
1668
|
-
children: [/* @__PURE__ */ jsx(SliderTrack, {
|
|
1669
|
-
className: "relative flex h-(--control-h) min-w-0 flex-1 cursor-pointer items-center disabled:cursor-not-allowed disabled:opacity-50",
|
|
1670
|
-
children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1671
|
-
/* @__PURE__ */ jsx("span", {
|
|
1672
|
-
"aria-hidden": true,
|
|
1673
|
-
className: "absolute inset-x-0 h-1.5 rounded-pill bg-muted"
|
|
1674
|
-
}),
|
|
1675
|
-
/* @__PURE__ */ jsx("span", {
|
|
1676
|
-
"aria-hidden": true,
|
|
1677
|
-
className: "absolute left-0 h-1.5 rounded-pill bg-primary",
|
|
1678
|
-
style: { width: `${state.getThumbPercent(0) * 100}%` }
|
|
1679
|
-
}),
|
|
1680
|
-
/* @__PURE__ */ jsx(SliderThumb, { className: "top-1/2 size-5 rounded-pill border-2 border-primary bg-background focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring" })
|
|
1681
|
-
] })
|
|
1682
|
-
}), editable ? /* @__PURE__ */ jsx(NumberField, {
|
|
1683
|
-
className: "w-28 shrink-0",
|
|
1684
|
-
"aria-label": `${name}, exact value`,
|
|
1685
|
-
value,
|
|
1686
|
-
onChange: (v) => v !== null && onChange(v),
|
|
1687
|
-
min,
|
|
1688
|
-
max,
|
|
1689
|
-
step,
|
|
1690
|
-
unit,
|
|
1691
|
-
locale,
|
|
1692
|
-
places: digits,
|
|
1693
|
-
required: true,
|
|
1694
|
-
disabled
|
|
1695
|
-
}) : !hideValue && /* @__PURE__ */ jsx(SliderOutput, {
|
|
1696
|
-
"aria-hidden": true,
|
|
1697
|
-
className: "w-16 shrink-0 text-right type-body-sm tabular-nums text-foreground",
|
|
1698
|
-
children: text
|
|
1699
|
-
})]
|
|
1700
|
-
})
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
/** Choose a colour with the platform picker, see and type its hex value, pick from the app's suggestions, and get a note when it would be hard to see on `against`. A half-typed value is never passed on. */
|
|
1704
|
-
function ColorField({ value, onChange, suggestions, against, againstLabel = "the background", minContrast = 3, disabled, id: idProp, className, "aria-label": ariaLabel }) {
|
|
1705
|
-
const { field, report } = useFieldControl();
|
|
1706
|
-
const label = ariaLabel ?? field?.label;
|
|
1707
|
-
const pickerName = label ? `${label}, picker` : "Colour picker";
|
|
1708
|
-
const [draft, setDraft] = React.useState(null);
|
|
1709
|
-
const [own, setOwn] = React.useState(false);
|
|
1710
|
-
const text = draft ?? value ?? "";
|
|
1711
|
-
const ratio = value && against ? contrastRatio(value, against) : null;
|
|
1712
|
-
const commitText = (t) => {
|
|
1713
|
-
if (t.trim() === "") {
|
|
1714
|
-
setOwn(false);
|
|
1715
|
-
report(void 0);
|
|
1716
|
-
if (value !== null) onChange(null);
|
|
1717
|
-
return true;
|
|
1718
|
-
}
|
|
1719
|
-
const hex = parseHex(t);
|
|
1720
|
-
if (!hex) {
|
|
1721
|
-
setOwn(true);
|
|
1722
|
-
report("Enter a colour like #1a7f64.");
|
|
1723
|
-
return false;
|
|
1724
|
-
}
|
|
1725
|
-
setOwn(false);
|
|
1726
|
-
report(void 0);
|
|
1727
|
-
if (hex !== value) onChange(hex);
|
|
1728
|
-
return true;
|
|
1729
|
-
};
|
|
1730
|
-
const pick = (hex) => {
|
|
1731
|
-
setDraft(null);
|
|
1732
|
-
setOwn(false);
|
|
1733
|
-
report(void 0);
|
|
1734
|
-
if (hex !== value) onChange(hex);
|
|
1735
|
-
};
|
|
1736
|
-
const invalid = field?.invalid || own;
|
|
1737
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1738
|
-
className: cn("grid min-w-0 gap-2", className),
|
|
1739
|
-
children: [
|
|
1740
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1741
|
-
className: cn(box, controlHeight.default, "gap-2 px-2"),
|
|
1742
|
-
"aria-invalid": invalid || void 0,
|
|
1743
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
1744
|
-
className: "relative size-6 shrink-0 overflow-hidden rounded-control border border-input",
|
|
1745
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
1746
|
-
"aria-hidden": true,
|
|
1747
|
-
className: cn("absolute inset-0", value === null && "bg-muted"),
|
|
1748
|
-
style: value ? { background: value } : void 0
|
|
1749
|
-
}), /* @__PURE__ */ jsx("input", {
|
|
1750
|
-
type: "color",
|
|
1751
|
-
"aria-label": pickerName,
|
|
1752
|
-
value: value ?? "#000000",
|
|
1753
|
-
disabled,
|
|
1754
|
-
onChange: (e) => pick(e.target.value),
|
|
1755
|
-
className: "absolute inset-0 size-full cursor-pointer opacity-0 disabled:cursor-not-allowed"
|
|
1756
|
-
})]
|
|
1757
|
-
}), /* @__PURE__ */ jsx("input", {
|
|
1758
|
-
id: idProp ?? field?.id,
|
|
1759
|
-
type: "text",
|
|
1760
|
-
autoComplete: "off",
|
|
1761
|
-
spellCheck: false,
|
|
1762
|
-
disabled,
|
|
1763
|
-
"aria-label": ariaLabel,
|
|
1764
|
-
"aria-describedby": field?.describedBy,
|
|
1765
|
-
"aria-invalid": invalid || void 0,
|
|
1766
|
-
placeholder: format.missing,
|
|
1767
|
-
value: text,
|
|
1768
|
-
onChange: (e) => setDraft(e.target.value),
|
|
1769
|
-
onBlur: () => {
|
|
1770
|
-
if (draft !== null && commitText(draft)) setDraft(null);
|
|
1771
|
-
},
|
|
1772
|
-
onKeyDown: (e) => {
|
|
1773
|
-
if (e.key === "Enter" && draft !== null && commitText(draft)) setDraft(null);
|
|
1774
|
-
if (e.key === "Escape" && draft !== null) {
|
|
1775
|
-
setDraft(null);
|
|
1776
|
-
setOwn(false);
|
|
1777
|
-
report(void 0);
|
|
1778
|
-
}
|
|
1779
|
-
},
|
|
1780
|
-
className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
1781
|
-
})]
|
|
1782
|
-
}),
|
|
1783
|
-
suggestions && suggestions.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
1784
|
-
role: "group",
|
|
1785
|
-
"aria-label": "Suggested colours",
|
|
1786
|
-
className: "flex flex-wrap gap-1.5",
|
|
1787
|
-
children: suggestions.map((hex) => /* @__PURE__ */ jsx("button", {
|
|
1788
|
-
type: "button",
|
|
1789
|
-
disabled,
|
|
1790
|
-
"aria-label": hex,
|
|
1791
|
-
"aria-pressed": value === hex,
|
|
1792
|
-
onClick: () => pick(hex),
|
|
1793
|
-
className: "size-6 cursor-pointer rounded-control border border-input transition-state aria-pressed:outline-2 aria-pressed:outline-offset-2 aria-pressed:outline-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
1794
|
-
style: { background: hex }
|
|
1795
|
-
}, hex))
|
|
1796
|
-
}),
|
|
1797
|
-
ratio !== null && ratio < minContrast && /* @__PURE__ */ jsxs("p", {
|
|
1798
|
-
className: "type-body-sm text-warning",
|
|
1799
|
-
children: [
|
|
1800
|
-
"Hard to see on ",
|
|
1801
|
-
againstLabel,
|
|
1802
|
-
": contrast ",
|
|
1803
|
-
format.decimal(ratio),
|
|
1804
|
-
":1, aim for ",
|
|
1805
|
-
format.decimal(minContrast),
|
|
1806
|
-
":1 or more."
|
|
1807
|
-
]
|
|
1808
|
-
})
|
|
1809
|
-
]
|
|
1810
|
-
});
|
|
1811
|
-
}
|
|
1812
1468
|
// src/components/alert.tsx
|
|
1813
1469
|
var tones = {
|
|
1814
1470
|
info: {
|
|
@@ -2629,7 +2285,7 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
|
|
|
2629
2285
|
});
|
|
2630
2286
|
}
|
|
2631
2287
|
// src/components/media.tsx
|
|
2632
|
-
var clamp$
|
|
2288
|
+
var clamp$3 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
2633
2289
|
var timecode = (t, { precision, fps }) => format.timecode(t, {
|
|
2634
2290
|
precision,
|
|
2635
2291
|
fps
|
|
@@ -2676,8 +2332,8 @@ function SeekBar({ time, duration: known, onSeek, marks = [], onMarkPress, buffe
|
|
|
2676
2332
|
const disabled = off || duration === 0;
|
|
2677
2333
|
const track = React.useRef(null);
|
|
2678
2334
|
const input = React.useRef(null);
|
|
2679
|
-
const frac = duration > 0 ? clamp$
|
|
2680
|
-
const seekTo = (t) => onSeek(clamp$
|
|
2335
|
+
const frac = duration > 0 ? clamp$3(time / duration, 0, 1) : 0;
|
|
2336
|
+
const seekTo = (t) => onSeek(clamp$3(t, 0, duration));
|
|
2681
2337
|
const shared = useSharedCursor();
|
|
2682
2338
|
const joined = Boolean(cursorProp) && shared !== null;
|
|
2683
2339
|
const mapping = typeof cursorProp === "object" ? cursorProp : void 0;
|
|
@@ -2714,7 +2370,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], onMarkPress, buffe
|
|
|
2714
2370
|
minValue: 0,
|
|
2715
2371
|
maxValue: Math.max(duration, fine),
|
|
2716
2372
|
step: fine,
|
|
2717
|
-
value: [clamp$
|
|
2373
|
+
value: [clamp$3(time, 0, duration)],
|
|
2718
2374
|
onChange: ([t]) => seekTo(t),
|
|
2719
2375
|
numberFormatter: timeText,
|
|
2720
2376
|
isDisabled: disabled
|
|
@@ -2756,7 +2412,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], onMarkPress, buffe
|
|
|
2756
2412
|
onPointerMove: (e) => {
|
|
2757
2413
|
if (!joined || duration === 0) return;
|
|
2758
2414
|
const box = e.currentTarget.getBoundingClientRect();
|
|
2759
|
-
shared.setPointer(toCursor(clamp$
|
|
2415
|
+
shared.setPointer(toCursor(clamp$3((e.clientX - box.left) / (box.width || 1) * duration, 0, duration)));
|
|
2760
2416
|
},
|
|
2761
2417
|
onPointerLeave: () => shared?.setPointer(null)
|
|
2762
2418
|
}),
|
|
@@ -2770,7 +2426,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], onMarkPress, buffe
|
|
|
2770
2426
|
buffered !== void 0 && duration > 0 && /* @__PURE__ */ jsx("span", {
|
|
2771
2427
|
"aria-hidden": true,
|
|
2772
2428
|
className: "absolute left-0 h-1.5 rounded-pill bg-neutral-4",
|
|
2773
|
-
style: { width: `${clamp$
|
|
2429
|
+
style: { width: `${clamp$3(buffered / duration, 0, 1) * 100}%` }
|
|
2774
2430
|
}),
|
|
2775
2431
|
/* @__PURE__ */ jsx("span", {
|
|
2776
2432
|
"aria-hidden": true,
|
|
@@ -2912,7 +2568,7 @@ function RateChoice({ rate, onRateChange, rates = [
|
|
|
2912
2568
|
* to the ends, M mutes. Pass the player's actions; the labels are the legend's words.
|
|
2913
2569
|
*/
|
|
2914
2570
|
function transportShortcuts({ toggle, seek, time, duration, frame = 1 / 30, jump = 1, toggleMute }) {
|
|
2915
|
-
const to = (t) => () => seek(clamp$
|
|
2571
|
+
const to = (t) => () => seek(clamp$3(t, 0, duration));
|
|
2916
2572
|
return [
|
|
2917
2573
|
{
|
|
2918
2574
|
keys: [" ", "k"],
|
|
@@ -3068,8 +2724,54 @@ function StageGuides({ safe, thirds, centre, className }) {
|
|
|
3068
2724
|
children: [draw("stroke-foreground", 3), draw("stroke-background", 1)]
|
|
3069
2725
|
});
|
|
3070
2726
|
}
|
|
2727
|
+
// src/components/media-group.tsx
|
|
2728
|
+
var groups = /* @__PURE__ */ new Map();
|
|
2729
|
+
/** Adds an element to a named group until the returned function is called; whenever one plays, the others pause. */
|
|
2730
|
+
function joinMediaGroup(name, el) {
|
|
2731
|
+
let members = groups.get(name);
|
|
2732
|
+
if (!members) groups.set(name, members = /* @__PURE__ */ new Set());
|
|
2733
|
+
members.add(el);
|
|
2734
|
+
const onPlay = () => {
|
|
2735
|
+
for (const other of groups.get(name) ?? []) if (other !== el && !other.paused) other.pause();
|
|
2736
|
+
};
|
|
2737
|
+
el.addEventListener("play", onPlay);
|
|
2738
|
+
return () => {
|
|
2739
|
+
el.removeEventListener("play", onPlay);
|
|
2740
|
+
members.delete(el);
|
|
2741
|
+
if (members.size === 0 && groups.get(name) === members) groups.delete(name);
|
|
2742
|
+
};
|
|
2743
|
+
}
|
|
2744
|
+
var GroupContext = React.createContext(null);
|
|
2745
|
+
/** The group a `MediaGroup` above this point names, or null. */
|
|
2746
|
+
function useMediaGroupName() {
|
|
2747
|
+
return React.useContext(GroupContext);
|
|
2748
|
+
}
|
|
2749
|
+
/** Players and elements under it play one at a time: starting one pauses the others. */
|
|
2750
|
+
function MediaGroup({ name, children }) {
|
|
2751
|
+
const own = React.useId();
|
|
2752
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, {
|
|
2753
|
+
value: name ?? own,
|
|
2754
|
+
children
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
/** Whether two windows are the same stretch. */
|
|
2758
|
+
var sameWindow = (a, b) => (a ?? null) === (b ?? null) || !!a && !!b && a.start === b.start && a.end === b.end;
|
|
2759
|
+
/** A row's play button for one window of a shared element: named for what it plays, pressed while it plays, a second press pauses. */
|
|
2760
|
+
function PlayWindowButton({ media, window: w, label, size = "sm", className }) {
|
|
2761
|
+
const playing = media.playing && sameWindow(media.window, w);
|
|
2762
|
+
return /* @__PURE__ */ jsx(IconButton, {
|
|
2763
|
+
icon: playing ? Pause : Play,
|
|
2764
|
+
label,
|
|
2765
|
+
size,
|
|
2766
|
+
className,
|
|
2767
|
+
"aria-pressed": playing,
|
|
2768
|
+
onClick: () => playing ? media.pause() : void media.playWindow(w)
|
|
2769
|
+
});
|
|
2770
|
+
}
|
|
3071
2771
|
// src/components/media-player.tsx
|
|
3072
2772
|
var idle = {
|
|
2773
|
+
ready: 0,
|
|
2774
|
+
waitingForMore: false,
|
|
3073
2775
|
playing: false,
|
|
3074
2776
|
time: 0,
|
|
3075
2777
|
duration: null,
|
|
@@ -3129,41 +2831,100 @@ var EVENTS = [
|
|
|
3129
2831
|
"error"
|
|
3130
2832
|
];
|
|
3131
2833
|
/** Follows an `<audio>` or `<video>` and returns its state and the requests a player makes. Works with the browser's own controls too. */
|
|
3132
|
-
function useMediaElement(ref) {
|
|
2834
|
+
function useMediaElement(ref, options = {}) {
|
|
3133
2835
|
const [snapshot, setSnapshot] = React.useState(idle);
|
|
3134
2836
|
const blocked = React.useRef(null);
|
|
3135
2837
|
const pendingSeek = React.useRef(null);
|
|
2838
|
+
const [ownWindow, setOwnWindow] = React.useState(null);
|
|
2839
|
+
const active = options.window ?? ownWindow;
|
|
2840
|
+
const win = React.useRef(active);
|
|
2841
|
+
win.current = active;
|
|
2842
|
+
const opts = React.useRef(options);
|
|
2843
|
+
opts.current = options;
|
|
2844
|
+
const windowEnded = React.useRef(false);
|
|
2845
|
+
const streamProblem = React.useRef(null);
|
|
2846
|
+
const edgePause = React.useRef(false);
|
|
2847
|
+
const contextGroup = useMediaGroupName();
|
|
2848
|
+
const group = options.group ?? contextGroup;
|
|
3136
2849
|
const read = React.useCallback(() => {
|
|
3137
2850
|
const el = ref.current;
|
|
3138
2851
|
if (!el) return;
|
|
3139
2852
|
const finite = Number.isFinite(el.duration) && el.duration > 0;
|
|
3140
|
-
|
|
2853
|
+
const growing = opts.current.growing === true;
|
|
2854
|
+
const seekEnd = el.seekable && el.seekable.length > 0 ? el.seekable.end(el.seekable.length - 1) : 0;
|
|
2855
|
+
const known = finite ? el.duration : growing && seekEnd > 0 ? seekEnd : null;
|
|
2856
|
+
const ready = growing ? seekEnd > 0 ? seekEnd : known ?? 0 : known ?? 0;
|
|
2857
|
+
const endedNow = el.ended && !growing;
|
|
2858
|
+
let error = blocked.current ?? (streamProblem.current ? {
|
|
2859
|
+
kind: "load",
|
|
2860
|
+
message: streamProblem.current
|
|
2861
|
+
} : null);
|
|
3141
2862
|
if (el.error && el.error.code !== 1) error = {
|
|
3142
2863
|
kind: "load",
|
|
3143
2864
|
message: LOAD_MESSAGES[el.error.code] ?? "It could not be played."
|
|
3144
2865
|
};
|
|
3145
2866
|
const next = {
|
|
2867
|
+
ready,
|
|
2868
|
+
waitingForMore: growing && known !== null && (el.ended || el.readyState < 3 && !el.paused) && el.currentTime >= known - 2,
|
|
3146
2869
|
playing: !el.paused && !el.ended,
|
|
3147
2870
|
time: Number.isFinite(el.currentTime) ? el.currentTime : 0,
|
|
3148
|
-
duration:
|
|
2871
|
+
duration: known,
|
|
3149
2872
|
buffered: bufferedAhead(el),
|
|
3150
2873
|
volume: el.muted ? 0 : Math.round(el.volume * 100),
|
|
3151
2874
|
muted: el.muted,
|
|
3152
2875
|
rate: el.playbackRate,
|
|
3153
|
-
ended:
|
|
2876
|
+
ended: endedNow,
|
|
3154
2877
|
loading: !error && el.networkState === 2 && el.readyState < 3 && !el.paused,
|
|
3155
2878
|
error
|
|
3156
2879
|
};
|
|
2880
|
+
if (growing && el.ended) edgePause.current = true;
|
|
2881
|
+
if (edgePause.current && known !== null && known > el.currentTime + .5 && el.paused) {
|
|
2882
|
+
edgePause.current = false;
|
|
2883
|
+
el.play().catch(() => {});
|
|
2884
|
+
}
|
|
3157
2885
|
setSnapshot((previous) => Object.keys(next).every((k) => Object.is(previous[k], next[k]) || k === "error" && previous.error?.message === next.error?.message && previous.error?.kind === next.error?.kind) ? previous : next);
|
|
3158
2886
|
}, [ref]);
|
|
2887
|
+
const enforce = React.useCallback((el) => {
|
|
2888
|
+
const w = win.current;
|
|
2889
|
+
if (!w || el.paused || windowEnded.current) return;
|
|
2890
|
+
if (el.currentTime < w.end) return;
|
|
2891
|
+
if (opts.current.loop) {
|
|
2892
|
+
el.currentTime = w.start;
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
windowEnded.current = true;
|
|
2896
|
+
el.pause();
|
|
2897
|
+
el.currentTime = w.end;
|
|
2898
|
+
opts.current.onWindowEnd?.();
|
|
2899
|
+
}, []);
|
|
3159
2900
|
useElementListeners(ref, (el) => {
|
|
2901
|
+
el.preservesPitch = true;
|
|
3160
2902
|
const on = (e) => {
|
|
3161
2903
|
if (e.type === "play" || e.type === "playing") blocked.current = null;
|
|
2904
|
+
if (e.type === "play") {
|
|
2905
|
+
windowEnded.current = false;
|
|
2906
|
+
const w = win.current;
|
|
2907
|
+
if (w && (el.currentTime < w.start || el.currentTime >= w.end)) el.currentTime = w.start;
|
|
2908
|
+
}
|
|
2909
|
+
if (e.type === "ended" && win.current && !windowEnded.current) {
|
|
2910
|
+
if (opts.current.loop) {
|
|
2911
|
+
el.currentTime = win.current.start;
|
|
2912
|
+
el.play().catch(() => {});
|
|
2913
|
+
} else {
|
|
2914
|
+
windowEnded.current = true;
|
|
2915
|
+
opts.current.onWindowEnd?.();
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
if (e.type === "timeupdate") enforce(el);
|
|
3162
2919
|
if (e.type === "loadedmetadata" && pendingSeek.current !== null) {
|
|
3163
2920
|
el.currentTime = pendingSeek.current;
|
|
3164
2921
|
pendingSeek.current = null;
|
|
3165
2922
|
}
|
|
3166
|
-
if (e.type === "emptied" || e.type === "loadstart")
|
|
2923
|
+
if (e.type === "emptied" || e.type === "loadstart") {
|
|
2924
|
+
blocked.current = null;
|
|
2925
|
+
streamProblem.current = null;
|
|
2926
|
+
}
|
|
2927
|
+
if (e.type === "pause" && !el.ended) edgePause.current = false;
|
|
3167
2928
|
read();
|
|
3168
2929
|
};
|
|
3169
2930
|
for (const type of EVENTS) el.addEventListener(type, on);
|
|
@@ -3172,6 +2933,51 @@ function useMediaElement(ref) {
|
|
|
3172
2933
|
for (const type of EVENTS) el.removeEventListener(type, on);
|
|
3173
2934
|
};
|
|
3174
2935
|
});
|
|
2936
|
+
const joined = React.useRef(null);
|
|
2937
|
+
React.useEffect(() => {
|
|
2938
|
+
const el = ref.current;
|
|
2939
|
+
if (joined.current && (joined.current.el !== el || joined.current.name !== group)) {
|
|
2940
|
+
joined.current.leave();
|
|
2941
|
+
joined.current = null;
|
|
2942
|
+
}
|
|
2943
|
+
if (el && group && !joined.current) joined.current = {
|
|
2944
|
+
el,
|
|
2945
|
+
name: group,
|
|
2946
|
+
leave: joinMediaGroup(group, el)
|
|
2947
|
+
};
|
|
2948
|
+
});
|
|
2949
|
+
React.useEffect(() => () => {
|
|
2950
|
+
joined.current?.leave();
|
|
2951
|
+
joined.current = null;
|
|
2952
|
+
}, []);
|
|
2953
|
+
const startKey = active ? `${active.start}:${active.end}` : null;
|
|
2954
|
+
React.useEffect(() => {
|
|
2955
|
+
const el = ref.current;
|
|
2956
|
+
if (!el || !active) return;
|
|
2957
|
+
windowEnded.current = false;
|
|
2958
|
+
if (el.readyState < 1) pendingSeek.current = active.start;
|
|
2959
|
+
else if (el.currentTime < active.start || el.currentTime >= active.end) el.currentTime = active.start;
|
|
2960
|
+
}, [startKey]);
|
|
2961
|
+
React.useEffect(() => {
|
|
2962
|
+
if (!snapshot.playing || !active && !options.onTimeUpdate) return;
|
|
2963
|
+
let frame = 0;
|
|
2964
|
+
const tick = () => {
|
|
2965
|
+
const el = ref.current;
|
|
2966
|
+
if (el) {
|
|
2967
|
+
enforce(el);
|
|
2968
|
+
opts.current.onTimeUpdate?.(el.currentTime);
|
|
2969
|
+
}
|
|
2970
|
+
frame = requestAnimationFrame(tick);
|
|
2971
|
+
};
|
|
2972
|
+
frame = requestAnimationFrame(tick);
|
|
2973
|
+
return () => cancelAnimationFrame(frame);
|
|
2974
|
+
}, [
|
|
2975
|
+
snapshot.playing,
|
|
2976
|
+
active !== null,
|
|
2977
|
+
options.onTimeUpdate !== void 0,
|
|
2978
|
+
enforce,
|
|
2979
|
+
ref
|
|
2980
|
+
]);
|
|
3175
2981
|
return React.useMemo(() => {
|
|
3176
2982
|
const play = async () => {
|
|
3177
2983
|
const el = ref.current;
|
|
@@ -3188,8 +2994,24 @@ function useMediaElement(ref) {
|
|
|
3188
2994
|
} else if (!(e instanceof DOMException && e.name === "AbortError")) read();
|
|
3189
2995
|
}
|
|
3190
2996
|
};
|
|
2997
|
+
const playWindow = async (w) => {
|
|
2998
|
+
const el = ref.current;
|
|
2999
|
+
if (!el) return;
|
|
3000
|
+
win.current = w;
|
|
3001
|
+
windowEnded.current = false;
|
|
3002
|
+
setOwnWindow(w);
|
|
3003
|
+
if (el.readyState < 1) pendingSeek.current = w.start;
|
|
3004
|
+
else el.currentTime = w.start;
|
|
3005
|
+
await play();
|
|
3006
|
+
};
|
|
3191
3007
|
return {
|
|
3192
3008
|
...snapshot,
|
|
3009
|
+
window: active,
|
|
3010
|
+
playWindow,
|
|
3011
|
+
reportProblem: (message) => {
|
|
3012
|
+
streamProblem.current = message;
|
|
3013
|
+
read();
|
|
3014
|
+
},
|
|
3193
3015
|
play,
|
|
3194
3016
|
pause: () => ref.current?.pause(),
|
|
3195
3017
|
toggle: () => {
|
|
@@ -3217,6 +3039,7 @@ function useMediaElement(ref) {
|
|
|
3217
3039
|
if (!el) return;
|
|
3218
3040
|
el.defaultPlaybackRate = rate;
|
|
3219
3041
|
el.playbackRate = rate;
|
|
3042
|
+
el.preservesPitch = true;
|
|
3220
3043
|
},
|
|
3221
3044
|
retry: () => {
|
|
3222
3045
|
const el = ref.current;
|
|
@@ -3224,6 +3047,12 @@ function useMediaElement(ref) {
|
|
|
3224
3047
|
const resume = !el.paused;
|
|
3225
3048
|
const at = el.currentTime;
|
|
3226
3049
|
blocked.current = null;
|
|
3050
|
+
streamProblem.current = null;
|
|
3051
|
+
if (opts.current.onRetry) {
|
|
3052
|
+
opts.current.onRetry(at);
|
|
3053
|
+
read();
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3227
3056
|
el.load();
|
|
3228
3057
|
if (at > 0) pendingSeek.current = at;
|
|
3229
3058
|
read();
|
|
@@ -3233,9 +3062,42 @@ function useMediaElement(ref) {
|
|
|
3233
3062
|
}, [
|
|
3234
3063
|
snapshot,
|
|
3235
3064
|
ref,
|
|
3236
|
-
read
|
|
3065
|
+
read,
|
|
3066
|
+
active
|
|
3237
3067
|
]);
|
|
3238
3068
|
}
|
|
3069
|
+
/**
|
|
3070
|
+
* Hands `src` to a stream engine (`attach`) for the element in `ref`, and ends the hold when `src` changes, `attach` does, or the component unmounts.
|
|
3071
|
+
* Use it for a plain `<video>` the app owns, with `useMediaElement`; `MediaPlayer` does it for `attach`.
|
|
3072
|
+
* Returns `reload`, for the player's Try again (`useMediaElement`'s `onRetry`), and gives the engine's failures to `onProblem` (`reportProblem`).
|
|
3073
|
+
*/
|
|
3074
|
+
function useAttachedSource(ref, src, attach, onProblem) {
|
|
3075
|
+
const hold = React.useRef(null);
|
|
3076
|
+
const problem = React.useRef(onProblem);
|
|
3077
|
+
problem.current = onProblem;
|
|
3078
|
+
React.useEffect(() => {
|
|
3079
|
+
const el = ref.current;
|
|
3080
|
+
const now = hold.current;
|
|
3081
|
+
if (now && now.el === el && now.src === src && now.attach === attach) return;
|
|
3082
|
+
now?.attachment.detach();
|
|
3083
|
+
hold.current = null;
|
|
3084
|
+
if (!el || !attach || !src) return;
|
|
3085
|
+
hold.current = {
|
|
3086
|
+
el,
|
|
3087
|
+
src,
|
|
3088
|
+
attach,
|
|
3089
|
+
attachment: attach(el, src, {
|
|
3090
|
+
startAt: 0,
|
|
3091
|
+
onProblem: (m) => problem.current?.(m)
|
|
3092
|
+
})
|
|
3093
|
+
};
|
|
3094
|
+
});
|
|
3095
|
+
React.useEffect(() => () => {
|
|
3096
|
+
hold.current?.attachment.detach();
|
|
3097
|
+
hold.current = null;
|
|
3098
|
+
}, []);
|
|
3099
|
+
return React.useMemo(() => ({ reload: (at) => hold.current?.attachment.reload(at) }), []);
|
|
3100
|
+
}
|
|
3239
3101
|
var keyPlayers = (() => {
|
|
3240
3102
|
const ids = /* @__PURE__ */ new Set();
|
|
3241
3103
|
let active = null;
|
|
@@ -3307,7 +3169,7 @@ function useCoarsePointer() {
|
|
|
3307
3169
|
* a touch device), with the failure to load shown and retried. For an editor or a replay, use the
|
|
3308
3170
|
* parts and `useMediaElement` directly.
|
|
3309
3171
|
*/
|
|
3310
|
-
function MediaPlayer({ label, kind = "audio", src, sources, index: controlledIndex, onIndexChange, autoAdvance = true, controls = "auto", autoPlay, poster, session, rates, shortcuts = true, onEnded, onTimeChange, className }) {
|
|
3172
|
+
function MediaPlayer({ label, kind = "audio", src, sources, index: controlledIndex, onIndexChange, autoAdvance = true, controls = "auto", autoPlay, poster, session, rates, shortcuts = true, attach, growing, window: bound, loop, showFull, group, onTimeUpdate, onWindowEnd, onEnded, onTimeChange, className }) {
|
|
3311
3173
|
const list = React.useMemo(() => sources ?? (src ? [{
|
|
3312
3174
|
src,
|
|
3313
3175
|
title: label
|
|
@@ -3320,7 +3182,17 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3320
3182
|
const index = Math.min(controlledIndex ?? ownIndex, Math.max(list.length - 1, 0));
|
|
3321
3183
|
const current = list[index];
|
|
3322
3184
|
const ref = React.useRef(null);
|
|
3323
|
-
const
|
|
3185
|
+
const stream = React.useRef({ reload: () => {} });
|
|
3186
|
+
const media = useMediaElement(ref, {
|
|
3187
|
+
window: bound,
|
|
3188
|
+
loop,
|
|
3189
|
+
group,
|
|
3190
|
+
onTimeUpdate,
|
|
3191
|
+
onWindowEnd,
|
|
3192
|
+
growing: growing !== void 0,
|
|
3193
|
+
onRetry: attach ? (t) => stream.current.reload(t) : void 0
|
|
3194
|
+
});
|
|
3195
|
+
stream.current = useAttachedSource(ref, current?.src, attach, media.reportProblem);
|
|
3324
3196
|
const coarse = useCoarsePointer();
|
|
3325
3197
|
const native = controls === "native" || controls === "auto" && coarse;
|
|
3326
3198
|
const go = React.useCallback((to) => {
|
|
@@ -3359,8 +3231,11 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3359
3231
|
media.play();
|
|
3360
3232
|
}
|
|
3361
3233
|
}, [current?.src]);
|
|
3234
|
+
const growingRef = React.useRef(growing !== void 0);
|
|
3235
|
+
growingRef.current = growing !== void 0;
|
|
3362
3236
|
const onEnd = React.useCallback(() => {
|
|
3363
3237
|
const k = keep.current;
|
|
3238
|
+
if (growingRef.current) return;
|
|
3364
3239
|
if (k.autoAdvance && k.index < k.last) {
|
|
3365
3240
|
resume.current = true;
|
|
3366
3241
|
k.go(k.index + 1);
|
|
@@ -3380,9 +3255,13 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3380
3255
|
});
|
|
3381
3256
|
}, [list]);
|
|
3382
3257
|
const total = offsets ? offsets[offsets.length - 1] + list[list.length - 1].duration : null;
|
|
3383
|
-
const
|
|
3384
|
-
const
|
|
3258
|
+
const cut = bound && !showFull ? bound : null;
|
|
3259
|
+
const time = cut ? Math.min(Math.max(media.time - cut.start, 0), cut.end - cut.start) : (offsets ? offsets[index] : 0) + media.time;
|
|
3260
|
+
const wholeLength = growing && list.length === 1 && list[0].duration ? list[0].duration : null;
|
|
3261
|
+
const duration = cut ? cut.end - cut.start : total ?? wholeLength ?? media.duration;
|
|
3385
3262
|
const seek = (t) => {
|
|
3263
|
+
if (growing && media.ready > 0) t = Math.min(t, media.ready);
|
|
3264
|
+
if (cut) return media.seek(cut.start + Math.min(Math.max(t, 0), cut.end - cut.start));
|
|
3386
3265
|
if (!offsets) return media.seek(t);
|
|
3387
3266
|
let to = offsets.length - 1;
|
|
3388
3267
|
while (to > 0 && offsets[to] > t) to--;
|
|
@@ -3499,7 +3378,7 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3499
3378
|
]);
|
|
3500
3379
|
const common = {
|
|
3501
3380
|
ref,
|
|
3502
|
-
src: current?.src,
|
|
3381
|
+
src: attach ? void 0 : current?.src,
|
|
3503
3382
|
controls: native,
|
|
3504
3383
|
autoPlay,
|
|
3505
3384
|
preload: "metadata",
|
|
@@ -3540,6 +3419,37 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3540
3419
|
className: "type-body-sm text-muted-foreground",
|
|
3541
3420
|
children: media.error.message
|
|
3542
3421
|
}),
|
|
3422
|
+
growing && /* @__PURE__ */ jsxs("div", {
|
|
3423
|
+
className: "flex flex-wrap items-center gap-x-3 gap-y-1",
|
|
3424
|
+
children: [
|
|
3425
|
+
/* @__PURE__ */ jsx(Status, {
|
|
3426
|
+
tone: "info",
|
|
3427
|
+
icon: LoaderCircle,
|
|
3428
|
+
children: "Still being made"
|
|
3429
|
+
}),
|
|
3430
|
+
growing.status && /* @__PURE__ */ jsx("span", {
|
|
3431
|
+
className: "type-body-sm text-muted-foreground",
|
|
3432
|
+
children: growing.status
|
|
3433
|
+
}),
|
|
3434
|
+
/* @__PURE__ */ jsx("span", {
|
|
3435
|
+
role: "status",
|
|
3436
|
+
className: "type-body-sm text-muted-foreground",
|
|
3437
|
+
children: media.waitingForMore ? "Waiting for more to be made. It will carry on by itself." : ""
|
|
3438
|
+
})
|
|
3439
|
+
]
|
|
3440
|
+
}),
|
|
3441
|
+
bound && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("p", {
|
|
3442
|
+
className: "type-caption text-muted-foreground tabular-nums",
|
|
3443
|
+
children: [
|
|
3444
|
+
format.runningTime(bound.start),
|
|
3445
|
+
" to ",
|
|
3446
|
+
format.runningTime(bound.end),
|
|
3447
|
+
loop ? ", looping" : ""
|
|
3448
|
+
]
|
|
3449
|
+
}), /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("span", {
|
|
3450
|
+
role: "status",
|
|
3451
|
+
children: media.playing ? `Playing ${format.runningTime(bound.start)} to ${format.runningTime(bound.end)}` : ""
|
|
3452
|
+
}) })] }),
|
|
3543
3453
|
!native && /* @__PURE__ */ jsxs("div", {
|
|
3544
3454
|
className: "grid gap-2",
|
|
3545
3455
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -3548,8 +3458,14 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3548
3458
|
time,
|
|
3549
3459
|
duration,
|
|
3550
3460
|
onSeek: seek,
|
|
3551
|
-
buffered: offsets ? void 0 : media.buffered,
|
|
3552
|
-
marks:
|
|
3461
|
+
buffered: growing ? media.ready : offsets ? void 0 : media.buffered,
|
|
3462
|
+
marks: bound && showFull ? [{
|
|
3463
|
+
time: bound.start,
|
|
3464
|
+
label: "Window starts"
|
|
3465
|
+
}, {
|
|
3466
|
+
time: bound.end,
|
|
3467
|
+
label: "Window ends"
|
|
3468
|
+
}] : offsets ? list.map((s, i) => ({
|
|
3553
3469
|
time: offsets[i],
|
|
3554
3470
|
label: s.title
|
|
3555
3471
|
})).slice(1) : [],
|
|
@@ -3606,182 +3522,1079 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
3606
3522
|
]
|
|
3607
3523
|
});
|
|
3608
3524
|
}
|
|
3609
|
-
// src/lib/
|
|
3610
|
-
/**
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
.
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
60,
|
|
3625
|
-
120,
|
|
3626
|
-
300,
|
|
3627
|
-
600,
|
|
3628
|
-
900,
|
|
3629
|
-
1800,
|
|
3630
|
-
3600,
|
|
3631
|
-
7200,
|
|
3632
|
-
14400,
|
|
3633
|
-
21600,
|
|
3634
|
-
43200,
|
|
3635
|
-
86400
|
|
3636
|
-
];
|
|
3637
|
-
/** The smallest step whose ticks are at least `minGapPx` apart at this zoom, so labels thin out instead of colliding. */
|
|
3638
|
-
function tickStep(pxPerUnit, minGapPx = 80) {
|
|
3639
|
-
return STEPS.find((s) => s * pxPerUnit >= minGapPx) ?? STEPS[STEPS.length - 1];
|
|
3640
|
-
}
|
|
3641
|
-
/** Tick times from `from` to `to` inclusive, on multiples of `step`. */
|
|
3642
|
-
function ticksBetween(from, to, step) {
|
|
3643
|
-
const out = [];
|
|
3644
|
-
const first = Math.ceil(from / step - 1e-9);
|
|
3645
|
-
for (let i = first; i * step <= to + 1e-9; i++) out.push(Math.round(i * step * 1e6) / 1e6 || 0);
|
|
3646
|
-
return out;
|
|
3525
|
+
// src/lib/transcript.ts
|
|
3526
|
+
/** The phrase being heard at `time`, as an index into `phrases` (sorted by start), or -1. A phrase is heard from its `start` up to, not including, its `end`. */
|
|
3527
|
+
function phraseAt(phrases, time) {
|
|
3528
|
+
let lo = 0;
|
|
3529
|
+
let hi = phrases.length - 1;
|
|
3530
|
+
let found = -1;
|
|
3531
|
+
while (lo <= hi) {
|
|
3532
|
+
const mid = lo + hi >> 1;
|
|
3533
|
+
if (phrases[mid].start <= time) {
|
|
3534
|
+
found = mid;
|
|
3535
|
+
lo = mid + 1;
|
|
3536
|
+
} else hi = mid - 1;
|
|
3537
|
+
}
|
|
3538
|
+
for (let i = found; i >= 0 && i > found - 8; i--) if (time < phrases[i].end) return i;
|
|
3539
|
+
return -1;
|
|
3647
3540
|
}
|
|
3648
|
-
/**
|
|
3649
|
-
function
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
const two = (n) => String(n).padStart(2, "0");
|
|
3656
|
-
const base = h > 0 ? `${h}:${two(m)}:${two(s)}` : `${m}:${two(s)}`;
|
|
3657
|
-
return decimals ? `${base}.${String(Math.round((time - whole) * 10 ** decimals)).padStart(decimals, "0")}` : base;
|
|
3541
|
+
/** The word being heard within a phrase at `time`: the last word that has started, until the phrase ends. -1 before the first word. */
|
|
3542
|
+
function wordAt(phrase, time) {
|
|
3543
|
+
if (time >= phrase.end) return -1;
|
|
3544
|
+
let found = -1;
|
|
3545
|
+
for (let i = 0; i < phrase.words.length; i++) if (phrase.words[i].start <= time) found = i;
|
|
3546
|
+
else break;
|
|
3547
|
+
return found;
|
|
3658
3548
|
}
|
|
3659
|
-
|
|
3660
|
-
|
|
3549
|
+
// src/components/virtual-list.tsx
|
|
3550
|
+
var FOOTER = "\0footer";
|
|
3551
|
+
/** A list that renders only its visible rows (React Aria's GridList and Virtualizer) from `virtualizeFrom` items, with arrow-key navigation between rows. */
|
|
3552
|
+
function VirtualList({ label, items, itemKey, children, estimateSize = 48, rowHeight, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
|
|
3553
|
+
const virtual = items.length >= virtualizeFrom;
|
|
3554
|
+
const rows = React.useMemo(() => items.map((item, index) => ({
|
|
3555
|
+
id: itemKey(item),
|
|
3556
|
+
item,
|
|
3557
|
+
index
|
|
3558
|
+
})), [items, itemKey]);
|
|
3559
|
+
const layoutOptions = React.useMemo(() => rowHeight ? { rowHeight } : { estimatedRowHeight: estimateSize }, [rowHeight, estimateSize]);
|
|
3560
|
+
const virtualise = virtual || bounded;
|
|
3561
|
+
const scrolls = virtualise;
|
|
3562
|
+
const list = /* @__PURE__ */ jsxs(GridList, {
|
|
3563
|
+
"aria-label": label,
|
|
3564
|
+
selectionMode: "none",
|
|
3565
|
+
"data-strata-scroll": "",
|
|
3566
|
+
className: cn("min-w-0 outline-none", scrolls && "overflow-y-auto", className),
|
|
3567
|
+
style: scrolls ? virtual ? { height } : { maxHeight: height } : void 0,
|
|
3568
|
+
children: [/* @__PURE__ */ jsx(Collection, {
|
|
3569
|
+
items: rows,
|
|
3570
|
+
children: (row) => /* @__PURE__ */ jsx(GridListItem, {
|
|
3571
|
+
id: row.id,
|
|
3572
|
+
textValue: row.id,
|
|
3573
|
+
"data-index": row.index,
|
|
3574
|
+
className: cn("min-w-0 outline-offset-[-2px]", row.index > 0 && "border-t border-border"),
|
|
3575
|
+
children: children(row.item, row.index)
|
|
3576
|
+
})
|
|
3577
|
+
}), footer && /* @__PURE__ */ jsx(GridListItem, {
|
|
3578
|
+
id: FOOTER,
|
|
3579
|
+
textValue: "More",
|
|
3580
|
+
className: "min-w-0",
|
|
3581
|
+
children: footer
|
|
3582
|
+
})]
|
|
3583
|
+
});
|
|
3584
|
+
return virtualise ? /* @__PURE__ */ jsx(Virtualizer, {
|
|
3585
|
+
layout: ListLayout,
|
|
3586
|
+
layoutOptions,
|
|
3587
|
+
children: list
|
|
3588
|
+
}) : list;
|
|
3661
3589
|
}
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3590
|
+
// src/components/transcript-view.tsx
|
|
3591
|
+
var ALL = "all";
|
|
3592
|
+
var capital = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
3593
|
+
var range = (a, b) => `${format.runningTime(a)}–${format.runningTime(b)}`;
|
|
3594
|
+
/** Timed text that follows playback: the heard word marked, any word or phrase pressed to play from, modes, speakers, follow and Jump to now. */
|
|
3595
|
+
function TranscriptView({ label, groups, time, onSeek, mode: controlledMode, onModeChange, modeLabels = {}, speaker: controlledSpeaker, onSpeakerChange, follow = true, announce = false, renderPlay, height = 480, className }) {
|
|
3596
|
+
const [ownMode, setOwnMode] = React.useState("original");
|
|
3597
|
+
const [ownSpeaker, setOwnSpeaker] = React.useState(ALL);
|
|
3598
|
+
const mode = controlledMode ?? ownMode;
|
|
3599
|
+
const speaker = controlledSpeaker ?? ownSpeaker;
|
|
3600
|
+
const modes = React.useMemo(() => ["original", ...new Set(groups.flatMap((g) => g.phrases.flatMap((p) => Object.keys(p.alt ?? {}))))], [groups]);
|
|
3601
|
+
const speakers = React.useMemo(() => [...new Set(groups.flatMap((g) => g.phrases.map((p) => p.speaker).filter((s) => Boolean(s))))], [groups]);
|
|
3602
|
+
const { rows, phrases } = React.useMemo(() => {
|
|
3603
|
+
const rows = [];
|
|
3604
|
+
const phrases = [];
|
|
3605
|
+
for (const g of groups) {
|
|
3606
|
+
const mine = g.phrases.filter((p) => speaker === ALL || p.speaker === speaker);
|
|
3607
|
+
if (mine.length === 0) continue;
|
|
3608
|
+
rows.push({
|
|
3609
|
+
kind: "heading",
|
|
3610
|
+
key: `group:${g.id}`,
|
|
3611
|
+
group: {
|
|
3612
|
+
...g,
|
|
3613
|
+
start: g.start ?? mine[0].start,
|
|
3614
|
+
end: g.end ?? mine[mine.length - 1].end
|
|
3615
|
+
}
|
|
3616
|
+
});
|
|
3617
|
+
for (const p of mine) {
|
|
3618
|
+
rows.push({
|
|
3619
|
+
kind: "phrase",
|
|
3620
|
+
key: p.id,
|
|
3621
|
+
phrase: p,
|
|
3622
|
+
index: phrases.length
|
|
3623
|
+
});
|
|
3624
|
+
phrases.push(p);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
return {
|
|
3628
|
+
rows,
|
|
3629
|
+
phrases
|
|
3630
|
+
};
|
|
3631
|
+
}, [groups, speaker]);
|
|
3632
|
+
const heard = phraseAt(phrases, time);
|
|
3633
|
+
const heardPhrase = heard >= 0 ? phrases[heard] : null;
|
|
3634
|
+
const heardWord = heardPhrase ? wordAt(heardPhrase, time) : -1;
|
|
3635
|
+
const heardText = heardPhrase ? mode === "original" ? heardPhrase.words.map((w) => w.text).join(" ") : heardPhrase.alt?.[mode] ?? heardPhrase.words.map((w) => w.text).join(" ") : "";
|
|
3636
|
+
const root = React.useRef(null);
|
|
3637
|
+
const [following, setFollowing] = React.useState(follow);
|
|
3638
|
+
React.useEffect(() => setFollowing(follow), [follow]);
|
|
3639
|
+
const ours = React.useRef(0);
|
|
3640
|
+
const scrollBox = () => root.current?.querySelector("[data-strata-scroll]") ?? null;
|
|
3641
|
+
const scrollToHeard = React.useCallback((id, tries = 0) => {
|
|
3642
|
+
const el = root.current?.querySelector(`[data-phrase="${CSS.escape(id)}"]`);
|
|
3643
|
+
ours.current = Date.now();
|
|
3644
|
+
if (el) {
|
|
3645
|
+
el.scrollIntoView?.({ block: "center" });
|
|
3646
|
+
return;
|
|
3647
|
+
}
|
|
3648
|
+
if (tries > 5) return;
|
|
3649
|
+
const box = scrollBox();
|
|
3650
|
+
const mounted = box ? [...box.querySelectorAll("[data-index]")] : [];
|
|
3651
|
+
if (box && mounted.length > 0 && box.scrollHeight > box.clientHeight) {
|
|
3652
|
+
const avg = mounted.reduce((sum, m) => sum + m.getBoundingClientRect().height, 0) / mounted.length;
|
|
3653
|
+
const index = rows.findIndex((r) => r.key === id);
|
|
3654
|
+
box.scrollTop = Math.max(index * avg - box.clientHeight / 2, 0);
|
|
3655
|
+
}
|
|
3656
|
+
requestAnimationFrame(() => scrollToHeard(id, tries + 1));
|
|
3657
|
+
}, [rows]);
|
|
3658
|
+
const heardId = heardPhrase?.id;
|
|
3659
|
+
React.useEffect(() => {
|
|
3660
|
+
if (following && heardId) scrollToHeard(heardId);
|
|
3661
|
+
}, [
|
|
3662
|
+
heardId,
|
|
3663
|
+
following,
|
|
3664
|
+
scrollToHeard
|
|
3665
|
+
]);
|
|
3666
|
+
React.useEffect(() => {
|
|
3667
|
+
let intent = 0;
|
|
3668
|
+
const meant = () => void (intent = Date.now());
|
|
3669
|
+
const onScroll = (e) => {
|
|
3670
|
+
const el = root.current;
|
|
3671
|
+
const target = e.target;
|
|
3672
|
+
if (!el || !target || !(target === document || target.contains?.(el) || el.contains(target))) return;
|
|
3673
|
+
if (Date.now() - ours.current < 400 || Date.now() - intent > 1e3) return;
|
|
3674
|
+
setFollowing(false);
|
|
3675
|
+
};
|
|
3676
|
+
const gestures = [
|
|
3677
|
+
"wheel",
|
|
3678
|
+
"touchstart",
|
|
3679
|
+
"touchmove",
|
|
3680
|
+
"keydown",
|
|
3681
|
+
"pointerdown"
|
|
3682
|
+
];
|
|
3683
|
+
for (const g of gestures) document.addEventListener(g, meant, {
|
|
3684
|
+
capture: true,
|
|
3685
|
+
passive: true
|
|
3686
|
+
});
|
|
3687
|
+
document.addEventListener("scroll", onScroll, true);
|
|
3688
|
+
return () => {
|
|
3689
|
+
for (const g of gestures) document.removeEventListener(g, meant, true);
|
|
3690
|
+
document.removeEventListener("scroll", onScroll, true);
|
|
3691
|
+
};
|
|
3692
|
+
}, []);
|
|
3693
|
+
const [said, setSaid] = React.useState("");
|
|
3694
|
+
React.useEffect(() => {
|
|
3695
|
+
if (announce) setSaid(heardText);
|
|
3696
|
+
}, [
|
|
3697
|
+
announce,
|
|
3698
|
+
heardId,
|
|
3699
|
+
heardText
|
|
3700
|
+
]);
|
|
3701
|
+
const setMode = (m) => {
|
|
3702
|
+
if (controlledMode === void 0) setOwnMode(m);
|
|
3703
|
+
onModeChange?.(m);
|
|
3669
3704
|
};
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
// src/components/timeline.tsx
|
|
3674
|
-
var EDGE_PX = 8;
|
|
3675
|
-
var DRAG_THRESHOLD = 3;
|
|
3676
|
-
var defaultFormat = (t) => tickLabel(t, 1);
|
|
3677
|
-
/** Zoom state for a timeline: `zoomIn`, `zoomOut`, and `fit` to a viewport width. Pass `zoom` and `setZoom` as the timeline's `zoom` and `onZoomChange`. */
|
|
3678
|
-
function useTimelineZoom({ initial = 20, min = .5, max = 400 } = {}) {
|
|
3679
|
-
const [zoom, set] = React.useState(initial);
|
|
3680
|
-
const setZoom = React.useCallback((z) => set(clamp$1(z, min, max)), [min, max]);
|
|
3681
|
-
return {
|
|
3682
|
-
zoom,
|
|
3683
|
-
setZoom,
|
|
3684
|
-
zoomIn: () => setZoom(zoom * 1.5),
|
|
3685
|
-
zoomOut: () => setZoom(zoom / 1.5),
|
|
3686
|
-
/** Zoom so `duration` fills `viewportWidth` pixels. */
|
|
3687
|
-
fit: (viewportWidth, duration) => setZoom(viewportWidth / Math.max(duration, 1e-6))
|
|
3705
|
+
const setSpeaker = (s) => {
|
|
3706
|
+
if (controlledSpeaker === void 0) setOwnSpeaker(s);
|
|
3707
|
+
onSpeakerChange?.(s);
|
|
3688
3708
|
};
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3709
|
+
const seek = (t, from) => {
|
|
3710
|
+
setFollowing(follow);
|
|
3711
|
+
onSeek(t, from);
|
|
3712
|
+
};
|
|
3713
|
+
const modeOptions = modes.map((m) => ({
|
|
3714
|
+
value: m,
|
|
3715
|
+
label: m === "original" ? modeLabels.original ?? "Original" : modeLabels[m] ?? capital(m)
|
|
3716
|
+
}));
|
|
3717
|
+
const speakerOptions = [{
|
|
3718
|
+
value: ALL,
|
|
3719
|
+
label: "Everyone"
|
|
3720
|
+
}, ...speakers.map((s) => ({
|
|
3721
|
+
value: s,
|
|
3722
|
+
label: s
|
|
3723
|
+
}))];
|
|
3692
3724
|
return /* @__PURE__ */ jsxs("div", {
|
|
3693
|
-
|
|
3725
|
+
ref: root,
|
|
3726
|
+
className: cn("grid min-w-0 gap-3", className),
|
|
3694
3727
|
children: [
|
|
3695
|
-
/* @__PURE__ */
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3728
|
+
(modes.length > 1 || speakers.length > 1) && /* @__PURE__ */ jsxs("div", {
|
|
3729
|
+
className: "flex flex-wrap items-center gap-x-4 gap-y-2",
|
|
3730
|
+
children: [modes.length > 1 && /* @__PURE__ */ jsx(ToggleGroup, {
|
|
3731
|
+
label: `${label}: text`,
|
|
3732
|
+
options: modeOptions,
|
|
3733
|
+
value: mode,
|
|
3734
|
+
onChange: setMode,
|
|
3735
|
+
size: "sm"
|
|
3736
|
+
}), speakers.length > 1 && (speakers.length <= 4 ? /* @__PURE__ */ jsx(ToggleGroup, {
|
|
3737
|
+
label: `${label}: speaker`,
|
|
3738
|
+
options: speakerOptions,
|
|
3739
|
+
value: speaker,
|
|
3740
|
+
onChange: setSpeaker,
|
|
3741
|
+
size: "sm"
|
|
3742
|
+
}) : /* @__PURE__ */ jsx(NativeSelect, {
|
|
3743
|
+
"aria-label": `${label}: speaker`,
|
|
3744
|
+
size: "sm",
|
|
3745
|
+
value: speaker,
|
|
3746
|
+
onChange: (e) => setSpeaker(e.target.value),
|
|
3747
|
+
children: speakerOptions.map((o) => /* @__PURE__ */ jsx("option", {
|
|
3748
|
+
value: o.value,
|
|
3749
|
+
children: o.label
|
|
3750
|
+
}, o.value))
|
|
3751
|
+
}))]
|
|
3700
3752
|
}),
|
|
3701
|
-
/* @__PURE__ */
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3753
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3754
|
+
className: "relative",
|
|
3755
|
+
children: [/* @__PURE__ */ jsx(VirtualList, {
|
|
3756
|
+
label,
|
|
3757
|
+
items: rows,
|
|
3758
|
+
itemKey: (r) => r.key,
|
|
3759
|
+
estimateSize: 72,
|
|
3760
|
+
height,
|
|
3761
|
+
virtualizeFrom: 100,
|
|
3762
|
+
children: (row) => row.kind === "heading" ? /* @__PURE__ */ jsxs("div", {
|
|
3763
|
+
className: "flex items-baseline gap-3 bg-surface-sunken px-3 py-2",
|
|
3764
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
3765
|
+
className: "type-label text-foreground",
|
|
3766
|
+
children: row.group.title
|
|
3767
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
3768
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
3769
|
+
children: range(row.group.start, row.group.end)
|
|
3770
|
+
})]
|
|
3771
|
+
}) : /* @__PURE__ */ jsx(PhraseRow, {
|
|
3772
|
+
phrase: row.phrase,
|
|
3773
|
+
mode,
|
|
3774
|
+
active: row.index === heard,
|
|
3775
|
+
word: row.index === heard ? heardWord : -1,
|
|
3776
|
+
onSeek: seek,
|
|
3777
|
+
play: renderPlay?.(row.phrase)
|
|
3778
|
+
})
|
|
3779
|
+
}), follow && !following && heardPhrase && /* @__PURE__ */ jsx("div", {
|
|
3780
|
+
className: "pointer-events-none absolute inset-x-0 bottom-2 flex justify-center",
|
|
3781
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
3782
|
+
className: "pointer-events-auto max-w-full shadow-overlay",
|
|
3783
|
+
onPress: () => setFollowing(true),
|
|
3784
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
3785
|
+
className: "truncate",
|
|
3786
|
+
children: ["Jump to now: ", heardText]
|
|
3787
|
+
})
|
|
3788
|
+
})
|
|
3789
|
+
})]
|
|
3706
3790
|
}),
|
|
3707
|
-
/* @__PURE__ */ jsx(
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
onClick: zoom.fit
|
|
3712
|
-
})
|
|
3791
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("span", {
|
|
3792
|
+
role: "status",
|
|
3793
|
+
children: said
|
|
3794
|
+
}) })
|
|
3713
3795
|
]
|
|
3714
3796
|
});
|
|
3715
3797
|
}
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
return (
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3798
|
+
function PhraseRow({ phrase, mode, active, word, onSeek, play }) {
|
|
3799
|
+
const alt = mode === "original" ? null : phrase.alt?.[mode] ?? null;
|
|
3800
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3801
|
+
"data-phrase": phrase.id,
|
|
3802
|
+
"data-active": active ? "" : void 0,
|
|
3803
|
+
"aria-current": active ? "true" : void 0,
|
|
3804
|
+
className: cn("flex items-start gap-2 border-l-2 border-transparent px-3 py-2", active && "border-primary bg-accent"),
|
|
3805
|
+
children: [play, /* @__PURE__ */ jsxs("div", {
|
|
3806
|
+
className: "min-w-0 flex-1",
|
|
3807
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
3808
|
+
className: "flex items-baseline gap-2",
|
|
3809
|
+
children: [phrase.speaker && /* @__PURE__ */ jsx("span", {
|
|
3810
|
+
className: "type-label text-muted-foreground",
|
|
3811
|
+
children: phrase.speaker
|
|
3812
|
+
}), /* @__PURE__ */ jsx(Button$1, {
|
|
3813
|
+
onPress: () => onSeek(phrase.start, { phraseId: phrase.id }),
|
|
3814
|
+
className: "rounded-control type-caption tabular-nums text-muted-foreground hover:text-foreground",
|
|
3815
|
+
"aria-label": `Play from ${format.runningTime(phrase.start)}`,
|
|
3816
|
+
children: format.runningTime(phrase.start)
|
|
3817
|
+
})]
|
|
3818
|
+
}), alt !== null ? /* @__PURE__ */ jsx(Button$1, {
|
|
3819
|
+
onPress: () => onSeek(phrase.start, { phraseId: phrase.id }),
|
|
3820
|
+
className: cn("rounded-control text-left type-body", active && "font-medium underline decoration-2 underline-offset-4"),
|
|
3821
|
+
children: alt
|
|
3822
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
3823
|
+
className: "type-body",
|
|
3824
|
+
children: phrase.words.map((w, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && " ", /* @__PURE__ */ jsx(Button$1, {
|
|
3825
|
+
"aria-current": i === word ? "true" : void 0,
|
|
3826
|
+
onPress: () => onSeek(w.start, {
|
|
3827
|
+
phraseId: phrase.id,
|
|
3828
|
+
wordIndex: i
|
|
3829
|
+
}),
|
|
3830
|
+
className: cn("rounded-control hover:bg-muted", i === word && "font-medium underline decoration-2 underline-offset-4"),
|
|
3831
|
+
children: w.text
|
|
3832
|
+
})] }, i))
|
|
3833
|
+
})]
|
|
3834
|
+
})]
|
|
3835
|
+
});
|
|
3836
|
+
}
|
|
3837
|
+
// src/lib/waveform.ts
|
|
3838
|
+
var isPair = (p) => typeof p.min === "object";
|
|
3839
|
+
/** Makes the lowest and highest sample of each slice from either form. A magnitude `m` is the pair `-m` to `m`. */
|
|
3840
|
+
function toPeakPair(peaks) {
|
|
3841
|
+
if (isPair(peaks)) {
|
|
3842
|
+
const n = Math.min(peaks.min.length, peaks.max.length);
|
|
3843
|
+
const min = new Float32Array(n);
|
|
3844
|
+
const max = new Float32Array(n);
|
|
3845
|
+
for (let i = 0; i < n; i++) {
|
|
3846
|
+
min[i] = Math.min(peaks.min[i], peaks.max[i]);
|
|
3847
|
+
max[i] = Math.max(peaks.min[i], peaks.max[i]);
|
|
3848
|
+
}
|
|
3849
|
+
return {
|
|
3850
|
+
min,
|
|
3851
|
+
max
|
|
3852
|
+
};
|
|
3853
|
+
}
|
|
3854
|
+
const n = peaks.length;
|
|
3855
|
+
const min = new Float32Array(n);
|
|
3856
|
+
const max = new Float32Array(n);
|
|
3857
|
+
for (let i = 0; i < n; i++) {
|
|
3858
|
+
const m = Math.abs(peaks[i]);
|
|
3859
|
+
min[i] = -m;
|
|
3860
|
+
max[i] = m;
|
|
3861
|
+
}
|
|
3862
|
+
return {
|
|
3863
|
+
min,
|
|
3864
|
+
max
|
|
3722
3865
|
};
|
|
3723
3866
|
}
|
|
3724
|
-
/**
|
|
3725
|
-
function
|
|
3726
|
-
const
|
|
3727
|
-
|
|
3728
|
-
const
|
|
3729
|
-
const
|
|
3730
|
-
|
|
3731
|
-
|
|
3867
|
+
/** The lowest and highest of `pair` over the fraction `from` to `to` of its length (0 to 1). A slice narrower than one entry takes the entry it falls in, so zooming past the data never leaves a gap. */
|
|
3868
|
+
function peaksBetween(pair, from, to) {
|
|
3869
|
+
const n = pair.min.length;
|
|
3870
|
+
if (n === 0) return [0, 0];
|
|
3871
|
+
const a = Math.min(Math.max(from, 0), 1) * n;
|
|
3872
|
+
const b = Math.min(Math.max(to, 0), 1) * n;
|
|
3873
|
+
const first = Math.min(Math.floor(a), n - 1);
|
|
3874
|
+
const last = Math.min(Math.max(Math.ceil(b) - 1, first), n - 1);
|
|
3875
|
+
let lo = Infinity;
|
|
3876
|
+
let hi = -Infinity;
|
|
3877
|
+
for (let i = first; i <= last; i++) {
|
|
3878
|
+
if (pair.min[i] < lo) lo = pair.min[i];
|
|
3879
|
+
if (pair.max[i] > hi) hi = pair.max[i];
|
|
3880
|
+
}
|
|
3881
|
+
return [lo, hi];
|
|
3882
|
+
}
|
|
3883
|
+
/** Resamples peaks to `buckets` entries: each is the lowest and highest of the entries it covers. Any length in, any length out. */
|
|
3884
|
+
function resamplePeaks(peaks, buckets) {
|
|
3885
|
+
const pair = toPeakPair(peaks);
|
|
3886
|
+
const count = Math.max(Math.floor(buckets), 0);
|
|
3887
|
+
const min = new Float32Array(count);
|
|
3888
|
+
const max = new Float32Array(count);
|
|
3889
|
+
for (let i = 0; i < count; i++) [min[i], max[i]] = peaksBetween(pair, i / count, (i + 1) / count);
|
|
3890
|
+
return {
|
|
3891
|
+
min,
|
|
3892
|
+
max
|
|
3893
|
+
};
|
|
3894
|
+
}
|
|
3895
|
+
/**
|
|
3896
|
+
* Reduces decoded audio to `buckets` peaks over all channels, in chunks, calling `progress` with
|
|
3897
|
+
* the buckets done and awaiting between chunks so the page stays responsive and `signal` can stop it.
|
|
3898
|
+
*/
|
|
3899
|
+
async function peaksFromAudio(audio, buckets, options = {}) {
|
|
3900
|
+
const { signal, progress, chunk = 256 } = options;
|
|
3901
|
+
const min = new Float32Array(buckets);
|
|
3902
|
+
const max = new Float32Array(buckets);
|
|
3903
|
+
const channels = Array.from({ length: audio.numberOfChannels }, (_, c) => audio.getChannelData(c));
|
|
3904
|
+
const size = audio.length / buckets;
|
|
3905
|
+
for (let i = 0; i < buckets; i++) {
|
|
3906
|
+
const from = Math.floor(i * size);
|
|
3907
|
+
const to = Math.max(Math.floor((i + 1) * size), from + 1);
|
|
3908
|
+
let lo = Infinity;
|
|
3909
|
+
let hi = -Infinity;
|
|
3910
|
+
for (const data of channels) for (let j = from; j < to && j < data.length; j++) {
|
|
3911
|
+
const v = data[j];
|
|
3912
|
+
if (v < lo) lo = v;
|
|
3913
|
+
if (v > hi) hi = v;
|
|
3914
|
+
}
|
|
3915
|
+
min[i] = Number.isFinite(lo) ? lo : 0;
|
|
3916
|
+
max[i] = Number.isFinite(hi) ? hi : 0;
|
|
3917
|
+
if ((i + 1) % chunk === 0 || i === buckets - 1) {
|
|
3918
|
+
progress?.(i + 1, buckets);
|
|
3919
|
+
if (signal?.aborted) throw new DOMException("The waveform was cancelled.", "AbortError");
|
|
3920
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
return {
|
|
3924
|
+
min,
|
|
3925
|
+
max
|
|
3926
|
+
};
|
|
3927
|
+
}
|
|
3928
|
+
/** The time at the pointer, given the visible range and the width. */
|
|
3929
|
+
var timeAt = (px, width, from, to) => from + Math.min(Math.max(px, 0), width) / (width || 1) * (to - from);
|
|
3930
|
+
/** Keeps a visible range of `span` seconds inside `0` to `duration`. */
|
|
3931
|
+
function clampView(from, span, duration) {
|
|
3932
|
+
const s = Math.min(Math.max(span, Math.min(duration, .05)), duration);
|
|
3933
|
+
const a = Math.min(Math.max(from, 0), Math.max(duration - s, 0));
|
|
3934
|
+
return [a, a + s];
|
|
3935
|
+
}
|
|
3936
|
+
// src/components/waveform.tsx
|
|
3937
|
+
var TONE$2 = {
|
|
3938
|
+
neutral: {
|
|
3939
|
+
fill: "var(--muted)",
|
|
3940
|
+
edge: "var(--muted-foreground)"
|
|
3941
|
+
},
|
|
3942
|
+
info: {
|
|
3943
|
+
fill: "var(--info-subtle)",
|
|
3944
|
+
edge: "var(--info)"
|
|
3945
|
+
},
|
|
3946
|
+
success: {
|
|
3947
|
+
fill: "var(--success-subtle)",
|
|
3948
|
+
edge: "var(--success)"
|
|
3949
|
+
},
|
|
3950
|
+
warning: {
|
|
3951
|
+
fill: "var(--warning-subtle)",
|
|
3952
|
+
edge: "var(--warning)"
|
|
3953
|
+
},
|
|
3954
|
+
danger: {
|
|
3955
|
+
fill: "var(--danger-subtle)",
|
|
3956
|
+
edge: "var(--danger)"
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
var MARK_LINE = {
|
|
3960
|
+
beat: {
|
|
3961
|
+
width: 1,
|
|
3962
|
+
opacity: .16
|
|
3963
|
+
},
|
|
3964
|
+
bar: {
|
|
3965
|
+
width: 1.5,
|
|
3966
|
+
opacity: .55
|
|
3967
|
+
},
|
|
3968
|
+
downbeat: {
|
|
3969
|
+
width: 2.5,
|
|
3970
|
+
opacity: 1
|
|
3971
|
+
},
|
|
3972
|
+
chapter: {
|
|
3973
|
+
width: 1.5,
|
|
3974
|
+
opacity: .9,
|
|
3975
|
+
dash: "4 3"
|
|
3976
|
+
}
|
|
3977
|
+
};
|
|
3978
|
+
var WORDS = {
|
|
3979
|
+
running: "Reading the waveform",
|
|
3980
|
+
finished: "Waveform ready",
|
|
3981
|
+
failed: "Could not read the waveform"
|
|
3982
|
+
};
|
|
3983
|
+
async function defaultDecode(data) {
|
|
3984
|
+
const Context = typeof AudioContext !== "undefined" ? AudioContext : globalThis.webkitAudioContext;
|
|
3985
|
+
if (!Context) throw new Error("This browser cannot decode audio.");
|
|
3986
|
+
const ctx = new Context();
|
|
3987
|
+
try {
|
|
3988
|
+
return await ctx.decodeAudioData(data);
|
|
3989
|
+
} finally {
|
|
3990
|
+
ctx.close?.();
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
var clamp$2 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
3994
|
+
var clock = (t) => format.runningTime(t);
|
|
3995
|
+
/** An audio waveform with marks, spans and a playhead: one slider you click, drag or key to seek, zoom, and a range to select. */
|
|
3996
|
+
function Waveform({ label, peaks, source, duration: given, time, onSeek, marks = [], spans = [], underlay, range: controlledRange, onRangeChange, step = 5, bigStep = 30, defaultView, buckets = 2e3, decode = defaultDecode, words = WORDS, disabled, className }) {
|
|
3997
|
+
const work = useClientWork(async ({ signal, progress }) => {
|
|
3998
|
+
const data = typeof source === "string" ? await (await fetch(source, { signal })).arrayBuffer() : await source.arrayBuffer();
|
|
3999
|
+
progress(0, buckets + 2);
|
|
4000
|
+
const audio = await decode(data);
|
|
4001
|
+
if (signal.aborted) throw new DOMException("The waveform was cancelled.", "AbortError");
|
|
4002
|
+
progress(1, buckets + 2);
|
|
4003
|
+
return {
|
|
4004
|
+
pair: await peaksFromAudio(audio, buckets, {
|
|
4005
|
+
signal,
|
|
4006
|
+
progress: (done) => progress(done + 1, buckets + 2)
|
|
4007
|
+
}),
|
|
4008
|
+
duration: audio.duration
|
|
4009
|
+
};
|
|
3732
4010
|
});
|
|
4011
|
+
const startWork = work.start;
|
|
4012
|
+
const cancelWork = work.cancel;
|
|
4013
|
+
React.useEffect(() => {
|
|
4014
|
+
if (source === void 0) return;
|
|
4015
|
+
startWork();
|
|
4016
|
+
return cancelWork;
|
|
4017
|
+
}, [
|
|
4018
|
+
source,
|
|
4019
|
+
startWork,
|
|
4020
|
+
cancelWork
|
|
4021
|
+
]);
|
|
4022
|
+
const pair = React.useMemo(() => peaks === void 0 ? null : toPeakPair(peaks), [peaks]) ?? (work.phase === "finished" ? work.result.pair : null);
|
|
4023
|
+
const duration = given ?? (work.phase === "finished" ? work.result.duration : 0);
|
|
4024
|
+
const ready = pair !== null && duration > 0;
|
|
4025
|
+
const [view, setView] = React.useState(defaultView ? [defaultView[0], defaultView[1]] : null);
|
|
4026
|
+
const [v0, v1] = view ? clampView(view[0], view[1] - view[0], duration || 1) : [0, duration];
|
|
4027
|
+
const zoomed = ready && v1 - v0 < duration - 1e-6;
|
|
4028
|
+
const span = Math.max(v1 - v0, 1e-6);
|
|
4029
|
+
const zoomBy = (factor, about) => {
|
|
4030
|
+
const centre = about ?? (time >= v0 && time <= v1 ? time : (v0 + v1) / 2);
|
|
4031
|
+
const next = clamp$2(span * factor, Math.min(duration, .5), duration);
|
|
4032
|
+
const from = centre - (centre - v0) / span * next;
|
|
4033
|
+
setView(next >= duration - 1e-6 ? null : clampView(from, next, duration));
|
|
4034
|
+
};
|
|
4035
|
+
const lastPan = React.useRef(0);
|
|
4036
|
+
React.useEffect(() => {
|
|
4037
|
+
if (!zoomed || time >= v0 && time <= v1 || Date.now() - lastPan.current < 3e3) return;
|
|
4038
|
+
setView(clampView(time - span * .2, span, duration));
|
|
4039
|
+
}, [time]);
|
|
4040
|
+
const [ownRange, setOwnRange] = React.useState(null);
|
|
4041
|
+
const range = controlledRange === void 0 ? ownRange : controlledRange;
|
|
4042
|
+
const setRange = (next) => {
|
|
4043
|
+
if (controlledRange === void 0) setOwnRange(next);
|
|
4044
|
+
onRangeChange?.(next);
|
|
4045
|
+
};
|
|
3733
4046
|
const [drag, setDrag] = React.useState(null);
|
|
3734
|
-
const
|
|
3735
|
-
const [focusId, setFocusId] = React.useState(null);
|
|
4047
|
+
const shown = drag ?? range;
|
|
3736
4048
|
const [said, setSaid] = React.useState("");
|
|
3737
|
-
const
|
|
3738
|
-
const
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
const laneLabel = (id) => lanes.find((l) => l.id === id)?.label ?? id;
|
|
3742
|
-
const width = Math.max((to - from) * zoom, 1);
|
|
3743
|
-
const x = (t) => (t - from) * zoom;
|
|
3744
|
-
React.useEffect(() => {
|
|
3745
|
-
const el = scroller.current;
|
|
4049
|
+
const box = React.useRef(null);
|
|
4050
|
+
const [width, setWidth] = React.useState(0);
|
|
4051
|
+
React.useLayoutEffect(() => {
|
|
4052
|
+
const el = box.current;
|
|
3746
4053
|
if (!el) return;
|
|
3747
|
-
const read = () =>
|
|
3748
|
-
left: el.scrollLeft,
|
|
3749
|
-
width: el.clientWidth || 640
|
|
3750
|
-
});
|
|
4054
|
+
const read = () => setWidth(Math.round(el.getBoundingClientRect().width));
|
|
3751
4055
|
read();
|
|
4056
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
3752
4057
|
const ro = new ResizeObserver(read);
|
|
3753
4058
|
ro.observe(el);
|
|
3754
|
-
|
|
3755
|
-
return () => {
|
|
3756
|
-
ro.disconnect();
|
|
3757
|
-
el.removeEventListener("scroll", read);
|
|
3758
|
-
};
|
|
4059
|
+
return () => ro.disconnect();
|
|
3759
4060
|
}, []);
|
|
4061
|
+
const gesture = React.useRef({
|
|
4062
|
+
zoomed,
|
|
4063
|
+
v0,
|
|
4064
|
+
span,
|
|
4065
|
+
duration,
|
|
4066
|
+
zoomBy
|
|
4067
|
+
});
|
|
4068
|
+
gesture.current = {
|
|
4069
|
+
zoomed,
|
|
4070
|
+
v0,
|
|
4071
|
+
span,
|
|
4072
|
+
duration,
|
|
4073
|
+
zoomBy
|
|
4074
|
+
};
|
|
3760
4075
|
React.useEffect(() => {
|
|
3761
|
-
const el =
|
|
3762
|
-
if (!
|
|
3763
|
-
const
|
|
3764
|
-
|
|
4076
|
+
const el = box.current;
|
|
4077
|
+
if (!el) return;
|
|
4078
|
+
const onWheel = (e) => {
|
|
4079
|
+
const g = gesture.current;
|
|
4080
|
+
const rect = el.getBoundingClientRect();
|
|
4081
|
+
if (e.ctrlKey || e.metaKey) {
|
|
4082
|
+
e.preventDefault();
|
|
4083
|
+
lastPan.current = Date.now();
|
|
4084
|
+
g.zoomBy(e.deltaY < 0 ? .8 : 1.25, timeAt(e.clientX - rect.left, rect.width, g.v0, g.v0 + g.span));
|
|
4085
|
+
} else if (g.zoomed && Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
|
|
4086
|
+
e.preventDefault();
|
|
4087
|
+
lastPan.current = Date.now();
|
|
4088
|
+
setView(clampView(g.v0 + e.deltaX / (rect.width || 1) * g.span, g.span, g.duration));
|
|
4089
|
+
}
|
|
4090
|
+
};
|
|
4091
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
4092
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
4093
|
+
}, []);
|
|
4094
|
+
const track = React.useRef(null);
|
|
4095
|
+
const input = React.useRef(null);
|
|
4096
|
+
const off = disabled || !ready;
|
|
4097
|
+
const timeText = React.useMemo(() => ({
|
|
4098
|
+
format: clock,
|
|
4099
|
+
formatRange: (a, b) => `${clock(a)} to ${clock(b)}`,
|
|
4100
|
+
resolvedOptions: () => ({ locale: "en-US" })
|
|
4101
|
+
}), []);
|
|
4102
|
+
const state = useSliderState({
|
|
4103
|
+
minValue: v0,
|
|
4104
|
+
maxValue: Math.max(v1, v0 + .01),
|
|
4105
|
+
step: .01,
|
|
4106
|
+
value: [clamp$2(time, v0, Math.max(v1, v0 + .01))],
|
|
4107
|
+
onChange: ([t]) => onSeek(clamp$2(t, 0, duration)),
|
|
4108
|
+
numberFormatter: timeText,
|
|
4109
|
+
isDisabled: off
|
|
4110
|
+
});
|
|
4111
|
+
const { groupProps, trackProps } = useSlider({
|
|
4112
|
+
"aria-label": label,
|
|
4113
|
+
isDisabled: off
|
|
4114
|
+
}, state, track);
|
|
4115
|
+
const { thumbProps, inputProps } = useSliderThumb({
|
|
4116
|
+
index: 0,
|
|
4117
|
+
trackRef: track,
|
|
4118
|
+
inputRef: input,
|
|
4119
|
+
"aria-label": label,
|
|
4120
|
+
isDisabled: off
|
|
4121
|
+
}, state);
|
|
4122
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
4123
|
+
const seekTo = (t) => onSeek(clamp$2(t, 0, duration));
|
|
4124
|
+
const onKeyDownCapture = (e) => {
|
|
4125
|
+
if (off) return;
|
|
4126
|
+
const big = e.shiftKey ? bigStep : step;
|
|
4127
|
+
const moves = {
|
|
4128
|
+
ArrowLeft: -big,
|
|
4129
|
+
ArrowDown: -big,
|
|
4130
|
+
ArrowRight: big,
|
|
4131
|
+
ArrowUp: big,
|
|
4132
|
+
PageDown: -bigStep,
|
|
4133
|
+
PageUp: bigStep
|
|
4134
|
+
};
|
|
4135
|
+
if (e.key in moves) seekTo(time + moves[e.key]);
|
|
4136
|
+
else if (e.key === "Home") seekTo(0);
|
|
4137
|
+
else if (e.key === "End") seekTo(duration);
|
|
4138
|
+
else if (e.key === "+" || e.key === "=") {
|
|
4139
|
+
zoomBy(.5);
|
|
4140
|
+
setSaid("Zoomed in");
|
|
4141
|
+
} else if (e.key === "-" || e.key === "_") {
|
|
4142
|
+
zoomBy(2);
|
|
4143
|
+
setSaid("Zoomed out");
|
|
4144
|
+
} else if (e.key === "0") {
|
|
4145
|
+
setView(null);
|
|
4146
|
+
setSaid("Showing the whole file");
|
|
4147
|
+
} else if (e.key === "[") {
|
|
4148
|
+
const to = range ? Math.max(range[1], time) : duration;
|
|
4149
|
+
setRange([time, to]);
|
|
4150
|
+
setSaid(`Range starts at ${clock(time)}`);
|
|
4151
|
+
} else if (e.key === "]") {
|
|
4152
|
+
const from = range ? Math.min(range[0], time) : 0;
|
|
4153
|
+
setRange([from, time]);
|
|
4154
|
+
setSaid(`Range ends at ${clock(time)}`);
|
|
4155
|
+
} else if (e.key === "Escape" && range) {
|
|
4156
|
+
setRange(null);
|
|
4157
|
+
setSaid("Range cleared");
|
|
4158
|
+
} else return;
|
|
4159
|
+
e.preventDefault();
|
|
4160
|
+
e.stopPropagation();
|
|
4161
|
+
};
|
|
4162
|
+
const startRange = (e) => {
|
|
4163
|
+
if (!e.shiftKey || off) return;
|
|
4164
|
+
e.stopPropagation();
|
|
4165
|
+
e.preventDefault();
|
|
4166
|
+
const el = e.currentTarget;
|
|
4167
|
+
const rect = el.getBoundingClientRect();
|
|
4168
|
+
const at = (x) => timeAt(x - rect.left, rect.width, v0, v1);
|
|
4169
|
+
const from = at(e.clientX);
|
|
4170
|
+
setDrag([from, from]);
|
|
4171
|
+
el.setPointerCapture?.(e.pointerId);
|
|
4172
|
+
const move = (m) => setDrag([Math.min(from, at(m.clientX)), Math.max(from, at(m.clientX))]);
|
|
4173
|
+
const up = (u) => {
|
|
4174
|
+
el.removeEventListener("pointermove", move);
|
|
4175
|
+
el.removeEventListener("pointerup", up);
|
|
4176
|
+
el.removeEventListener("pointercancel", up);
|
|
4177
|
+
const a = Math.min(from, at(u.clientX));
|
|
4178
|
+
const b = Math.max(from, at(u.clientX));
|
|
4179
|
+
setDrag(null);
|
|
4180
|
+
if (b - a > .05) {
|
|
4181
|
+
setRange([a, b]);
|
|
4182
|
+
setSaid(`Range ${clock(a)} to ${clock(b)}`);
|
|
4183
|
+
}
|
|
4184
|
+
};
|
|
4185
|
+
el.addEventListener("pointermove", move);
|
|
4186
|
+
el.addEventListener("pointerup", up);
|
|
4187
|
+
el.addEventListener("pointercancel", up);
|
|
4188
|
+
};
|
|
4189
|
+
const column = 2;
|
|
4190
|
+
const bars = React.useMemo(() => {
|
|
4191
|
+
if (!pair || width === 0 || duration <= 0) return "";
|
|
4192
|
+
let d = "";
|
|
4193
|
+
for (let x = 0; x < width; x += column) {
|
|
4194
|
+
const [lo, hi] = peaksBetween(pair, (v0 + x / width * (v1 - v0)) / duration, (v0 + (x + column) / width * (v1 - v0)) / duration);
|
|
4195
|
+
if (!Number.isFinite(lo)) continue;
|
|
4196
|
+
const top = 50 - clamp$2(hi, -1, 1) * 48;
|
|
4197
|
+
const bottom = 50 - clamp$2(lo, -1, 1) * 48;
|
|
4198
|
+
d += `M${x + .5} ${top.toFixed(1)}V${Math.max(bottom, top + 1).toFixed(1)}`;
|
|
4199
|
+
}
|
|
4200
|
+
return d;
|
|
3765
4201
|
}, [
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
4202
|
+
pair,
|
|
4203
|
+
width,
|
|
4204
|
+
v0,
|
|
4205
|
+
v1,
|
|
4206
|
+
duration
|
|
3769
4207
|
]);
|
|
3770
|
-
React.
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
}, [
|
|
3777
|
-
const
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
4208
|
+
const clipId = React.useId();
|
|
4209
|
+
const px = (t) => (t - v0) / span * width;
|
|
4210
|
+
const visibleMarks = marks.filter((m) => m.time >= v0 && m.time <= v1);
|
|
4211
|
+
const thin = visibleMarks.length > width / 8;
|
|
4212
|
+
const listedMarks = marks.filter((m) => m.label && (m.listed ?? m.kind !== "beat"));
|
|
4213
|
+
const counts = marks.reduce((c, m) => (c[m.kind ?? "mark"] = (c[m.kind ?? "mark"] ?? 0) + 1, c), {});
|
|
4214
|
+
const summary = ready ? `${clock(duration)} long${Object.keys(counts).length ? `, ${Object.entries(counts).map(([k, n]) => `${n} ${k}${n === 1 ? "" : "s"}`).join(", ")}` : ""}${spans.length ? `, ${spans.length} span${spans.length === 1 ? "" : "s"}` : ""}${zoomed ? `, showing ${clock(v0)} to ${clock(v1)}` : ""}${range ? `, range ${clock(range[0])} to ${clock(range[1])}` : ""}` : "";
|
|
4215
|
+
const summaryId = React.useId();
|
|
4216
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4217
|
+
role: "group",
|
|
4218
|
+
"aria-label": label,
|
|
4219
|
+
className: cn("grid min-w-0 gap-2", className),
|
|
4220
|
+
children: [
|
|
4221
|
+
source !== void 0 && work.phase !== "finished" && work.phase !== "idle" && /* @__PURE__ */ jsx(JobStatus, {
|
|
4222
|
+
label: `${label}: reading`,
|
|
4223
|
+
running: work.phase === "running",
|
|
4224
|
+
words,
|
|
4225
|
+
summary: work.phase === "failed" ? work.error instanceof Error ? work.error.message : "The file could not be read." : work.phase === "cancelled" ? "Stopped." : "Reducing the sound to a picture.",
|
|
4226
|
+
current: work.current,
|
|
4227
|
+
total: work.total,
|
|
4228
|
+
failed: work.phase === "failed",
|
|
4229
|
+
cancelled: work.phase === "cancelled",
|
|
4230
|
+
onCancel: work.cancel
|
|
4231
|
+
}),
|
|
4232
|
+
source !== void 0 && (work.phase === "failed" || work.phase === "cancelled") && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
|
|
4233
|
+
size: "sm",
|
|
4234
|
+
onPress: () => void work.start(),
|
|
4235
|
+
children: "Try again"
|
|
4236
|
+
}) }),
|
|
4237
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4238
|
+
ref: box,
|
|
4239
|
+
className: cn("relative w-full overflow-hidden rounded-surface border border-border bg-surface-sunken", off && "opacity-60"),
|
|
4240
|
+
style: { height: "calc(var(--control-h) * 2.5)" },
|
|
4241
|
+
onPointerDownCapture: startRange,
|
|
4242
|
+
onMouseDownCapture: (e) => e.shiftKey && e.stopPropagation(),
|
|
4243
|
+
children: [
|
|
4244
|
+
underlay && ready && /* @__PURE__ */ jsx("div", {
|
|
4245
|
+
"aria-hidden": true,
|
|
4246
|
+
className: "absolute inset-y-0 [&>*]:size-full [&>img]:object-fill",
|
|
4247
|
+
style: {
|
|
4248
|
+
left: `${-v0 / span * 100}%`,
|
|
4249
|
+
width: `${duration / span * 100}%`
|
|
4250
|
+
},
|
|
4251
|
+
children: underlay
|
|
4252
|
+
}),
|
|
4253
|
+
ready && width > 0 && /* @__PURE__ */ jsxs("svg", {
|
|
4254
|
+
"aria-hidden": true,
|
|
4255
|
+
className: "absolute inset-0 size-full",
|
|
4256
|
+
viewBox: `0 0 ${width} 100`,
|
|
4257
|
+
preserveAspectRatio: "none",
|
|
4258
|
+
children: [
|
|
4259
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", {
|
|
4260
|
+
id: clipId,
|
|
4261
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
4262
|
+
x: 0,
|
|
4263
|
+
y: 0,
|
|
4264
|
+
width: Math.max(0, Math.min(px(time), width)),
|
|
4265
|
+
height: 100
|
|
4266
|
+
})
|
|
4267
|
+
}) }),
|
|
4268
|
+
spans.map((s) => {
|
|
4269
|
+
const a = clamp$2(px(s.from), 0, width);
|
|
4270
|
+
const b = clamp$2(px(s.to), 0, width);
|
|
4271
|
+
const tone = TONE$2[s.tone ?? "neutral"];
|
|
4272
|
+
return b > a ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
|
|
4273
|
+
x: a,
|
|
4274
|
+
y: 0,
|
|
4275
|
+
width: b - a,
|
|
4276
|
+
height: 100,
|
|
4277
|
+
fill: tone.fill,
|
|
4278
|
+
opacity: .7
|
|
4279
|
+
}), /* @__PURE__ */ jsx("rect", {
|
|
4280
|
+
x: a,
|
|
4281
|
+
y: 0,
|
|
4282
|
+
width: b - a,
|
|
4283
|
+
height: 4,
|
|
4284
|
+
fill: tone.edge
|
|
4285
|
+
})] }, `${s.from}-${s.to}-${s.label}`) : null;
|
|
4286
|
+
}),
|
|
4287
|
+
shown && /* @__PURE__ */ jsx("rect", {
|
|
4288
|
+
x: clamp$2(px(shown[0]), 0, width),
|
|
4289
|
+
y: 0,
|
|
4290
|
+
width: Math.max(clamp$2(px(shown[1]), 0, width) - clamp$2(px(shown[0]), 0, width), 1),
|
|
4291
|
+
height: 100,
|
|
4292
|
+
fill: "var(--primary-5)",
|
|
4293
|
+
opacity: .45
|
|
4294
|
+
}),
|
|
4295
|
+
/* @__PURE__ */ jsx("path", {
|
|
4296
|
+
d: bars,
|
|
4297
|
+
stroke: "var(--muted-foreground)",
|
|
4298
|
+
strokeWidth: 1.5,
|
|
4299
|
+
vectorEffect: "non-scaling-stroke",
|
|
4300
|
+
fill: "none"
|
|
4301
|
+
}),
|
|
4302
|
+
/* @__PURE__ */ jsx("path", {
|
|
4303
|
+
d: bars,
|
|
4304
|
+
stroke: "var(--primary)",
|
|
4305
|
+
strokeWidth: 1.5,
|
|
4306
|
+
vectorEffect: "non-scaling-stroke",
|
|
4307
|
+
fill: "none",
|
|
4308
|
+
clipPath: `url(#${clipId})`
|
|
4309
|
+
}),
|
|
4310
|
+
visibleMarks.map((m) => {
|
|
4311
|
+
const kind = m.kind ?? "bar";
|
|
4312
|
+
if (thin && kind === "beat") return null;
|
|
4313
|
+
const line = MARK_LINE[kind];
|
|
4314
|
+
return /* @__PURE__ */ jsx("line", {
|
|
4315
|
+
x1: px(m.time),
|
|
4316
|
+
x2: px(m.time),
|
|
4317
|
+
y1: 0,
|
|
4318
|
+
y2: 100,
|
|
4319
|
+
stroke: "var(--foreground)",
|
|
4320
|
+
strokeWidth: line.width,
|
|
4321
|
+
strokeDasharray: line.dash,
|
|
4322
|
+
opacity: line.opacity,
|
|
4323
|
+
vectorEffect: "non-scaling-stroke"
|
|
4324
|
+
}, `${m.time}-${kind}`);
|
|
4325
|
+
}),
|
|
4326
|
+
shown && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("line", {
|
|
4327
|
+
x1: px(shown[0]),
|
|
4328
|
+
x2: px(shown[0]),
|
|
4329
|
+
y1: 0,
|
|
4330
|
+
y2: 100,
|
|
4331
|
+
stroke: "var(--primary)",
|
|
4332
|
+
strokeWidth: 2,
|
|
4333
|
+
vectorEffect: "non-scaling-stroke"
|
|
4334
|
+
}), /* @__PURE__ */ jsx("line", {
|
|
4335
|
+
x1: px(shown[1]),
|
|
4336
|
+
x2: px(shown[1]),
|
|
4337
|
+
y1: 0,
|
|
4338
|
+
y2: 100,
|
|
4339
|
+
stroke: "var(--primary)",
|
|
4340
|
+
strokeWidth: 2,
|
|
4341
|
+
vectorEffect: "non-scaling-stroke"
|
|
4342
|
+
})] }),
|
|
4343
|
+
time >= v0 && time <= v1 && /* @__PURE__ */ jsx("line", {
|
|
4344
|
+
x1: px(time),
|
|
4345
|
+
x2: px(time),
|
|
4346
|
+
y1: 0,
|
|
4347
|
+
y2: 100,
|
|
4348
|
+
stroke: "var(--primary)",
|
|
4349
|
+
strokeWidth: 2,
|
|
4350
|
+
vectorEffect: "non-scaling-stroke"
|
|
4351
|
+
})
|
|
4352
|
+
]
|
|
4353
|
+
}),
|
|
4354
|
+
/* @__PURE__ */ jsx("div", {
|
|
4355
|
+
...groupProps,
|
|
4356
|
+
className: "absolute inset-0",
|
|
4357
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
4358
|
+
...trackProps,
|
|
4359
|
+
ref: track,
|
|
4360
|
+
className: cn("relative size-full touch-none", off ? "cursor-not-allowed" : "cursor-pointer", isFocusVisible && "outline-2 -outline-offset-2 outline-ring"),
|
|
4361
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
4362
|
+
...thumbProps,
|
|
4363
|
+
className: "absolute inset-y-0 w-0",
|
|
4364
|
+
style: { left: `${clamp$2((time - v0) / span, 0, 1) * 100}%` },
|
|
4365
|
+
children: /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
|
|
4366
|
+
ref: input,
|
|
4367
|
+
...mergeProps(inputProps, focusProps, { "aria-describedby": summaryId }),
|
|
4368
|
+
"aria-labelledby": void 0,
|
|
4369
|
+
onKeyDownCapture
|
|
4370
|
+
}) })
|
|
4371
|
+
})
|
|
4372
|
+
})
|
|
4373
|
+
})
|
|
4374
|
+
]
|
|
4375
|
+
}),
|
|
4376
|
+
/* @__PURE__ */ jsxs(VisuallyHidden, { children: [
|
|
4377
|
+
/* @__PURE__ */ jsx("p", {
|
|
4378
|
+
id: summaryId,
|
|
4379
|
+
children: summary
|
|
4380
|
+
}),
|
|
4381
|
+
/* @__PURE__ */ jsx("span", {
|
|
4382
|
+
role: "status",
|
|
4383
|
+
children: said
|
|
4384
|
+
}),
|
|
4385
|
+
spans.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
4386
|
+
"aria-label": "Spans",
|
|
4387
|
+
children: spans.map((s) => /* @__PURE__ */ jsxs("li", { children: [
|
|
4388
|
+
s.label,
|
|
4389
|
+
": ",
|
|
4390
|
+
clock(s.from),
|
|
4391
|
+
" to ",
|
|
4392
|
+
clock(s.to)
|
|
4393
|
+
] }, `${s.from}-${s.to}-${s.label}`))
|
|
4394
|
+
}),
|
|
4395
|
+
listedMarks.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
4396
|
+
"aria-label": "Marks",
|
|
4397
|
+
children: listedMarks.map((m) => /* @__PURE__ */ jsxs("li", { children: [
|
|
4398
|
+
m.label,
|
|
4399
|
+
", ",
|
|
4400
|
+
clock(m.time)
|
|
4401
|
+
] }, `${m.time}-${m.label}`))
|
|
4402
|
+
})
|
|
4403
|
+
] }),
|
|
4404
|
+
spans.length > 0 && ready && /* @__PURE__ */ jsx("ul", {
|
|
4405
|
+
"aria-hidden": true,
|
|
4406
|
+
className: "flex flex-wrap gap-x-4 gap-y-1 type-caption text-muted-foreground",
|
|
4407
|
+
children: [...new Map(spans.map((s) => [`${s.tone ?? "neutral"}:${s.label}`, s])).values()].map((s) => /* @__PURE__ */ jsxs("li", {
|
|
4408
|
+
className: "inline-flex items-center gap-1.5",
|
|
4409
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4410
|
+
className: "h-2 w-3.5 rounded-sm border border-border",
|
|
4411
|
+
style: {
|
|
4412
|
+
background: TONE$2[s.tone ?? "neutral"].fill,
|
|
4413
|
+
borderTopColor: TONE$2[s.tone ?? "neutral"].edge,
|
|
4414
|
+
borderTopWidth: 3
|
|
4415
|
+
}
|
|
4416
|
+
}), s.label]
|
|
4417
|
+
}, `${s.tone}${s.label}`))
|
|
4418
|
+
})
|
|
4419
|
+
]
|
|
4420
|
+
});
|
|
4421
|
+
}
|
|
4422
|
+
// src/lib/timeline.ts
|
|
4423
|
+
/** Steps a person would write on a scale, in seconds: 1, 2, 5 and 10 × 10ⁿ below a minute, then 15 s, 30 s, minutes, quarter hours, hours, days. ux-research components.md §3.8: ticks land on values people would write. */
|
|
4424
|
+
var STEPS = [
|
|
4425
|
+
.01,
|
|
4426
|
+
.02,
|
|
4427
|
+
.05,
|
|
4428
|
+
.1,
|
|
4429
|
+
.2,
|
|
4430
|
+
.5,
|
|
4431
|
+
1,
|
|
4432
|
+
2,
|
|
4433
|
+
5,
|
|
4434
|
+
10,
|
|
4435
|
+
15,
|
|
4436
|
+
30,
|
|
4437
|
+
60,
|
|
4438
|
+
120,
|
|
4439
|
+
300,
|
|
4440
|
+
600,
|
|
4441
|
+
900,
|
|
4442
|
+
1800,
|
|
4443
|
+
3600,
|
|
4444
|
+
7200,
|
|
4445
|
+
14400,
|
|
4446
|
+
21600,
|
|
4447
|
+
43200,
|
|
4448
|
+
86400
|
|
4449
|
+
];
|
|
4450
|
+
/** The smallest step whose ticks are at least `minGapPx` apart at this zoom, so labels thin out instead of colliding. */
|
|
4451
|
+
function tickStep(pxPerUnit, minGapPx = 80) {
|
|
4452
|
+
return STEPS.find((s) => s * pxPerUnit >= minGapPx) ?? STEPS[STEPS.length - 1];
|
|
4453
|
+
}
|
|
4454
|
+
/** Tick times from `from` to `to` inclusive, on multiples of `step`. */
|
|
4455
|
+
function ticksBetween(from, to, step) {
|
|
4456
|
+
const out = [];
|
|
4457
|
+
const first = Math.ceil(from / step - 1e-9);
|
|
4458
|
+
for (let i = first; i * step <= to + 1e-9; i++) out.push(Math.round(i * step * 1e6) / 1e6 || 0);
|
|
4459
|
+
return out;
|
|
4460
|
+
}
|
|
4461
|
+
/** A tick's label: m:ss, h:mm:ss, with tenths or hundredths when the step is under a second. */
|
|
4462
|
+
function tickLabel(time, step) {
|
|
4463
|
+
const decimals = step < .1 ? 2 : step < 1 ? 1 : 0;
|
|
4464
|
+
const whole = Math.floor(time + 1e-9);
|
|
4465
|
+
const h = Math.floor(whole / 3600);
|
|
4466
|
+
const m = Math.floor(whole % 3600 / 60);
|
|
4467
|
+
const s = whole % 60;
|
|
4468
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
4469
|
+
const base = h > 0 ? `${h}:${two(m)}:${two(s)}` : `${m}:${two(s)}`;
|
|
4470
|
+
return decimals ? `${base}.${String(Math.round((time - whole) * 10 ** decimals)).padStart(decimals, "0")}` : base;
|
|
4471
|
+
}
|
|
4472
|
+
function clamp$1(value, min, max) {
|
|
4473
|
+
return Math.min(Math.max(value, min), max);
|
|
4474
|
+
}
|
|
4475
|
+
/** The point to snap `time` to: the nearest of `points` within `thresholdPx` at this zoom, or `null`. */
|
|
4476
|
+
function snapTo(time, points, pxPerUnit, thresholdPx = 8) {
|
|
4477
|
+
let best = null;
|
|
4478
|
+
for (const p of points) if (Math.abs(p - time) * pxPerUnit <= thresholdPx && (best === null || Math.abs(p - time) < Math.abs(best - time))) best = p;
|
|
4479
|
+
return best === null ? null : {
|
|
4480
|
+
time: best,
|
|
4481
|
+
point: best
|
|
4482
|
+
};
|
|
4483
|
+
}
|
|
4484
|
+
/** Round away float noise from adding steps (0.1 + 0.2). */
|
|
4485
|
+
var tidy = (n) => Math.round(n * 1e6) / 1e6;
|
|
4486
|
+
// src/components/timeline.tsx
|
|
4487
|
+
var EDGE_PX = 8;
|
|
4488
|
+
var DRAG_THRESHOLD = 3;
|
|
4489
|
+
var defaultFormat = (t) => tickLabel(t, 1);
|
|
4490
|
+
/** Zoom state for a timeline: `zoomIn`, `zoomOut`, and `fit` to a viewport width. Pass `zoom` and `setZoom` as the timeline's `zoom` and `onZoomChange`. */
|
|
4491
|
+
function useTimelineZoom({ initial = 20, min = .5, max = 400 } = {}) {
|
|
4492
|
+
const [zoom, set] = React.useState(initial);
|
|
4493
|
+
const setZoom = React.useCallback((z) => set(clamp$1(z, min, max)), [min, max]);
|
|
4494
|
+
return {
|
|
4495
|
+
zoom,
|
|
4496
|
+
setZoom,
|
|
4497
|
+
zoomIn: () => setZoom(zoom * 1.5),
|
|
4498
|
+
zoomOut: () => setZoom(zoom / 1.5),
|
|
4499
|
+
/** Zoom so `duration` fills `viewportWidth` pixels. */
|
|
4500
|
+
fit: (viewportWidth, duration) => setZoom(viewportWidth / Math.max(duration, 1e-6))
|
|
4501
|
+
};
|
|
4502
|
+
}
|
|
4503
|
+
/** Zoom in, zoom out and fit, as named icon buttons for a timeline's toolbar. */
|
|
4504
|
+
function TimelineZoomControls({ zoom }) {
|
|
4505
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4506
|
+
className: "flex items-center gap-1",
|
|
4507
|
+
children: [
|
|
4508
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4509
|
+
icon: ZoomOut,
|
|
4510
|
+
label: "Zoom out",
|
|
4511
|
+
hint: "-",
|
|
4512
|
+
onClick: zoom.zoomOut
|
|
4513
|
+
}),
|
|
4514
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4515
|
+
icon: ZoomIn,
|
|
4516
|
+
label: "Zoom in",
|
|
4517
|
+
hint: "+",
|
|
4518
|
+
onClick: zoom.zoomIn
|
|
4519
|
+
}),
|
|
4520
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4521
|
+
icon: Maximize2,
|
|
4522
|
+
label: "Fit to view",
|
|
4523
|
+
hint: "0",
|
|
4524
|
+
onClick: zoom.fit
|
|
4525
|
+
})
|
|
4526
|
+
]
|
|
4527
|
+
});
|
|
4528
|
+
}
|
|
4529
|
+
/** A rule that refuses an item overlapping another in its lane, for `validate`: names the item in the way. */
|
|
4530
|
+
function noOverlap(items) {
|
|
4531
|
+
return (id, next) => {
|
|
4532
|
+
const me = items.find((i) => i.id === id);
|
|
4533
|
+
const other = items.find((i) => i.id !== id && i.lane === next.lane && i.start < next.start + next.length - 1e-9 && next.start < i.start + i.length - 1e-9);
|
|
4534
|
+
return other ? `${me?.label ?? "This"} would overlap ${other.label}.` : null;
|
|
4535
|
+
};
|
|
4536
|
+
}
|
|
4537
|
+
/** Items placed on a zoomable time axis in lanes, with a current-time rule and markers. Reports every move, trim, selection and time change; the app applies them. Keyboard-complete, and only the items near the view are rendered. */
|
|
4538
|
+
function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, position, onPositionChange, follow, markers = [], selectedIds, onSelect, onItemChange, onDelete, validate, snapPoints = [], snap = true, step = 1, minLength, renderItem, kindColours, laneRows = 1, dropTypes, dropLength, onDrop, validateDrop, formatTime = defaultFormat, empty, className }) {
|
|
4539
|
+
const min = minLength ?? step;
|
|
4540
|
+
const scroller = React.useRef(null);
|
|
4541
|
+
const laneRefs = React.useRef(/* @__PURE__ */ new Map());
|
|
4542
|
+
const [view, setView] = React.useState({
|
|
4543
|
+
left: 0,
|
|
4544
|
+
width: 640
|
|
4545
|
+
});
|
|
4546
|
+
const [drag, setDrag] = React.useState(null);
|
|
4547
|
+
const dragRef = React.useRef(null);
|
|
4548
|
+
const [focusId, setFocusId] = React.useState(null);
|
|
4549
|
+
const [said, setSaid] = React.useState("");
|
|
4550
|
+
const [hover, setHover] = React.useState(null);
|
|
4551
|
+
const refocus = React.useRef(null);
|
|
4552
|
+
const selected = selectedIds ?? /* @__PURE__ */ new Set();
|
|
4553
|
+
const laneIndex = React.useMemo(() => new Map(lanes.map((l, i) => [l.id, i])), [lanes]);
|
|
4554
|
+
const laneLabel = (id) => lanes.find((l) => l.id === id)?.label ?? id;
|
|
4555
|
+
const width = Math.max((to - from) * zoom, 1);
|
|
4556
|
+
const x = (t) => (t - from) * zoom;
|
|
4557
|
+
React.useEffect(() => {
|
|
4558
|
+
const el = scroller.current;
|
|
4559
|
+
if (!el) return;
|
|
4560
|
+
const read = () => setView({
|
|
4561
|
+
left: el.scrollLeft,
|
|
4562
|
+
width: el.clientWidth || 640
|
|
4563
|
+
});
|
|
4564
|
+
read();
|
|
4565
|
+
const ro = new ResizeObserver(read);
|
|
4566
|
+
ro.observe(el);
|
|
4567
|
+
el.addEventListener("scroll", read, { passive: true });
|
|
4568
|
+
return () => {
|
|
4569
|
+
ro.disconnect();
|
|
4570
|
+
el.removeEventListener("scroll", read);
|
|
4571
|
+
};
|
|
4572
|
+
}, []);
|
|
4573
|
+
React.useEffect(() => {
|
|
4574
|
+
const el = scroller.current;
|
|
4575
|
+
if (!follow || position === void 0 || !el) return;
|
|
4576
|
+
const px = x(position);
|
|
4577
|
+
if (px < el.scrollLeft || px > el.scrollLeft + el.clientWidth - 24) el.scrollLeft = Math.max(px - el.clientWidth * .25, 0);
|
|
4578
|
+
}, [
|
|
4579
|
+
follow,
|
|
4580
|
+
position,
|
|
4581
|
+
zoom
|
|
4582
|
+
]);
|
|
4583
|
+
React.useEffect(() => {
|
|
4584
|
+
const id = refocus.current;
|
|
4585
|
+
if (!id) return;
|
|
4586
|
+
refocus.current = null;
|
|
4587
|
+
const el = scroller.current?.querySelector(`[data-item="${CSS.escape(id)}"]`);
|
|
4588
|
+
if (el && document.activeElement !== el && (!document.activeElement || document.activeElement === document.body || !scroller.current?.contains(document.activeElement))) el.focus();
|
|
4589
|
+
}, [items]);
|
|
4590
|
+
const sorted = React.useMemo(() => {
|
|
4591
|
+
const byLane = /* @__PURE__ */ new Map();
|
|
4592
|
+
for (const l of lanes) byLane.set(l.id, []);
|
|
4593
|
+
for (const i of items) byLane.get(i.lane)?.push(i);
|
|
4594
|
+
for (const list of byLane.values()) list.sort((a, b) => a.start - b.start);
|
|
4595
|
+
return byLane;
|
|
4596
|
+
}, [lanes, items]);
|
|
4597
|
+
const snapTimes = React.useMemo(() => {
|
|
3785
4598
|
const pts = [...snapPoints, ...markers.map((m) => m.time)];
|
|
3786
4599
|
if (position !== void 0) pts.push(position);
|
|
3787
4600
|
return pts;
|
|
@@ -5080,47 +5893,6 @@ function TileBox({ label }) {
|
|
|
5080
5893
|
})
|
|
5081
5894
|
});
|
|
5082
5895
|
}
|
|
5083
|
-
// src/components/virtual-list.tsx
|
|
5084
|
-
var FOOTER = "\0footer";
|
|
5085
|
-
/** A list that renders only its visible rows (React Aria's GridList and Virtualizer) from `virtualizeFrom` items, with arrow-key navigation between rows. */
|
|
5086
|
-
function VirtualList({ label, items, itemKey, children, estimateSize = 48, rowHeight, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
|
|
5087
|
-
const virtual = items.length >= virtualizeFrom;
|
|
5088
|
-
const rows = React.useMemo(() => items.map((item, index) => ({
|
|
5089
|
-
id: itemKey(item),
|
|
5090
|
-
item,
|
|
5091
|
-
index
|
|
5092
|
-
})), [items, itemKey]);
|
|
5093
|
-
const layoutOptions = React.useMemo(() => rowHeight ? { rowHeight } : { estimatedRowHeight: estimateSize }, [rowHeight, estimateSize]);
|
|
5094
|
-
const virtualise = virtual || bounded;
|
|
5095
|
-
const scrolls = virtualise;
|
|
5096
|
-
const list = /* @__PURE__ */ jsxs(GridList, {
|
|
5097
|
-
"aria-label": label,
|
|
5098
|
-
selectionMode: "none",
|
|
5099
|
-
"data-strata-scroll": "",
|
|
5100
|
-
className: cn("min-w-0 outline-none", scrolls && "overflow-y-auto", className),
|
|
5101
|
-
style: scrolls ? virtual ? { height } : { maxHeight: height } : void 0,
|
|
5102
|
-
children: [/* @__PURE__ */ jsx(Collection, {
|
|
5103
|
-
items: rows,
|
|
5104
|
-
children: (row) => /* @__PURE__ */ jsx(GridListItem, {
|
|
5105
|
-
id: row.id,
|
|
5106
|
-
textValue: row.id,
|
|
5107
|
-
"data-index": row.index,
|
|
5108
|
-
className: cn("min-w-0 outline-offset-[-2px]", row.index > 0 && "border-t border-border"),
|
|
5109
|
-
children: children(row.item, row.index)
|
|
5110
|
-
})
|
|
5111
|
-
}), footer && /* @__PURE__ */ jsx(GridListItem, {
|
|
5112
|
-
id: FOOTER,
|
|
5113
|
-
textValue: "More",
|
|
5114
|
-
className: "min-w-0",
|
|
5115
|
-
children: footer
|
|
5116
|
-
})]
|
|
5117
|
-
});
|
|
5118
|
-
return virtualise ? /* @__PURE__ */ jsx(Virtualizer, {
|
|
5119
|
-
layout: ListLayout,
|
|
5120
|
-
layoutOptions,
|
|
5121
|
-
children: list
|
|
5122
|
-
}) : list;
|
|
5123
|
-
}
|
|
5124
5896
|
// src/components/infinite-list.tsx
|
|
5125
5897
|
var PendingFocus = React.createContext(null);
|
|
5126
5898
|
function MoreFailed({ message, retry }) {
|
|
@@ -10157,6 +10929,2120 @@ function SaveStatus({ state, onRetry, className }) {
|
|
|
10157
10929
|
]
|
|
10158
10930
|
});
|
|
10159
10931
|
}
|
|
10160
|
-
|
|
10932
|
+
// src/lib/rich-text.ts
|
|
10933
|
+
var WORD = /[\p{L}\p{N}_-]/u;
|
|
10934
|
+
/** Finds ids in `text`, longest first, never inside a longer word. Overlaps go to the earlier, longer match. */
|
|
10935
|
+
function matchEntities(text, matcher) {
|
|
10936
|
+
if (!matcher) return [];
|
|
10937
|
+
if (typeof matcher === "function") return [...matcher(text)].sort((a, b) => a.start - b.start);
|
|
10938
|
+
const ids = [...new Set(matcher)].filter(Boolean).sort((a, b) => b.length - a.length);
|
|
10939
|
+
const found = [];
|
|
10940
|
+
let i = 0;
|
|
10941
|
+
while (i < text.length) {
|
|
10942
|
+
let hit;
|
|
10943
|
+
if (i === 0 || !WORD.test(text[i - 1])) {
|
|
10944
|
+
for (const id of ids) if (text.startsWith(id, i) && (i + id.length >= text.length || !WORD.test(text[i + id.length]))) {
|
|
10945
|
+
hit = id;
|
|
10946
|
+
break;
|
|
10947
|
+
}
|
|
10948
|
+
}
|
|
10949
|
+
if (hit) {
|
|
10950
|
+
found.push({
|
|
10951
|
+
start: i,
|
|
10952
|
+
end: i + hit.length,
|
|
10953
|
+
id: hit
|
|
10954
|
+
});
|
|
10955
|
+
i += hit.length;
|
|
10956
|
+
} else i++;
|
|
10957
|
+
}
|
|
10958
|
+
return found;
|
|
10959
|
+
}
|
|
10960
|
+
/** A link is safe when its scheme is http, https or mailto. */
|
|
10961
|
+
function safeHref(href) {
|
|
10962
|
+
try {
|
|
10963
|
+
const url = new URL(href);
|
|
10964
|
+
return [
|
|
10965
|
+
"http:",
|
|
10966
|
+
"https:",
|
|
10967
|
+
"mailto:"
|
|
10968
|
+
].includes(url.protocol) ? url.href : null;
|
|
10969
|
+
} catch {
|
|
10970
|
+
return null;
|
|
10971
|
+
}
|
|
10972
|
+
}
|
|
10973
|
+
function plain(text, matcher) {
|
|
10974
|
+
const out = [];
|
|
10975
|
+
let at = 0;
|
|
10976
|
+
for (const m of matchEntities(text, matcher)) {
|
|
10977
|
+
if (m.start < at) continue;
|
|
10978
|
+
if (m.start > at) out.push({
|
|
10979
|
+
type: "text",
|
|
10980
|
+
text: text.slice(at, m.start)
|
|
10981
|
+
});
|
|
10982
|
+
out.push({
|
|
10983
|
+
type: "entity",
|
|
10984
|
+
id: m.id,
|
|
10985
|
+
text: text.slice(m.start, m.end)
|
|
10986
|
+
});
|
|
10987
|
+
at = m.end;
|
|
10988
|
+
}
|
|
10989
|
+
if (at < text.length) out.push({
|
|
10990
|
+
type: "text",
|
|
10991
|
+
text: text.slice(at)
|
|
10992
|
+
});
|
|
10993
|
+
return out;
|
|
10994
|
+
}
|
|
10995
|
+
/** Parses one line's inline marks. Unclosed marks stay as the text they were typed as. */
|
|
10996
|
+
function parseInline(text, matcher) {
|
|
10997
|
+
const out = [];
|
|
10998
|
+
let buffer = "";
|
|
10999
|
+
const flush = () => {
|
|
11000
|
+
if (buffer) out.push(...plain(buffer, matcher));
|
|
11001
|
+
buffer = "";
|
|
11002
|
+
};
|
|
11003
|
+
let i = 0;
|
|
11004
|
+
while (i < text.length) {
|
|
11005
|
+
if (text.startsWith("**", i)) {
|
|
11006
|
+
const end = text.indexOf("**", i + 2);
|
|
11007
|
+
if (end > i + 2) {
|
|
11008
|
+
flush();
|
|
11009
|
+
out.push({
|
|
11010
|
+
type: "bold",
|
|
11011
|
+
children: parseInline(text.slice(i + 2, end), matcher)
|
|
11012
|
+
});
|
|
11013
|
+
i = end + 2;
|
|
11014
|
+
continue;
|
|
11015
|
+
}
|
|
11016
|
+
} else if (text[i] === "`") {
|
|
11017
|
+
const end = text.indexOf("`", i + 1);
|
|
11018
|
+
if (end > i + 1) {
|
|
11019
|
+
flush();
|
|
11020
|
+
out.push({
|
|
11021
|
+
type: "code",
|
|
11022
|
+
text: text.slice(i + 1, end)
|
|
11023
|
+
});
|
|
11024
|
+
i = end + 1;
|
|
11025
|
+
continue;
|
|
11026
|
+
}
|
|
11027
|
+
} else if (text[i] === "[") {
|
|
11028
|
+
const m = /^\[([^\]]+)\]\(([^)\s]+)\)/.exec(text.slice(i));
|
|
11029
|
+
if (m) {
|
|
11030
|
+
const href = safeHref(m[2]);
|
|
11031
|
+
flush();
|
|
11032
|
+
if (href) out.push({
|
|
11033
|
+
type: "link",
|
|
11034
|
+
href,
|
|
11035
|
+
children: parseInline(m[1], matcher)
|
|
11036
|
+
});
|
|
11037
|
+
else out.push({
|
|
11038
|
+
type: "text",
|
|
11039
|
+
text: m[1]
|
|
11040
|
+
});
|
|
11041
|
+
i += m[0].length;
|
|
11042
|
+
continue;
|
|
11043
|
+
}
|
|
11044
|
+
}
|
|
11045
|
+
buffer += text[i];
|
|
11046
|
+
i++;
|
|
11047
|
+
}
|
|
11048
|
+
flush();
|
|
11049
|
+
return out;
|
|
11050
|
+
}
|
|
11051
|
+
/** Parses blocks: blank-line separated paragraphs, and runs of `- ` or `1. ` lines as lists. */
|
|
11052
|
+
function parseRichText(text, matcher) {
|
|
11053
|
+
const blocks = [];
|
|
11054
|
+
let paragraph = [];
|
|
11055
|
+
let list = null;
|
|
11056
|
+
const endParagraph = () => {
|
|
11057
|
+
if (paragraph.length) blocks.push({
|
|
11058
|
+
type: "paragraph",
|
|
11059
|
+
children: parseInline(paragraph.join(" "), matcher)
|
|
11060
|
+
});
|
|
11061
|
+
paragraph = [];
|
|
11062
|
+
};
|
|
11063
|
+
const endList = () => {
|
|
11064
|
+
if (list) blocks.push({
|
|
11065
|
+
type: "list",
|
|
11066
|
+
...list
|
|
11067
|
+
});
|
|
11068
|
+
list = null;
|
|
11069
|
+
};
|
|
11070
|
+
for (const line of text.split(/\r?\n/)) {
|
|
11071
|
+
const item = /^\s*(?:([-*])|(\d+)[.)])\s+(.*)$/.exec(line);
|
|
11072
|
+
if (item) {
|
|
11073
|
+
endParagraph();
|
|
11074
|
+
const ordered = item[2] !== void 0;
|
|
11075
|
+
if (list && list.ordered !== ordered) endList();
|
|
11076
|
+
list ??= {
|
|
11077
|
+
ordered,
|
|
11078
|
+
items: []
|
|
11079
|
+
};
|
|
11080
|
+
list.items.push(parseInline(item[3], matcher));
|
|
11081
|
+
} else if (!line.trim()) {
|
|
11082
|
+
endParagraph();
|
|
11083
|
+
endList();
|
|
11084
|
+
} else {
|
|
11085
|
+
endList();
|
|
11086
|
+
paragraph.push(line.trim());
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11089
|
+
endParagraph();
|
|
11090
|
+
endList();
|
|
11091
|
+
return blocks;
|
|
11092
|
+
}
|
|
11093
|
+
/** The plain words of a text with the marks removed: what a live region announces. */
|
|
11094
|
+
function plainText(text) {
|
|
11095
|
+
return text.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/\*\*|`/g, "").replace(/^\s*(?:[-*]|\d+[.)])\s+/gm, "").replace(/\s+/g, " ").trim();
|
|
11096
|
+
}
|
|
11097
|
+
// src/components/conversation.tsx
|
|
11098
|
+
var LINK = "text-primary underline underline-offset-2 hover:no-underline";
|
|
11099
|
+
function renderInline(nodes, onOpen, keyBase = "") {
|
|
11100
|
+
return nodes.map((n, i) => {
|
|
11101
|
+
const key = `${keyBase}${i}`;
|
|
11102
|
+
switch (n.type) {
|
|
11103
|
+
case "text": return /* @__PURE__ */ jsx(React.Fragment, { children: n.text }, key);
|
|
11104
|
+
case "bold": return /* @__PURE__ */ jsx("strong", {
|
|
11105
|
+
className: "font-semibold",
|
|
11106
|
+
children: renderInline(n.children, onOpen, `${key}.`)
|
|
11107
|
+
}, key);
|
|
11108
|
+
case "code": return /* @__PURE__ */ jsx("code", {
|
|
11109
|
+
className: "rounded-control bg-muted px-1 py-0.5 font-mono type-caption",
|
|
11110
|
+
children: n.text
|
|
11111
|
+
}, key);
|
|
11112
|
+
case "link": return /* @__PURE__ */ jsx("a", {
|
|
11113
|
+
href: n.href,
|
|
11114
|
+
target: "_blank",
|
|
11115
|
+
rel: "noopener noreferrer",
|
|
11116
|
+
className: LINK,
|
|
11117
|
+
children: renderInline(n.children, onOpen, `${key}.`)
|
|
11118
|
+
}, key);
|
|
11119
|
+
case "entity": return onOpen ? /* @__PURE__ */ jsx("button", {
|
|
11120
|
+
type: "button",
|
|
11121
|
+
onClick: () => onOpen(n.id),
|
|
11122
|
+
className: cn(LINK, "cursor-pointer font-mono type-caption"),
|
|
11123
|
+
children: n.text
|
|
11124
|
+
}, key) : /* @__PURE__ */ jsx("code", {
|
|
11125
|
+
className: "font-mono type-caption",
|
|
11126
|
+
children: n.text
|
|
11127
|
+
}, key);
|
|
11128
|
+
}
|
|
11129
|
+
});
|
|
11130
|
+
}
|
|
11131
|
+
function renderBlocks(blocks, onOpen) {
|
|
11132
|
+
return blocks.map((b, i) => b.type === "paragraph" ? /* @__PURE__ */ jsx("p", { children: renderInline(b.children, onOpen) }, i) : b.ordered ? /* @__PURE__ */ jsx("ol", {
|
|
11133
|
+
className: "list-decimal space-y-1 pl-5",
|
|
11134
|
+
children: b.items.map((it, j) => /* @__PURE__ */ jsx("li", { children: renderInline(it, onOpen) }, j))
|
|
11135
|
+
}, i) : /* @__PURE__ */ jsx("ul", {
|
|
11136
|
+
className: "list-disc space-y-1 pl-5",
|
|
11137
|
+
children: b.items.map((it, j) => /* @__PURE__ */ jsx("li", { children: renderInline(it, onOpen) }, j))
|
|
11138
|
+
}, i));
|
|
11139
|
+
}
|
|
11140
|
+
/** Draws a small safe subset of text (bold, code, lists, http links) and turns known ids into buttons. Never HTML: whatever the string holds is shown as text. */
|
|
11141
|
+
function RichText({ children, entities, onOpen, className }) {
|
|
11142
|
+
const blocks = React.useMemo(() => parseRichText(children, entities), [children, entities]);
|
|
11143
|
+
return /* @__PURE__ */ jsx("div", {
|
|
11144
|
+
className: cn("space-y-2 break-words type-body", className),
|
|
11145
|
+
children: renderBlocks(blocks, onOpen)
|
|
11146
|
+
});
|
|
11147
|
+
}
|
|
11148
|
+
var NEAR_BOTTOM = 24;
|
|
11149
|
+
/** A thread of turns: answers stream, finish or fail in place; the log follows only while the person is at the bottom (with Jump to latest), and a finished answer is announced once, politely. */
|
|
11150
|
+
function Conversation({ label, turns, answerName, personName = "You", entities, onOpen, onRetry, empty, lookedUpLabel = "What it looked up", className }) {
|
|
11151
|
+
const box = React.useRef(null);
|
|
11152
|
+
const [atBottom, setAtBottom] = React.useState(true);
|
|
11153
|
+
const following = React.useRef(true);
|
|
11154
|
+
const [announcement, setAnnouncement] = React.useState("");
|
|
11155
|
+
const last = turns[turns.length - 1];
|
|
11156
|
+
const toBottom = React.useCallback(() => {
|
|
11157
|
+
const el = box.current;
|
|
11158
|
+
if (el) el.scrollTop = el.scrollHeight;
|
|
11159
|
+
following.current = true;
|
|
11160
|
+
setAtBottom(true);
|
|
11161
|
+
}, []);
|
|
11162
|
+
const onScroll = () => {
|
|
11163
|
+
const el = box.current;
|
|
11164
|
+
if (!el) return;
|
|
11165
|
+
const near = el.scrollHeight - el.scrollTop - el.clientHeight <= NEAR_BOTTOM;
|
|
11166
|
+
following.current = near;
|
|
11167
|
+
setAtBottom(near);
|
|
11168
|
+
};
|
|
11169
|
+
React.useLayoutEffect(() => {
|
|
11170
|
+
if (last?.role === "person" || following.current) toBottom();
|
|
11171
|
+
}, [
|
|
11172
|
+
turns.length,
|
|
11173
|
+
last?.text,
|
|
11174
|
+
last?.state,
|
|
11175
|
+
last?.role,
|
|
11176
|
+
toBottom
|
|
11177
|
+
]);
|
|
11178
|
+
const states = React.useRef(/* @__PURE__ */ new Map());
|
|
11179
|
+
React.useEffect(() => {
|
|
11180
|
+
for (const t of turns) {
|
|
11181
|
+
const before = states.current.get(t.id);
|
|
11182
|
+
if (t.role === "answer" && before === "streaming" && t.state !== "streaming") setAnnouncement(t.state === "failed" ? `${answerName} could not answer: ${t.error}` : `${answerName} answered: ${plainText(t.text).slice(0, 160)}`);
|
|
11183
|
+
states.current.set(t.id, t.state ?? "done");
|
|
11184
|
+
}
|
|
11185
|
+
}, [turns, answerName]);
|
|
11186
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
11187
|
+
className: cn("relative flex min-h-0 flex-col", className),
|
|
11188
|
+
children: [
|
|
11189
|
+
/* @__PURE__ */ jsx("div", {
|
|
11190
|
+
role: "region",
|
|
11191
|
+
"aria-label": label,
|
|
11192
|
+
ref: box,
|
|
11193
|
+
onScroll,
|
|
11194
|
+
tabIndex: 0,
|
|
11195
|
+
className: "min-h-0 flex-1 space-y-4 overflow-y-auto rounded-surface p-1",
|
|
11196
|
+
children: turns.length === 0 ? empty : turns.map((t) => /* @__PURE__ */ jsxs("article", {
|
|
11197
|
+
"aria-label": `${t.role === "person" ? personName : answerName}, ${format.clock(t.time)}`,
|
|
11198
|
+
"aria-busy": t.state === "streaming",
|
|
11199
|
+
className: cn("flex flex-col gap-1", t.role === "person" && "items-end"),
|
|
11200
|
+
children: [
|
|
11201
|
+
/* @__PURE__ */ jsxs("header", {
|
|
11202
|
+
className: "flex items-baseline gap-2 type-caption text-muted-foreground",
|
|
11203
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
11204
|
+
className: "type-label text-foreground",
|
|
11205
|
+
children: t.role === "person" ? personName : answerName
|
|
11206
|
+
}), /* @__PURE__ */ jsx("time", {
|
|
11207
|
+
dateTime: new Date(t.time).toISOString(),
|
|
11208
|
+
children: format.clock(t.time)
|
|
11209
|
+
})]
|
|
11210
|
+
}),
|
|
11211
|
+
/* @__PURE__ */ jsxs("div", {
|
|
11212
|
+
className: cn("max-w-prose rounded-surface px-3 py-2", t.role === "person" ? "bg-muted" : "border border-border"),
|
|
11213
|
+
children: [
|
|
11214
|
+
t.state === "streaming" && !t.text ? /* @__PURE__ */ jsxs("p", {
|
|
11215
|
+
className: "type-body-sm text-muted-foreground",
|
|
11216
|
+
children: [answerName, " is working on it…"]
|
|
11217
|
+
}) : /* @__PURE__ */ jsx(RichText, {
|
|
11218
|
+
entities,
|
|
11219
|
+
onOpen,
|
|
11220
|
+
children: t.text
|
|
11221
|
+
}),
|
|
11222
|
+
t.state === "streaming" && t.text && /* @__PURE__ */ jsx("p", {
|
|
11223
|
+
className: "mt-1 type-caption text-muted-foreground",
|
|
11224
|
+
children: "Still writing…"
|
|
11225
|
+
}),
|
|
11226
|
+
t.state === "failed" && /* @__PURE__ */ jsxs("div", {
|
|
11227
|
+
className: "mt-2 flex flex-wrap items-center gap-3 type-body-sm text-danger",
|
|
11228
|
+
children: [/* @__PURE__ */ jsx("span", { children: t.error }), /* @__PURE__ */ jsx(Button, {
|
|
11229
|
+
size: "sm",
|
|
11230
|
+
onClick: () => onRetry(t.id),
|
|
11231
|
+
children: "Try again"
|
|
11232
|
+
})]
|
|
11233
|
+
})
|
|
11234
|
+
]
|
|
11235
|
+
}),
|
|
11236
|
+
t.lookedUp && t.state !== "streaming" && /* @__PURE__ */ jsx(Disclosure, {
|
|
11237
|
+
summary: lookedUpLabel,
|
|
11238
|
+
className: "max-w-prose type-body-sm",
|
|
11239
|
+
children: t.lookedUp
|
|
11240
|
+
})
|
|
11241
|
+
]
|
|
11242
|
+
}, t.id))
|
|
11243
|
+
}),
|
|
11244
|
+
!atBottom && /* @__PURE__ */ jsxs(Button, {
|
|
11245
|
+
size: "sm",
|
|
11246
|
+
variant: "outline",
|
|
11247
|
+
onClick: toBottom,
|
|
11248
|
+
className: "absolute bottom-2 left-1/2 -translate-x-1/2 shadow-overlay",
|
|
11249
|
+
children: [/* @__PURE__ */ jsx(ArrowDown, {}), " Jump to latest"]
|
|
11250
|
+
}),
|
|
11251
|
+
/* @__PURE__ */ jsx("div", {
|
|
11252
|
+
role: "status",
|
|
11253
|
+
"aria-live": "polite",
|
|
11254
|
+
className: "sr-only",
|
|
11255
|
+
children: announcement
|
|
11256
|
+
})
|
|
11257
|
+
]
|
|
11258
|
+
});
|
|
11259
|
+
}
|
|
11260
|
+
/** The box a question is typed in: Enter sends, Shift+Enter is a new line, disabled with its reason while answering (and Stop), suggestions as buttons. */
|
|
11261
|
+
function Composer({ label, onSend, answering = false, onStop, answeringReason, suggestions, sendLabel = "Send", className }) {
|
|
11262
|
+
const [text, setText] = React.useState("");
|
|
11263
|
+
const reasonId = React.useId();
|
|
11264
|
+
const send = (value) => {
|
|
11265
|
+
const v = value.trim();
|
|
11266
|
+
if (!v || answering) return;
|
|
11267
|
+
onSend(v);
|
|
11268
|
+
setText("");
|
|
11269
|
+
};
|
|
11270
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
11271
|
+
className: cn("space-y-2", className),
|
|
11272
|
+
children: [
|
|
11273
|
+
suggestions && suggestions.length > 0 && !answering && /* @__PURE__ */ jsx("div", {
|
|
11274
|
+
role: "group",
|
|
11275
|
+
"aria-label": "Suggested questions",
|
|
11276
|
+
className: "flex flex-wrap gap-2",
|
|
11277
|
+
children: suggestions.map((s) => /* @__PURE__ */ jsx(Button, {
|
|
11278
|
+
size: "sm",
|
|
11279
|
+
onClick: () => send(s),
|
|
11280
|
+
children: s
|
|
11281
|
+
}, s))
|
|
11282
|
+
}),
|
|
11283
|
+
/* @__PURE__ */ jsxs("form", {
|
|
11284
|
+
className: "flex items-end gap-2",
|
|
11285
|
+
onSubmit: (e) => {
|
|
11286
|
+
e.preventDefault();
|
|
11287
|
+
send(text);
|
|
11288
|
+
},
|
|
11289
|
+
children: [/* @__PURE__ */ jsx(Textarea, {
|
|
11290
|
+
"aria-label": label,
|
|
11291
|
+
"aria-describedby": answering ? reasonId : void 0,
|
|
11292
|
+
rows: 2,
|
|
11293
|
+
value: text,
|
|
11294
|
+
disabled: answering,
|
|
11295
|
+
onChange: (e) => setText(e.target.value),
|
|
11296
|
+
onKeyDown: (e) => {
|
|
11297
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
11298
|
+
e.preventDefault();
|
|
11299
|
+
send(text);
|
|
11300
|
+
}
|
|
11301
|
+
},
|
|
11302
|
+
className: "min-h-0 flex-1 resize-none"
|
|
11303
|
+
}), answering ? /* @__PURE__ */ jsxs(Button, {
|
|
11304
|
+
onClick: onStop,
|
|
11305
|
+
children: [/* @__PURE__ */ jsx(Square, {}), " Stop"]
|
|
11306
|
+
}) : /* @__PURE__ */ jsxs(Button, {
|
|
11307
|
+
type: "submit",
|
|
11308
|
+
variant: "default",
|
|
11309
|
+
disabled: !text.trim(),
|
|
11310
|
+
children: [
|
|
11311
|
+
/* @__PURE__ */ jsx(Send, {}),
|
|
11312
|
+
" ",
|
|
11313
|
+
sendLabel
|
|
11314
|
+
]
|
|
11315
|
+
})]
|
|
11316
|
+
}),
|
|
11317
|
+
answering && /* @__PURE__ */ jsx("p", {
|
|
11318
|
+
id: reasonId,
|
|
11319
|
+
className: "type-caption text-muted-foreground",
|
|
11320
|
+
children: answeringReason
|
|
11321
|
+
})
|
|
11322
|
+
]
|
|
11323
|
+
});
|
|
11324
|
+
}
|
|
11325
|
+
// src/components/lightbox.tsx
|
|
11326
|
+
var NARROW = "(max-width: 719px)";
|
|
11327
|
+
function useNarrow() {
|
|
11328
|
+
const [narrow, setNarrow] = React.useState(() => typeof matchMedia === "function" && matchMedia(NARROW).matches);
|
|
11329
|
+
React.useEffect(() => {
|
|
11330
|
+
if (typeof matchMedia !== "function") return;
|
|
11331
|
+
const q = matchMedia(NARROW);
|
|
11332
|
+
const on = () => setNarrow(q.matches);
|
|
11333
|
+
on();
|
|
11334
|
+
q.addEventListener("change", on);
|
|
11335
|
+
return () => q.removeEventListener("change", on);
|
|
11336
|
+
}, []);
|
|
11337
|
+
return narrow;
|
|
11338
|
+
}
|
|
11339
|
+
/** A picture from a set in a full-size dialog: previous/next and arrow keys, "3 of 40", zoom and pan, details beside it, neighbours preloaded, a `missing` sentence for one that fails, and a Compare ticked hand-off. Focus returns to the tile that opened it. */
|
|
11340
|
+
function Lightbox({ title, items, index, onIndexChange, open, onOpenChange, missing, details, detailsLabel = "Details", ticked, onCompare, aspect = 3 / 2 }) {
|
|
11341
|
+
const last = items.length - 1;
|
|
11342
|
+
const at = Math.min(Math.max(index, 0), Math.max(last, 0));
|
|
11343
|
+
const item = items[at];
|
|
11344
|
+
const narrow = useNarrow();
|
|
11345
|
+
const [failed, setFailed] = React.useState(/* @__PURE__ */ new Set());
|
|
11346
|
+
const [natural, setNatural] = React.useState(null);
|
|
11347
|
+
const frame = React.useRef(null);
|
|
11348
|
+
const { viewport, setViewport } = useViewport(FIT);
|
|
11349
|
+
const zoom = useZoom({
|
|
11350
|
+
viewport,
|
|
11351
|
+
setViewport,
|
|
11352
|
+
frame,
|
|
11353
|
+
natural: natural ?? item?.natural ?? null
|
|
11354
|
+
});
|
|
11355
|
+
React.useEffect(() => {
|
|
11356
|
+
setViewport(FIT);
|
|
11357
|
+
setNatural(null);
|
|
11358
|
+
}, [item?.id, setViewport]);
|
|
11359
|
+
React.useEffect(() => {
|
|
11360
|
+
if (!open || typeof Image === "undefined") return;
|
|
11361
|
+
for (const n of [items[at - 1], items[at + 1]]) if (n) new Image().src = n.src;
|
|
11362
|
+
}, [
|
|
11363
|
+
open,
|
|
11364
|
+
at,
|
|
11365
|
+
items
|
|
11366
|
+
]);
|
|
11367
|
+
const go = (to) => onIndexChange(Math.min(Math.max(to, 0), last));
|
|
11368
|
+
const keys = React.useRef((_) => {});
|
|
11369
|
+
keys.current = (e) => {
|
|
11370
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
11371
|
+
if (e.target.closest?.("[role=\"toolbar\"], input, textarea, select, [contenteditable=\"true\"]")) return;
|
|
11372
|
+
const to = e.key === "ArrowLeft" ? at - 1 : e.key === "ArrowRight" ? at + 1 : e.key === "Home" ? 0 : e.key === "End" ? last : null;
|
|
11373
|
+
if (to === null) return;
|
|
11374
|
+
e.preventDefault();
|
|
11375
|
+
go(to);
|
|
11376
|
+
};
|
|
11377
|
+
React.useEffect(() => {
|
|
11378
|
+
if (!open) return;
|
|
11379
|
+
const on = (e) => keys.current(e);
|
|
11380
|
+
window.addEventListener("keydown", on);
|
|
11381
|
+
return () => window.removeEventListener("keydown", on);
|
|
11382
|
+
}, [open]);
|
|
11383
|
+
const ready = ticked && onCompare && ticked.length >= 2;
|
|
11384
|
+
const body = item && details ? details(item) : null;
|
|
11385
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
11386
|
+
open,
|
|
11387
|
+
onOpenChange,
|
|
11388
|
+
title,
|
|
11389
|
+
size: "full",
|
|
11390
|
+
children: item && /* @__PURE__ */ jsxs("div", {
|
|
11391
|
+
className: "flex h-full min-h-0 flex-col gap-3 outline-none",
|
|
11392
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
11393
|
+
className: "flex flex-wrap items-center gap-2",
|
|
11394
|
+
children: [
|
|
11395
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
11396
|
+
icon: ChevronLeft,
|
|
11397
|
+
label: "Previous picture",
|
|
11398
|
+
onPress: () => go(at - 1),
|
|
11399
|
+
disabled: at === 0
|
|
11400
|
+
}),
|
|
11401
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
11402
|
+
icon: ChevronRight,
|
|
11403
|
+
label: "Next picture",
|
|
11404
|
+
onPress: () => go(at + 1),
|
|
11405
|
+
disabled: at === last
|
|
11406
|
+
}),
|
|
11407
|
+
/* @__PURE__ */ jsxs("span", {
|
|
11408
|
+
className: "type-label tabular-nums",
|
|
11409
|
+
"aria-live": "polite",
|
|
11410
|
+
"aria-atomic": "true",
|
|
11411
|
+
children: [
|
|
11412
|
+
at + 1,
|
|
11413
|
+
" of ",
|
|
11414
|
+
items.length
|
|
11415
|
+
]
|
|
11416
|
+
}),
|
|
11417
|
+
/* @__PURE__ */ jsx(Toolbar, {
|
|
11418
|
+
label: "Zoom",
|
|
11419
|
+
className: "ml-2 flex items-center gap-1",
|
|
11420
|
+
children: /* @__PURE__ */ jsx(ZoomControls, {
|
|
11421
|
+
viewport,
|
|
11422
|
+
zoom,
|
|
11423
|
+
natural: natural ?? item.natural ?? null
|
|
11424
|
+
})
|
|
11425
|
+
}),
|
|
11426
|
+
onCompare && ticked && /* @__PURE__ */ jsxs(Button, {
|
|
11427
|
+
size: "sm",
|
|
11428
|
+
className: "ml-auto",
|
|
11429
|
+
disabled: !ready,
|
|
11430
|
+
onPress: () => onCompare(ticked),
|
|
11431
|
+
children: [
|
|
11432
|
+
"Compare ticked (",
|
|
11433
|
+
ticked.length,
|
|
11434
|
+
")"
|
|
11435
|
+
]
|
|
11436
|
+
})
|
|
11437
|
+
]
|
|
11438
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
11439
|
+
className: cn("flex min-h-0 flex-1 gap-4", narrow ? "flex-col" : "flex-row"),
|
|
11440
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
11441
|
+
className: "min-h-0 min-w-0 flex-1",
|
|
11442
|
+
children: failed.has(item.id) ? /* @__PURE__ */ jsx("p", {
|
|
11443
|
+
role: "img",
|
|
11444
|
+
"aria-label": item.label,
|
|
11445
|
+
className: "grid h-full min-h-40 place-items-center rounded-surface border border-dashed border-border p-6 text-center type-body text-muted-foreground",
|
|
11446
|
+
children: missing
|
|
11447
|
+
}) : /* @__PURE__ */ jsx(ViewportFrame, {
|
|
11448
|
+
ref: frame,
|
|
11449
|
+
label: item.label,
|
|
11450
|
+
aspect,
|
|
11451
|
+
viewport,
|
|
11452
|
+
setViewport,
|
|
11453
|
+
maxHeight: narrow ? "50svh" : "calc(100svh - 12rem)",
|
|
11454
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
11455
|
+
src: item.src,
|
|
11456
|
+
alt: item.label,
|
|
11457
|
+
draggable: false,
|
|
11458
|
+
className: "size-full object-contain",
|
|
11459
|
+
onLoad: (e) => setNatural([e.currentTarget.naturalWidth, e.currentTarget.naturalHeight]),
|
|
11460
|
+
onError: () => setFailed((f) => new Set(f).add(item.id))
|
|
11461
|
+
}, item.id)
|
|
11462
|
+
})
|
|
11463
|
+
}), body && (narrow ? /* @__PURE__ */ jsx(Disclosure, {
|
|
11464
|
+
summary: detailsLabel,
|
|
11465
|
+
className: "shrink-0",
|
|
11466
|
+
children: body
|
|
11467
|
+
}) : /* @__PURE__ */ jsx("aside", {
|
|
11468
|
+
"aria-label": detailsLabel,
|
|
11469
|
+
className: "min-h-0 w-72 shrink-0 overflow-y-auto",
|
|
11470
|
+
children: body
|
|
11471
|
+
}))]
|
|
11472
|
+
})]
|
|
11473
|
+
})
|
|
11474
|
+
});
|
|
11475
|
+
}
|
|
11476
|
+
// src/lib/region.ts
|
|
11477
|
+
var HANDLES = [
|
|
11478
|
+
"nw",
|
|
11479
|
+
"n",
|
|
11480
|
+
"ne",
|
|
11481
|
+
"e",
|
|
11482
|
+
"se",
|
|
11483
|
+
"s",
|
|
11484
|
+
"sw",
|
|
11485
|
+
"w"
|
|
11486
|
+
];
|
|
11487
|
+
/** Moves a rectangle by (dx, dy), stopping at the bounds (it keeps its size). */
|
|
11488
|
+
function moveRect(r, dx, dy, bounds) {
|
|
11489
|
+
const x = Math.min(Math.max(r.x + dx, bounds.x), bounds.x + bounds.w - r.w);
|
|
11490
|
+
const y = Math.min(Math.max(r.y + dy, bounds.y), bounds.y + bounds.h - r.h);
|
|
11491
|
+
return {
|
|
11492
|
+
...r,
|
|
11493
|
+
x,
|
|
11494
|
+
y
|
|
11495
|
+
};
|
|
11496
|
+
}
|
|
11497
|
+
/** Puts a rectangle inside the bounds and at least `min` size, keeping its aspect if one is set (shrinking it to fit). */
|
|
11498
|
+
function fitRect(r, { bounds, min, aspect }) {
|
|
11499
|
+
let { w, h } = r;
|
|
11500
|
+
const mw = min?.w ?? 0;
|
|
11501
|
+
const mh = min?.h ?? 0;
|
|
11502
|
+
if (aspect) {
|
|
11503
|
+
w = Math.max(w, mw, mh * aspect);
|
|
11504
|
+
h = w / aspect;
|
|
11505
|
+
const scale = Math.min(1, bounds.w / w, bounds.h / h);
|
|
11506
|
+
w *= scale;
|
|
11507
|
+
h *= scale;
|
|
11508
|
+
} else {
|
|
11509
|
+
w = Math.min(Math.max(w, mw), bounds.w);
|
|
11510
|
+
h = Math.min(Math.max(h, mh), bounds.h);
|
|
11511
|
+
}
|
|
11512
|
+
return moveRect({
|
|
11513
|
+
x: r.x,
|
|
11514
|
+
y: r.y,
|
|
11515
|
+
w,
|
|
11516
|
+
h
|
|
11517
|
+
}, 0, 0, bounds);
|
|
11518
|
+
}
|
|
11519
|
+
/**
|
|
11520
|
+
* Drags `handle` of `r` by (dx, dy). The opposite edge or corner stays where it is. Without an
|
|
11521
|
+
* aspect each edge stops at the bounds and at `min` from the edge opposite; with one the rectangle
|
|
11522
|
+
* keeps its shape: a corner follows the larger of the two movements, an edge changes its own
|
|
11523
|
+
* dimension and the other grows or shrinks about the middle. The result is always inside the bounds.
|
|
11524
|
+
*/
|
|
11525
|
+
function resizeRect(r, handle, dx, dy, { bounds, min, aspect }) {
|
|
11526
|
+
const mw = Math.max(min?.w ?? 0, aspect ? (min?.h ?? 0) * aspect : 0, 0);
|
|
11527
|
+
const mh = Math.max(min?.h ?? 0, aspect ? mw / aspect : 0, 0);
|
|
11528
|
+
const left = r.x;
|
|
11529
|
+
const top = r.y;
|
|
11530
|
+
const right = r.x + r.w;
|
|
11531
|
+
const bottom = r.y + r.h;
|
|
11532
|
+
const hasW = handle.includes("w");
|
|
11533
|
+
const hasE = handle.includes("e");
|
|
11534
|
+
const hasN = handle.includes("n");
|
|
11535
|
+
const hasS = handle.includes("s");
|
|
11536
|
+
if (!aspect) {
|
|
11537
|
+
const nl = hasW ? Math.min(Math.max(left + dx, bounds.x), right - mw) : left;
|
|
11538
|
+
const nr = hasE ? Math.max(Math.min(right + dx, bounds.x + bounds.w), left + mw) : right;
|
|
11539
|
+
const nt = hasN ? Math.min(Math.max(top + dy, bounds.y), bottom - mh) : top;
|
|
11540
|
+
const nb = hasS ? Math.max(Math.min(bottom + dy, bounds.y + bounds.h), top + mh) : bottom;
|
|
11541
|
+
return {
|
|
11542
|
+
x: nl,
|
|
11543
|
+
y: nt,
|
|
11544
|
+
w: nr - nl,
|
|
11545
|
+
h: nb - nt
|
|
11546
|
+
};
|
|
11547
|
+
}
|
|
11548
|
+
const corner = (hasW || hasE) && (hasN || hasS);
|
|
11549
|
+
const ax = hasW ? right : left;
|
|
11550
|
+
const ay = hasN ? bottom : top;
|
|
11551
|
+
const cx = r.x + r.w / 2;
|
|
11552
|
+
const cy = r.y + r.h / 2;
|
|
11553
|
+
const roomW = hasW ? ax - bounds.x : hasE ? bounds.x + bounds.w - ax : 2 * Math.min(cx - bounds.x, bounds.x + bounds.w - cx);
|
|
11554
|
+
const roomH = hasN ? ay - bounds.y : hasS ? bounds.y + bounds.h - ay : 2 * Math.min(cy - bounds.y, bounds.y + bounds.h - cy);
|
|
11555
|
+
let w;
|
|
11556
|
+
if (corner) {
|
|
11557
|
+
const wantW = r.w + (hasW ? -dx : dx);
|
|
11558
|
+
const wantH = r.h + (hasN ? -dy : dy);
|
|
11559
|
+
w = Math.max(wantW, wantH * aspect);
|
|
11560
|
+
} else if (hasW || hasE) w = r.w + (hasW ? -dx : dx);
|
|
11561
|
+
else w = (r.h + (hasN ? -dy : dy)) * aspect;
|
|
11562
|
+
w = Math.min(Math.max(w, mw), roomW, roomH * aspect);
|
|
11563
|
+
const h = w / aspect;
|
|
11564
|
+
return {
|
|
11565
|
+
x: hasW ? ax - w : hasE ? ax : cx - w / 2,
|
|
11566
|
+
y: hasN ? ay - h : hasS ? ay : cy - h / 2,
|
|
11567
|
+
w,
|
|
11568
|
+
h
|
|
11569
|
+
};
|
|
11570
|
+
}
|
|
11571
|
+
/** A rectangle drawn by dragging from one corner point to another, ordered and fitted to the limits. */
|
|
11572
|
+
function drawRect(start, b, limits) {
|
|
11573
|
+
const { bounds, aspect } = limits;
|
|
11574
|
+
const a = {
|
|
11575
|
+
x: Math.min(Math.max(start.x, bounds.x), bounds.x + bounds.w),
|
|
11576
|
+
y: Math.min(Math.max(start.y, bounds.y), bounds.y + bounds.h)
|
|
11577
|
+
};
|
|
11578
|
+
const px = Math.min(Math.max(b.x, bounds.x), bounds.x + bounds.w);
|
|
11579
|
+
const py = Math.min(Math.max(b.y, bounds.y), bounds.y + bounds.h);
|
|
11580
|
+
let w = Math.abs(px - a.x);
|
|
11581
|
+
let h = Math.abs(py - a.y);
|
|
11582
|
+
if (aspect) {
|
|
11583
|
+
w = Math.max(w, h * aspect);
|
|
11584
|
+
h = w / aspect;
|
|
11585
|
+
const roomW = px < a.x ? a.x - bounds.x : bounds.x + bounds.w - a.x;
|
|
11586
|
+
const roomH = py < a.y ? a.y - bounds.y : bounds.y + bounds.h - a.y;
|
|
11587
|
+
const scale = Math.min(1, roomW / w, roomH / h);
|
|
11588
|
+
w *= scale;
|
|
11589
|
+
h *= scale;
|
|
11590
|
+
}
|
|
11591
|
+
return {
|
|
11592
|
+
x: px < a.x ? a.x - w : a.x,
|
|
11593
|
+
y: py < a.y ? a.y - h : a.y,
|
|
11594
|
+
w,
|
|
11595
|
+
h
|
|
11596
|
+
};
|
|
11597
|
+
}
|
|
11598
|
+
/** The eased share of the way at time `t` (0 to 1). */
|
|
11599
|
+
function ease(t, easing = "ease-in-out") {
|
|
11600
|
+
const c = Math.min(Math.max(t, 0), 1);
|
|
11601
|
+
return easing === "linear" ? c : c < .5 ? 2 * c * c : 1 - (-2 * c + 2) ** 2 / 2;
|
|
11602
|
+
}
|
|
11603
|
+
/** The rectangle part-way from `a` to `b` at time `t` (0 to 1), eased. Corner and size move together. */
|
|
11604
|
+
function lerpRect(a, b, t, easing = "ease-in-out") {
|
|
11605
|
+
const k = ease(t, easing);
|
|
11606
|
+
const mix = (p, q) => p + (q - p) * k;
|
|
11607
|
+
return {
|
|
11608
|
+
x: mix(a.x, b.x),
|
|
11609
|
+
y: mix(a.y, b.y),
|
|
11610
|
+
w: mix(a.w, b.w),
|
|
11611
|
+
h: mix(a.h, b.h)
|
|
11612
|
+
};
|
|
11613
|
+
}
|
|
11614
|
+
/** True when two rectangles are the same to the unit's thousandth. */
|
|
11615
|
+
var sameRect = (a, b) => [
|
|
11616
|
+
"x",
|
|
11617
|
+
"y",
|
|
11618
|
+
"w",
|
|
11619
|
+
"h"
|
|
11620
|
+
].every((k) => Math.abs(a[k] - b[k]) < .001);
|
|
11621
|
+
// src/components/region-editor.tsx
|
|
11622
|
+
var TONE$1 = {
|
|
11623
|
+
neutral: {
|
|
11624
|
+
edge: "var(--foreground)",
|
|
11625
|
+
fill: "var(--muted)"
|
|
11626
|
+
},
|
|
11627
|
+
info: {
|
|
11628
|
+
edge: "var(--info)",
|
|
11629
|
+
fill: "var(--info-subtle)"
|
|
11630
|
+
},
|
|
11631
|
+
success: {
|
|
11632
|
+
edge: "var(--success)",
|
|
11633
|
+
fill: "var(--success-subtle)"
|
|
11634
|
+
},
|
|
11635
|
+
warning: {
|
|
11636
|
+
edge: "var(--warning)",
|
|
11637
|
+
fill: "var(--warning-subtle)"
|
|
11638
|
+
},
|
|
11639
|
+
danger: {
|
|
11640
|
+
edge: "var(--danger)",
|
|
11641
|
+
fill: "var(--danger-subtle)"
|
|
11642
|
+
}
|
|
11643
|
+
};
|
|
11644
|
+
var CURSOR = {
|
|
11645
|
+
n: "ns-resize",
|
|
11646
|
+
s: "ns-resize",
|
|
11647
|
+
e: "ew-resize",
|
|
11648
|
+
w: "ew-resize",
|
|
11649
|
+
ne: "nesw-resize",
|
|
11650
|
+
sw: "nesw-resize",
|
|
11651
|
+
nw: "nwse-resize",
|
|
11652
|
+
se: "nwse-resize"
|
|
11653
|
+
};
|
|
11654
|
+
var HANDLE_AT = {
|
|
11655
|
+
nw: "left-0 top-0 -translate-x-1/2 -translate-y-1/2",
|
|
11656
|
+
n: "left-1/2 top-0 -translate-x-1/2 -translate-y-1/2",
|
|
11657
|
+
ne: "right-0 top-0 translate-x-1/2 -translate-y-1/2",
|
|
11658
|
+
e: "right-0 top-1/2 translate-x-1/2 -translate-y-1/2",
|
|
11659
|
+
se: "right-0 bottom-0 translate-x-1/2 translate-y-1/2",
|
|
11660
|
+
s: "left-1/2 bottom-0 -translate-x-1/2 translate-y-1/2",
|
|
11661
|
+
sw: "left-0 bottom-0 -translate-x-1/2 translate-y-1/2",
|
|
11662
|
+
w: "left-0 top-1/2 -translate-x-1/2 -translate-y-1/2"
|
|
11663
|
+
};
|
|
11664
|
+
var round = (n) => format.integer(Math.round(n));
|
|
11665
|
+
/** A window said in words. */
|
|
11666
|
+
var describeRegion = (r) => `${r.label}: ${round(r.w)} wide by ${round(r.h)} high, ${round(r.x)} across and ${round(r.y)} down`;
|
|
11667
|
+
/** Draw and move one or two named windows on a picture, with pointer, keyboard and numbers kept in step; aspect and bounds hold through all three; two windows make a from/to move with a Watch preview. */
|
|
11668
|
+
function RegionEditor({ label, children, size, regions, onChange, selectedId, onSelectedChange, aspect, min, bounds, step, onDraw, mode = "single", onPreview, duration = 1500, easing = "ease-in-out", fields = true, unit = "px", defaults, className }) {
|
|
11669
|
+
const [w, h] = size;
|
|
11670
|
+
const limits = React.useMemo(() => ({
|
|
11671
|
+
bounds: bounds ?? {
|
|
11672
|
+
x: 0,
|
|
11673
|
+
y: 0,
|
|
11674
|
+
w,
|
|
11675
|
+
h
|
|
11676
|
+
},
|
|
11677
|
+
min: min ?? {
|
|
11678
|
+
w: w / 20,
|
|
11679
|
+
h: h / 20
|
|
11680
|
+
},
|
|
11681
|
+
aspect
|
|
11682
|
+
}), [
|
|
11683
|
+
bounds,
|
|
11684
|
+
min,
|
|
11685
|
+
w,
|
|
11686
|
+
h,
|
|
11687
|
+
aspect
|
|
11688
|
+
]);
|
|
11689
|
+
const stride = step ?? Math.max(w, h) / 100;
|
|
11690
|
+
const [own, setOwn] = React.useState(regions[0]?.id ?? null);
|
|
11691
|
+
const selected = selectedId !== void 0 ? selectedId : own;
|
|
11692
|
+
const select = (id) => {
|
|
11693
|
+
setOwn(id);
|
|
11694
|
+
onSelectedChange?.(id);
|
|
11695
|
+
};
|
|
11696
|
+
const overlay = React.useRef(null);
|
|
11697
|
+
const [draft, setDraft] = React.useState(null);
|
|
11698
|
+
const [drawing, setDrawing] = React.useState(null);
|
|
11699
|
+
const gesture = React.useRef(null);
|
|
11700
|
+
const [said, setSaid] = React.useState("");
|
|
11701
|
+
const hintId = React.useId();
|
|
11702
|
+
const rectOf = (r) => draft?.id === r.id ? draft.rect : r;
|
|
11703
|
+
const shown = regions.map((r) => ({
|
|
11704
|
+
...r,
|
|
11705
|
+
...rectOf(r)
|
|
11706
|
+
}));
|
|
11707
|
+
const keep = (id, rect) => {
|
|
11708
|
+
const before = regions.find((r) => r.id === id);
|
|
11709
|
+
setDraft(null);
|
|
11710
|
+
if (before && !sameRect(before, rect)) onChange(regions.map((r) => r.id === id ? {
|
|
11711
|
+
...r,
|
|
11712
|
+
...rect
|
|
11713
|
+
} : r));
|
|
11714
|
+
};
|
|
11715
|
+
const say = (r) => setSaid(describeRegion(r));
|
|
11716
|
+
const unitsAt = (e) => {
|
|
11717
|
+
const box = overlay.current?.getBoundingClientRect();
|
|
11718
|
+
if (!box || !box.width || !box.height) return {
|
|
11719
|
+
x: 0,
|
|
11720
|
+
y: 0
|
|
11721
|
+
};
|
|
11722
|
+
return {
|
|
11723
|
+
x: (e.clientX - box.left) / box.width * w,
|
|
11724
|
+
y: (e.clientY - box.top) / box.height * h
|
|
11725
|
+
};
|
|
11726
|
+
};
|
|
11727
|
+
const capture = (e) => e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
11728
|
+
const beginMove = (e, r) => {
|
|
11729
|
+
if (e.button !== 0) return;
|
|
11730
|
+
e.stopPropagation();
|
|
11731
|
+
capture(e);
|
|
11732
|
+
select(r.id);
|
|
11733
|
+
gesture.current = {
|
|
11734
|
+
kind: "move",
|
|
11735
|
+
id: r.id,
|
|
11736
|
+
start: rectOf(r),
|
|
11737
|
+
from: unitsAt(e)
|
|
11738
|
+
};
|
|
11739
|
+
};
|
|
11740
|
+
const beginResize = (e, r, handle) => {
|
|
11741
|
+
if (e.button !== 0) return;
|
|
11742
|
+
e.stopPropagation();
|
|
11743
|
+
capture(e);
|
|
11744
|
+
select(r.id);
|
|
11745
|
+
gesture.current = {
|
|
11746
|
+
kind: "resize",
|
|
11747
|
+
id: r.id,
|
|
11748
|
+
handle,
|
|
11749
|
+
start: rectOf(r),
|
|
11750
|
+
from: unitsAt(e)
|
|
11751
|
+
};
|
|
11752
|
+
};
|
|
11753
|
+
const beginDraw = (e) => {
|
|
11754
|
+
if (e.button !== 0 || !onDraw || e.target !== e.currentTarget) return;
|
|
11755
|
+
capture(e);
|
|
11756
|
+
gesture.current = {
|
|
11757
|
+
kind: "draw",
|
|
11758
|
+
from: unitsAt(e)
|
|
11759
|
+
};
|
|
11760
|
+
};
|
|
11761
|
+
const onMove = (e) => {
|
|
11762
|
+
const g = gesture.current;
|
|
11763
|
+
if (!g) return;
|
|
11764
|
+
const at = unitsAt(e);
|
|
11765
|
+
if (g.kind === "draw") setDrawing(drawRect(g.from, at, limits));
|
|
11766
|
+
else {
|
|
11767
|
+
const dx = at.x - g.from.x;
|
|
11768
|
+
const dy = at.y - g.from.y;
|
|
11769
|
+
setDraft({
|
|
11770
|
+
id: g.id,
|
|
11771
|
+
rect: g.kind === "move" ? moveRect(g.start, dx, dy, limits.bounds) : resizeRect(g.start, g.handle, dx, dy, limits)
|
|
11772
|
+
});
|
|
11773
|
+
}
|
|
11774
|
+
};
|
|
11775
|
+
const onUp = () => {
|
|
11776
|
+
const g = gesture.current;
|
|
11777
|
+
gesture.current = null;
|
|
11778
|
+
if (!g) return;
|
|
11779
|
+
if (g.kind === "draw") {
|
|
11780
|
+
const r = drawing;
|
|
11781
|
+
setDrawing(null);
|
|
11782
|
+
if (r && r.w >= limits.min.w && r.h >= limits.min.h) onDraw?.(r);
|
|
11783
|
+
} else if (draft) {
|
|
11784
|
+
keep(draft.id, draft.rect);
|
|
11785
|
+
const kept = regions.find((x) => x.id === draft.id);
|
|
11786
|
+
if (kept) say({
|
|
11787
|
+
...kept,
|
|
11788
|
+
...draft.rect
|
|
11789
|
+
});
|
|
11790
|
+
}
|
|
11791
|
+
};
|
|
11792
|
+
const keys = (e, r) => {
|
|
11793
|
+
const now = rectOf(r);
|
|
11794
|
+
if (e.key === "Escape") {
|
|
11795
|
+
if (draft?.id === r.id) {
|
|
11796
|
+
e.preventDefault();
|
|
11797
|
+
e.stopPropagation();
|
|
11798
|
+
setDraft(null);
|
|
11799
|
+
setSaid(`${r.label}: change undone`);
|
|
11800
|
+
}
|
|
11801
|
+
return;
|
|
11802
|
+
}
|
|
11803
|
+
if (e.key === "Enter") {
|
|
11804
|
+
if (draft?.id === r.id) {
|
|
11805
|
+
e.preventDefault();
|
|
11806
|
+
e.stopPropagation();
|
|
11807
|
+
keep(r.id, draft.rect);
|
|
11808
|
+
say({
|
|
11809
|
+
...r,
|
|
11810
|
+
...draft.rect
|
|
11811
|
+
});
|
|
11812
|
+
}
|
|
11813
|
+
return;
|
|
11814
|
+
}
|
|
11815
|
+
const dir = {
|
|
11816
|
+
ArrowLeft: [-1, 0],
|
|
11817
|
+
ArrowRight: [1, 0],
|
|
11818
|
+
ArrowUp: [0, -1],
|
|
11819
|
+
ArrowDown: [0, 1]
|
|
11820
|
+
}[e.key];
|
|
11821
|
+
if (!dir || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
11822
|
+
e.preventDefault();
|
|
11823
|
+
e.stopPropagation();
|
|
11824
|
+
const next = e.shiftKey ? resizeRect(now, dir[0] ? "e" : "s", dir[0] * stride, dir[1] * stride, limits) : moveRect(now, dir[0] * stride, dir[1] * stride, limits.bounds);
|
|
11825
|
+
setDraft({
|
|
11826
|
+
id: r.id,
|
|
11827
|
+
rect: next
|
|
11828
|
+
});
|
|
11829
|
+
say({
|
|
11830
|
+
...r,
|
|
11831
|
+
...next
|
|
11832
|
+
});
|
|
11833
|
+
};
|
|
11834
|
+
const chosen = shown.find((r) => r.id === selected);
|
|
11835
|
+
const setSide = (key, value) => {
|
|
11836
|
+
if (!chosen || value === null) return;
|
|
11837
|
+
const cur = rectOf(chosen);
|
|
11838
|
+
const next = key === "x" || key === "y" ? moveRect(cur, key === "x" ? value - cur.x : 0, key === "y" ? value - cur.y : 0, limits.bounds) : resizeRect(cur, key === "w" ? "e" : "s", key === "w" ? value - cur.w : 0, key === "h" ? value - cur.h : 0, limits);
|
|
11839
|
+
keep(chosen.id, next);
|
|
11840
|
+
say({
|
|
11841
|
+
...chosen,
|
|
11842
|
+
...next
|
|
11843
|
+
});
|
|
11844
|
+
};
|
|
11845
|
+
const [watching, setWatching] = React.useState(null);
|
|
11846
|
+
const frame = React.useRef(0);
|
|
11847
|
+
const [from, to] = [shown[0], shown[1]];
|
|
11848
|
+
const stopWatch = React.useCallback(() => {
|
|
11849
|
+
cancelAnimationFrame(frame.current);
|
|
11850
|
+
setWatching(null);
|
|
11851
|
+
}, []);
|
|
11852
|
+
React.useEffect(() => () => cancelAnimationFrame(frame.current), []);
|
|
11853
|
+
const watch = () => {
|
|
11854
|
+
if (!from || !to) return;
|
|
11855
|
+
if (watching) return stopWatch();
|
|
11856
|
+
const a = {
|
|
11857
|
+
x: from.x,
|
|
11858
|
+
y: from.y,
|
|
11859
|
+
w: from.w,
|
|
11860
|
+
h: from.h
|
|
11861
|
+
};
|
|
11862
|
+
const b = {
|
|
11863
|
+
x: to.x,
|
|
11864
|
+
y: to.y,
|
|
11865
|
+
w: to.w,
|
|
11866
|
+
h: to.h
|
|
11867
|
+
};
|
|
11868
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
11869
|
+
onPreview?.(b, 1);
|
|
11870
|
+
setWatching(b);
|
|
11871
|
+
frame.current = window.setTimeout(() => setWatching(null), 600);
|
|
11872
|
+
return;
|
|
11873
|
+
}
|
|
11874
|
+
const began = performance.now();
|
|
11875
|
+
setWatching(a);
|
|
11876
|
+
const tick = (now) => {
|
|
11877
|
+
const t = Math.min((now - began) / duration, 1);
|
|
11878
|
+
const rect = lerpRect(a, b, t, easing);
|
|
11879
|
+
onPreview?.(rect, t);
|
|
11880
|
+
setWatching(rect);
|
|
11881
|
+
if (t < 1) frame.current = requestAnimationFrame(tick);
|
|
11882
|
+
else frame.current = window.setTimeout(() => setWatching(null), 400);
|
|
11883
|
+
};
|
|
11884
|
+
frame.current = requestAnimationFrame(tick);
|
|
11885
|
+
};
|
|
11886
|
+
const pct = (r) => ({
|
|
11887
|
+
left: `${r.x / w * 100}%`,
|
|
11888
|
+
top: `${r.y / h * 100}%`,
|
|
11889
|
+
width: `${r.w / w * 100}%`,
|
|
11890
|
+
height: `${r.h / h * 100}%`
|
|
11891
|
+
});
|
|
11892
|
+
const modified = defaults ? !(defaults.length === regions.length && defaults.every((d, i) => regions[i] && sameRect(d, regions[i]) && d.id === regions[i].id)) : false;
|
|
11893
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
11894
|
+
className: cn("space-y-3", className),
|
|
11895
|
+
children: [
|
|
11896
|
+
/* @__PURE__ */ jsxs("div", {
|
|
11897
|
+
className: "relative overflow-hidden rounded-surface border border-border bg-surface-sunken",
|
|
11898
|
+
style: { aspectRatio: `${w} / ${h}` },
|
|
11899
|
+
children: [children, /* @__PURE__ */ jsxs("div", {
|
|
11900
|
+
ref: overlay,
|
|
11901
|
+
role: "group",
|
|
11902
|
+
"aria-label": label,
|
|
11903
|
+
"aria-describedby": hintId,
|
|
11904
|
+
className: cn("absolute inset-0 touch-none select-none", onDraw && "cursor-crosshair"),
|
|
11905
|
+
onPointerDown: beginDraw,
|
|
11906
|
+
onPointerMove: onMove,
|
|
11907
|
+
onPointerUp: onUp,
|
|
11908
|
+
onPointerCancel: () => {
|
|
11909
|
+
gesture.current = null;
|
|
11910
|
+
setDraft(null);
|
|
11911
|
+
setDrawing(null);
|
|
11912
|
+
},
|
|
11913
|
+
children: [
|
|
11914
|
+
mode === "move" && from && to && /* @__PURE__ */ jsxs("svg", {
|
|
11915
|
+
className: "pointer-events-none absolute inset-0 size-full",
|
|
11916
|
+
viewBox: `0 0 ${w} ${h}`,
|
|
11917
|
+
preserveAspectRatio: "none",
|
|
11918
|
+
"aria-hidden": true,
|
|
11919
|
+
children: [/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("marker", {
|
|
11920
|
+
id: `${hintId}-arrow`,
|
|
11921
|
+
viewBox: "0 0 10 10",
|
|
11922
|
+
refX: "8",
|
|
11923
|
+
refY: "5",
|
|
11924
|
+
markerWidth: "6",
|
|
11925
|
+
markerHeight: "6",
|
|
11926
|
+
orient: "auto-start-reverse",
|
|
11927
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
11928
|
+
d: "M0 0 10 5 0 10z",
|
|
11929
|
+
fill: "var(--foreground)"
|
|
11930
|
+
})
|
|
11931
|
+
}) }), /* @__PURE__ */ jsx("line", {
|
|
11932
|
+
x1: from.x + from.w / 2,
|
|
11933
|
+
y1: from.y + from.h / 2,
|
|
11934
|
+
x2: to.x + to.w / 2,
|
|
11935
|
+
y2: to.y + to.h / 2,
|
|
11936
|
+
stroke: "var(--foreground)",
|
|
11937
|
+
strokeWidth: 2,
|
|
11938
|
+
vectorEffect: "non-scaling-stroke",
|
|
11939
|
+
strokeDasharray: "6 4",
|
|
11940
|
+
markerEnd: `url(#${hintId}-arrow)`
|
|
11941
|
+
})]
|
|
11942
|
+
}),
|
|
11943
|
+
shown.map((r) => {
|
|
11944
|
+
const tone = TONE$1[r.tone ?? "neutral"];
|
|
11945
|
+
const active = r.id === selected;
|
|
11946
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
11947
|
+
role: "group",
|
|
11948
|
+
"aria-roledescription": "region",
|
|
11949
|
+
"aria-label": describeRegion(r),
|
|
11950
|
+
tabIndex: 0,
|
|
11951
|
+
"data-region": r.id,
|
|
11952
|
+
"data-selected": active || void 0,
|
|
11953
|
+
onFocus: () => select(r.id),
|
|
11954
|
+
onBlur: (e) => {
|
|
11955
|
+
if (draft?.id === r.id && !e.currentTarget.contains(e.relatedTarget)) keep(r.id, draft.rect);
|
|
11956
|
+
},
|
|
11957
|
+
onKeyDown: (e) => keys(e, r),
|
|
11958
|
+
onPointerDown: (e) => beginMove(e, r),
|
|
11959
|
+
className: cn("absolute cursor-move border-2 outline-offset-2 transition-state", active ? "z-10" : "opacity-90"),
|
|
11960
|
+
style: {
|
|
11961
|
+
...pct(r),
|
|
11962
|
+
borderColor: tone.edge,
|
|
11963
|
+
backgroundColor: `color-mix(in oklab, ${tone.fill} 35%, transparent)`,
|
|
11964
|
+
borderStyle: active ? "solid" : "dashed"
|
|
11965
|
+
},
|
|
11966
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
11967
|
+
className: "pointer-events-none absolute left-0 top-0 max-w-full -translate-y-full truncate rounded-t-control px-1.5 type-caption",
|
|
11968
|
+
style: {
|
|
11969
|
+
backgroundColor: tone.edge,
|
|
11970
|
+
color: "var(--background)"
|
|
11971
|
+
},
|
|
11972
|
+
children: r.label
|
|
11973
|
+
}), active && HANDLES.map((handle) => /* @__PURE__ */ jsx("span", {
|
|
11974
|
+
"aria-hidden": true,
|
|
11975
|
+
"data-handle": handle,
|
|
11976
|
+
onPointerDown: (e) => beginResize(e, r, handle),
|
|
11977
|
+
className: cn("absolute size-3 rounded-pill border-2 bg-background", HANDLE_AT[handle]),
|
|
11978
|
+
style: {
|
|
11979
|
+
borderColor: tone.edge,
|
|
11980
|
+
cursor: CURSOR[handle]
|
|
11981
|
+
}
|
|
11982
|
+
}, handle))]
|
|
11983
|
+
}, r.id);
|
|
11984
|
+
}),
|
|
11985
|
+
drawing && /* @__PURE__ */ jsx("div", {
|
|
11986
|
+
"aria-hidden": true,
|
|
11987
|
+
className: "pointer-events-none absolute border-2 border-dashed border-foreground bg-foreground/10",
|
|
11988
|
+
style: pct(drawing)
|
|
11989
|
+
}),
|
|
11990
|
+
watching && /* @__PURE__ */ jsx("div", {
|
|
11991
|
+
"aria-hidden": true,
|
|
11992
|
+
"data-preview": true,
|
|
11993
|
+
className: "pointer-events-none absolute z-20 border-2 border-foreground bg-foreground/15",
|
|
11994
|
+
style: pct(watching)
|
|
11995
|
+
})
|
|
11996
|
+
]
|
|
11997
|
+
})]
|
|
11998
|
+
}),
|
|
11999
|
+
/* @__PURE__ */ jsxs("p", {
|
|
12000
|
+
id: hintId,
|
|
12001
|
+
className: "type-caption text-muted-foreground",
|
|
12002
|
+
children: [onDraw ? "Drag on the picture to draw a window. " : "", "Drag a window to move it, or its handles to resize. Keys: arrows move, Shift and arrows resize, Enter keeps, Escape undoes."]
|
|
12003
|
+
}),
|
|
12004
|
+
(mode === "move" || defaults && modified) && /* @__PURE__ */ jsxs("div", {
|
|
12005
|
+
className: "flex flex-wrap items-center gap-2",
|
|
12006
|
+
children: [mode === "move" && /* @__PURE__ */ jsxs(Button, {
|
|
12007
|
+
size: "sm",
|
|
12008
|
+
onPress: watch,
|
|
12009
|
+
disabled: !from || !to,
|
|
12010
|
+
children: [
|
|
12011
|
+
watching ? /* @__PURE__ */ jsx(Square, {}) : /* @__PURE__ */ jsx(Play, {}),
|
|
12012
|
+
" ",
|
|
12013
|
+
watching ? "Stop" : "Watch"
|
|
12014
|
+
]
|
|
12015
|
+
}), defaults && modified && /* @__PURE__ */ jsx(Button, {
|
|
12016
|
+
size: "sm",
|
|
12017
|
+
variant: "ghost",
|
|
12018
|
+
onPress: () => {
|
|
12019
|
+
stopWatch();
|
|
12020
|
+
onChange(defaults);
|
|
12021
|
+
setSaid("Windows put back as they began");
|
|
12022
|
+
},
|
|
12023
|
+
children: "Reset"
|
|
12024
|
+
})]
|
|
12025
|
+
}),
|
|
12026
|
+
fields && chosen && /* @__PURE__ */ jsxs("div", {
|
|
12027
|
+
role: "group",
|
|
12028
|
+
"aria-label": `Position and size of ${chosen.label}`,
|
|
12029
|
+
className: "grid grid-cols-2 gap-3 sm:grid-cols-4",
|
|
12030
|
+
children: [
|
|
12031
|
+
/* @__PURE__ */ jsx(PropertyRow, {
|
|
12032
|
+
label: "Across",
|
|
12033
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
12034
|
+
value: Math.round(chosen.x),
|
|
12035
|
+
onChange: (v) => setSide("x", v),
|
|
12036
|
+
min: limits.bounds.x,
|
|
12037
|
+
max: limits.bounds.x + limits.bounds.w - chosen.w,
|
|
12038
|
+
unit,
|
|
12039
|
+
size: "sm"
|
|
12040
|
+
})
|
|
12041
|
+
}),
|
|
12042
|
+
/* @__PURE__ */ jsx(PropertyRow, {
|
|
12043
|
+
label: "Down",
|
|
12044
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
12045
|
+
value: Math.round(chosen.y),
|
|
12046
|
+
onChange: (v) => setSide("y", v),
|
|
12047
|
+
min: limits.bounds.y,
|
|
12048
|
+
max: limits.bounds.y + limits.bounds.h - chosen.h,
|
|
12049
|
+
unit,
|
|
12050
|
+
size: "sm"
|
|
12051
|
+
})
|
|
12052
|
+
}),
|
|
12053
|
+
/* @__PURE__ */ jsx(PropertyRow, {
|
|
12054
|
+
label: "Width",
|
|
12055
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
12056
|
+
value: Math.round(chosen.w),
|
|
12057
|
+
onChange: (v) => setSide("w", v),
|
|
12058
|
+
min: Math.ceil(limits.min.w),
|
|
12059
|
+
max: Math.floor(limits.bounds.w),
|
|
12060
|
+
unit,
|
|
12061
|
+
size: "sm"
|
|
12062
|
+
})
|
|
12063
|
+
}),
|
|
12064
|
+
/* @__PURE__ */ jsx(PropertyRow, {
|
|
12065
|
+
label: "Height",
|
|
12066
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
12067
|
+
value: Math.round(chosen.h),
|
|
12068
|
+
onChange: (v) => setSide("h", v),
|
|
12069
|
+
min: Math.ceil(limits.min.h),
|
|
12070
|
+
max: Math.floor(limits.bounds.h),
|
|
12071
|
+
unit,
|
|
12072
|
+
size: "sm"
|
|
12073
|
+
})
|
|
12074
|
+
})
|
|
12075
|
+
]
|
|
12076
|
+
}),
|
|
12077
|
+
/* @__PURE__ */ jsx("div", {
|
|
12078
|
+
role: "status",
|
|
12079
|
+
"aria-live": "polite",
|
|
12080
|
+
className: "sr-only",
|
|
12081
|
+
children: said
|
|
12082
|
+
})
|
|
12083
|
+
]
|
|
12084
|
+
});
|
|
12085
|
+
}
|
|
12086
|
+
// src/lib/sequence.ts
|
|
12087
|
+
var EPS = 1e-9;
|
|
12088
|
+
/** The grid point nearest to `time`, or `time` itself when there is no grid. */
|
|
12089
|
+
function snapToGrid(time, grid) {
|
|
12090
|
+
if (grid === void 0) return time;
|
|
12091
|
+
if (typeof grid === "number") return grid > 0 ? tidy(Math.round(time / grid) * grid) : time;
|
|
12092
|
+
let best = time;
|
|
12093
|
+
let gap = Infinity;
|
|
12094
|
+
for (const p of grid) if (Math.abs(p - time) < gap) [best, gap] = [p, Math.abs(p - time)];
|
|
12095
|
+
return best;
|
|
12096
|
+
}
|
|
12097
|
+
/** The next grid point after `time` in a direction (`1` later, `-1` earlier); `fallback` is the step when there is no grid. A point `time` is already on is stepped past. */
|
|
12098
|
+
function stepOnGrid(time, dir, grid, fallback) {
|
|
12099
|
+
if (grid === void 0) return tidy(time + dir * fallback);
|
|
12100
|
+
if (typeof grid === "number") {
|
|
12101
|
+
if (grid <= 0) return tidy(time + dir * fallback);
|
|
12102
|
+
return tidy((dir > 0 ? Math.floor(time / grid + EPS) + 1 : Math.ceil(time / grid - EPS) - 1) * grid);
|
|
12103
|
+
}
|
|
12104
|
+
const points = [...grid].sort((a, b) => a - b);
|
|
12105
|
+
return (dir > 0 ? points.find((p) => p > time + EPS) : [...points].reverse().find((p) => p < time - EPS)) ?? tidy(time + dir * fallback);
|
|
12106
|
+
}
|
|
12107
|
+
/** Grid points inside `[from, to]`, for drawing on a ruler. At most `limit`, so a fine grid on a long axis stays cheap. */
|
|
12108
|
+
function gridPoints(grid, from, to, limit = 2e3) {
|
|
12109
|
+
if (grid === void 0) return [];
|
|
12110
|
+
if (typeof grid !== "number") return grid.filter((p) => p >= from - EPS && p <= to + EPS).slice(0, limit);
|
|
12111
|
+
if (grid <= 0) return [];
|
|
12112
|
+
const out = [];
|
|
12113
|
+
for (let i = Math.ceil(from / grid - EPS); i * grid <= to + EPS && out.length < limit; i++) out.push(tidy(i * grid) || 0);
|
|
12114
|
+
return out;
|
|
12115
|
+
}
|
|
12116
|
+
/** Puts `time` inside the room, and says which end held it (with the app's reason) when one did. */
|
|
12117
|
+
function clampToRoom(time, room) {
|
|
12118
|
+
const t = clamp$1(time, room.min, room.max);
|
|
12119
|
+
if (t > time + EPS) return {
|
|
12120
|
+
time: t,
|
|
12121
|
+
limit: {
|
|
12122
|
+
side: "min",
|
|
12123
|
+
at: room.min,
|
|
12124
|
+
reason: room.minReason
|
|
12125
|
+
}
|
|
12126
|
+
};
|
|
12127
|
+
if (t < time - EPS) return {
|
|
12128
|
+
time: t,
|
|
12129
|
+
limit: {
|
|
12130
|
+
side: "max",
|
|
12131
|
+
at: room.max,
|
|
12132
|
+
reason: room.maxReason
|
|
12133
|
+
}
|
|
12134
|
+
};
|
|
12135
|
+
return {
|
|
12136
|
+
time: t,
|
|
12137
|
+
limit: null
|
|
12138
|
+
};
|
|
12139
|
+
}
|
|
12140
|
+
/** Where a dragged cut lands: held by the room (saying which end, if the pointer is beyond it), otherwise snapped to the grid, and never to a grid point outside the room. */
|
|
12141
|
+
function settleCut(wanted, grid, room) {
|
|
12142
|
+
const held = clampToRoom(wanted, room);
|
|
12143
|
+
const snapped = snapToGrid(held.time, grid);
|
|
12144
|
+
return {
|
|
12145
|
+
time: snapped >= room.min - EPS && snapped <= room.max + EPS ? snapped : held.time,
|
|
12146
|
+
limit: held.limit
|
|
12147
|
+
};
|
|
12148
|
+
}
|
|
12149
|
+
// src/components/sequence-timeline.tsx
|
|
12150
|
+
var seconds = (n) => `${tidy(Math.round(n * 10) / 10)} s`;
|
|
12151
|
+
var at = (t) => tickLabel(t, .1);
|
|
12152
|
+
/** A gapless strip of windows whose cuts are dragged or stepped, snapping to a beat grid inside the room the app gives; each cut is a slider that announces both windows' new lengths; Shift+click chooses a run. */
|
|
12153
|
+
function SequenceTimeline({ label, items, zoom, onCutChange, room, minLength = .1, grid, step = .1, selected = [], onSelectRange, renderItem, height = "5rem", className }) {
|
|
12154
|
+
const start = items[0]?.start ?? 0;
|
|
12155
|
+
const end = items[items.length - 1]?.end ?? 0;
|
|
12156
|
+
const span = Math.max(end - start, 1e-6);
|
|
12157
|
+
const track = React.useRef(null);
|
|
12158
|
+
const [fit, setFit] = React.useState(800);
|
|
12159
|
+
React.useLayoutEffect(() => {
|
|
12160
|
+
const el = track.current?.parentElement;
|
|
12161
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
12162
|
+
const read = () => setFit(el.clientWidth || 800);
|
|
12163
|
+
read();
|
|
12164
|
+
const ro = new ResizeObserver(read);
|
|
12165
|
+
ro.observe(el);
|
|
12166
|
+
return () => ro.disconnect();
|
|
12167
|
+
}, []);
|
|
12168
|
+
const pxPerUnit = zoom ?? fit / span;
|
|
12169
|
+
const [drag, setDrag] = React.useState(null);
|
|
12170
|
+
const [said, setSaid] = React.useState("");
|
|
12171
|
+
const anchor = React.useRef(null);
|
|
12172
|
+
const roomFor = React.useCallback((i) => room?.(i) ?? {
|
|
12173
|
+
min: items[i].start + minLength,
|
|
12174
|
+
max: items[i + 1].end - minLength
|
|
12175
|
+
}, [
|
|
12176
|
+
room,
|
|
12177
|
+
items,
|
|
12178
|
+
minLength
|
|
12179
|
+
]);
|
|
12180
|
+
const view = items.map((it, i) => ({
|
|
12181
|
+
...it,
|
|
12182
|
+
start: drag && drag.index === i - 1 ? drag.time : it.start,
|
|
12183
|
+
end: drag && drag.index === i ? drag.time : it.end
|
|
12184
|
+
}));
|
|
12185
|
+
const change = (i, time) => ({
|
|
12186
|
+
before: {
|
|
12187
|
+
...items[i],
|
|
12188
|
+
end: time
|
|
12189
|
+
},
|
|
12190
|
+
after: {
|
|
12191
|
+
...items[i + 1],
|
|
12192
|
+
start: time
|
|
12193
|
+
}
|
|
12194
|
+
});
|
|
12195
|
+
const words = (i, time) => `Cut ${i + 1} moved to ${at(time)}. Window ${i + 1} is ${seconds(time - items[i].start)}, window ${i + 2} is ${seconds(items[i + 1].end - time)}.`;
|
|
12196
|
+
const timeAt = (clientX) => {
|
|
12197
|
+
const box = track.current?.getBoundingClientRect();
|
|
12198
|
+
if (!box || !box.width) return start;
|
|
12199
|
+
return start + (clientX - box.left) / box.width * span;
|
|
12200
|
+
};
|
|
12201
|
+
const keys = (e, i) => {
|
|
12202
|
+
const r = roomFor(i);
|
|
12203
|
+
const now = items[i].end;
|
|
12204
|
+
let target = null;
|
|
12205
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
12206
|
+
const dir = e.key === "ArrowRight" ? 1 : -1;
|
|
12207
|
+
target = e.shiftKey ? now + dir : stepOnGrid(now, dir, grid, step);
|
|
12208
|
+
} else if (e.key === "Home") target = r.min;
|
|
12209
|
+
else if (e.key === "End") target = r.max;
|
|
12210
|
+
if (target === null) return;
|
|
12211
|
+
e.preventDefault();
|
|
12212
|
+
const { time, limit } = clampToRoom(tidy(target), r);
|
|
12213
|
+
if (Math.abs(time - now) < 1e-9) {
|
|
12214
|
+
const why = limit?.reason ?? (e.key === "End" || e.key === "ArrowRight" ? r.maxReason : r.minReason);
|
|
12215
|
+
setSaid(`Cut ${i + 1} stays at ${at(now)}.${why ? ` ${why}` : ""}`);
|
|
12216
|
+
return;
|
|
12217
|
+
}
|
|
12218
|
+
onCutChange(i, time, change(i, time));
|
|
12219
|
+
setSaid(words(i, time) + (limit?.reason ? ` ${limit.reason}` : ""));
|
|
12220
|
+
};
|
|
12221
|
+
const begin = (e, i) => {
|
|
12222
|
+
if (e.button !== 0) return;
|
|
12223
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
12224
|
+
setDrag({
|
|
12225
|
+
index: i,
|
|
12226
|
+
time: items[i].end,
|
|
12227
|
+
refused: null
|
|
12228
|
+
});
|
|
12229
|
+
};
|
|
12230
|
+
const drive = (e) => {
|
|
12231
|
+
if (!drag) return;
|
|
12232
|
+
const { time, limit } = settleCut(timeAt(e.clientX), grid, roomFor(drag.index));
|
|
12233
|
+
setDrag({
|
|
12234
|
+
index: drag.index,
|
|
12235
|
+
time,
|
|
12236
|
+
refused: limit ? `Cut ${drag.index + 1} stops at ${at(limit.at)}.${limit.reason ? ` ${limit.reason}` : ""}` : null
|
|
12237
|
+
});
|
|
12238
|
+
};
|
|
12239
|
+
const release = () => {
|
|
12240
|
+
if (!drag) return;
|
|
12241
|
+
const d = drag;
|
|
12242
|
+
setDrag(null);
|
|
12243
|
+
if (Math.abs(d.time - items[d.index].end) > 1e-9) {
|
|
12244
|
+
onCutChange(d.index, d.time, change(d.index, d.time));
|
|
12245
|
+
setSaid(words(d.index, d.time) + (d.refused ? ` ${d.refused}` : ""));
|
|
12246
|
+
} else if (d.refused) setSaid(d.refused);
|
|
12247
|
+
};
|
|
12248
|
+
const step0 = tickStep(pxPerUnit);
|
|
12249
|
+
const ticks = ticksBetween(start, end, step0);
|
|
12250
|
+
const all = gridPoints(grid, start, end);
|
|
12251
|
+
const beats = (end - start) / Math.max(all.length, 1) * pxPerUnit >= 4 ? all : [];
|
|
12252
|
+
const pct = (t) => `${(t - start) / span * 100}%`;
|
|
12253
|
+
const choose = (e, id) => {
|
|
12254
|
+
if (!onSelectRange) return;
|
|
12255
|
+
const here = items.findIndex((x) => x.id === id);
|
|
12256
|
+
const from = anchor.current ? items.findIndex((x) => x.id === anchor.current) : -1;
|
|
12257
|
+
if (e.shiftKey && from >= 0) {
|
|
12258
|
+
const [a, b] = from <= here ? [from, here] : [here, from];
|
|
12259
|
+
onSelectRange(items.slice(a, b + 1).map((x) => x.id));
|
|
12260
|
+
} else {
|
|
12261
|
+
anchor.current = id;
|
|
12262
|
+
onSelectRange([id]);
|
|
12263
|
+
}
|
|
12264
|
+
};
|
|
12265
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
12266
|
+
className: cn("min-w-0", className),
|
|
12267
|
+
children: [
|
|
12268
|
+
/* @__PURE__ */ jsx("div", {
|
|
12269
|
+
role: "group",
|
|
12270
|
+
"aria-label": label,
|
|
12271
|
+
className: "overflow-x-auto pb-2",
|
|
12272
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
12273
|
+
ref: track,
|
|
12274
|
+
className: "relative",
|
|
12275
|
+
style: { width: zoom ? `${span * zoom}px` : "100%" },
|
|
12276
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
12277
|
+
"aria-hidden": true,
|
|
12278
|
+
className: "relative h-6 border-b border-border",
|
|
12279
|
+
children: [ticks.map((t) => /* @__PURE__ */ jsx("span", {
|
|
12280
|
+
className: "absolute top-0 -translate-x-1/2 type-caption tabular-nums text-muted-foreground",
|
|
12281
|
+
style: { left: pct(t) },
|
|
12282
|
+
children: tickLabel(t, step0)
|
|
12283
|
+
}, t)), beats.map((p) => /* @__PURE__ */ jsx("span", {
|
|
12284
|
+
"data-beat": true,
|
|
12285
|
+
className: "absolute bottom-0 h-1.5 w-px bg-border",
|
|
12286
|
+
style: { left: pct(p) }
|
|
12287
|
+
}, `b${p}`))]
|
|
12288
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
12289
|
+
className: "relative mt-1",
|
|
12290
|
+
style: { height },
|
|
12291
|
+
children: [view.map((it) => {
|
|
12292
|
+
const on = selected.includes(it.id);
|
|
12293
|
+
return /* @__PURE__ */ jsx("button", {
|
|
12294
|
+
type: "button",
|
|
12295
|
+
"aria-pressed": on,
|
|
12296
|
+
"aria-label": `${it.label}, ${at(it.start)} to ${at(it.end)}`,
|
|
12297
|
+
onClick: (e) => choose(e, it.id),
|
|
12298
|
+
className: cn("absolute inset-y-0 min-w-0 cursor-pointer overflow-hidden rounded-control border px-1.5 text-left transition-state", on ? "border-primary bg-primary/10" : "border-border bg-muted hover:bg-muted/70"),
|
|
12299
|
+
style: {
|
|
12300
|
+
left: pct(it.start),
|
|
12301
|
+
width: `calc(${(it.end - it.start) / span * 100}% - 2px)`
|
|
12302
|
+
},
|
|
12303
|
+
children: renderItem ? renderItem(it, on) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
12304
|
+
className: "block truncate type-label",
|
|
12305
|
+
children: it.label
|
|
12306
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
12307
|
+
className: "block truncate type-caption tabular-nums text-muted-foreground",
|
|
12308
|
+
children: seconds(it.end - it.start)
|
|
12309
|
+
})] })
|
|
12310
|
+
}, it.id);
|
|
12311
|
+
}), items.slice(0, -1).map((it, i) => {
|
|
12312
|
+
const r = roomFor(i);
|
|
12313
|
+
const now = drag?.index === i ? drag.time : it.end;
|
|
12314
|
+
return /* @__PURE__ */ jsx("div", {
|
|
12315
|
+
role: "slider",
|
|
12316
|
+
tabIndex: 0,
|
|
12317
|
+
"aria-label": `Cut ${i + 1}, between window ${i + 1} and window ${i + 2}`,
|
|
12318
|
+
"aria-orientation": "horizontal",
|
|
12319
|
+
"aria-valuemin": r.min,
|
|
12320
|
+
"aria-valuemax": r.max,
|
|
12321
|
+
"aria-valuenow": now,
|
|
12322
|
+
"aria-valuetext": at(now),
|
|
12323
|
+
"data-cut": i,
|
|
12324
|
+
onKeyDown: (e) => keys(e, i),
|
|
12325
|
+
onPointerDown: (e) => begin(e, i),
|
|
12326
|
+
onPointerMove: drive,
|
|
12327
|
+
onPointerUp: release,
|
|
12328
|
+
onPointerCancel: () => setDrag(null),
|
|
12329
|
+
className: "group absolute inset-y-0 z-10 w-3 -translate-x-1/2 cursor-ew-resize touch-none outline-offset-1",
|
|
12330
|
+
style: { left: pct(now) },
|
|
12331
|
+
children: /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 left-1/2 w-0.5 -translate-x-1/2 rounded-pill bg-foreground group-hover:w-1 group-focus-visible:w-1" })
|
|
12332
|
+
}, `cut${it.id}`);
|
|
12333
|
+
})]
|
|
12334
|
+
})]
|
|
12335
|
+
})
|
|
12336
|
+
}),
|
|
12337
|
+
drag?.refused && /* @__PURE__ */ jsxs("p", {
|
|
12338
|
+
className: "mt-1 flex items-center gap-1.5 type-body-sm text-danger",
|
|
12339
|
+
children: [
|
|
12340
|
+
/* @__PURE__ */ jsx(Ban, {
|
|
12341
|
+
className: "size-4 shrink-0",
|
|
12342
|
+
"aria-hidden": true
|
|
12343
|
+
}),
|
|
12344
|
+
" ",
|
|
12345
|
+
drag.refused
|
|
12346
|
+
]
|
|
12347
|
+
}),
|
|
12348
|
+
/* @__PURE__ */ jsx("div", {
|
|
12349
|
+
role: "status",
|
|
12350
|
+
"aria-live": "polite",
|
|
12351
|
+
className: "sr-only",
|
|
12352
|
+
children: said
|
|
12353
|
+
})
|
|
12354
|
+
]
|
|
12355
|
+
});
|
|
12356
|
+
}
|
|
12357
|
+
// src/components/tree.tsx
|
|
12358
|
+
var Context = React.createContext(null);
|
|
12359
|
+
var useCtx = () => React.useContext(Context);
|
|
12360
|
+
var NOTE = "\0";
|
|
12361
|
+
var isNote = (key) => key.includes(NOTE);
|
|
12362
|
+
var ROW = "flex min-h-(--control-h-sm) min-w-0 items-center gap-1 rounded-control pr-2 type-body-sm";
|
|
12363
|
+
function Row$1({ level, children }) {
|
|
12364
|
+
return /* @__PURE__ */ jsx("div", {
|
|
12365
|
+
className: ROW,
|
|
12366
|
+
style: { paddingInlineStart: `${level * 1.25 + .25}rem` },
|
|
12367
|
+
children
|
|
12368
|
+
});
|
|
12369
|
+
}
|
|
12370
|
+
function Node$1({ node }) {
|
|
12371
|
+
const c = useCtx();
|
|
12372
|
+
const key = c.nodeKey(node);
|
|
12373
|
+
c.nodes.set(key, node);
|
|
12374
|
+
const branch = c.isBranch ? c.isBranch(node) : true;
|
|
12375
|
+
const open = branch && c.expanded.isOpen(key);
|
|
12376
|
+
const name = c.nodeLabel(node);
|
|
12377
|
+
return /* @__PURE__ */ jsxs(TreeItem, {
|
|
12378
|
+
id: key,
|
|
12379
|
+
textValue: name,
|
|
12380
|
+
hasChildItems: branch,
|
|
12381
|
+
className: "outline-none",
|
|
12382
|
+
children: [/* @__PURE__ */ jsx(TreeItemContent, { children: ({ level, isSelected, isExpanded }) => /* @__PURE__ */ jsxs("div", {
|
|
12383
|
+
title: name,
|
|
12384
|
+
className: cn(ROW, "cursor-pointer outline-offset-[-2px] hover:bg-muted", isSelected && "bg-surface-sunken font-medium"),
|
|
12385
|
+
style: { paddingInlineStart: `${(level - 1) * 1.25 + .25}rem` },
|
|
12386
|
+
"data-selected": isSelected || void 0,
|
|
12387
|
+
children: [
|
|
12388
|
+
branch ? /* @__PURE__ */ jsx(Button$1, {
|
|
12389
|
+
slot: "chevron",
|
|
12390
|
+
className: "grid size-6 shrink-0 place-items-center rounded-control text-muted-foreground",
|
|
12391
|
+
children: /* @__PURE__ */ jsx(ChevronRight, {
|
|
12392
|
+
"aria-hidden": true,
|
|
12393
|
+
className: cn("size-4", isExpanded && "rotate-90")
|
|
12394
|
+
})
|
|
12395
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
12396
|
+
"aria-hidden": true,
|
|
12397
|
+
className: "size-6 shrink-0"
|
|
12398
|
+
}),
|
|
12399
|
+
branch ? isExpanded ? /* @__PURE__ */ jsx(FolderOpen, {
|
|
12400
|
+
"aria-hidden": true,
|
|
12401
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
12402
|
+
}) : /* @__PURE__ */ jsx(Folder, {
|
|
12403
|
+
"aria-hidden": true,
|
|
12404
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
12405
|
+
}) : null,
|
|
12406
|
+
/* @__PURE__ */ jsx("span", {
|
|
12407
|
+
className: "min-w-0 flex-1 truncate",
|
|
12408
|
+
children: c.renderNode ? c.renderNode(node, {
|
|
12409
|
+
expanded: isExpanded,
|
|
12410
|
+
selected: isSelected,
|
|
12411
|
+
level,
|
|
12412
|
+
branch
|
|
12413
|
+
}) : name
|
|
12414
|
+
})
|
|
12415
|
+
]
|
|
12416
|
+
}) }), open ? /* @__PURE__ */ jsx(Children, { node }) : branch && /* @__PURE__ */ jsx(ClosedChild, { id: `${key}${NOTE}closed` })]
|
|
12417
|
+
});
|
|
12418
|
+
}
|
|
12419
|
+
function ClosedChild({ id }) {
|
|
12420
|
+
return /* @__PURE__ */ jsx(TreeItem, {
|
|
12421
|
+
id,
|
|
12422
|
+
textValue: "",
|
|
12423
|
+
isDisabled: true,
|
|
12424
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: () => null })
|
|
12425
|
+
}, "closed");
|
|
12426
|
+
}
|
|
12427
|
+
function Nodes({ nodes }) {
|
|
12428
|
+
const c = useCtx();
|
|
12429
|
+
return /* @__PURE__ */ jsx(Fragment, { children: nodes.map((n) => /* @__PURE__ */ jsx(Node$1, { node: n }, c.nodeKey(n))) });
|
|
12430
|
+
}
|
|
12431
|
+
function Children({ node }) {
|
|
12432
|
+
const c = useCtx();
|
|
12433
|
+
const key = c.nodeKey(node);
|
|
12434
|
+
const load = c.useChildren(node);
|
|
12435
|
+
if (load.status === "loading") return /* @__PURE__ */ jsx(TreeItem, {
|
|
12436
|
+
id: `${key}${NOTE}loading`,
|
|
12437
|
+
textValue: "Loading",
|
|
12438
|
+
isDisabled: true,
|
|
12439
|
+
className: "outline-none",
|
|
12440
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
12441
|
+
level: level - 1,
|
|
12442
|
+
children: [
|
|
12443
|
+
/* @__PURE__ */ jsx("span", {
|
|
12444
|
+
"aria-hidden": true,
|
|
12445
|
+
className: "size-6 shrink-0"
|
|
12446
|
+
}),
|
|
12447
|
+
/* @__PURE__ */ jsx("span", {
|
|
12448
|
+
role: "status",
|
|
12449
|
+
className: "sr-only",
|
|
12450
|
+
children: "Loading"
|
|
12451
|
+
}),
|
|
12452
|
+
c.loadingRow ?? /* @__PURE__ */ jsx("span", {
|
|
12453
|
+
"aria-hidden": true,
|
|
12454
|
+
className: "h-3 w-32 animate-pulse rounded-pill bg-muted"
|
|
12455
|
+
})
|
|
12456
|
+
]
|
|
12457
|
+
}) })
|
|
12458
|
+
}, "loading");
|
|
12459
|
+
if (load.status === "error") return /* @__PURE__ */ jsx(TreeItem, {
|
|
12460
|
+
id: `${key}${NOTE}error`,
|
|
12461
|
+
textValue: load.message,
|
|
12462
|
+
className: "outline-none",
|
|
12463
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
12464
|
+
level: level - 1,
|
|
12465
|
+
children: [
|
|
12466
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
12467
|
+
"aria-hidden": true,
|
|
12468
|
+
className: "size-4 shrink-0 text-danger"
|
|
12469
|
+
}),
|
|
12470
|
+
/* @__PURE__ */ jsx("span", {
|
|
12471
|
+
className: "min-w-0 flex-1 truncate text-danger",
|
|
12472
|
+
title: load.message,
|
|
12473
|
+
children: load.message
|
|
12474
|
+
}),
|
|
12475
|
+
/* @__PURE__ */ jsx(Button, {
|
|
12476
|
+
size: "sm",
|
|
12477
|
+
onPress: load.retry,
|
|
12478
|
+
children: "Try again"
|
|
12479
|
+
})
|
|
12480
|
+
]
|
|
12481
|
+
}) })
|
|
12482
|
+
}, "error");
|
|
12483
|
+
if (load.data.length === 0) return /* @__PURE__ */ jsx(TreeItem, {
|
|
12484
|
+
id: `${key}${NOTE}empty`,
|
|
12485
|
+
textValue: c.emptyRow,
|
|
12486
|
+
isDisabled: true,
|
|
12487
|
+
className: "outline-none",
|
|
12488
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
12489
|
+
level: level - 1,
|
|
12490
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
12491
|
+
"aria-hidden": true,
|
|
12492
|
+
className: "size-6 shrink-0"
|
|
12493
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
12494
|
+
className: "text-muted-foreground",
|
|
12495
|
+
children: c.emptyRow
|
|
12496
|
+
})]
|
|
12497
|
+
}) })
|
|
12498
|
+
}, "empty");
|
|
12499
|
+
return /* @__PURE__ */ jsx(Nodes, { nodes: load.data });
|
|
12500
|
+
}
|
|
12501
|
+
/** A hierarchy whose children load as each node opens (a `useChildren` hook per open node): a skeleton row, a Try again row and an "empty" row per node, type-ahead and arrow keys, single selection, open state optionally in the URL, always virtualised. */
|
|
12502
|
+
function Tree({ label, roots, useChildren, nodeKey, nodeLabel, isBranch, renderNode, selected, onSelect, expanded, loadingRow, emptyRow, height = "24rem", className }) {
|
|
12503
|
+
const nodes = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
12504
|
+
const ctx = {
|
|
12505
|
+
useChildren,
|
|
12506
|
+
nodeKey,
|
|
12507
|
+
nodeLabel,
|
|
12508
|
+
isBranch,
|
|
12509
|
+
renderNode,
|
|
12510
|
+
selected,
|
|
12511
|
+
onSelect,
|
|
12512
|
+
expanded,
|
|
12513
|
+
loadingRow,
|
|
12514
|
+
emptyRow,
|
|
12515
|
+
nodes
|
|
12516
|
+
};
|
|
12517
|
+
if (roots.status === "loading") return /* @__PURE__ */ jsx("div", {
|
|
12518
|
+
role: "status",
|
|
12519
|
+
"aria-label": `${label}: loading`,
|
|
12520
|
+
className: cn("space-y-2 p-2", className),
|
|
12521
|
+
children: [
|
|
12522
|
+
0,
|
|
12523
|
+
1,
|
|
12524
|
+
2,
|
|
12525
|
+
3
|
|
12526
|
+
].map((i) => /* @__PURE__ */ jsx("div", {
|
|
12527
|
+
"aria-hidden": true,
|
|
12528
|
+
className: "h-4 animate-pulse rounded-pill bg-muted",
|
|
12529
|
+
style: { width: `${70 - i * 10}%` }
|
|
12530
|
+
}, i))
|
|
12531
|
+
});
|
|
12532
|
+
if (roots.status === "error") return /* @__PURE__ */ jsxs("div", {
|
|
12533
|
+
role: "alert",
|
|
12534
|
+
className: cn("flex items-center gap-3 rounded-surface bg-danger-subtle p-3 text-danger", className),
|
|
12535
|
+
children: [
|
|
12536
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
12537
|
+
"aria-hidden": true,
|
|
12538
|
+
className: "size-5 shrink-0"
|
|
12539
|
+
}),
|
|
12540
|
+
/* @__PURE__ */ jsx("p", {
|
|
12541
|
+
className: "min-w-0 flex-1 type-body-sm",
|
|
12542
|
+
children: roots.message
|
|
12543
|
+
}),
|
|
12544
|
+
/* @__PURE__ */ jsx(Button, {
|
|
12545
|
+
size: "sm",
|
|
12546
|
+
onPress: roots.retry,
|
|
12547
|
+
children: "Try again"
|
|
12548
|
+
})
|
|
12549
|
+
]
|
|
12550
|
+
});
|
|
12551
|
+
const choose = (keys) => {
|
|
12552
|
+
const first = keys === "all" ? void 0 : [...keys][0];
|
|
12553
|
+
if (first === void 0 || isNote(String(first))) return;
|
|
12554
|
+
const key = String(first);
|
|
12555
|
+
const node = nodes.get(key);
|
|
12556
|
+
if (node !== void 0) onSelect(key, node);
|
|
12557
|
+
};
|
|
12558
|
+
const tree = /* @__PURE__ */ jsx(Tree$1, {
|
|
12559
|
+
"aria-label": label,
|
|
12560
|
+
selectionMode: "single",
|
|
12561
|
+
disallowEmptySelection: true,
|
|
12562
|
+
selectedKeys: selected === null ? [] : [selected],
|
|
12563
|
+
onSelectionChange: choose,
|
|
12564
|
+
expandedKeys: expanded.expanded,
|
|
12565
|
+
onExpandedChange: (keys) => expanded.onChange(new Set([...keys].map(String).filter((k) => !isNote(k)))),
|
|
12566
|
+
renderEmptyState: () => /* @__PURE__ */ jsx("p", {
|
|
12567
|
+
className: "p-3 type-body-sm text-muted-foreground",
|
|
12568
|
+
children: emptyRow
|
|
12569
|
+
}),
|
|
12570
|
+
className: cn("min-w-0 overflow-y-auto outline-none", className),
|
|
12571
|
+
style: { maxHeight: height },
|
|
12572
|
+
"data-strata-scroll": "",
|
|
12573
|
+
children: /* @__PURE__ */ jsx(Nodes, { nodes: roots.data })
|
|
12574
|
+
});
|
|
12575
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
12576
|
+
value: ctx,
|
|
12577
|
+
children: /* @__PURE__ */ jsx(Virtualizer, {
|
|
12578
|
+
layout: ListLayout,
|
|
12579
|
+
layoutOptions: { rowHeight: 32 },
|
|
12580
|
+
children: tree
|
|
12581
|
+
})
|
|
12582
|
+
});
|
|
12583
|
+
}
|
|
12584
|
+
// src/components/folder-picker.tsx
|
|
12585
|
+
var SEP = "/";
|
|
12586
|
+
var parts = (path) => path.split(SEP).filter(Boolean);
|
|
12587
|
+
var join = (parent, name) => `${parent === SEP ? "" : parent}${SEP}${name}`;
|
|
12588
|
+
/** The parent of a path, or `null` at the top. */
|
|
12589
|
+
var parentOf = (path) => {
|
|
12590
|
+
const p = parts(path);
|
|
12591
|
+
return p.length <= 1 ? null : `${SEP}${p.slice(0, -1).join(SEP)}`;
|
|
12592
|
+
};
|
|
12593
|
+
/** Every folder from the top down to `path`, which the tree must have open to show it. */
|
|
12594
|
+
var ancestorsOf = (path) => parts(path).slice(0, -1).map((_, i, a) => `${SEP}${a.slice(0, i + 1).join(SEP)}`);
|
|
12595
|
+
/** A server folder chooser: a lazy tree, a breadcrumb that is also editable text, Up, recents, a New folder field that shows the server's refusal, and Choose this folder as the one filled button. */
|
|
12596
|
+
function FolderPicker({ label, useFolders, value, onChange, onChoose, expanded, recent, onCreate, topLabel = "Top", emptyRow = "No folders", height = "18rem", className }) {
|
|
12597
|
+
const roots = useFolders(null);
|
|
12598
|
+
const [editing, setEditing] = React.useState(false);
|
|
12599
|
+
const [text, setText] = React.useState("");
|
|
12600
|
+
const go = (path) => onChange(path);
|
|
12601
|
+
React.useEffect(() => {
|
|
12602
|
+
if (!value) return;
|
|
12603
|
+
const open = ancestorsOf(value).filter((a) => !expanded.isOpen(a));
|
|
12604
|
+
if (open.length) expanded.onChange(/* @__PURE__ */ new Set([...expanded.expanded, ...open]));
|
|
12605
|
+
}, [value, expanded]);
|
|
12606
|
+
const [name, setName] = React.useState("");
|
|
12607
|
+
const created = useAsyncAction(async (name) => {
|
|
12608
|
+
if (!value) return;
|
|
12609
|
+
await onCreate?.(value, name);
|
|
12610
|
+
setName("");
|
|
12611
|
+
go(join(value, name));
|
|
12612
|
+
expanded.setOpen(value, true);
|
|
12613
|
+
}, { validate: (name) => name.trim() ? void 0 : { name: "Name the new folder." } });
|
|
12614
|
+
const crumbs = value ? parts(value) : [];
|
|
12615
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
12616
|
+
"aria-label": label,
|
|
12617
|
+
className: cn("space-y-3", className),
|
|
12618
|
+
children: [
|
|
12619
|
+
/* @__PURE__ */ jsxs("div", {
|
|
12620
|
+
className: "flex flex-wrap items-center gap-2",
|
|
12621
|
+
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
12622
|
+
icon: ArrowUp,
|
|
12623
|
+
label: "Up one folder",
|
|
12624
|
+
onPress: () => go(value ? parentOf(value) : null),
|
|
12625
|
+
disabled: !value
|
|
12626
|
+
}), editing ? /* @__PURE__ */ jsxs("form", {
|
|
12627
|
+
className: "flex min-w-0 flex-1 items-center gap-2",
|
|
12628
|
+
onSubmit: (e) => {
|
|
12629
|
+
e.preventDefault();
|
|
12630
|
+
const typed = text.trim();
|
|
12631
|
+
go(typed ? (typed.startsWith(SEP) ? typed : `${SEP}${typed}`).replace(/\/+$/, "") || SEP : null);
|
|
12632
|
+
setEditing(false);
|
|
12633
|
+
},
|
|
12634
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
12635
|
+
"aria-label": "Folder path",
|
|
12636
|
+
value: text,
|
|
12637
|
+
autoFocus: true,
|
|
12638
|
+
onChange: (e) => setText(e.target.value),
|
|
12639
|
+
onKeyDown: (e) => e.key === "Escape" && (e.stopPropagation(), setEditing(false)),
|
|
12640
|
+
className: "min-w-0 flex-1 font-mono",
|
|
12641
|
+
size: "sm"
|
|
12642
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
12643
|
+
size: "sm",
|
|
12644
|
+
type: "submit",
|
|
12645
|
+
children: "Go"
|
|
12646
|
+
})]
|
|
12647
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("nav", {
|
|
12648
|
+
"aria-label": "Folder path",
|
|
12649
|
+
className: "min-w-0 flex-1",
|
|
12650
|
+
children: /* @__PURE__ */ jsxs("ol", {
|
|
12651
|
+
className: "flex flex-wrap items-center gap-x-1 type-body-sm",
|
|
12652
|
+
children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Button, {
|
|
12653
|
+
size: "sm",
|
|
12654
|
+
variant: "ghost",
|
|
12655
|
+
onPress: () => go(null),
|
|
12656
|
+
"aria-current": value ? void 0 : "location",
|
|
12657
|
+
children: topLabel
|
|
12658
|
+
}) }), crumbs.map((c, i) => {
|
|
12659
|
+
const path = `${SEP}${crumbs.slice(0, i + 1).join(SEP)}`;
|
|
12660
|
+
const last = i === crumbs.length - 1;
|
|
12661
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
12662
|
+
className: "flex min-w-0 items-center gap-1",
|
|
12663
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
12664
|
+
"aria-hidden": true,
|
|
12665
|
+
className: "text-muted-foreground",
|
|
12666
|
+
children: "/"
|
|
12667
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
12668
|
+
size: "sm",
|
|
12669
|
+
variant: "ghost",
|
|
12670
|
+
title: path,
|
|
12671
|
+
onPress: () => go(path),
|
|
12672
|
+
"aria-current": last ? "location" : void 0,
|
|
12673
|
+
className: cn("max-w-48 truncate", last && "font-medium"),
|
|
12674
|
+
children: c
|
|
12675
|
+
})]
|
|
12676
|
+
}, path);
|
|
12677
|
+
})]
|
|
12678
|
+
})
|
|
12679
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
12680
|
+
icon: Pencil,
|
|
12681
|
+
label: "Edit path",
|
|
12682
|
+
onPress: () => {
|
|
12683
|
+
setText(value ?? "");
|
|
12684
|
+
setEditing(true);
|
|
12685
|
+
}
|
|
12686
|
+
})] })]
|
|
12687
|
+
}),
|
|
12688
|
+
/* @__PURE__ */ jsx("div", {
|
|
12689
|
+
className: "rounded-surface border border-border",
|
|
12690
|
+
children: /* @__PURE__ */ jsx(Tree, {
|
|
12691
|
+
label: `${label}: folders`,
|
|
12692
|
+
roots,
|
|
12693
|
+
useChildren: (f) => useFolders(f.path),
|
|
12694
|
+
nodeKey: (f) => f.path,
|
|
12695
|
+
nodeLabel: (f) => f.name,
|
|
12696
|
+
renderNode: (f) => /* @__PURE__ */ jsxs("span", {
|
|
12697
|
+
className: "flex min-w-0 items-baseline gap-2",
|
|
12698
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
12699
|
+
className: "truncate",
|
|
12700
|
+
children: f.name
|
|
12701
|
+
}), f.count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
12702
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
12703
|
+
children: format.integer(f.count)
|
|
12704
|
+
})]
|
|
12705
|
+
}),
|
|
12706
|
+
selected: value,
|
|
12707
|
+
onSelect: (key) => onChange(key),
|
|
12708
|
+
expanded,
|
|
12709
|
+
emptyRow,
|
|
12710
|
+
height
|
|
12711
|
+
})
|
|
12712
|
+
}),
|
|
12713
|
+
recent && recent.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
12714
|
+
role: "group",
|
|
12715
|
+
"aria-label": "Recent folders",
|
|
12716
|
+
className: "flex flex-wrap items-center gap-2",
|
|
12717
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
12718
|
+
className: "type-caption text-muted-foreground",
|
|
12719
|
+
children: "Recent"
|
|
12720
|
+
}), recent.map((r) => /* @__PURE__ */ jsx(Button, {
|
|
12721
|
+
size: "sm",
|
|
12722
|
+
variant: "outline",
|
|
12723
|
+
title: r,
|
|
12724
|
+
onPress: () => go(r),
|
|
12725
|
+
className: "max-w-64 truncate font-mono",
|
|
12726
|
+
children: r
|
|
12727
|
+
}, r))]
|
|
12728
|
+
}),
|
|
12729
|
+
onCreate && /* @__PURE__ */ jsx("form", {
|
|
12730
|
+
onSubmit: (e) => {
|
|
12731
|
+
e.preventDefault();
|
|
12732
|
+
created.run(name.trim());
|
|
12733
|
+
},
|
|
12734
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
12735
|
+
label: "New folder",
|
|
12736
|
+
hint: value ? `It will be made in ${value}.` : "Open a folder first.",
|
|
12737
|
+
error: created.fieldErrors.name ?? (created.phase === "error" ? created.error : void 0),
|
|
12738
|
+
action: /* @__PURE__ */ jsx(AsyncButton, {
|
|
12739
|
+
type: "submit",
|
|
12740
|
+
phase: created.phase,
|
|
12741
|
+
error: created.error,
|
|
12742
|
+
disabled: !value,
|
|
12743
|
+
labels: {
|
|
12744
|
+
idle: "Make folder",
|
|
12745
|
+
pending: "Making…",
|
|
12746
|
+
done: "Made"
|
|
12747
|
+
}
|
|
12748
|
+
}),
|
|
12749
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
12750
|
+
value: name,
|
|
12751
|
+
disabled: !value,
|
|
12752
|
+
onChange: (e) => {
|
|
12753
|
+
setName(e.target.value);
|
|
12754
|
+
created.clearFieldError("name");
|
|
12755
|
+
}
|
|
12756
|
+
})
|
|
12757
|
+
})
|
|
12758
|
+
}),
|
|
12759
|
+
/* @__PURE__ */ jsx("div", {
|
|
12760
|
+
className: "flex justify-end",
|
|
12761
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
12762
|
+
variant: "default",
|
|
12763
|
+
disabled: !value,
|
|
12764
|
+
onPress: () => value && onChoose(value),
|
|
12765
|
+
children: "Choose this folder"
|
|
12766
|
+
})
|
|
12767
|
+
})
|
|
12768
|
+
]
|
|
12769
|
+
});
|
|
12770
|
+
}
|
|
12771
|
+
// src/lib/marks.ts
|
|
12772
|
+
/** The ids from `a` to `b` inclusive, in document order whichever way round they are given. Empty when either is not in `ids`. */
|
|
12773
|
+
function rangeBetween(ids, a, b) {
|
|
12774
|
+
if (a === null || b === null) return [];
|
|
12775
|
+
const i = ids.indexOf(a);
|
|
12776
|
+
const j = ids.indexOf(b);
|
|
12777
|
+
if (i < 0 || j < 0) return [];
|
|
12778
|
+
return ids.slice(Math.min(i, j), Math.max(i, j) + 1);
|
|
12779
|
+
}
|
|
12780
|
+
/** How many ids carry each mark key. Ids with no mark are not counted. */
|
|
12781
|
+
function countMarks(marks, ids) {
|
|
12782
|
+
const out = {};
|
|
12783
|
+
for (const id of ids ?? Object.keys(marks)) {
|
|
12784
|
+
const m = marks[id];
|
|
12785
|
+
if (m) out[m] = (out[m] ?? 0) + 1;
|
|
12786
|
+
}
|
|
12787
|
+
return out;
|
|
12788
|
+
}
|
|
12789
|
+
/** The id `by` places from `from` in `ids`, held to the ends; the first (or last) when `from` is not set. */
|
|
12790
|
+
function stepId(ids, from, by) {
|
|
12791
|
+
if (ids.length === 0) return null;
|
|
12792
|
+
const i = from === null ? -1 : ids.indexOf(from);
|
|
12793
|
+
if (i < 0) return by >= 0 ? ids[0] : ids[ids.length - 1];
|
|
12794
|
+
return ids[Math.min(Math.max(i + by, 0), ids.length - 1)];
|
|
12795
|
+
}
|
|
12796
|
+
// src/components/markable-text.tsx
|
|
12797
|
+
var TONE = {
|
|
12798
|
+
neutral: {
|
|
12799
|
+
fill: "var(--muted)",
|
|
12800
|
+
edge: "var(--muted-foreground)"
|
|
12801
|
+
},
|
|
12802
|
+
info: {
|
|
12803
|
+
fill: "var(--info-subtle)",
|
|
12804
|
+
edge: "var(--info)"
|
|
12805
|
+
},
|
|
12806
|
+
success: {
|
|
12807
|
+
fill: "var(--success-subtle)",
|
|
12808
|
+
edge: "var(--success)"
|
|
12809
|
+
},
|
|
12810
|
+
warning: {
|
|
12811
|
+
fill: "var(--warning-subtle)",
|
|
12812
|
+
edge: "var(--warning)"
|
|
12813
|
+
},
|
|
12814
|
+
danger: {
|
|
12815
|
+
fill: "var(--danger-subtle)",
|
|
12816
|
+
edge: "var(--danger)"
|
|
12817
|
+
}
|
|
12818
|
+
};
|
|
12819
|
+
var MarksContext = React.createContext(null);
|
|
12820
|
+
/** One word (or phrase, or clip) that can be marked. Draws its mark, its selection and the caret; inside a `MarkableText`. */
|
|
12821
|
+
function Mark({ id, children, className }) {
|
|
12822
|
+
const c = React.useContext(MarksContext);
|
|
12823
|
+
if (!c) return /* @__PURE__ */ jsx("span", {
|
|
12824
|
+
className,
|
|
12825
|
+
children
|
|
12826
|
+
});
|
|
12827
|
+
const kind = c.kinds.find((k) => k.key === c.marks[id]);
|
|
12828
|
+
const tone = kind && TONE[kind.tone];
|
|
12829
|
+
const on = c.selected.has(id);
|
|
12830
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
12831
|
+
"data-mark-id": id,
|
|
12832
|
+
"data-mark": kind?.key,
|
|
12833
|
+
"data-selected": on || void 0,
|
|
12834
|
+
"data-caret": c.caret === id || void 0,
|
|
12835
|
+
onPointerDown: (e) => c.press(e, id),
|
|
12836
|
+
onPointerEnter: () => c.over(id),
|
|
12837
|
+
className: cn("cursor-text rounded-control px-px", on && "bg-primary/20", c.caret === id && "outline-2 outline-primary", className),
|
|
12838
|
+
style: kind && tone ? {
|
|
12839
|
+
backgroundColor: on ? void 0 : tone.fill,
|
|
12840
|
+
textDecorationLine: "underline",
|
|
12841
|
+
textDecorationStyle: kind.pattern,
|
|
12842
|
+
textDecorationColor: tone.edge,
|
|
12843
|
+
textDecorationThickness: "2px",
|
|
12844
|
+
textUnderlineOffset: "3px"
|
|
12845
|
+
} : void 0,
|
|
12846
|
+
children: [children, kind && /* @__PURE__ */ jsxs("span", {
|
|
12847
|
+
className: "sr-only",
|
|
12848
|
+
children: [
|
|
12849
|
+
" (",
|
|
12850
|
+
kind.label.toLowerCase(),
|
|
12851
|
+
")"
|
|
12852
|
+
]
|
|
12853
|
+
})]
|
|
12854
|
+
});
|
|
12855
|
+
}
|
|
12856
|
+
/** "12 words must use, 3 never": a count for each kind in use, with its icon. */
|
|
12857
|
+
function MarkSummary({ marks, kinds, unit = ["word", "words"], className }) {
|
|
12858
|
+
const counts = countMarks(marks);
|
|
12859
|
+
const used = kinds.filter((k) => counts[k.key]);
|
|
12860
|
+
if (!used.length) return /* @__PURE__ */ jsx("p", {
|
|
12861
|
+
className: cn("type-caption text-muted-foreground", className),
|
|
12862
|
+
children: "Nothing marked yet."
|
|
12863
|
+
});
|
|
12864
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
12865
|
+
"aria-label": "Marked",
|
|
12866
|
+
className: cn("flex flex-wrap gap-x-4 gap-y-1 type-body-sm", className),
|
|
12867
|
+
children: used.map((k) => {
|
|
12868
|
+
const Icon = k.icon;
|
|
12869
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
12870
|
+
className: "inline-flex items-center gap-1.5",
|
|
12871
|
+
children: [
|
|
12872
|
+
Icon && /* @__PURE__ */ jsx(Icon, {
|
|
12873
|
+
"aria-hidden": true,
|
|
12874
|
+
className: "size-4"
|
|
12875
|
+
}),
|
|
12876
|
+
/* @__PURE__ */ jsx("span", {
|
|
12877
|
+
className: "tabular-nums",
|
|
12878
|
+
children: format.count(counts[k.key], unit[0], unit[1])
|
|
12879
|
+
}),
|
|
12880
|
+
" ",
|
|
12881
|
+
k.label.toLowerCase()
|
|
12882
|
+
]
|
|
12883
|
+
}, k.key);
|
|
12884
|
+
})
|
|
12885
|
+
});
|
|
12886
|
+
}
|
|
12887
|
+
/** Selects ids over `<Mark>` words by drag, Shift+click and Shift+arrows (a run in the app's order, so it holds across virtualised rows), offers the app's marks as chorded commands in a bar, says each change in words, and lists what is marked. */
|
|
12888
|
+
function MarkableText({ label, ids, marks, kinds, onMark, clearKeys = [], onCaretChange, unit = ["word", "words"], summary = true, children, className }) {
|
|
12889
|
+
const [anchor, setAnchor] = React.useState(null);
|
|
12890
|
+
const [caret, setCaret] = React.useState(null);
|
|
12891
|
+
const [said, setSaid] = React.useState("");
|
|
12892
|
+
const dragging = React.useRef(false);
|
|
12893
|
+
const hintId = React.useId();
|
|
12894
|
+
const run = React.useMemo(() => rangeBetween(ids, anchor, caret), [
|
|
12895
|
+
ids,
|
|
12896
|
+
anchor,
|
|
12897
|
+
caret
|
|
12898
|
+
]);
|
|
12899
|
+
const selected = React.useMemo(() => new Set(run), [run]);
|
|
12900
|
+
const n = run.length;
|
|
12901
|
+
const counted = (k) => format.count(k, unit[0], unit[1]);
|
|
12902
|
+
const moveCaret = (id, extend) => {
|
|
12903
|
+
if (id === null) return;
|
|
12904
|
+
setCaret(id);
|
|
12905
|
+
if (!extend || anchor === null) setAnchor(id);
|
|
12906
|
+
onCaretChange?.(id);
|
|
12907
|
+
};
|
|
12908
|
+
const apply = (kind) => {
|
|
12909
|
+
if (!n) return;
|
|
12910
|
+
onMark(run, kind);
|
|
12911
|
+
const k = kinds.find((x) => x.key === kind);
|
|
12912
|
+
setSaid(kind === null ? `${counted(n)} cleared` : `${counted(n)} marked ${k?.label.toLowerCase() ?? kind}`);
|
|
12913
|
+
};
|
|
12914
|
+
const commands = [...kinds.map((k) => ({
|
|
12915
|
+
id: `mark-${k.key}`,
|
|
12916
|
+
label: k.label,
|
|
12917
|
+
keys: k.keys,
|
|
12918
|
+
icon: k.icon,
|
|
12919
|
+
disabled: n ? false : "Select words first",
|
|
12920
|
+
run: () => apply(k.key)
|
|
12921
|
+
})), {
|
|
12922
|
+
id: "mark-clear",
|
|
12923
|
+
label: "Clear mark",
|
|
12924
|
+
keys: clearKeys,
|
|
12925
|
+
disabled: n ? false : "Select words first",
|
|
12926
|
+
run: () => apply(null)
|
|
12927
|
+
}];
|
|
12928
|
+
useCommands(commands);
|
|
12929
|
+
React.useEffect(() => {
|
|
12930
|
+
const stop = () => dragging.current = false;
|
|
12931
|
+
window.addEventListener("pointerup", stop);
|
|
12932
|
+
return () => window.removeEventListener("pointerup", stop);
|
|
12933
|
+
}, []);
|
|
12934
|
+
const ctx = {
|
|
12935
|
+
kinds,
|
|
12936
|
+
marks,
|
|
12937
|
+
selected,
|
|
12938
|
+
caret,
|
|
12939
|
+
press: (e, id) => {
|
|
12940
|
+
if (e.button !== 0) return;
|
|
12941
|
+
dragging.current = true;
|
|
12942
|
+
if (e.shiftKey && anchor !== null) setCaret(id);
|
|
12943
|
+
else {
|
|
12944
|
+
setAnchor(id);
|
|
12945
|
+
setCaret(id);
|
|
12946
|
+
}
|
|
12947
|
+
onCaretChange?.(id);
|
|
12948
|
+
setSaid("");
|
|
12949
|
+
},
|
|
12950
|
+
over: (id) => {
|
|
12951
|
+
if (dragging.current && id !== caret) setCaret(id);
|
|
12952
|
+
}
|
|
12953
|
+
};
|
|
12954
|
+
React.useEffect(() => {
|
|
12955
|
+
if (n > 1) setSaid(`${counted(n)} selected`);
|
|
12956
|
+
else if (n === 1 && caret) setSaid(`${document.querySelector(`[data-mark-id="${CSS.escape(caret)}"]`)?.textContent ?? caret}`);
|
|
12957
|
+
}, [n, caret]);
|
|
12958
|
+
const keys = (e) => {
|
|
12959
|
+
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
|
12960
|
+
const to = e.key === "ArrowRight" ? stepId(ids, caret, 1) : e.key === "ArrowLeft" ? stepId(ids, caret, -1) : e.key === "Home" ? ids[0] ?? null : e.key === "End" ? ids[ids.length - 1] ?? null : void 0;
|
|
12961
|
+
if (to !== void 0) {
|
|
12962
|
+
e.preventDefault();
|
|
12963
|
+
moveCaret(to, e.shiftKey);
|
|
12964
|
+
} else if (e.key === "Escape" && (anchor !== null || caret !== null)) {
|
|
12965
|
+
e.preventDefault();
|
|
12966
|
+
setAnchor(null);
|
|
12967
|
+
setCaret(null);
|
|
12968
|
+
setSaid("Selection cleared");
|
|
12969
|
+
}
|
|
12970
|
+
};
|
|
12971
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
12972
|
+
className: cn("space-y-2", className),
|
|
12973
|
+
children: [
|
|
12974
|
+
n > 0 && /* @__PURE__ */ jsxs(Toolbar, {
|
|
12975
|
+
label: "Marks",
|
|
12976
|
+
className: "sticky top-0 z-10 flex flex-wrap items-center gap-2 rounded-surface border border-border bg-background p-1.5",
|
|
12977
|
+
children: [
|
|
12978
|
+
/* @__PURE__ */ jsxs("span", {
|
|
12979
|
+
className: "px-1 type-label tabular-nums",
|
|
12980
|
+
children: [counted(n), " selected"]
|
|
12981
|
+
}),
|
|
12982
|
+
kinds.map((k) => {
|
|
12983
|
+
const Icon = k.icon;
|
|
12984
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
12985
|
+
size: "sm",
|
|
12986
|
+
onPress: () => apply(k.key),
|
|
12987
|
+
children: [
|
|
12988
|
+
Icon && /* @__PURE__ */ jsx(Icon, {}),
|
|
12989
|
+
" ",
|
|
12990
|
+
k.label
|
|
12991
|
+
]
|
|
12992
|
+
}, k.key);
|
|
12993
|
+
}),
|
|
12994
|
+
/* @__PURE__ */ jsx(Button, {
|
|
12995
|
+
size: "sm",
|
|
12996
|
+
variant: "ghost",
|
|
12997
|
+
onPress: () => apply(null),
|
|
12998
|
+
children: "Clear mark"
|
|
12999
|
+
}),
|
|
13000
|
+
/* @__PURE__ */ jsx(Button, {
|
|
13001
|
+
size: "sm",
|
|
13002
|
+
variant: "ghost",
|
|
13003
|
+
onPress: () => {
|
|
13004
|
+
setAnchor(null);
|
|
13005
|
+
setCaret(null);
|
|
13006
|
+
},
|
|
13007
|
+
children: "Deselect"
|
|
13008
|
+
})
|
|
13009
|
+
]
|
|
13010
|
+
}),
|
|
13011
|
+
/* @__PURE__ */ jsx(MarksContext.Provider, {
|
|
13012
|
+
value: ctx,
|
|
13013
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
13014
|
+
role: "group",
|
|
13015
|
+
"aria-label": label,
|
|
13016
|
+
"aria-describedby": hintId,
|
|
13017
|
+
tabIndex: 0,
|
|
13018
|
+
onKeyDown: keys,
|
|
13019
|
+
className: "select-none rounded-surface outline-offset-2",
|
|
13020
|
+
children
|
|
13021
|
+
})
|
|
13022
|
+
}),
|
|
13023
|
+
/* @__PURE__ */ jsx("p", {
|
|
13024
|
+
id: hintId,
|
|
13025
|
+
className: "type-caption text-muted-foreground",
|
|
13026
|
+
children: "Drag across words, or Shift+click, to select. Left and Right move; Shift and arrows select; Escape clears."
|
|
13027
|
+
}),
|
|
13028
|
+
/* @__PURE__ */ jsx(CommandLegend, {
|
|
13029
|
+
commands,
|
|
13030
|
+
label: "Mark keys"
|
|
13031
|
+
}),
|
|
13032
|
+
summary && /* @__PURE__ */ jsx(MarkSummary, {
|
|
13033
|
+
marks,
|
|
13034
|
+
kinds,
|
|
13035
|
+
unit
|
|
13036
|
+
}),
|
|
13037
|
+
/* @__PURE__ */ jsx("div", {
|
|
13038
|
+
role: "status",
|
|
13039
|
+
"aria-live": "polite",
|
|
13040
|
+
className: "sr-only",
|
|
13041
|
+
children: said
|
|
13042
|
+
})
|
|
13043
|
+
]
|
|
13044
|
+
});
|
|
13045
|
+
}
|
|
13046
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, ContextMenu, Conversation, CursorScope, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, PlayWindowButton, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, SaveStatus, SeekBar, SelectableGrid, SequenceTimeline, SideNav, Skeleton, Slider, SortableList, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewportFrame, VirtualList, VolumeControl, Waveform, Workspace, actualPixelsScale, ancestorsOf, boxViewport, buttonVariants, canFullscreen, clampToRoom, clampViewport, cn, colorSchemeScript, commandShortcut, countMarks, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, describeRegion, detectPlatform, diffWords, differences, drawRect, ease, fetchJson, fieldErrorsOf, fitRect, format, formatChord, gainToVolume, geo, gridPoints, isReservedChord, isTypingTarget, joinMediaGroup, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveRect, noOverlap, parentOf, parseChord, parseInline, parseRichText, parseSort, peaksFromAudio, phraseAt, plainText, rangeBetween, readErrorBody, readPixels, regionShares, resample, resamplePeaks, resizeRect, safeHref, serialiseSort, settleCut, snapToGrid, staleOf, stepId, stepOnGrid, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useMediaElement, useSelection, useSharedCursor, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, useWorkspaceState, valueAt, wordAt, zoomAt };
|
|
10161
13047
|
|
|
10162
13048
|
//# sourceMappingURL=index.js.map
|