strata-react 1.3.19 → 1.3.20

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.
Files changed (49) hide show
  1. package/README.md +31 -6
  2. package/UPGRADING.md +7 -1
  3. package/dist/{errors-jep2voNI.js → button-KGJI6jQr.js} +3 -95
  4. package/dist/button-KGJI6jQr.js.map +1 -0
  5. package/dist/components/byte-view.d.ts +32 -0
  6. package/dist/components/console.d.ts +34 -0
  7. package/dist/components/disclosure.d.ts +2 -0
  8. package/dist/components/file-intake.d.ts +9 -0
  9. package/dist/components/hotkeys.d.ts +4 -0
  10. package/dist/components/pixel-image.d.ts +29 -0
  11. package/dist/components/shortcut-editor.d.ts +44 -0
  12. package/dist/components/tree.d.ts +4 -2
  13. package/dist/components/workspace.d.ts +22 -2
  14. package/dist/errors-BUvY1Z4d.js +95 -0
  15. package/dist/errors-BUvY1Z4d.js.map +1 -0
  16. package/dist/{field-t4Hoer0d.js → field-BjeE_FeB.js} +6 -101
  17. package/dist/field-BjeE_FeB.js.map +1 -0
  18. package/dist/index.d.ts +8 -3
  19. package/dist/index.js +937 -13
  20. package/dist/index.js.map +1 -1
  21. package/dist/lib/object-url.d.ts +2 -0
  22. package/dist/map.js +3 -2
  23. package/dist/map.js.map +1 -1
  24. package/dist/{microphone-B5ITwm4G.js → microphone-Bo3WaXgD.js} +5 -3
  25. package/dist/{microphone-B5ITwm4G.js.map → microphone-Bo3WaXgD.js.map} +1 -1
  26. package/dist/panorama.js +3 -3
  27. package/dist/scene/camera.d.ts +71 -0
  28. package/dist/scene/index.d.ts +2 -0
  29. package/dist/scene/scene-viewport.d.ts +46 -0
  30. package/dist/scene.js +526 -0
  31. package/dist/scene.js.map +1 -0
  32. package/dist/strata.bare.css +1 -0
  33. package/dist/strata.css +1 -0
  34. package/dist/strata.migrate.css +1 -0
  35. package/dist/testing/index.d.ts +1 -0
  36. package/dist/testing/layout.d.ts +1 -1
  37. package/dist/testing/setup.d.ts +14 -0
  38. package/dist/testing.js +21 -5
  39. package/dist/testing.js.map +1 -1
  40. package/dist/{theme-DXacprlw.js → theme-CxYZkUNk.js} +3 -2
  41. package/dist/{theme-DXacprlw.js.map → theme-CxYZkUNk.js.map} +1 -1
  42. package/dist/tooltip-DhqrDtyu.js +103 -0
  43. package/dist/tooltip-DhqrDtyu.js.map +1 -0
  44. package/dist/{value-controls-DB5l5Qe2.js → value-controls-Dq2-QpvA.js} +8 -4
  45. package/dist/value-controls-Dq2-QpvA.js.map +1 -0
  46. package/package.json +6 -1
  47. package/dist/errors-jep2voNI.js.map +0 -1
  48. package/dist/field-t4Hoer0d.js.map +0 -1
  49. package/dist/value-controls-DB5l5Qe2.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
- import { _ as typeSteps, a as Textarea, c as useSearchParam, d as MISSING, f as NBSP, g as cn, h as toDate, i as NativeSelect, l as Tooltip, m as format, n as Field, o as useFieldControl, p as createFormat, r as Input, s as controlHeight, t as ChoiceGroup, u as KeyText } from "./field-t4Hoer0d.js";
2
- import { a as fieldErrorsOf, c as IconButton, d as isDev, f as useInView, i as errorPayload, l as RowAction, n as describeActionError, o as readErrorBody, r as describeHttpError, s as Button, t as HttpError, u as buttonVariants } from "./errors-jep2voNI.js";
3
- import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-B5ITwm4G.js";
4
- import { a as useAsyncAction, c as KeysLegend, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as useHotkeys } from "./value-controls-DB5l5Qe2.js";
1
+ import { i as typeSteps, n as KeyText, r as cn, t as Tooltip } from "./tooltip-DhqrDtyu.js";
2
+ import { a as Textarea, c as useSearchParam, d as createFormat, f as format, i as NativeSelect, l as MISSING, n as Field, o as useFieldControl, p as toDate, r as Input, s as controlHeight, t as ChoiceGroup, u as NBSP } from "./field-BjeE_FeB.js";
3
+ import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-KGJI6jQr.js";
4
+ import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-Bo3WaXgD.js";
5
+ import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-Dq2-QpvA.js";
5
6
  import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-DDGBPiTJ.js";
6
- import { a as PaletteChoice, c as paletteScript, d as usePalette, f as useSystemColorScheme, i as PALETTE_STORAGE_KEY, l as palettes, n as ColorSchemeChoice, o as ThemeProvider, p as Density, r as DEFAULT_PALETTE, s as colorSchemeScript, t as COLOR_SCHEME_STORAGE_KEY, u as useColorScheme } from "./theme-DXacprlw.js";
7
+ import { a as fieldErrorsOf, i as errorPayload, n as describeActionError, o as readErrorBody, r as describeHttpError, t as HttpError } from "./errors-BUvY1Z4d.js";
8
+ import { a as PaletteChoice, c as paletteScript, d as usePalette, f as useSystemColorScheme, i as PALETTE_STORAGE_KEY, l as palettes, n as ColorSchemeChoice, o as ThemeProvider, p as Density, r as DEFAULT_PALETTE, s as colorSchemeScript, t as COLOR_SCHEME_STORAGE_KEY, u as useColorScheme } from "./theme-CxYZkUNk.js";
7
9
  import * as React from "react";
8
10
  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, Link, ListBox, ListBoxItem, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, RouterProvider, Row, SearchField, Select, SelectValue, 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, Tree as Tree$1, TreeItem, TreeItemContent, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
9
11
  import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronDown, ChevronLeft, ChevronRight, CircleAlert, CircleCheck, CircleDashed, Clock, CloudOff, Columns2, Ellipsis, Eye, EyeOff, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, Pencil, Play, Redo2, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
@@ -2812,6 +2814,12 @@ function api(expanded, set, single) {
2812
2814
  else next.delete(key);
2813
2815
  set(next);
2814
2816
  },
2817
+ toggle: (key) => {
2818
+ const next = single ? /* @__PURE__ */ new Set() : new Set(expanded);
2819
+ if (expanded.has(key)) next.delete(key);
2820
+ else next.add(key);
2821
+ set(next);
2822
+ },
2815
2823
  collapseAll: () => set(/* @__PURE__ */ new Set())
2816
2824
  };
2817
2825
  }
@@ -8012,6 +8020,82 @@ function FileDropZone({ onFiles, acceptLabel, title, disabled, refuseTypes, chil
8012
8020
  ] })
8013
8021
  });
8014
8022
  }
