@nextlyhq/ui 0.0.2-alpha.52 → 0.0.2-alpha.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -22,11 +22,15 @@ var buttonVariants = cva(
22
22
  variant: {
23
23
  default: "bg-primary text-primary-foreground border border-transparent hover:opacity-90",
24
24
  primary: "bg-primary text-primary-foreground border border-transparent hover:opacity-90",
25
- // Solid fill uses the emphasis token so white on-color text stays AA in
26
- // dark mode (the base token is the readable text color, too light here).
27
- // Hover darkens to a deeper shade instead of opacity-90, which would
28
- // composite the fill toward the page and drop white text under 4.5:1.
29
- destructive: "bg-destructive-solid text-destructive-foreground border border-transparent hover:bg-destructive-700",
25
+ // Solid fill uses the emphasis token so on-color text stays AA in dark
26
+ // mode (the base token is the readable text color, too light here).
27
+ // Hover darkens to a deeper shade rather than opacity-90, which would
28
+ // composite the fill toward the page and drop the label under 4.5:1.
29
+ // One step, not two: the label is white in light mode and black in
30
+ // dark, so mixing the fill toward black moves it away from the label in
31
+ // one mode and into it in the other. `-600` clears both (5.92:1 light,
32
+ // 5.67:1 dark); `-700` reads at 3.70:1 against the dark label.
33
+ destructive: "bg-destructive-solid text-destructive-foreground border border-transparent hover:bg-destructive-600",
30
34
  // border-border is the decorative separator token, and it is the right
31
35
  // one here: a button is identified by its label and fill, so its edge
32
36
  // carries no meaning on its own and is not held to the 3:1 minimum that
@@ -2317,6 +2321,1155 @@ var ResizableHandle = ({
2317
2321
  ]
2318
2322
  }
2319
2323
  );
2324
+
2325
+ // src/components/tree-view.tsx
2326
+ import { useVirtualizer } from "@tanstack/react-virtual";
2327
+ import { ChevronRight as ChevronRight3 } from "lucide-react";
2328
+ import * as React10 from "react";
2329
+ import { jsx as jsx36, jsxs as jsxs15 } from "react/jsx-runtime";
2330
+ var ROW_HEIGHT = 28;
2331
+ var INDENT_PER_LEVEL = 12;
2332
+ function textOf(node) {
2333
+ if (typeof node.textValue === "string") return node.textValue;
2334
+ return typeof node.label === "string" ? node.label : "";
2335
+ }
2336
+ function flatten(nodes, expanded) {
2337
+ const rows = [];
2338
+ const pending = [{ list: nodes, index: 0, level: 0 }];
2339
+ while (pending.length > 0) {
2340
+ const frame = pending[pending.length - 1];
2341
+ if (frame === void 0 || frame.index >= frame.list.length) {
2342
+ pending.pop();
2343
+ continue;
2344
+ }
2345
+ const node = frame.list[frame.index];
2346
+ const posInSet = frame.index;
2347
+ frame.index += 1;
2348
+ if (node === void 0) continue;
2349
+ const hasChildren = node.children !== void 0;
2350
+ rows.push({
2351
+ node,
2352
+ level: frame.level,
2353
+ setSize: frame.list.length,
2354
+ posInSet,
2355
+ parentId: frame.parentId,
2356
+ hasChildren
2357
+ });
2358
+ if (hasChildren && expanded.has(node.id)) {
2359
+ pending.push({
2360
+ list: node.children ?? [],
2361
+ index: 0,
2362
+ level: frame.level + 1,
2363
+ parentId: node.id
2364
+ });
2365
+ }
2366
+ }
2367
+ return rows;
2368
+ }
2369
+ function useControllable(controlled, fallback) {
2370
+ const [uncontrolled, setUncontrolled] = React10.useState(fallback);
2371
+ return [
2372
+ controlled === void 0 ? uncontrolled : controlled,
2373
+ setUncontrolled
2374
+ ];
2375
+ }
2376
+ var TreeView = React10.forwardRef(
2377
+ ({
2378
+ nodes,
2379
+ expandedIds,
2380
+ defaultExpandedIds,
2381
+ onExpandedChange,
2382
+ selectedId,
2383
+ defaultSelectedId,
2384
+ onSelectedChange,
2385
+ className,
2386
+ "aria-label": ariaLabel,
2387
+ "aria-labelledby": ariaLabelledBy,
2388
+ "aria-describedby": ariaDescribedBy,
2389
+ ...props
2390
+ }, forwardedRef) => {
2391
+ const scrollRef = React10.useRef(null);
2392
+ const attachScroll = React10.useCallback(
2393
+ (node) => {
2394
+ scrollRef.current = node;
2395
+ if (typeof forwardedRef === "function") forwardedRef(node);
2396
+ else if (forwardedRef !== null && forwardedRef !== void 0) {
2397
+ forwardedRef.current = node;
2398
+ }
2399
+ },
2400
+ [forwardedRef]
2401
+ );
2402
+ const [expandedState, setExpandedState] = useControllable(
2403
+ expandedIds === void 0 ? void 0 : [...expandedIds],
2404
+ [...defaultExpandedIds ?? []]
2405
+ );
2406
+ const expanded = React10.useMemo(
2407
+ () => new Set(expandedIds ?? expandedState),
2408
+ [expandedIds, expandedState]
2409
+ );
2410
+ const [selected, setSelected] = useControllable(
2411
+ selectedId === void 0 ? void 0 : selectedId,
2412
+ defaultSelectedId ?? null
2413
+ );
2414
+ const rows = React10.useMemo(
2415
+ () => flatten(nodes, expanded),
2416
+ [nodes, expanded]
2417
+ );
2418
+ const [activeId, setActiveId] = React10.useState(null);
2419
+ const activeIndex = Math.max(
2420
+ 0,
2421
+ rows.findIndex((row) => row.node.id === (activeId ?? selected))
2422
+ );
2423
+ const virtualizer = useVirtualizer({
2424
+ count: rows.length,
2425
+ getScrollElement: () => scrollRef.current,
2426
+ estimateSize: () => ROW_HEIGHT,
2427
+ overscan: 8
2428
+ });
2429
+ const commitExpanded = (next) => {
2430
+ const ids = [...next];
2431
+ if (expandedIds === void 0) setExpandedState(ids);
2432
+ onExpandedChange?.(ids);
2433
+ };
2434
+ const setExpansion = (id, open) => {
2435
+ const next = new Set(expanded);
2436
+ if (open) next.add(id);
2437
+ else next.delete(id);
2438
+ commitExpanded(next);
2439
+ };
2440
+ const choose = (id) => {
2441
+ if (selectedId === void 0) setSelected(id);
2442
+ onSelectedChange?.(id);
2443
+ };
2444
+ const focusRow = (index) => {
2445
+ const row = rows[index];
2446
+ if (row === void 0) return;
2447
+ setActiveId(row.node.id);
2448
+ virtualizer.scrollToIndex(index, { align: "auto" });
2449
+ requestAnimationFrame(() => {
2450
+ const element = scrollRef.current?.querySelector(
2451
+ `[data-tree-index="${index}"]`
2452
+ );
2453
+ element?.focus();
2454
+ });
2455
+ };
2456
+ const step = (from, delta) => {
2457
+ for (let index = from + delta; index >= 0 && index < rows.length; index += delta) {
2458
+ if (rows[index]?.node.disabled !== true) return index;
2459
+ }
2460
+ return from;
2461
+ };
2462
+ const typeahead = React10.useRef({ query: "", at: 0 });
2463
+ const onKeyDown = (event) => {
2464
+ const index = activeIndex;
2465
+ const row = rows[index];
2466
+ if (row === void 0) return;
2467
+ switch (event.key) {
2468
+ case "ArrowDown":
2469
+ event.preventDefault();
2470
+ focusRow(step(index, 1));
2471
+ return;
2472
+ case "ArrowUp":
2473
+ event.preventDefault();
2474
+ focusRow(step(index, -1));
2475
+ return;
2476
+ case "ArrowRight":
2477
+ event.preventDefault();
2478
+ if (row.hasChildren && !expanded.has(row.node.id)) {
2479
+ setExpansion(row.node.id, true);
2480
+ } else if (row.hasChildren) {
2481
+ for (let child = index + 1; child < rows.length && (rows[child]?.level ?? 0) > row.level; child += 1) {
2482
+ if (rows[child]?.parentId === row.node.id && rows[child]?.node.disabled !== true) {
2483
+ focusRow(child);
2484
+ break;
2485
+ }
2486
+ }
2487
+ }
2488
+ return;
2489
+ case "ArrowLeft":
2490
+ event.preventDefault();
2491
+ if (row.hasChildren && expanded.has(row.node.id)) {
2492
+ setExpansion(row.node.id, false);
2493
+ } else if (row.parentId !== void 0) {
2494
+ let ancestor = row.parentId;
2495
+ while (ancestor !== void 0) {
2496
+ const at = rows.findIndex(
2497
+ (candidate) => candidate.node.id === ancestor
2498
+ );
2499
+ if (at < 0) break;
2500
+ if (rows[at]?.node.disabled !== true) {
2501
+ focusRow(at);
2502
+ break;
2503
+ }
2504
+ ancestor = rows[at]?.parentId;
2505
+ }
2506
+ }
2507
+ return;
2508
+ case "Home":
2509
+ event.preventDefault();
2510
+ focusRow(rows[0]?.node.disabled === true ? step(0, 1) : 0);
2511
+ return;
2512
+ case "End": {
2513
+ event.preventDefault();
2514
+ const last = rows.length - 1;
2515
+ focusRow(rows[last]?.node.disabled === true ? step(last, -1) : last);
2516
+ return;
2517
+ }
2518
+ case "Enter":
2519
+ case " ":
2520
+ event.preventDefault();
2521
+ if (row.node.disabled !== true) choose(row.node.id);
2522
+ return;
2523
+ case "*": {
2524
+ event.preventDefault();
2525
+ const next = new Set(expanded);
2526
+ for (const sibling of rows) {
2527
+ if (sibling.parentId === row.parentId && sibling.hasChildren) {
2528
+ next.add(sibling.node.id);
2529
+ }
2530
+ }
2531
+ commitExpanded(next);
2532
+ return;
2533
+ }
2534
+ default:
2535
+ break;
2536
+ }
2537
+ if (event.key.length !== 1 || event.metaKey || event.ctrlKey || event.altKey) {
2538
+ return;
2539
+ }
2540
+ event.preventDefault();
2541
+ const now = Date.now();
2542
+ const state = typeahead.current;
2543
+ state.query = now - state.at > 500 ? event.key : state.query + event.key;
2544
+ state.at = now;
2545
+ const query = state.query.toLowerCase();
2546
+ for (let offset = 1; offset <= rows.length; offset += 1) {
2547
+ const candidate = rows[(index + offset) % rows.length];
2548
+ if (candidate === void 0 || candidate.node.disabled === true)
2549
+ continue;
2550
+ if (textOf(candidate.node).toLowerCase().startsWith(query)) {
2551
+ focusRow(rows.indexOf(candidate));
2552
+ return;
2553
+ }
2554
+ }
2555
+ };
2556
+ const virtualItems = virtualizer.getVirtualItems();
2557
+ const usable = (index) => rows[index]?.node.disabled !== true;
2558
+ const tabStopIndex = virtualItems.some((item) => item.index === activeIndex) && usable(activeIndex) ? activeIndex : virtualItems.find((item) => usable(item.index))?.index ?? -1;
2559
+ return /* @__PURE__ */ jsx36(
2560
+ "div",
2561
+ {
2562
+ ref: attachScroll,
2563
+ className: cn("overflow-auto", className),
2564
+ ...props,
2565
+ children: /* @__PURE__ */ jsx36(
2566
+ "div",
2567
+ {
2568
+ role: "tree",
2569
+ "aria-label": ariaLabel,
2570
+ "aria-labelledby": ariaLabelledBy,
2571
+ "aria-describedby": ariaDescribedBy,
2572
+ onKeyDown,
2573
+ style: { height: virtualizer.getTotalSize(), position: "relative" },
2574
+ children: virtualItems.map((item) => {
2575
+ const row = rows[item.index];
2576
+ if (row === void 0) return null;
2577
+ const isSelected = selected === row.node.id;
2578
+ return /* @__PURE__ */ jsxs15(
2579
+ "div",
2580
+ {
2581
+ "data-tree-index": item.index,
2582
+ role: "treeitem",
2583
+ "aria-level": row.level + 1,
2584
+ "aria-setsize": row.setSize,
2585
+ "aria-posinset": row.posInSet + 1,
2586
+ "aria-selected": isSelected,
2587
+ "aria-expanded": row.hasChildren ? expanded.has(row.node.id) : void 0,
2588
+ "aria-disabled": row.node.disabled === true ? true : void 0,
2589
+ tabIndex: item.index === tabStopIndex ? 0 : -1,
2590
+ onFocus: () => setActiveId(row.node.id),
2591
+ onClick: () => {
2592
+ if (row.node.disabled === true) return;
2593
+ setActiveId(row.node.id);
2594
+ choose(row.node.id);
2595
+ },
2596
+ className: cn(
2597
+ "absolute left-0 flex w-full select-none items-center gap-1 rounded-sm pr-2 text-sm outline-none",
2598
+ "focus-visible:ring-1 focus-visible:ring-ring",
2599
+ row.node.disabled === true ? "pointer-events-none opacity-50" : "cursor-pointer",
2600
+ isSelected ? "bg-muted text-foreground" : "hover:bg-muted/50"
2601
+ ),
2602
+ style: {
2603
+ height: item.size,
2604
+ transform: `translateY(${item.start}px)`,
2605
+ paddingLeft: 4 + row.level * INDENT_PER_LEVEL
2606
+ },
2607
+ children: [
2608
+ /* @__PURE__ */ jsx36(
2609
+ "span",
2610
+ {
2611
+ "aria-hidden": "true",
2612
+ className: "flex size-4 shrink-0 items-center justify-center",
2613
+ onClick: (event) => {
2614
+ if (!row.hasChildren) return;
2615
+ event.stopPropagation();
2616
+ setExpansion(row.node.id, !expanded.has(row.node.id));
2617
+ },
2618
+ children: row.hasChildren ? /* @__PURE__ */ jsx36(
2619
+ ChevronRight3,
2620
+ {
2621
+ className: cn(
2622
+ "size-3.5 text-muted-foreground transition-transform",
2623
+ expanded.has(row.node.id) && "rotate-90"
2624
+ )
2625
+ }
2626
+ ) : null
2627
+ }
2628
+ ),
2629
+ row.node.icon !== void 0 ? /* @__PURE__ */ jsx36("span", { className: "flex size-4 shrink-0 items-center justify-center text-muted-foreground", children: row.node.icon }) : null,
2630
+ /* @__PURE__ */ jsx36("span", { className: "truncate", children: row.node.label })
2631
+ ]
2632
+ },
2633
+ row.node.id
2634
+ );
2635
+ })
2636
+ }
2637
+ )
2638
+ }
2639
+ );
2640
+ }
2641
+ );
2642
+ TreeView.displayName = "TreeView";
2643
+
2644
+ // src/components/slider.tsx
2645
+ import * as SliderPrimitive from "@radix-ui/react-slider";
2646
+ import * as React11 from "react";
2647
+
2648
+ // src/lib/dev-warn.ts
2649
+ var emitted = /* @__PURE__ */ new Set();
2650
+ var SPEAKING_ENVIRONMENTS = /* @__PURE__ */ new Set(["development", "test"]);
2651
+ function isDevelopmentRuntime() {
2652
+ if (typeof process === "undefined") return false;
2653
+ const env = process?.env?.NODE_ENV;
2654
+ return env !== void 0 && SPEAKING_ENVIRONMENTS.has(env);
2655
+ }
2656
+ function devWarnOnce(condition, message) {
2657
+ if (condition) return;
2658
+ if (!isDevelopmentRuntime()) return;
2659
+ if (emitted.has(message)) return;
2660
+ emitted.add(message);
2661
+ console.warn(`[@nextlyhq/ui] ${message}`);
2662
+ }
2663
+
2664
+ // src/components/slider.tsx
2665
+ import { jsx as jsx37, jsxs as jsxs16 } from "react/jsx-runtime";
2666
+ function thumbCount(value, defaultValue) {
2667
+ return Math.max(1, value?.length ?? defaultValue?.length ?? 1);
2668
+ }
2669
+ function hasAccessibleName(value) {
2670
+ return value !== void 0 && value.trim() !== "";
2671
+ }
2672
+ var Slider = React11.forwardRef(
2673
+ ({
2674
+ className,
2675
+ value,
2676
+ defaultValue,
2677
+ thumbs,
2678
+ orientation = "horizontal",
2679
+ "aria-label": ariaLabel,
2680
+ "aria-labelledby": ariaLabelledBy,
2681
+ ...props
2682
+ }, ref) => {
2683
+ const initialUncontrolledCount = React11.useRef(
2684
+ thumbCount(void 0, defaultValue)
2685
+ ).current;
2686
+ const count = value?.length ?? initialUncontrolledCount;
2687
+ const isEmptyDefault = defaultValue !== void 0 && defaultValue.length === 0;
2688
+ const isEmptyControlled = value !== void 0 && value.length === 0;
2689
+ devWarnOnce(
2690
+ !isEmptyDefault && !isEmptyControlled,
2691
+ "Slider: `value`/`defaultValue` must hold one number per thumb, and an empty array holds none \u2014 the control has nothing to slide. An empty `defaultValue` falls back to `min`; an empty `value` renders nothing at all, because a controlled slider cannot be given a value without taking state the caller owns. Render nothing until the value is loaded rather than passing `[]`."
2692
+ );
2693
+ if (isEmptyControlled) return null;
2694
+ const isNamed = (index) => {
2695
+ const own = thumbs?.[index];
2696
+ if (hasAccessibleName(own?.["aria-label"])) return true;
2697
+ if (hasAccessibleName(own?.["aria-labelledby"])) return true;
2698
+ return count === 1 && (hasAccessibleName(ariaLabel) || hasAccessibleName(ariaLabelledBy));
2699
+ };
2700
+ devWarnOnce(
2701
+ Array.from({ length: count }).every((_, i) => isNamed(i)),
2702
+ "Slider: every thumb needs an accessible name. A single thumb may take it from the root's `aria-label`/`aria-labelledby`; a range needs one `thumbs` entry per thumb, because the root's name is not inherited and two thumbs sharing one name are announced identically."
2703
+ );
2704
+ const ariaFor = (index) => {
2705
+ const supplied = thumbs?.[index] ?? {};
2706
+ const ownLabel = hasAccessibleName(supplied["aria-label"]) ? supplied["aria-label"] : void 0;
2707
+ const ownLabelledBy = hasAccessibleName(supplied["aria-labelledby"]) ? supplied["aria-labelledby"] : void 0;
2708
+ if (count !== 1) {
2709
+ return {
2710
+ ...supplied,
2711
+ "aria-label": ownLabel,
2712
+ "aria-labelledby": ownLabelledBy
2713
+ };
2714
+ }
2715
+ const namesItself = ownLabel !== void 0 || ownLabelledBy !== void 0;
2716
+ return {
2717
+ "aria-label": namesItself ? ownLabel : ariaLabel,
2718
+ "aria-labelledby": namesItself ? ownLabelledBy : ariaLabelledBy,
2719
+ "aria-valuetext": supplied["aria-valuetext"],
2720
+ "aria-describedby": supplied["aria-describedby"]
2721
+ };
2722
+ };
2723
+ const isVertical = orientation === "vertical";
2724
+ return (
2725
+ // `aria-label`/`aria-labelledby` are destructured out above rather than
2726
+ // spread here: left on the root they would be a second, roleless copy
2727
+ // of a name only the thumb is read for.
2728
+ /* @__PURE__ */ jsxs16(
2729
+ SliderPrimitive.Root,
2730
+ {
2731
+ ref,
2732
+ className: cn(
2733
+ "relative flex touch-none select-none items-center",
2734
+ // WCAG 2.5.8 wants a 24px target. Padding alone does not reach it: the
2735
+ // thumb is absolutely positioned, so the cross-axis size is the 6px
2736
+ // track plus the padding — 22px with `py-2`. An explicit minimum
2737
+ // states the target rather than leaving it to arithmetic that moves
2738
+ // whenever the track thickness does.
2739
+ isVertical ? (
2740
+ // A vertical slider needs a LENGTH, and it cannot inherit one:
2741
+ // `h-full` inside an auto-height parent resolves to zero, leaving
2742
+ // a control with no track to drag along. A concrete default is
2743
+ // usable everywhere and, being a plain utility, is replaced by a
2744
+ // caller's own `h-*` — including `h-full`, for the fill-the-parent
2745
+ // case this default gives up.
2746
+ "h-44 min-w-6 flex-col px-2"
2747
+ ) : "min-h-6 w-full py-2",
2748
+ "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
2749
+ className
2750
+ ),
2751
+ orientation,
2752
+ value,
2753
+ defaultValue: isEmptyDefault ? void 0 : defaultValue,
2754
+ ...props,
2755
+ children: [
2756
+ /* @__PURE__ */ jsx37(
2757
+ SliderPrimitive.Track,
2758
+ {
2759
+ className: cn(
2760
+ "bg-secondary relative grow overflow-hidden rounded-full",
2761
+ isVertical ? "h-full w-1.5" : "h-1.5 w-full"
2762
+ ),
2763
+ children: /* @__PURE__ */ jsx37(
2764
+ SliderPrimitive.Range,
2765
+ {
2766
+ className: cn(
2767
+ "bg-primary absolute",
2768
+ isVertical ? "w-full" : "h-full"
2769
+ )
2770
+ }
2771
+ )
2772
+ }
2773
+ ),
2774
+ Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx37(
2775
+ SliderPrimitive.Thumb,
2776
+ {
2777
+ ...ariaFor(i),
2778
+ className: cn(
2779
+ "border-primary bg-background block h-4 w-4 rounded-full border-2",
2780
+ "ring-offset-background transition-colors",
2781
+ "focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-2",
2782
+ "focus-visible:ring-offset-2",
2783
+ "disabled:pointer-events-none disabled:opacity-50"
2784
+ )
2785
+ },
2786
+ i
2787
+ ))
2788
+ ]
2789
+ }
2790
+ )
2791
+ );
2792
+ }
2793
+ );
2794
+ Slider.displayName = SliderPrimitive.Root.displayName;
2795
+
2796
+ // src/lib/shortcuts/react.tsx
2797
+ import * as React12 from "react";
2798
+
2799
+ // src/lib/shortcuts/key-spec.ts
2800
+ function normalizeKey(key) {
2801
+ return [...key].length === 1 ? key.toLowerCase() : key;
2802
+ }
2803
+ function shiftIsMeaningful(key) {
2804
+ if (key.length > 1) return true;
2805
+ if (key === " ") return true;
2806
+ return /[\p{L}\p{N}]/u.test(key);
2807
+ }
2808
+ function parseKeys(spec) {
2809
+ const steps = spec.trim().split(/\s+/).filter(Boolean);
2810
+ if (steps.length === 0) {
2811
+ throw new Error(`Shortcut spec is empty: ${JSON.stringify(spec)}`);
2812
+ }
2813
+ return steps.map((step) => parseChord(step, spec));
2814
+ }
2815
+ function parseChord(step, spec) {
2816
+ const trailingPlusIsKey = step.length > 2 && step.endsWith("++");
2817
+ const body = trailingPlusIsKey ? step.slice(0, -1) : step;
2818
+ const parts = step === "+" ? ["+"] : body.split("+").filter(Boolean);
2819
+ let mod = false;
2820
+ let ctrl = false;
2821
+ let meta = false;
2822
+ let alt = false;
2823
+ let shift = false;
2824
+ let key;
2825
+ for (const raw of parts) {
2826
+ switch (raw.toLowerCase()) {
2827
+ case "mod":
2828
+ mod = true;
2829
+ break;
2830
+ case "ctrl":
2831
+ case "control":
2832
+ ctrl = true;
2833
+ break;
2834
+ case "meta":
2835
+ case "cmd":
2836
+ case "command":
2837
+ meta = true;
2838
+ break;
2839
+ case "alt":
2840
+ case "option":
2841
+ alt = true;
2842
+ break;
2843
+ case "shift":
2844
+ shift = true;
2845
+ break;
2846
+ case "space":
2847
+ key = " ";
2848
+ break;
2849
+ default:
2850
+ if (key !== void 0) {
2851
+ throw new Error(
2852
+ `Shortcut step "${step}" names two keys ("${key}" and "${raw}") in ${JSON.stringify(spec)}`
2853
+ );
2854
+ }
2855
+ key = raw;
2856
+ }
2857
+ }
2858
+ if (trailingPlusIsKey) {
2859
+ if (key !== void 0) {
2860
+ throw new Error(
2861
+ `Shortcut step has more than one key: ${JSON.stringify(step)} in ${JSON.stringify(spec)}`
2862
+ );
2863
+ }
2864
+ key = "+";
2865
+ }
2866
+ if (key === void 0) {
2867
+ throw new Error(
2868
+ `Shortcut step "${step}" names modifiers but no key, in ${JSON.stringify(spec)}`
2869
+ );
2870
+ }
2871
+ return { key: normalizeKey(key), mod, ctrl, meta, alt, shift };
2872
+ }
2873
+ function chordMatches(chord, key, state, isApple) {
2874
+ if (normalizeKey(key) !== chord.key) return false;
2875
+ const wantsCtrl = chord.ctrl || chord.mod && !isApple;
2876
+ const wantsMeta = chord.meta || chord.mod && isApple;
2877
+ if (state.metaKey !== wantsMeta) return false;
2878
+ const altGraph = state.getModifierState?.("AltGraph") ?? false;
2879
+ const synthetic = altGraph && [...chord.key].length === 1 && !wantsCtrl && !chord.alt;
2880
+ if (!synthetic) {
2881
+ if (state.ctrlKey !== wantsCtrl) return false;
2882
+ if (state.altKey !== chord.alt) return false;
2883
+ }
2884
+ if (shiftIsMeaningful(chord.key) && state.shiftKey !== chord.shift)
2885
+ return false;
2886
+ return true;
2887
+ }
2888
+ function detectApplePlatform() {
2889
+ if (typeof navigator === "undefined") return false;
2890
+ const candidate = navigator;
2891
+ const platform = candidate.userAgentData?.platform ?? navigator.platform ?? "";
2892
+ return /mac|iphone|ipad|ipod/i.test(platform);
2893
+ }
2894
+
2895
+ // src/lib/shortcuts/manager.ts
2896
+ var DEFAULT_SEQUENCE_TIMEOUT_MS = 1e3;
2897
+ function signature(event) {
2898
+ return event.code || event.key;
2899
+ }
2900
+ function eventTarget(event) {
2901
+ const path = event.composedPath?.();
2902
+ return path && path.length > 0 ? path[0] ?? null : event.target;
2903
+ }
2904
+ function asElement(target) {
2905
+ if (target === null || typeof target !== "object") return null;
2906
+ const node = target;
2907
+ if (node.nodeType !== 1 || typeof node.tagName !== "string") return null;
2908
+ return target;
2909
+ }
2910
+ function inputType(element) {
2911
+ if (element.tagName !== "INPUT") return "";
2912
+ const value = element.type;
2913
+ return typeof value === "string" ? value.toLowerCase() : "";
2914
+ }
2915
+ function controlOwnsKey(target, event) {
2916
+ if (event.ctrlKey || event.metaKey || event.altKey) return false;
2917
+ const element = asElement(target);
2918
+ if (!element) return false;
2919
+ const tag = element.tagName;
2920
+ const type = inputType(element);
2921
+ if (tag === "BUTTON" || type === "button" || type === "submit" || type === "reset" || type === "image") {
2922
+ return event.key === " " || event.key === "Enter";
2923
+ }
2924
+ if (tag === "A" && element.getAttribute("href") !== null) {
2925
+ return event.key === "Enter";
2926
+ }
2927
+ if (tag === "SUMMARY") return event.key === " " || event.key === "Enter";
2928
+ if (type === "checkbox") return event.key === " ";
2929
+ if (type === "color") return event.key === " " || event.key === "Enter";
2930
+ if (type === "file") return event.key === " " || event.key === "Enter";
2931
+ if (type === "range") {
2932
+ return event.key.startsWith("Arrow") || RANGE_KEYS.has(event.key);
2933
+ }
2934
+ if (type === "radio") {
2935
+ return event.key === " " || event.key.startsWith("Arrow");
2936
+ }
2937
+ return false;
2938
+ }
2939
+ function isTypingTarget(target) {
2940
+ const element = asElement(target);
2941
+ if (!element) return false;
2942
+ if (element.isContentEditable) return true;
2943
+ const tag = element.tagName;
2944
+ if (tag === "TEXTAREA") return true;
2945
+ if (tag === "SELECT") return true;
2946
+ if (tag === "INPUT") {
2947
+ return !NON_TEXT_INPUT_TYPES.has(inputType(element));
2948
+ }
2949
+ const role = element.getAttribute("role");
2950
+ return role !== null && TYPE_AHEAD_ROLES.has(role);
2951
+ }
2952
+ var NON_TEXT_INPUT_TYPES = /* @__PURE__ */ new Set([
2953
+ "button",
2954
+ "checkbox",
2955
+ "color",
2956
+ "file",
2957
+ "hidden",
2958
+ "image",
2959
+ "radio",
2960
+ "range",
2961
+ "reset",
2962
+ "submit"
2963
+ ]);
2964
+ function firesWhileTyping(prepared) {
2965
+ const explicit = prepared.binding.whenTyping;
2966
+ if (explicit !== void 0) return explicit;
2967
+ const first = prepared.keys[0];
2968
+ if (first === void 0) return false;
2969
+ return first.mod || first.ctrl || first.meta || first.alt || first.key === "Escape";
2970
+ }
2971
+ function createShortcutManager(options = {}) {
2972
+ const isApple = options.isApple ?? detectApplePlatform();
2973
+ const sequenceTimeoutMs = options.sequenceTimeoutMs ?? DEFAULT_SEQUENCE_TIMEOUT_MS;
2974
+ const now = options.now ?? (() => Date.now());
2975
+ const layers = /* @__PURE__ */ new Set();
2976
+ let nextSequence = 0;
2977
+ let pendingAt = null;
2978
+ let pendingLayer = null;
2979
+ const consumedPresses = /* @__PURE__ */ new Map();
2980
+ let pendingKey = null;
2981
+ function layerShape(bindings, options2) {
2982
+ const keys = bindings.map((b) => b.binding.keys).join("\0");
2983
+ return `${keys}${options2.depth}${options2.blocking === true}${options2.enabled !== false}`;
2984
+ }
2985
+ function blocking() {
2986
+ return ordered().some((layer) => layer.options.blocking === true);
2987
+ }
2988
+ function abandonSequence() {
2989
+ pendingAt = null;
2990
+ pressedEvents.length = 0;
2991
+ pendingLayer = null;
2992
+ pendingKey = null;
2993
+ }
2994
+ function prepare(bindings) {
2995
+ return bindings.map((binding) => ({
2996
+ binding,
2997
+ keys: parseKeys(binding.keys)
2998
+ }));
2999
+ }
3000
+ function ordered() {
3001
+ return [...layers].filter((layer) => layer.options.enabled !== false).sort(
3002
+ (a, b) => b.options.depth - a.options.depth || b.sequence - a.sequence
3003
+ );
3004
+ }
3005
+ function matchDepth(prepared, pressed) {
3006
+ if (pressed.length > prepared.keys.length) return "none";
3007
+ for (let i = 0; i < pressed.length; i++) {
3008
+ const chord = prepared.keys[i];
3009
+ const event = pressed[i];
3010
+ if (chord === void 0 || event === void 0) return "none";
3011
+ if (!chordMatches(chord, event.key, event, isApple)) return "none";
3012
+ }
3013
+ return pressed.length === prepared.keys.length ? "exact" : "prefix";
3014
+ }
3015
+ function fire(prepared, event, invoke) {
3016
+ if (prepared.binding.preventDefault !== false) event.preventDefault();
3017
+ if (invoke) prepared.binding.run(event);
3018
+ }
3019
+ function insertsText(event, typing) {
3020
+ if (event.key === "Tab")
3021
+ return !event.ctrlKey && !event.metaKey && !event.altKey;
3022
+ if (!typing) return false;
3023
+ const altGraph = event.getModifierState?.("AltGraph") ?? false;
3024
+ if (!altGraph && (event.ctrlKey || event.metaKey)) {
3025
+ const letter = event.key.length === 1 ? event.key.toLowerCase() : event.key;
3026
+ if (letter === "z" && event.shiftKey) return !event.altKey;
3027
+ if (letter === REDO_LETTER)
3028
+ return !isApple && !event.shiftKey && !event.altKey;
3029
+ if (EDITING_NAVIGATION.has(event.key)) return !event.altKey || isApple;
3030
+ if (event.shiftKey || event.altKey) return false;
3031
+ return EDITING_LETTERS.has(letter);
3032
+ }
3033
+ if (!altGraph && event.altKey) {
3034
+ if ((event.key === "ArrowDown" || event.key === "ArrowUp") && asElement(eventTarget(event))?.tagName === "SELECT") {
3035
+ return true;
3036
+ }
3037
+ if (!isApple) return false;
3038
+ if (EDITING_NAVIGATION.has(event.key)) return true;
3039
+ }
3040
+ if (event.key === "Dead" || event.key === "Process") return true;
3041
+ if ([...event.key].length === 1) return true;
3042
+ if (AMBIGUOUS_KEYS.has(event.key)) return targetOwnsAmbiguousKey(event);
3043
+ return FIELD_KEYS.has(event.key);
3044
+ }
3045
+ function offer(pressed, event, typing, invoke) {
3046
+ for (const layer of ordered()) {
3047
+ const mayMatch = pressed.length <= 1 || pendingLayer === null || layer === pendingLayer;
3048
+ if (mayMatch) {
3049
+ let prefixed = false;
3050
+ for (const prepared of layer.bindings) {
3051
+ if (typing && !firesWhileTyping(prepared)) continue;
3052
+ if (prepared.binding.when && !prepared.binding.when()) continue;
3053
+ const depth = matchDepth(prepared, pressed);
3054
+ if (depth === "exact") {
3055
+ fire(prepared, event, invoke);
3056
+ return "fired";
3057
+ }
3058
+ if (depth === "prefix") prefixed = true;
3059
+ }
3060
+ if (prefixed) {
3061
+ pendingLayer = layer;
3062
+ event.preventDefault();
3063
+ return "pending";
3064
+ }
3065
+ }
3066
+ if (layer.options.blocking) return "blocked";
3067
+ }
3068
+ return "none";
3069
+ }
3070
+ function warnOnPrefixConflicts(prepared, layerName) {
3071
+ const resolved = (chord) => {
3072
+ const ctrl = chord.ctrl || chord.mod && !isApple;
3073
+ const meta = chord.meta || chord.mod && isApple;
3074
+ const shift = shiftIsMeaningful(chord.key) ? chord.shift : false;
3075
+ return `${chord.key}\0${ctrl}${meta}${chord.alt}${shift}`;
3076
+ };
3077
+ const sameChord = (a, b) => resolved(a) === resolved(b);
3078
+ for (const short of prepared) {
3079
+ for (const long of prepared) {
3080
+ if (short === long || short.keys.length >= long.keys.length) continue;
3081
+ if (short.binding.when !== void 0) continue;
3082
+ if (!firesWhileTyping(short) && firesWhileTyping(long)) continue;
3083
+ if (short.keys.every((chord, i) => sameChord(chord, long.keys[i]))) {
3084
+ devWarnOnce(
3085
+ false,
3086
+ `shortcuts: in layer "${layerName}", "${short.binding.keys}" is a prefix of "${long.binding.keys}", so the longer one can never fire. Bind one or the other.`
3087
+ );
3088
+ }
3089
+ }
3090
+ }
3091
+ }
3092
+ const watchers = /* @__PURE__ */ new Set();
3093
+ let snapshot = null;
3094
+ function computeSnapshot() {
3095
+ return ordered().flatMap(
3096
+ (layer) => layer.bindings.map((prepared) => ({
3097
+ keys: prepared.binding.keys,
3098
+ description: prepared.binding.description,
3099
+ layer: layer.options.name
3100
+ }))
3101
+ );
3102
+ }
3103
+ function sameShortcuts(a, b) {
3104
+ return a.length === b.length && a.every(
3105
+ (entry, index) => entry.keys === b[index]?.keys && entry.description === b[index]?.description && entry.layer === b[index]?.layer
3106
+ );
3107
+ }
3108
+ function changed() {
3109
+ const previous = snapshot;
3110
+ snapshot = null;
3111
+ if (watchers.size === 0) return;
3112
+ const next = computeSnapshot();
3113
+ if (previous && sameShortcuts(previous, next)) {
3114
+ snapshot = previous;
3115
+ return;
3116
+ }
3117
+ snapshot = next;
3118
+ for (const watcher of watchers) watcher();
3119
+ }
3120
+ const pressedEvents = [];
3121
+ function runOffer(pressed, event, typing) {
3122
+ try {
3123
+ return offer(pressed, event, typing, true);
3124
+ } catch (error) {
3125
+ abandonSequence();
3126
+ consumedPresses.delete(signature(event));
3127
+ throw error;
3128
+ }
3129
+ }
3130
+ function handle(event) {
3131
+ if (event.defaultPrevented) {
3132
+ abandonSequence();
3133
+ return true;
3134
+ }
3135
+ if (event.isComposing) {
3136
+ abandonSequence();
3137
+ return true;
3138
+ }
3139
+ if (MODIFIER_KEYS.has(event.key)) return blocking();
3140
+ if (controlOwnsKey(eventTarget(event), event)) {
3141
+ abandonSequence();
3142
+ return true;
3143
+ }
3144
+ const typing = isTypingTarget(eventTarget(event));
3145
+ if (event.repeat) {
3146
+ if (pendingKey !== signature(event)) {
3147
+ abandonSequence();
3148
+ }
3149
+ const held = consumedPresses.get(signature(event));
3150
+ if (held) {
3151
+ if (held.prevented) {
3152
+ event.preventDefault();
3153
+ } else {
3154
+ const still = offer([event], event, typing, false);
3155
+ if (still !== "fired" && !insertsText(event, typing)) {
3156
+ event.preventDefault();
3157
+ }
3158
+ }
3159
+ return true;
3160
+ }
3161
+ const repeated = offer([event], event, typing, false);
3162
+ if (repeated === "blocked" && !insertsText(event, typing)) {
3163
+ event.preventDefault();
3164
+ }
3165
+ return repeated !== "none";
3166
+ }
3167
+ if (pendingAt !== null && now() - pendingAt > sequenceTimeoutMs) {
3168
+ abandonSequence();
3169
+ }
3170
+ pressedEvents.push(event);
3171
+ let outcome = runOffer(pressedEvents, event, typing);
3172
+ if (pressedEvents.length > 1 && (outcome === "none" || outcome === "blocked")) {
3173
+ abandonSequence();
3174
+ pressedEvents.push(event);
3175
+ outcome = runOffer(pressedEvents, event, typing);
3176
+ }
3177
+ if (outcome === "pending") {
3178
+ pendingAt = now();
3179
+ pendingKey = signature(event);
3180
+ consumedPresses.set(signature(event), {
3181
+ prevented: event.defaultPrevented
3182
+ });
3183
+ return true;
3184
+ }
3185
+ abandonSequence();
3186
+ if (outcome === "blocked") {
3187
+ if (!insertsText(event, typing)) event.preventDefault();
3188
+ }
3189
+ const consumed = outcome === "fired" || outcome === "blocked";
3190
+ if (consumed) {
3191
+ consumedPresses.set(signature(event), {
3192
+ prevented: event.defaultPrevented
3193
+ });
3194
+ } else {
3195
+ consumedPresses.delete(signature(event));
3196
+ }
3197
+ return consumed;
3198
+ }
3199
+ return {
3200
+ register(bindings, layerOptions) {
3201
+ const prepared = prepare(bindings);
3202
+ const layer = {
3203
+ options: layerOptions,
3204
+ bindings: prepared,
3205
+ sequence: nextSequence++,
3206
+ shape: layerShape(prepared, layerOptions)
3207
+ };
3208
+ warnOnPrefixConflicts(layer.bindings, layerOptions.name);
3209
+ layers.add(layer);
3210
+ changed();
3211
+ return {
3212
+ update(nextBindings, nextOptions) {
3213
+ layer.bindings = prepare(nextBindings);
3214
+ layer.options = nextOptions;
3215
+ warnOnPrefixConflicts(layer.bindings, nextOptions.name);
3216
+ const shape = layerShape(layer.bindings, nextOptions);
3217
+ const shapeChanged = shape !== layer.shape;
3218
+ layer.shape = shape;
3219
+ if (shapeChanged && pendingLayer === layer) abandonSequence();
3220
+ changed();
3221
+ },
3222
+ dispose() {
3223
+ layers.delete(layer);
3224
+ changed();
3225
+ if (pendingLayer === layer) abandonSequence();
3226
+ }
3227
+ };
3228
+ },
3229
+ handle,
3230
+ attach(target) {
3231
+ const listener = (event) => {
3232
+ try {
3233
+ if (handle(event)) event.stopPropagation();
3234
+ } catch (error) {
3235
+ event.stopPropagation();
3236
+ throw error;
3237
+ }
3238
+ };
3239
+ target.addEventListener("keydown", listener);
3240
+ return () => {
3241
+ target.removeEventListener("keydown", listener);
3242
+ abandonSequence();
3243
+ consumedPresses.clear();
3244
+ };
3245
+ },
3246
+ subscribe(onChange) {
3247
+ watchers.add(onChange);
3248
+ return () => {
3249
+ watchers.delete(onChange);
3250
+ };
3251
+ },
3252
+ activeBindings() {
3253
+ if (snapshot) return snapshot;
3254
+ snapshot = computeSnapshot();
3255
+ return snapshot;
3256
+ }
3257
+ };
3258
+ }
3259
+ var MODIFIER_KEYS = /* @__PURE__ */ new Set([
3260
+ "Control",
3261
+ "Meta",
3262
+ "Alt",
3263
+ "Shift",
3264
+ // A dedicated AltGraph key reports its own keydown before the character-producing one. Without
3265
+ // it here, pressing AltGraph mid-sequence abandons the sequence before the character that would
3266
+ // have completed it ever arrives.
3267
+ "AltGraph"
3268
+ ]);
3269
+ var TYPE_AHEAD_ROLES = /* @__PURE__ */ new Set([
3270
+ "textbox",
3271
+ "combobox",
3272
+ "listbox",
3273
+ // The focused element inside an open listbox is the OPTION, and it is what the event reports;
3274
+ // the listbox itself is only its ancestor.
3275
+ "option",
3276
+ "menu",
3277
+ "menuitem",
3278
+ "menuitemcheckbox",
3279
+ "menuitemradio"
3280
+ ]);
3281
+ var RANGE_KEYS = /* @__PURE__ */ new Set(["Home", "End", "PageUp", "PageDown"]);
3282
+ var EDITING_LETTERS = /* @__PURE__ */ new Set(["a", "c", "v", "x", "z"]);
3283
+ var REDO_LETTER = "y";
3284
+ var EDITING_NAVIGATION = /* @__PURE__ */ new Set([
3285
+ "Insert",
3286
+ "ArrowLeft",
3287
+ "ArrowRight",
3288
+ "ArrowUp",
3289
+ "ArrowDown",
3290
+ "Home",
3291
+ "End",
3292
+ "Backspace",
3293
+ "Delete"
3294
+ ]);
3295
+ var AMBIGUOUS_KEYS = /* @__PURE__ */ new Set(["Enter", "PageUp", "PageDown"]);
3296
+ function targetOwnsAmbiguousKey(event) {
3297
+ const element = asElement(eventTarget(event));
3298
+ if (element === null) return false;
3299
+ const multiline = element.tagName === "TEXTAREA" || element.isContentEditable;
3300
+ if (event.key === "Enter") return multiline;
3301
+ return multiline || element.tagName === "SELECT";
3302
+ }
3303
+ var FIELD_KEYS = /* @__PURE__ */ new Set([
3304
+ "Backspace",
3305
+ "Delete",
3306
+ "ArrowUp",
3307
+ "ArrowDown",
3308
+ "ArrowLeft",
3309
+ "ArrowRight",
3310
+ "Home",
3311
+ "End",
3312
+ // Shift+Insert pastes and carries no ctrl or meta, so it arrives here rather than at the
3313
+ // chord branch where Ctrl+Insert is recognised.
3314
+ "Insert",
3315
+ // Tab moves focus, and a blocking layer must NOT take it. The documented case for blocking is
3316
+ // a modal, whose focus trap only calls `preventDefault()` at the first and last tabbable
3317
+ // element — ordinary moves between the controls inside it rely on the browser default.
3318
+ // Suppressing every Tab therefore pinned focus to one control in exactly the situation
3319
+ // blocking exists to serve. A layer that genuinely wants Tab binds it.
3320
+ "Tab"
3321
+ ]);
3322
+
3323
+ // src/lib/shortcuts/react.tsx
3324
+ import { jsx as jsx38 } from "react/jsx-runtime";
3325
+ var ShortcutContext = React12.createContext(null);
3326
+ var ownersByTarget = /* @__PURE__ */ new WeakMap();
3327
+ var useIsomorphicLayoutEffect = typeof document === "undefined" ? React12.useEffect : React12.useLayoutEffect;
3328
+ function optionsFingerprint(options) {
3329
+ return [
3330
+ options.isApple ?? "auto",
3331
+ options.sequenceTimeoutMs ?? "default",
3332
+ options.now ? "clock" : "no-clock"
3333
+ ].join("\0");
3334
+ }
3335
+ function ShortcutProvider({
3336
+ children,
3337
+ target,
3338
+ ...managerOptions
3339
+ }) {
3340
+ const parent = React12.useContext(ShortcutContext);
3341
+ const resolvedTarget = target === null ? null : target ?? (typeof document === "undefined" ? null : document);
3342
+ const nestedOnSameTarget = parent !== null && parent.target === resolvedTarget;
3343
+ const optionsRef = React12.useRef(managerOptions);
3344
+ const ownManagers = React12.useRef(/* @__PURE__ */ new WeakMap());
3345
+ const ownDetached = React12.useRef(null);
3346
+ const detached = React12.useMemo(() => {
3347
+ if (resolvedTarget === null) {
3348
+ ownDetached.current ??= createShortcutManager(optionsRef.current);
3349
+ return ownDetached.current;
3350
+ }
3351
+ const existing = ownManagers.current.get(resolvedTarget);
3352
+ if (existing) return existing;
3353
+ const created = createShortcutManager(optionsRef.current);
3354
+ ownManagers.current.set(resolvedTarget, created);
3355
+ return created;
3356
+ }, [resolvedTarget]);
3357
+ let owner = resolvedTarget === null ? null : ownersByTarget.get(resolvedTarget);
3358
+ const fingerprint = optionsFingerprint(optionsRef.current);
3359
+ if (resolvedTarget !== null && (!owner || owner.retired)) {
3360
+ owner = {
3361
+ manager: detached,
3362
+ providers: 0,
3363
+ retired: false,
3364
+ options: fingerprint
3365
+ };
3366
+ ownersByTarget.set(resolvedTarget, owner);
3367
+ }
3368
+ const adoptedDiffers = Boolean(owner) && owner?.options !== fingerprint || nestedOnSameTarget && parent !== null && parent.options !== fingerprint;
3369
+ devWarnOnce(
3370
+ !adoptedDiffers,
3371
+ "ShortcutProvider: another provider is already listening on this target with different options, so the ones passed here are being ignored. Managers are shared per target; give the providers matching options, or a target of their own."
3372
+ );
3373
+ const manager = nestedOnSameTarget && parent ? parent.manager : owner ? owner.manager : detached;
3374
+ useIsomorphicLayoutEffect(() => {
3375
+ if (resolvedTarget === null) return;
3376
+ let entry = ownersByTarget.get(resolvedTarget);
3377
+ if (!entry) {
3378
+ entry = {
3379
+ manager,
3380
+ providers: 0,
3381
+ retired: false,
3382
+ options: optionsFingerprint(optionsRef.current)
3383
+ };
3384
+ ownersByTarget.set(resolvedTarget, entry);
3385
+ }
3386
+ const owned = entry;
3387
+ owned.providers += 1;
3388
+ owned.retired = false;
3389
+ if (owned.providers === 1) {
3390
+ owned.detach = owned.manager.attach(resolvedTarget);
3391
+ }
3392
+ return () => {
3393
+ owned.providers -= 1;
3394
+ if (owned.providers === 0) {
3395
+ owned.detach?.();
3396
+ owned.detach = void 0;
3397
+ owned.retired = true;
3398
+ }
3399
+ };
3400
+ }, [resolvedTarget, manager]);
3401
+ const depth = nestedOnSameTarget && parent ? parent.depth : 0;
3402
+ const value = React12.useMemo(
3403
+ () => ({ manager, depth, target: resolvedTarget, options: fingerprint }),
3404
+ [manager, depth, resolvedTarget, fingerprint]
3405
+ );
3406
+ return /* @__PURE__ */ jsx38(ShortcutContext.Provider, { value, children });
3407
+ }
3408
+ function ShortcutScope({
3409
+ children
3410
+ }) {
3411
+ const parent = React12.useContext(ShortcutContext);
3412
+ if (!parent) {
3413
+ throw new Error("ShortcutScope must be rendered inside a ShortcutProvider");
3414
+ }
3415
+ const value = React12.useMemo(
3416
+ () => ({
3417
+ manager: parent.manager,
3418
+ depth: parent.depth + 1,
3419
+ target: parent.target,
3420
+ // Inherited: a scope raises precedence, it does not build a manager, so the options in force
3421
+ // are still the ones the provider above it used.
3422
+ options: parent.options
3423
+ }),
3424
+ [parent.manager, parent.depth, parent.target, parent.options]
3425
+ );
3426
+ return /* @__PURE__ */ jsx38(ShortcutContext.Provider, { value, children });
3427
+ }
3428
+ function useShortcuts(bindings, options) {
3429
+ const context = React12.useContext(ShortcutContext);
3430
+ if (!context) {
3431
+ throw new Error("useShortcuts must be called inside a ShortcutProvider");
3432
+ }
3433
+ const { manager, depth } = context;
3434
+ const registration = React12.useRef(null);
3435
+ const latest = React12.useRef({ bindings, options });
3436
+ useIsomorphicLayoutEffect(() => {
3437
+ registration.current = manager.register([], {
3438
+ name: latest.current.options.name,
3439
+ depth
3440
+ });
3441
+ return () => {
3442
+ registration.current?.dispose();
3443
+ registration.current = null;
3444
+ };
3445
+ }, [manager, depth]);
3446
+ useIsomorphicLayoutEffect(() => {
3447
+ latest.current = { bindings, options };
3448
+ registration.current?.update(bindings, {
3449
+ name: options.name,
3450
+ depth,
3451
+ enabled: options.enabled,
3452
+ blocking: options.blocking
3453
+ });
3454
+ });
3455
+ }
3456
+ function useShortcutManager() {
3457
+ const context = React12.useContext(ShortcutContext);
3458
+ if (!context) {
3459
+ throw new Error(
3460
+ "useShortcutManager must be called inside a ShortcutProvider"
3461
+ );
3462
+ }
3463
+ return context.manager;
3464
+ }
3465
+ function useActiveShortcuts() {
3466
+ const manager = useShortcutManager();
3467
+ return React12.useSyncExternalStore(
3468
+ manager.subscribe,
3469
+ manager.activeBindings,
3470
+ manager.activeBindings
3471
+ );
3472
+ }
2320
3473
  export {
2321
3474
  Accordion,
2322
3475
  AccordionContent,
@@ -2436,7 +3589,10 @@ export {
2436
3589
  SheetPortal,
2437
3590
  SheetTitle,
2438
3591
  SheetTrigger,
3592
+ ShortcutProvider,
3593
+ ShortcutScope,
2439
3594
  Skeleton,
3595
+ Slider,
2440
3596
  Spinner,
2441
3597
  Stack,
2442
3598
  Stat,
@@ -2464,18 +3620,24 @@ export {
2464
3620
  TooltipContent,
2465
3621
  TooltipProvider,
2466
3622
  TooltipTrigger,
3623
+ TreeView,
2467
3624
  alertVariants,
2468
3625
  avatarVariants,
2469
3626
  badgeVariants,
2470
3627
  buttonVariants,
2471
3628
  cardVariants,
3629
+ createShortcutManager,
2472
3630
  dialogContentVariants,
2473
3631
  inputVariants,
3632
+ parseKeys,
2474
3633
  progressVariants,
2475
3634
  selectTriggerVariants,
2476
3635
  sheetVariants,
2477
3636
  spinnerVariants,
2478
3637
  toast,
2479
- usePortalContainer
3638
+ useActiveShortcuts,
3639
+ usePortalContainer,
3640
+ useShortcutManager,
3641
+ useShortcuts
2480
3642
  };
2481
3643
  //# sourceMappingURL=index.mjs.map