8023
+ var carriesFiles = (e, refuse) => {
8024
+ const types = Array.from(e.dataTransfer?.types ?? []);
8025
+ return types.includes("Files") && !refusesDrag({ has: (type) => types.includes(type) }, ["application/x-strata-drag", ...refuse]);
8026
+ };
8027
+ /** While files are dragged anywhere over the window, a dim overlay names what is taken ("Drop to add PAK files"); a drop calls `onFiles`. The app's own drags never trigger it. Keep a `FileButton` beside it for the keyboard and phones. */
8028
+ function FileDropOverlay({ onFiles, acceptLabel, disabled, refuseTypes }) {
8029
+ const [over, setOver] = React.useState(false);
8030
+ const live = React.useRef({
8031
+ onFiles,
8032
+ refuseTypes: refuseTypes ?? []
8033
+ });
8034
+ live.current = {
8035
+ onFiles,
8036
+ refuseTypes: refuseTypes ?? []
8037
+ };
8038
+ React.useEffect(() => {
8039
+ if (disabled) return;
8040
+ let depth = 0;
8041
+ const reset = () => {
8042
+ depth = 0;
8043
+ setOver(false);
8044
+ };
8045
+ const enter = (e) => {
8046
+ if (!carriesFiles(e, live.current.refuseTypes)) return;
8047
+ depth += 1;
8048
+ setOver(true);
8049
+ };
8050
+ const hover = (e) => {
8051
+ if (!carriesFiles(e, live.current.refuseTypes)) return;
8052
+ e.preventDefault();
8053
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
8054
+ };
8055
+ const leave = (e) => {
8056
+ if (!carriesFiles(e, live.current.refuseTypes)) return;
8057
+ depth = Math.max(0, depth - 1);
8058
+ if (depth === 0) setOver(false);
8059
+ };
8060
+ const drop = (e) => {
8061
+ const wanted = carriesFiles(e, live.current.refuseTypes);
8062
+ reset();
8063
+ if (!wanted || e.defaultPrevented) return;
8064
+ e.preventDefault();
8065
+ const files = Array.from(e.dataTransfer?.items ?? []).filter((i) => i.kind === "file").map((i) => i.getAsFile()).filter((f) => f !== null);
8066
+ const list = files.length ? files : Array.from(e.dataTransfer?.files ?? []);
8067
+ if (list.length) live.current.onFiles(list);
8068
+ };
8069
+ document.addEventListener("dragenter", enter);
8070
+ document.addEventListener("dragover", hover);
8071
+ document.addEventListener("dragleave", leave);
8072
+ document.addEventListener("drop", drop);
8073
+ document.addEventListener("dragend", reset);
8074
+ return () => {
8075
+ document.removeEventListener("dragenter", enter);
8076
+ document.removeEventListener("dragover", hover);
8077
+ document.removeEventListener("dragleave", leave);
8078
+ document.removeEventListener("drop", drop);
8079
+ document.removeEventListener("dragend", reset);
8080
+ };
8081
+ }, [disabled]);
8082
+ if (!over || disabled) return null;
8083
+ return /* @__PURE__ */ jsx("div", {
8084
+ "aria-hidden": true,
8085
+ "data-file-drop-overlay": true,
8086
+ className: "pointer-events-none fixed inset-0 layer-overlay grid place-items-center scrim p-6",
8087
+ children: /* @__PURE__ */ jsxs("div", {
8088
+ className: "flex items-center gap-3 rounded-overlay border-2 border-dashed border-primary bg-background px-6 py-5 shadow-overlay",
8089
+ children: [/* @__PURE__ */ jsx(Upload, {
8090
+ "aria-hidden": true,
8091
+ className: "size-5 text-primary"
8092
+ }), /* @__PURE__ */ jsxs("p", {
8093
+ className: "type-heading",
8094
+ children: ["Drop to add ", acceptLabel]
8095
+ })]
8096
+ })
8097
+ });
8098
+ }
8015
8099
  var rowStatus = {
8016
8100
  processing: {
8017
8101
  tone: "info",
@@ -8128,6 +8212,812 @@ function MissingFile({ name, accept, onRelink, thumbnail, className }) {
8128
8212
  })]
8129
8213
  });
8130
8214
  }
8215
+ // src/lib/object-url.ts
8216
+ /** Bytes (or a Blob) as an object URL: made once per value, revoked when the value changes or the component unmounts. `null` until made, and for `null` data. `type` is the MIME type for bytes ("audio/wav"); a Blob keeps its own unless `type` is given. */
8217
+ function useObjectUrl(data, type) {
8218
+ const [url, setUrl] = React.useState(null);
8219
+ React.useEffect(() => {
8220
+ if (data === null || data === void 0) {
8221
+ setUrl(null);
8222
+ return;
8223
+ }
8224
+ const blob = data instanceof Blob && (type === void 0 || data.type === type) ? data : new Blob([data], type ? { type } : void 0);
8225
+ const made = URL.createObjectURL(blob);
8226
+ setUrl(made);
8227
+ return () => {
8228
+ URL.revokeObjectURL(made);
8229
+ setUrl((now) => now === made ? null : now);
8230
+ };
8231
+ }, [data, type]);
8232
+ return url;
8233
+ }
8234
+ // src/components/pixel-image.tsx
8235
+ var sizeOf = (p) => p.image ? {
8236
+ width: p.image.width,
8237
+ height: p.image.height,
8238
+ data: p.image.data
8239
+ } : {
8240
+ width: p.width,
8241
+ height: p.height,
8242
+ data: p.rgba
8243
+ };
8244
+ /** The zoom a picture is drawn at: a whole number, at least 1. */
8245
+ function pixelZoom(width, height, zoom = "fit", maxSize = 512) {
8246
+ if (typeof zoom === "number") return Math.max(1, Math.round(zoom));
8247
+ return Math.max(1, Math.floor(maxSize / Math.max(1, width, height)));
8248
+ }
8249
+ /** A decoded RGBA picture on a canvas at a whole-number zoom with square pixels, a checkerboard behind clear pixels, named with its size. */
8250
+ function PixelImage({ label, zoom = "fit", maxSize = 512, className, ...source }) {
8251
+ const { width, height, data } = sizeOf(source);
8252
+ const canvas = React.useRef(null);
8253
+ const complete = data.length === width * height * 4 && width > 0 && height > 0;
8254
+ const scale = pixelZoom(width, height, zoom, maxSize);
8255
+ React.useEffect(() => {
8256
+ const el = canvas.current;
8257
+ if (!el || !complete) return;
8258
+ let ctx = null;
8259
+ try {
8260
+ ctx = el.getContext("2d");
8261
+ } catch {
8262
+ ctx = null;
8263
+ }
8264
+ if (!ctx) return;
8265
+ const picture = ctx.createImageData(width, height);
8266
+ picture.data.set(data);
8267
+ ctx.putImageData(picture, 0, 0);
8268
+ }, [
8269
+ data,
8270
+ width,
8271
+ height,
8272
+ complete
8273
+ ]);
8274
+ if (!complete) return /* @__PURE__ */ jsx("span", {
8275
+ role: "img",
8276
+ "aria-label": `${label}, no picture data`,
8277
+ className: cn("inline-grid min-h-16 min-w-40 place-items-center rounded-control border border-dashed border-border bg-surface-sunken px-3 type-body-sm text-muted-foreground", className),
8278
+ children: /* @__PURE__ */ jsx("span", {
8279
+ "aria-hidden": true,
8280
+ children: "No picture data"
8281
+ })
8282
+ });
8283
+ const name = `${label}, ${format.integer(width)} by ${format.integer(height)} pixels${scale > 1 ? `, shown at ${scale}×` : ""}`;
8284
+ return /* @__PURE__ */ jsx("span", {
8285
+ className: cn("inline-block w-fit max-w-full overflow-auto rounded-control align-top", className),
8286
+ style: {
8287
+ backgroundColor: "var(--surface-sunken)",
8288
+ backgroundImage: "conic-gradient(var(--muted) 25%, transparent 0 50%, var(--muted) 0 75%, transparent 0)",
8289
+ backgroundSize: "16px 16px"
8290
+ },
8291
+ children: /* @__PURE__ */ jsx("canvas", {
8292
+ ref: canvas,
8293
+ role: "img",
8294
+ "aria-label": name,
8295
+ width,
8296
+ height,
8297
+ className: "image-pixelated block",
8298
+ style: {
8299
+ width: width * scale,
8300
+ height: height * scale
8301
+ }
8302
+ })
8303
+ });
8304
+ }
8305
+ /** The same pixels as a PNG `Blob`, for a download (`useObjectUrl` makes the link). Rejects where there is no canvas. */
8306
+ function rgbaToBlob(width, height, rgba) {
8307
+ return new Promise((resolve, reject) => {
8308
+ const el = document.createElement("canvas");
8309
+ el.width = width;
8310
+ el.height = height;
8311
+ const ctx = el.getContext("2d");
8312
+ if (!ctx) return reject(/* @__PURE__ */ new Error("This browser cannot draw the picture, so it cannot be saved."));
8313
+ const picture = ctx.createImageData(width, height);
8314
+ picture.data.set(rgba);
8315
+ ctx.putImageData(picture, 0, 0);
8316
+ el.toBlob((blob) => blob ? resolve(blob) : reject(/* @__PURE__ */ new Error("The picture could not be saved.")), "image/png");
8317
+ });
8318
+ }
8319
+ // src/components/byte-view.tsx
8320
+ var PER_ROW = 16;
8321
+ var ROW_PX = 20;
8322
+ var OVERSCAN = 4;
8323
+ var MAX_PX = 8e6;
8324
+ var tints = {
8325
+ neutral: "bg-muted",
8326
+ info: "bg-info-subtle",
8327
+ success: "bg-success-subtle",
8328
+ warning: "bg-warning-subtle",
8329
+ danger: "bg-danger-subtle"
8330
+ };
8331
+ var cellStyle = (k) => ({
8332
+ width: "2ch",
8333
+ marginLeft: k === 8 ? "1ch" : void 0
8334
+ });
8335
+ var hex = (n, width = 2) => n.toString(16).padStart(width, "0");
8336
+ var tintOf = (h) => h ? tints[h.tone ?? "neutral"] : void 0;
8337
+ var printable = (b) => b >= 32 && b < 127 ? String.fromCharCode(b) : "·";
8338
+ /** A virtualised hex dump: offsets, sixteen bytes a row and the printable characters, byte and range keyboard, and the selected range reported as `{ start, end }`. */
8339
+ function ByteView({ bytes, label, offset = 0, highlight, defaultSelection, onSelectionChange, height = 320, className }) {
8340
+ const total = bytes.length;
8341
+ const rows = Math.ceil(total / PER_ROW);
8342
+ const visibleRows = Math.max(1, Math.floor(height / ROW_PX));
8343
+ const fullHeight = rows * ROW_PX;
8344
+ const spacer = Math.max(Math.min(fullHeight, MAX_PX), height);
8345
+ const scrollRange = Math.max(0, spacer - height);
8346
+ const rowRange = Math.max(0, rows - height / ROW_PX);
8347
+ const rowAt = (top) => scrollRange > 0 ? top / scrollRange * rowRange : 0;
8348
+ const topOfRow = (row) => rowRange > 0 ? row / rowRange * scrollRange : 0;
8349
+ const scroller = React.useRef(null);
8350
+ const [scrollTop, setScrollTop] = React.useState(0);
8351
+ const firstFloat = rowAt(scrollTop);
8352
+ const first = Math.min(Math.max(0, rows - 1), Math.floor(firstFloat));
8353
+ const fraction = firstFloat - first;
8354
+ const [rawAnchor, setAnchor] = React.useState(defaultSelection ? defaultSelection.start : null);
8355
+ const [rawCursor, setCursor] = React.useState(defaultSelection ? Math.max(defaultSelection.start, defaultSelection.end - 1) : null);
8356
+ const clampTo = (n) => n === null || total === 0 ? null : Math.min(n, total - 1);
8357
+ const anchor = clampTo(rawAnchor);
8358
+ const cursor = clampTo(rawCursor);
8359
+ const range = anchor === null || cursor === null ? null : {
8360
+ start: Math.min(anchor, cursor),
8361
+ end: Math.max(anchor, cursor) + 1
8362
+ };
8363
+ const notify = React.useRef(onSelectionChange);
8364
+ notify.current = onSelectionChange;
8365
+ const select = (nextAnchor, nextCursor) => {
8366
+ setAnchor(nextAnchor);
8367
+ setCursor(nextCursor);
8368
+ notify.current?.({
8369
+ start: Math.min(nextAnchor, nextCursor),
8370
+ end: Math.max(nextAnchor, nextCursor) + 1
8371
+ });
8372
+ };
8373
+ const reveal = (index) => {
8374
+ const el = scroller.current;
8375
+ if (!el) return;
8376
+ const row = Math.floor(index / PER_ROW);
8377
+ const now = rowAt(el.scrollTop);
8378
+ if (row < Math.ceil(now)) el.scrollTop = topOfRow(row);
8379
+ else if (row >= Math.floor(now) + visibleRows) el.scrollTop = topOfRow(row - visibleRows + 1);
8380
+ setScrollTop(el.scrollTop);
8381
+ };
8382
+ const move = (to, extend) => {
8383
+ if (total === 0) return;
8384
+ const index = Math.min(Math.max(0, to), total - 1);
8385
+ select(extend && anchor !== null ? anchor : index, index);
8386
+ reveal(index);
8387
+ };
8388
+ const onKeyDown = (e) => {
8389
+ if (total === 0) return;
8390
+ const at = cursor ?? 0;
8391
+ const extend = e.shiftKey;
8392
+ const rowStart = Math.floor(at / PER_ROW) * PER_ROW;
8393
+ switch (e.key) {
8394
+ case "ArrowLeft":
8395
+ move(cursor === null ? 0 : at - 1, extend);
8396
+ break;
8397
+ case "ArrowRight":
8398
+ move(cursor === null ? 0 : at + 1, extend);
8399
+ break;
8400
+ case "ArrowUp":
8401
+ move(cursor === null ? 0 : at - PER_ROW, extend);
8402
+ break;
8403
+ case "ArrowDown":
8404
+ move(cursor === null ? 0 : at + PER_ROW, extend);
8405
+ break;
8406
+ case "PageUp":
8407
+ move(at - visibleRows * PER_ROW, extend);
8408
+ break;
8409
+ case "PageDown":
8410
+ move(at + visibleRows * PER_ROW, extend);
8411
+ break;
8412
+ case "Home":
8413
+ move(e.ctrlKey || e.metaKey ? 0 : rowStart, extend);
8414
+ break;
8415
+ case "End":
8416
+ move(e.ctrlKey || e.metaKey ? total - 1 : rowStart + PER_ROW - 1, extend);
8417
+ break;
8418
+ case "Escape":
8419
+ if (cursor === null || anchor === cursor) return;
8420
+ select(cursor, cursor);
8421
+ break;
8422
+ default: return;
8423
+ }
8424
+ e.preventDefault();
8425
+ };
8426
+ const byteAt = (target) => {
8427
+ const cell = target?.closest?.("[data-i]");
8428
+ return cell ? Number(cell.dataset.i) : null;
8429
+ };
8430
+ const onPointerDown = (e) => {
8431
+ if (e.button !== 0) return;
8432
+ const i = byteAt(e.target);
8433
+ e.currentTarget.focus({ preventScroll: true });
8434
+ if (i === null) return;
8435
+ select(e.shiftKey && anchor !== null ? anchor : i, i);
8436
+ };
8437
+ const onPointerMove = (e) => {
8438
+ if (!(e.buttons & 1) || anchor === null) return;
8439
+ const i = byteAt(e.target);
8440
+ if (i !== null && i !== cursor) select(anchor, i);
8441
+ };
8442
+ const hexWidth = Math.max(6, hex(offset + Math.max(0, total - 1), 1).length);
8443
+ const marked = (i) => highlight?.find((h) => i >= h.start && i < h.end);
8444
+ const said = (() => {
8445
+ if (cursor === null || range === null) return "";
8446
+ const b = bytes[cursor];
8447
+ const inside = marked(cursor)?.label;
8448
+ const count = range.end - range.start;
8449
+ return `${`Byte 0x${hex(offset + cursor, 1)} of ${format.integer(total)}: ${hex(b)}, ${b}`}${count > 1 ? `; ${format.integer(count)} bytes selected, 0x${hex(offset + range.start, 1)} to 0x${hex(offset + range.end - 1, 1)}` : ""}${inside ? `; in ${inside}` : ""}`;
8450
+ })();
8451
+ const lastRow = Math.min(rows - 1, first + visibleRows + OVERSCAN);
8452
+ const drawn = [];
8453
+ for (let r = Math.max(0, first - OVERSCAN); r <= lastRow; r++) drawn.push(r);
8454
+ return /* @__PURE__ */ jsxs("div", {
8455
+ className: cn("grid min-w-0 gap-1", className),
8456
+ children: [/* @__PURE__ */ jsx("div", {
8457
+ role: "group",
8458
+ "aria-label": `${label}, ${format.integer(total)} ${total === 1 ? "byte" : "bytes"}`,
8459
+ tabIndex: 0,
8460
+ onKeyDown,
8461
+ onFocus: (e) => {
8462
+ if (e.target === e.currentTarget && cursor === null && total > 0) select(0, 0);
8463
+ },
8464
+ onPointerDown,
8465
+ onPointerMove,
8466
+ className: "min-w-0 overflow-x-auto rounded-control border border-border bg-surface-sunken font-mono type-body-sm tabular-nums outline-offset-2 select-none",
8467
+ children: /* @__PURE__ */ jsxs("div", {
8468
+ "aria-hidden": true,
8469
+ className: "w-max min-w-full",
8470
+ children: [/* @__PURE__ */ jsxs("div", {
8471
+ className: "flex h-5 items-center gap-3 border-b border-border px-3 text-muted-foreground",
8472
+ children: [
8473
+ /* @__PURE__ */ jsx("span", {
8474
+ style: { width: `${hexWidth}ch` },
8475
+ children: "Offset"
8476
+ }),
8477
+ /* @__PURE__ */ jsx("span", {
8478
+ className: "flex",
8479
+ style: { columnGap: "1ch" },
8480
+ children: Array.from({ length: PER_ROW }, (_, i) => /* @__PURE__ */ jsx("span", {
8481
+ className: "text-center",
8482
+ style: cellStyle(i),
8483
+ children: hex(i)
8484
+ }, i))
8485
+ }),
8486
+ /* @__PURE__ */ jsx("span", { children: "Text" })
8487
+ ]
8488
+ }), /* @__PURE__ */ jsx("div", {
8489
+ ref: scroller,
8490
+ onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
8491
+ className: "overflow-y-auto",
8492
+ style: { height },
8493
+ children: /* @__PURE__ */ jsx("div", {
8494
+ style: { height: spacer },
8495
+ className: "relative",
8496
+ children: /* @__PURE__ */ jsx("div", {
8497
+ className: "sticky top-0 overflow-hidden",
8498
+ style: { height },
8499
+ children: /* @__PURE__ */ jsx("div", {
8500
+ style: { transform: `translateY(${-fraction * ROW_PX}px)` },
8501
+ children: drawn.map((r) => {
8502
+ const base = r * PER_ROW;
8503
+ const count = Math.min(PER_ROW, total - base);
8504
+ return /* @__PURE__ */ jsxs("div", {
8505
+ "data-row": r,
8506
+ className: "flex items-center gap-3 px-3",
8507
+ style: {
8508
+ height: ROW_PX,
8509
+ position: "absolute",
8510
+ top: (r - first) * ROW_PX,
8511
+ left: 0,
8512
+ right: 0
8513
+ },
8514
+ children: [
8515
+ /* @__PURE__ */ jsx("span", {
8516
+ className: "text-muted-foreground",
8517
+ style: { width: `${hexWidth}ch` },
8518
+ children: hex(offset + base, hexWidth)
8519
+ }),
8520
+ /* @__PURE__ */ jsx("span", {
8521
+ className: "flex",
8522
+ style: { columnGap: "1ch" },
8523
+ children: Array.from({ length: PER_ROW }, (_, k) => {
8524
+ const i = base + k;
8525
+ if (k >= count) return /* @__PURE__ */ jsx("span", { style: cellStyle(k) }, k);
8526
+ const inRange = range !== null && i >= range.start && i < range.end;
8527
+ return /* @__PURE__ */ jsx("span", {
8528
+ "data-i": i,
8529
+ "data-selected": inRange || void 0,
8530
+ "data-cursor": i === cursor || void 0,
8531
+ style: cellStyle(k),
8532
+ className: cn("rounded-control text-center", inRange ? "bg-primary text-primary-foreground" : tintOf(marked(i)), i === cursor && "outline-2 outline-ring"),
8533
+ children: hex(bytes[i])
8534
+ }, k);
8535
+ })
8536
+ }),
8537
+ /* @__PURE__ */ jsx("span", {
8538
+ className: "flex",
8539
+ children: Array.from({ length: count }, (_, k) => {
8540
+ const i = base + k;
8541
+ const inRange = range !== null && i >= range.start && i < range.end;
8542
+ return /* @__PURE__ */ jsx("span", {
8543
+ "data-i": i,
8544
+ style: { width: "1ch" },
8545
+ className: cn("text-center", inRange ? "bg-primary text-primary-foreground" : tintOf(marked(i))),
8546
+ children: printable(bytes[i])
8547
+ }, k);
8548
+ })
8549
+ })
8550
+ ]
8551
+ }, r);
8552
+ })
8553
+ })
8554
+ })
8555
+ })
8556
+ })]
8557
+ })
8558
+ }), /* @__PURE__ */ jsx("p", {
8559
+ role: "status",
8560
+ className: "type-caption text-muted-foreground tabular-nums",
8561
+ children: total === 0 ? "No bytes." : said
8562
+ })]
8563
+ });
8564
+ }
8565
+ // src/components/console.tsx
8566
+ var LEVEL_WORD = {
8567
+ warning: {
8568
+ word: "Warning",
8569
+ tone: "warning"
8570
+ },
8571
+ error: {
8572
+ word: "Error",
8573
+ tone: "danger"
8574
+ }
8575
+ };
8576
+ var lineKey = (line) => String(line.id);
8577
+ function readHistory(key) {
8578
+ if (!key) return [];
8579
+ try {
8580
+ const parsed = JSON.parse(window.localStorage.getItem(key) ?? "[]");
8581
+ return Array.isArray(parsed) ? parsed.filter((c) => typeof c === "string").slice(-100) : [];
8582
+ } catch {
8583
+ return [];
8584
+ }
8585
+ }
8586
+ /** The longest start every string shares. */
8587
+ function commonStart(items) {
8588
+ if (items.length === 0) return "";
8589
+ let prefix = items[0];
8590
+ for (const item of items) while (!item.startsWith(prefix)) prefix = prefix.slice(0, -1);
8591
+ return prefix;
8592
+ }
8593
+ /** A command console: a polite, virtualised log pinned to its end, above a command line with history (Up, Down) and Tab completion from the app's list. */
8594
+ function Console({ label, lines, onCommand, complete, historyKey, height = 320, lineHeight, commandLabel = "Command", inputRef, className }) {
8595
+ const [text, setText] = React.useState("");
8596
+ const history = React.useRef(readHistory(historyKey));
8597
+ const [cursor, setCursor] = React.useState(null);
8598
+ const draft = React.useRef("");
8599
+ const [matches, setMatches] = React.useState([]);
8600
+ const box = React.useRef(null);
8601
+ const [pinned, setPinned] = React.useState(true);
8602
+ const scroller = () => box.current?.querySelector("[data-strata-scroll]") ?? null;
8603
+ const toEnd = React.useCallback(() => {
8604
+ const el = scroller();
8605
+ if (el) el.scrollTop = el.scrollHeight;
8606
+ }, []);
8607
+ React.useEffect(() => {
8608
+ const el = scroller();
8609
+ if (!el) return;
8610
+ const onScroll = () => setPinned(el.scrollHeight - el.scrollTop - el.clientHeight < 8);
8611
+ el.addEventListener("scroll", onScroll);
8612
+ return () => el.removeEventListener("scroll", onScroll);
8613
+ });
8614
+ React.useLayoutEffect(() => {
8615
+ if (pinned) toEnd();
8616
+ const frame = requestAnimationFrame(() => pinned && toEnd());
8617
+ return () => cancelAnimationFrame(frame);
8618
+ }, [
8619
+ lines,
8620
+ pinned,
8621
+ toEnd
8622
+ ]);
8623
+ const run = () => {
8624
+ const command = text.trim();
8625
+ if (!command) return;
8626
+ if (history.current[history.current.length - 1] !== command) history.current = [...history.current, command].slice(-100);
8627
+ if (historyKey) try {
8628
+ window.localStorage.setItem(historyKey, JSON.stringify(history.current));
8629
+ } catch {}
8630
+ setText("");
8631
+ setCursor(null);
8632
+ setMatches([]);
8633
+ setPinned(true);
8634
+ onCommand(command);
8635
+ };
8636
+ const walk = (direction) => {
8637
+ const past = history.current;
8638
+ if (past.length === 0) return;
8639
+ if (cursor === null) {
8640
+ if (direction === 1) return;
8641
+ draft.current = text;
8642
+ setCursor(past.length - 1);
8643
+ setText(past[past.length - 1]);
8644
+ return;
8645
+ }
8646
+ const next = cursor + direction;
8647
+ if (next < 0) return;
8648
+ if (next >= past.length) {
8649
+ setCursor(null);
8650
+ setText(draft.current);
8651
+ } else {
8652
+ setCursor(next);
8653
+ setText(past[next]);
8654
+ }
8655
+ };
8656
+ const onKeyDown = (e) => {
8657
+ if (e.nativeEvent.isComposing) return;
8658
+ if (e.key === "ArrowUp" || e.key === "ArrowDown") {
8659
+ e.preventDefault();
8660
+ walk(e.key === "ArrowUp" ? -1 : 1);
8661
+ } else if (e.key === "Tab" && complete && !e.shiftKey && text.length > 0) {
8662
+ const found = complete(text);
8663
+ if (found.length === 0) return;
8664
+ e.preventDefault();
8665
+ const start = commonStart(found);
8666
+ if (start.length > text.length) setText(start);
8667
+ setMatches(found.length > 1 ? found : []);
8668
+ } else if (e.key === "Escape") setMatches([]);
8669
+ };
8670
+ return /* @__PURE__ */ jsxs("section", {
8671
+ "aria-label": label,
8672
+ className: cn("grid min-w-0 gap-2", className),
8673
+ children: [
8674
+ /* @__PURE__ */ jsxs("div", {
8675
+ ref: box,
8676
+ role: "log",
8677
+ "aria-live": "polite",
8678
+ "aria-relevant": "additions",
8679
+ "aria-label": `${label}: log`,
8680
+ className: "relative min-w-0 rounded-control border border-border bg-surface-sunken",
8681
+ children: [
8682
+ /* @__PURE__ */ jsx(VirtualList, {
8683
+ label: `${label} lines`,
8684
+ items: lines,
8685
+ itemKey: lineKey,
8686
+ height,
8687
+ bounded: true,
8688
+ estimateSize: 24,
8689
+ rowHeight: lineHeight,
8690
+ children: (line) => {
8691
+ const word = LEVEL_WORD[line.level ?? "info"];
8692
+ return /* @__PURE__ */ jsxs("div", {
8693
+ className: cn("flex min-w-0 items-start gap-2 px-3 py-0.5 font-mono type-body-sm", line.level === "echo" && "text-muted-foreground"),
8694
+ children: [
8695
+ word ? /* @__PURE__ */ jsx(Status, {
8696
+ tone: word.tone,
8697
+ children: word.word
8698
+ }) : line.level === "echo" ? /* @__PURE__ */ jsx("span", {
8699
+ "aria-hidden": true,
8700
+ children: "›"
8701
+ }) : null,
8702
+ line.level === "echo" && /* @__PURE__ */ jsx("span", {
8703
+ className: "sr-only",
8704
+ children: "Command: "
8705
+ }),
8706
+ /* @__PURE__ */ jsx("span", {
8707
+ title: lineHeight ? line.text : void 0,
8708
+ className: cn("min-w-0 flex-1", lineHeight ? "truncate" : "break-words whitespace-pre-wrap"),
8709
+ children: line.text
8710
+ })
8711
+ ]
8712
+ });
8713
+ }
8714
+ }),
8715
+ lines.length === 0 && /* @__PURE__ */ jsx("p", {
8716
+ className: "px-3 py-2 type-body-sm text-muted-foreground",
8717
+ children: "Nothing has been written yet."
8718
+ }),
8719
+ !pinned && /* @__PURE__ */ jsxs(Button, {
8720
+ size: "sm",
8721
+ variant: "outline",
8722
+ onPress: () => {
8723
+ setPinned(true);
8724
+ toEnd();
8725
+ },
8726
+ className: "absolute bottom-2 left-1/2 -translate-x-1/2 shadow-overlay",
8727
+ children: [/* @__PURE__ */ jsx(ArrowDown, {}), " Latest"]
8728
+ })
8729
+ ]
8730
+ }),
8731
+ /* @__PURE__ */ jsx("form", {
8732
+ onSubmit: (e) => {
8733
+ e.preventDefault();
8734
+ run();
8735
+ },
8736
+ children: /* @__PURE__ */ jsx(Field, {
8737
+ label: commandLabel,
8738
+ action: /* @__PURE__ */ jsx(Button, {
8739
+ type: "submit",
8740
+ children: "Run"
8741
+ }),
8742
+ children: /* @__PURE__ */ jsx(Input, {
8743
+ ref: inputRef,
8744
+ value: text,
8745
+ onChange: (e) => {
8746
+ setText(e.target.value);
8747
+ setCursor(null);
8748
+ setMatches([]);
8749
+ },
8750
+ onKeyDown,
8751
+ autoComplete: "off",
8752
+ autoCapitalize: "off",
8753
+ autoCorrect: "off",
8754
+ spellCheck: false,
8755
+ className: "font-mono"
8756
+ })
8757
+ })
8758
+ }),
8759
+ /* @__PURE__ */ jsx("p", {
8760
+ role: "status",
8761
+ className: cn("type-caption text-muted-foreground", matches.length === 0 && "sr-only"),
8762
+ children: matches.length > 0 ? `${matches.length} matches: ${matches.join(", ")}` : ""
8763
+ })
8764
+ ]
8765
+ });
8766
+ }
8767
+ // src/components/shortcut-editor.tsx
8768
+ var idOf = (s) => s.id ?? s.label;
8769
+ var MODIFIER_KEYS = /* @__PURE__ */ new Set([
8770
+ "Shift",
8771
+ "Control",
8772
+ "Alt",
8773
+ "Meta",
8774
+ "AltGraph",
8775
+ "CapsLock",
8776
+ "Fn",
8777
+ "OS"
8778
+ ]);
8779
+ /** Holds a person's rebound keys over a default `Shortcut[]`, remembered under `storageKey` and handed to `onChange`. The result's `shortcuts` is what `useHotkeys` and `KeysLegend` take. */
8780
+ function useRebindableShortcuts(defaults, { storageKey, initial, onChange } = {}) {
8781
+ const [overrides, setOverrides] = React.useState(() => {
8782
+ if (initial) return initial;
8783
+ if (!storageKey) return {};
8784
+ try {
8785
+ const parsed = JSON.parse(window.localStorage.getItem(storageKey) ?? "{}");
8786
+ if (!parsed || typeof parsed !== "object") return {};
8787
+ const out = {};
8788
+ for (const [id, keys] of Object.entries(parsed)) if (Array.isArray(keys) && keys.every((k) => typeof k === "string") && keys.length > 0) out[id] = keys;
8789
+ return out;
8790
+ } catch {
8791
+ return {};
8792
+ }
8793
+ });
8794
+ const latest = React.useRef({
8795
+ onChange,
8796
+ storageKey
8797
+ });
8798
+ latest.current = {
8799
+ onChange,
8800
+ storageKey
8801
+ };
8802
+ const current = React.useRef(overrides);
8803
+ const commit = React.useCallback((next) => {
8804
+ current.current = next;
8805
+ setOverrides(next);
8806
+ const { onChange: notify, storageKey: key } = latest.current;
8807
+ if (key) try {
8808
+ window.localStorage.setItem(key, JSON.stringify(next));
8809
+ } catch {}
8810
+ notify?.(next);
8811
+ }, []);
8812
+ return React.useMemo(() => ({
8813
+ shortcuts: defaults.map((s) => overrides[idOf(s)] ? {
8814
+ ...s,
8815
+ keys: overrides[idOf(s)]
8816
+ } : { ...s }),
8817
+ defaults,
8818
+ overrides,
8819
+ isChanged: (id) => id in overrides,
8820
+ setKeys: (id, keys) => {
8821
+ const next = { ...current.current };
8822
+ if (keys === null) delete next[id];
8823
+ else next[id] = keys;
8824
+ commit(next);
8825
+ },
8826
+ resetAll: () => commit({})
8827
+ }), [
8828
+ defaults,
8829
+ overrides,
8830
+ commit
8831
+ ]);
8832
+ }
8833
+ /** Judges a key pressed while recording for the shortcut `id`, against the current list. */
8834
+ function checkKey(e, id, shortcuts) {
8835
+ if (e.ctrlKey || e.metaKey || e.altKey) {
8836
+ const chord = [
8837
+ e.ctrlKey && "Ctrl",
8838
+ e.metaKey && "Meta",
8839
+ e.altKey && "Alt",
8840
+ e.shiftKey && "Shift",
8841
+ e.key.length === 1 ? e.key.toUpperCase() : e.key
8842
+ ].filter(Boolean).join("+");
8843
+ return {
8844
+ ok: false,
8845
+ reason: isReservedChord(chord) ? `${formatChord(chord)} belongs to the browser.` : `${formatChord(chord)} is a chord, and shortcuts here are single keys: Ctrl, Cmd and Alt belong to the browser and the system.`
8846
+ };
8847
+ }
8848
+ if (e.key === "Tab") return {
8849
+ ok: false,
8850
+ reason: "Tab moves between controls, so it cannot be a shortcut."
8851
+ };
8852
+ const other = shortcuts.find((s) => idOf(s) !== id && !s.disabled && s.keys.includes(e.key));
8853
+ return other ? {
8854
+ ok: "conflict",
8855
+ key: e.key,
8856
+ other
8857
+ } : {
8858
+ ok: true,
8859
+ key: e.key
8860
+ };
8861
+ }
8862
+ /** Each shortcut with its keys and a "Change" that records the next key pressed; refuses keys that cannot be bound, names a conflict and offers a swap, and resets one or all. Edits the list a `useRebindableShortcuts` holds. */
8863
+ function ShortcutEditor({ rebinding, label = "Keyboard shortcuts", className }) {
8864
+ const { shortcuts, defaults, setKeys, isChanged, resetAll, overrides } = rebinding;
8865
+ const [recording, setRecording] = React.useState(null);
8866
+ const [conflict, setConflict] = React.useState(null);
8867
+ const [said, setSaid] = React.useState("");
8868
+ const keysOf = (id) => shortcuts.find((s) => idOf(s) === id).keys;
8869
+ const apply = (id, key, swapWith) => {
8870
+ const own = keysOf(id);
8871
+ const old = own[0];
8872
+ setKeys(id, [key, ...own.slice(1).filter((k) => k !== key)]);
8873
+ if (swapWith) {
8874
+ const theirs = keysOf(idOf(swapWith)).map((k) => k === key ? old : k);
8875
+ setKeys(idOf(swapWith), [...new Set(theirs)]);
8876
+ }
8877
+ };
8878
+ const onKeyDown = (e, shortcut) => {
8879
+ const id = idOf(shortcut);
8880
+ if (e.nativeEvent.isComposing) return;
8881
+ if (e.key === "Tab") {
8882
+ setRecording(null);
8883
+ setSaid("Tab moves between controls, so it cannot be a shortcut. Kept " + keyName(shortcut.keys[0] ?? "") + " for " + shortcut.label + ".");
8884
+ return;
8885
+ }
8886
+ e.stopPropagation();
8887
+ if (e.key === "Escape") {
8888
+ e.preventDefault();
8889
+ setRecording(null);
8890
+ setSaid(`Kept ${keyName(shortcut.keys[0] ?? "")} for ${shortcut.label}.`);
8891
+ return;
8892
+ }
8893
+ if (MODIFIER_KEYS.has(e.key)) return;
8894
+ e.preventDefault();
8895
+ const found = checkKey(e.nativeEvent, id, shortcuts);
8896
+ if (found.ok === false) {
8897
+ setSaid(found.reason);
8898
+ return;
8899
+ }
8900
+ setRecording(null);
8901
+ if (found.ok === "conflict") {
8902
+ setConflict({
8903
+ id,
8904
+ key: found.key,
8905
+ other: found.other
8906
+ });
8907
+ setSaid(`${keyName(found.key)} is already ${found.other.label}. Swap?`);
8908
+ return;
8909
+ }
8910
+ apply(id, found.key);
8911
+ setSaid(`${shortcut.label} is now ${keyName(found.key)}.`);
8912
+ };
8913
+ const anyChanged = Object.keys(overrides).length > 0;
8914
+ return /* @__PURE__ */ jsxs("section", {
8915
+ "aria-label": label,
8916
+ className: cn("grid min-w-0 gap-3", className),
8917
+ children: [/* @__PURE__ */ jsx("ul", {
8918
+ className: "grid min-w-0 divide-y divide-border rounded-surface border border-border",
8919
+ children: shortcuts.map((shortcut) => {
8920
+ const id = idOf(shortcut);
8921
+ const mine = conflict?.id === id ? conflict : null;
8922
+ const isRecording = recording === id;
8923
+ return /* @__PURE__ */ jsxs("li", {
8924
+ className: cn("flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 px-3 py-2", shortcut.disabled && "opacity-50"),
8925
+ children: [
8926
+ /* @__PURE__ */ jsx("span", {
8927
+ className: "min-w-0 flex-1 type-body-sm",
8928
+ children: shortcut.label
8929
+ }),
8930
+ /* @__PURE__ */ jsx("span", {
8931
+ className: "flex items-center gap-1",
8932
+ children: shortcut.keys.map((k, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("span", {
8933
+ className: "sr-only",
8934
+ children: " or "
8935
+ }), /* @__PURE__ */ jsx("kbd", {
8936
+ className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono type-caption text-foreground",
8937
+ children: /* @__PURE__ */ jsx(KeyText, { children: keyName(k) })
8938
+ })] }, k))
8939
+ }),
8940
+ isRecording ? /* @__PURE__ */ jsx(Button, {
8941
+ size: "sm",
8942
+ variant: "default",
8943
+ autoFocus: true,
8944
+ "aria-label": `Press a key for ${shortcut.label}. Escape cancels.`,
8945
+ onKeyDown: (e) => onKeyDown(e, shortcut),
8946
+ onBlur: () => setRecording((now) => now === id ? null : now),
8947
+ children: "Press a key…"
8948
+ }) : /* @__PURE__ */ jsx(Button, {
8949
+ size: "sm",
8950
+ "aria-label": `Change ${shortcut.label}`,
8951
+ disabled: shortcut.disabled,
8952
+ onPress: () => {
8953
+ setConflict(null);
8954
+ setRecording(id);
8955
+ setSaid(`Press the new key for ${shortcut.label}. Escape cancels.`);
8956
+ },
8957
+ children: "Change"
8958
+ }),
8959
+ isChanged(id) && !isRecording && /* @__PURE__ */ jsxs(Button, {
8960
+ size: "sm",
8961
+ variant: "ghost",
8962
+ "aria-label": `Reset ${shortcut.label}`,
8963
+ onPress: () => {
8964
+ setKeys(id, null);
8965
+ setConflict(null);
8966
+ const original = defaults.find((s) => idOf(s) === id);
8967
+ setSaid(`${shortcut.label} is back to ${keyName(original?.keys[0] ?? "")}.`);
8968
+ },
8969
+ children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), " Reset"]
8970
+ }),
8971
+ mine && /* @__PURE__ */ jsxs("p", {
8972
+ className: "flex basis-full flex-wrap items-center gap-2 type-body-sm text-warning",
8973
+ children: [
8974
+ /* @__PURE__ */ jsxs("span", { children: [
8975
+ "Already “",
8976
+ mine.other.label,
8977
+ "”: swap?"
8978
+ ] }),
8979
+ /* @__PURE__ */ jsx(Button, {
8980
+ size: "sm",
8981
+ onPress: () => {
8982
+ const given = keysOf(id)[0] ?? "";
8983
+ apply(id, mine.key, mine.other);
8984
+ setConflict(null);
8985
+ setSaid(`${shortcut.label} is now ${keyName(mine.key)}, and ${mine.other.label} has ${keyName(given)}.`);
8986
+ },
8987
+ children: "Swap"
8988
+ }),
8989
+ /* @__PURE__ */ jsx(Button, {
8990
+ size: "sm",
8991
+ variant: "ghost",
8992
+ onPress: () => {
8993
+ setConflict(null);
8994
+ setSaid("Nothing changed.");
8995
+ },
8996
+ children: "Keep as it was"
8997
+ })
8998
+ ]
8999
+ })
9000
+ ]
9001
+ }, id);
9002
+ })
9003
+ }), /* @__PURE__ */ jsxs("div", {
9004
+ className: "flex items-center gap-3",
9005
+ children: [anyChanged && /* @__PURE__ */ jsx(Button, {
9006
+ size: "sm",
9007
+ onPress: () => {
9008
+ resetAll();
9009
+ setConflict(null);
9010
+ setSaid("Every shortcut is back to its default.");
9011
+ },
9012
+ children: "Reset all"
9013
+ }), /* @__PURE__ */ jsx("p", {
9014
+ role: "status",
9015
+ className: "min-w-0 flex-1 type-body-sm text-muted-foreground",
9016
+ children: said
9017
+ })]
9018
+ })]
9019
+ });
9020
+ }
8131
9021
  // src/lib/file-intake.ts
8132
9022
  /** Whether a file matches one entry of an `accept` list: extension, exact type or `family/*`, ignoring case. */
8133
9023
  function matchesAccept(file, accept) {
@@ -15554,7 +16444,7 @@ var SlotContext = React.createContext({
15554
16444
  stacked: false
15555
16445
  });
15556
16446
  /** The workspace: a labelled region that holds the splits and panes, and stacks them when narrow. */
15557
- function Workspace({ label, state, narrowBelow = 720, className, children }) {
16447
+ function Workspace({ label, state, narrowBelow = 720, onFiles, acceptLabel, className, children }) {
15558
16448
  const ref = React.useRef(null);
15559
16449
  const { setNarrow } = state;
15560
16450
  React.useLayoutEffect(() => {
@@ -15571,21 +16461,49 @@ function Workspace({ label, state, narrowBelow = 720, className, children }) {
15571
16461
  }, [narrowBelow, setNarrow]);
15572
16462
  return /* @__PURE__ */ jsx(StateContext.Provider, {
15573
16463
  value: state,
15574
- children: /* @__PURE__ */ jsx("div", {
16464
+ children: /* @__PURE__ */ jsxs("div", {
15575
16465
  ref,
15576
16466
  role: "group",
15577
16467
  "aria-label": label,
15578
16468
  className: cn("flex h-full min-h-0 min-w-0 flex-col overflow-hidden bg-background", className),
15579
- children
16469
+ children: [children, onFiles && /* @__PURE__ */ jsx(FileDropOverlay, {
16470
+ onFiles,
16471
+ acceptLabel: acceptLabel ?? "files"
16472
+ })]
15580
16473
  })
15581
16474
  });
15582
16475
  }
16476
+ /** The bar across the top of a `Workspace`: the tool's name as the heading, a polite status line, the few actions, then an end slot for the scheme and palette choice. Wraps on a phone. */
16477
+ function WorkspaceBar({ title, status, actions, end, className }) {
16478
+ return /* @__PURE__ */ jsxs("header", {
16479
+ className: cn("flex min-h-(--control-h) shrink-0 flex-wrap items-center gap-x-3 gap-y-1 border-b border-border px-3 py-1", className),
16480
+ children: [
16481
+ /* @__PURE__ */ jsx("h1", {
16482
+ className: "type-label min-w-0 shrink-0",
16483
+ children: title
16484
+ }),
16485
+ /* @__PURE__ */ jsx("p", {
16486
+ role: "status",
16487
+ className: "type-body-sm min-w-0 flex-1 truncate text-muted-foreground tabular-nums",
16488
+ children: status
16489
+ }),
16490
+ actions && /* @__PURE__ */ jsx("div", {
16491
+ className: "flex shrink-0 items-center gap-2",
16492
+ children: actions
16493
+ }),
16494
+ end && /* @__PURE__ */ jsx("div", {
16495
+ className: "flex shrink-0 items-center gap-2",
16496
+ children: end
16497
+ })
16498
+ ]
16499
+ });
16500
+ }
15583
16501
  var iconsFor = (direction, edge, stacked) => {
15584
16502
  if (stacked || direction === "column") return edge === "start" ? [PanelTopClose, PanelTopOpen] : [PanelBottomClose, PanelBottomOpen];
15585
16503
  return edge === "end" ? [PanelRightClose, PanelRightOpen] : [PanelLeftClose, PanelLeftOpen];
15586
16504
  };
15587
16505
  /** A region of a workspace with a consistent header (name, actions, fold button) and a body that scrolls. */
15588
- function Pane({ id, name, grow, size = 280, min, max, collapsible, defaultCollapsed, actions, className, children }) {
16506
+ function Pane({ id, name, grow, size = 280, min, max, collapsible, defaultCollapsed, actions, flush, className, children }) {
15589
16507
  const state = useState_();
15590
16508
  const { direction, edge, stacked } = React.useContext(SlotContext);
15591
16509
  const headingId = React.useId();
@@ -15642,7 +16560,7 @@ function Pane({ id, name, grow, size = 280, min, max, collapsible, defaultCollap
15642
16560
  }), /* @__PURE__ */ jsx("div", {
15643
16561
  id: `pane-body-${id}`,
15644
16562
  hidden: folded,
15645
- className: "min-h-0 min-w-0 flex-1 overflow-auto",
16563
+ className: cn("min-h-0 min-w-0 flex-1 overflow-auto", !flush && "p-3"),
15646
16564
  children
15647
16565
  })]
15648
16566
  });
@@ -18346,7 +19264,7 @@ function Children({ node }) {
18346
19264
  return /* @__PURE__ */ jsx(Nodes, { nodes: load.data });
18347
19265
  }
18348
19266
  /** 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. */
18349
- function Tree({ label, roots, useChildren, nodeKey, nodeLabel, isBranch, renderNode, selected, onSelect, choices, current, onCurrentChange, count, badge, sortChildren, reveal, resolveBranch, coverNoun = ["item", "items"], expanded, beforeOpen, loadingRow, emptyRow, height = "24rem", className }) {
19267
+ function Tree({ label, roots, useChildren, nodeKey, nodeLabel, isBranch, renderNode, selected, onSelect, choices, current, onCurrentChange, count, badge, sortChildren, reveal, resolveBranch, coverNoun = ["item", "items"], branchPress = "select", expanded, beforeOpen, loadingRow, emptyRow, height = "24rem", className }) {
18350
19268
  const nodes = React.useRef(/* @__PURE__ */ new Map()).current;
18351
19269
  const [covered, setCovered] = React.useState("");
18352
19270
  const scroller = React.useRef(null);
@@ -18476,7 +19394,13 @@ function Tree({ label, roots, useChildren, nodeKey, nodeLabel, isBranch, renderN
18476
19394
  if (first === void 0 || isNote(String(first))) return;
18477
19395
  const key = String(first);
18478
19396
  const node = nodes.get(key);
18479
- if (node !== void 0) onSelect?.(key, node);
19397
+ if (node === void 0) return;
19398
+ if (branchPress === "toggle" && (isBranch ? isBranch(node) : true)) {
19399
+ if (!expanded.isOpen(key) && beforeOpen?.(node) === false) return;
19400
+ expanded.toggle(key);
19401
+ return;
19402
+ }
19403
+ onSelect?.(key, node);
18480
19404
  };
18481
19405
  const displayKeys = choices ? [.../* @__PURE__ */ new Set([...choices.selected, ...nodes.keys()])].filter((k) => stateOf(k) === "on" || choices.selected.has(k) && !nodes.has(k)) : [];
18482
19406
  const shown = () => {
@@ -18802,6 +19726,6 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
18802
19726
  ]
18803
19727
  });
18804
19728
  }
18805
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
19729
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, ShortcutEditor, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
18806
19730
 
18807
19731
  //# sourceMappingURL=index.js.map