unsys-canvas 0.2.0 → 0.2.2

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, lazy, memo, useLayoutEffect, useCallback, useState, useEffect, Suspense, useRef, Component, useMemo, useContext } from 'react';
1
+ import { createContext, lazy, memo, useLayoutEffect, useCallback, useState, useEffect, Suspense, useRef, Component, useContext } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import '@excalidraw/excalidraw/index.css';
4
4
  import katex from 'katex';
@@ -2075,50 +2075,18 @@ function unsysCanvasRevealScroll(elements, appState, pad = 40) {
2075
2075
  }
2076
2076
  return { scrollX, scrollY };
2077
2077
  }
2078
- function unsysCanvasSelectionViewportRect(elements, appState) {
2079
- const bounds = unsysCanvasContentBounds(elements);
2080
- if (!bounds) return null;
2081
- const topLeft = unsysCanvasSceneToViewport({ x: bounds.minX, y: bounds.minY }, appState);
2082
- const bottomRight = unsysCanvasSceneToViewport({ x: bounds.maxX, y: bounds.maxY }, appState);
2083
- return {
2084
- left: Math.min(topLeft.x, bottomRight.x),
2085
- top: Math.min(topLeft.y, bottomRight.y),
2086
- right: Math.max(topLeft.x, bottomRight.x),
2087
- bottom: Math.max(topLeft.y, bottomRight.y)
2088
- };
2089
- }
2090
2078
  function unsysCanvasViewportToHost(point, host) {
2091
2079
  return {
2092
2080
  x: point.x - (Number(host?.left) || 0),
2093
2081
  y: point.y - (Number(host?.top) || 0)
2094
2082
  };
2095
2083
  }
2096
- function unsysCanvasSelectionHostRect(elements, appState, host) {
2097
- const rect = unsysCanvasSelectionViewportRect(elements, appState);
2098
- if (!rect) return null;
2099
- const originLeft = Number(host?.left) || 0;
2100
- const originTop = Number(host?.top) || 0;
2101
- return {
2102
- left: rect.left - originLeft,
2103
- top: rect.top - originTop,
2104
- right: rect.right - originLeft,
2105
- bottom: rect.bottom - originTop
2106
- };
2107
- }
2108
2084
  function ileLearnMoreSelectionKey(selectedElementIds) {
2109
2085
  return Object.keys(selectedElementIds ?? {}).filter((id) => Boolean(selectedElementIds?.[id])).sort().join(",");
2110
2086
  }
2111
2087
  function unsysCanvasPromptMode(selectedElementIds) {
2112
2088
  return ileLearnMoreSelectionKey(selectedElementIds) ? "commands" : "ask";
2113
2089
  }
2114
- function unsysCanvasSlashBarOpen(input) {
2115
- return Boolean(input.selectionActive && input.slashIntent);
2116
- }
2117
- function unsysCanvasSlashKeyOpensBar(input) {
2118
- if (input.typingInField) return false;
2119
- if (!input.selectionActive) return false;
2120
- return input.key === "/";
2121
- }
2122
2090
 
2123
2091
  // src/lib/work-canvas/work-canvas-xai-parse.ts
2124
2092
  var UNSYS_CANVAS_REPLY_TEXT_KEYS = [
@@ -2991,9 +2959,9 @@ var UNSYS_CANVAS_COMMANDS = [
2991
2959
  }
2992
2960
  ];
2993
2961
  var UNSYS_CANVAS_CHEATSHEET_LABEL = "Command cheat sheet";
2994
- var UNSYS_CANVAS_COMMAND_PICKER_LABEL = "Command picker";
2995
- var UNSYS_CANVAS_COMMAND_PICKER_SHORTCUT = "/";
2996
- var UNSYS_CANVAS_COMMAND_PICKER_TOOLTIP = "Type to filter commands, then Enter to run one on the current selection. Escape closes. Shortcut / while something is selected. Also right-click or the / control near the selection.";
2962
+ var UNSYS_CANVAS_CONTEXT_MENU_ROW_LABEL = "Right-click menu";
2963
+ var UNSYS_CANVAS_CONTEXT_MENU_ROW_HINT = "Right-click";
2964
+ var UNSYS_CANVAS_CONTEXT_MENU_ROW_TOOLTIP = "Right-click a selection. Every command is listed in the Commands section at the top of the board menu, with its shortcut. Click one to run it on that selection. On touch, press and hold.";
2997
2965
  function unsysCanvasCommandsFor(_guide, extras = []) {
2998
2966
  const catalog = UNSYS_CANVAS_COMMANDS.map((command) => ({ ...command }));
2999
2967
  const seen = new Set(catalog.map((command) => command.id));
@@ -3073,33 +3041,6 @@ function filterUnsysCanvasCommands(query, guide, extras = []) {
3073
3041
  (command) => unsysCanvasCommandMatchNames(command).some((name) => name.startsWith(q))
3074
3042
  );
3075
3043
  }
3076
- function unsysCanvasFuzzySubsequence(name, query) {
3077
- let i = 0;
3078
- for (const ch of name) {
3079
- if (ch === query[i]) i += 1;
3080
- if (i >= query.length) return true;
3081
- }
3082
- return false;
3083
- }
3084
- function unsysCanvasCommandFuzzyScore(command, query) {
3085
- const q = String(query || "").trim().toLowerCase();
3086
- if (!q) return 1;
3087
- if (command.shortcut && command.shortcut.toLowerCase() === q) return 100;
3088
- let best = 0;
3089
- for (const name of unsysCanvasCommandMatchNames(command)) {
3090
- if (name === q) best = Math.max(best, 90);
3091
- else if (name.startsWith(q)) best = Math.max(best, 80);
3092
- else if (name.includes(q)) best = Math.max(best, 50);
3093
- else if (unsysCanvasFuzzySubsequence(name, q)) best = Math.max(best, 20);
3094
- }
3095
- return best;
3096
- }
3097
- function fuzzyFilterUnsysCanvasCommands(query, guide, extras = []) {
3098
- const catalog = unsysCanvasCommandsFor(guide, extras);
3099
- const q = String(query || "").trim().toLowerCase();
3100
- if (!q) return catalog;
3101
- return catalog.map((command) => ({ command, score: unsysCanvasCommandFuzzyScore(command, q) })).filter((row) => row.score > 0).sort((a, b) => b.score - a.score || a.command.label.localeCompare(b.command.label)).map((row) => row.command);
3102
- }
3103
3044
  function unsysCanvasCommandDraft(raw) {
3104
3045
  const trimmed = String(raw ?? "").trim();
3105
3046
  if (!trimmed.startsWith("/")) {
@@ -3705,184 +3646,116 @@ function CanvasPromptBar({
3705
3646
  useEffect(() => () => publishCommands(null), [publishCommands]);
3706
3647
  return null;
3707
3648
  }
3708
- var UNSYS_CANVAS_COMMAND_RAIL_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 whitespace-nowrap rounded-none border border-white/45 bg-black px-1.5 py-2 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
3709
- var UNSYS_CANVAS_COMMAND_SIDEBAR_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 overflow-hidden whitespace-nowrap rounded-none border border-white/35 bg-black px-1.5 py-1.5 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
3710
- var UNSYS_CANVAS_COMMAND_SIDEBAR_MARK_CLASS = "h-3.5 w-3.5 shrink-0";
3711
- var UNSYS_CANVAS_COMMAND_STRIPE_CLASS = "pointer-events-auto relative flex h-10 w-10 shrink-0 items-center justify-center rounded-none border border-white/35 bg-black text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
3712
- var UNSYS_CANVAS_COMMAND_STRIPE_MARK_CLASS = "h-4 w-4 shrink-0";
3713
- var ICON_PATHS = {
3714
- focus: "M8 2v2.5M8 11.5V14M2 8h2.5M11.5 8H14M8 5.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z",
3715
- next: "M2 8h9M8 4.5l4.5 3.5L8 11.5M13.5 3.5v9",
3716
- simplify: "M3 4h10M3 8h7M3 12h4",
3717
- breakdown: "M2 6.5h4v3H2zM10 2.5h4v3h-4zM10 10.5h4v3h-4zM6 8h4M10 8V4M10 8v6.5",
3718
- concepts: "M2 2.5h4v3H2zM10 2.5h4v3h-4zM6 10.5h4v3H6zM4 5.5v5M12 5.5v5M8 8.5v2",
3719
- define: "M3 2.5h10v11H3zM5.5 5.5h5M5.5 8h7M5.5 10.5h4",
3720
- answer: "M3 3h10v7H8l-3 3v-3H3z",
3721
- draw: "M10.5 2.5l3 3-8 8H2.5v-3zM9 4l3 3",
3722
- refactor: "M4 3h5v2H6.5A4.5 4.5 0 1 1 3 10M12 13H7v-2h2.5A4.5 4.5 0 1 1 13 6",
3723
- pretty: "M2.5 2.5h11v11H2.5zM5 6h6M5 8.5h6M5 11h4",
3724
- picker: "M3 4.5h10M3 8h7M3 11.5h4",
3725
- dictate: "M8 2.5a2 2 0 0 1 2 2V8a2 2 0 1 1-4 0V4.5a2 2 0 0 1 2-2zM5 8.5a3 3 0 0 0 6 0M8 11.5V14",
3726
- pointer: "M4.2 8.2a3.6 3.6 0 1 1 3.6-3.6l5.8 5.8a2.2 2.2 0 0 1-3.1 3.1zM9.4 9.4l2.1 2.1M7 7.2l1.3 1.3M4.8 4.8l1.8 1.8",
3727
- commit: "M3 8h10M10 5l3 3-3 3",
3728
- "rail-expand": "M6 3l5 5-5 5",
3729
- "rail-collapse": "M10 3L5 8l5 5",
3730
- boards: "M2.5 3.5h4.5v4.5H2.5zM9 3.5h4.5v4.5H9zM2.5 10h4.5v3H2.5zM9 10h4.5v3H9z",
3731
- save: "M3 8.5V13h10V8.5M8 2.5v8M5 8l3 3 3-3"
3649
+
3650
+ // src/lib/work-canvas/work-canvas-context-menu.ts
3651
+ var UNSYS_CANVAS_CONTEXT_MENU_LABEL = "Commands";
3652
+ var UNSYS_CANVAS_CONTEXT_MENU_SELECTORS = {
3653
+ list: "ul.context-menu",
3654
+ popover: ".context-menu-popover",
3655
+ item: "context-menu-item",
3656
+ label: "context-menu-item__label",
3657
+ shortcut: "context-menu-item__shortcut",
3658
+ separator: "context-menu-item-separator",
3659
+ /** Only on the menu for a canvas click, never for a selection. */
3660
+ canvasOnlyTestId: "selectAll"
3732
3661
  };
3733
- function CommandMark({
3734
- id,
3735
- className = "h-3.5 w-3.5"
3736
- }) {
3737
- const d = ICON_PATHS[id] ?? ICON_PATHS.simplify;
3738
- return /* @__PURE__ */ jsx(
3739
- "svg",
3740
- {
3741
- viewBox: "0 0 16 16",
3742
- className,
3743
- fill: "none",
3744
- stroke: "currentColor",
3745
- strokeWidth: 1.4,
3746
- strokeLinecap: "round",
3747
- strokeLinejoin: "round",
3748
- "aria-hidden": true,
3749
- "data-unsys-canvas-command-mark": id,
3750
- "data-command-icon": id,
3751
- children: /* @__PURE__ */ jsx("path", { d })
3752
- }
3753
- );
3662
+ function unsysCanvasContextMenuEntries(extras = []) {
3663
+ return unsysCanvasCommandsFor(null, extras).map((command) => ({
3664
+ id: command.id,
3665
+ label: command.label,
3666
+ shortcut: unsysCanvasCommandShortcutLabel(command.shortcut),
3667
+ title: command.tooltip
3668
+ }));
3754
3669
  }
3755
- function UnsysCanvasCommandPicker({
3756
- open,
3757
- left,
3758
- top,
3759
- query,
3760
- extras = [],
3761
- onQueryChange,
3762
- onRun,
3763
- onClose
3764
- }) {
3765
- const inputRef = useRef(null);
3766
- const [active, setActive] = useState(0);
3767
- const matches = useMemo(
3768
- () => fuzzyFilterUnsysCanvasCommands(query, null, extras),
3769
- [extras, query]
3770
- );
3771
- useEffect(() => {
3772
- setActive(0);
3773
- }, [query, open]);
3774
- useEffect(() => {
3775
- if (!open) return;
3776
- inputRef.current?.focus();
3777
- inputRef.current?.select();
3778
- }, [open]);
3779
- if (!open) return null;
3780
- const runAt = (index) => {
3781
- const command = matches[index];
3782
- if (!command) return;
3783
- onRun(command.id);
3784
- };
3785
- return /* @__PURE__ */ jsxs(
3786
- "div",
3787
- {
3788
- "data-unsys-canvas-command-picker": true,
3789
- role: "dialog",
3790
- "aria-label": UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3791
- className: "pointer-events-auto absolute z-[70] w-[16.5rem] border border-white bg-black text-white shadow-[0_12px_40px_rgba(0,0,0,0.55)]",
3792
- style: { left, top },
3793
- onMouseDown: (event) => event.preventDefault(),
3794
- children: [
3795
- /* @__PURE__ */ jsx(
3796
- "input",
3797
- {
3798
- ref: inputRef,
3799
- "data-unsys-canvas-command-picker-input": true,
3800
- value: query,
3801
- onChange: (event) => onQueryChange(event.target.value.replace(/^\//, "")),
3802
- placeholder: "Filter commands",
3803
- "aria-label": UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3804
- className: "w-full border-b border-white/30 bg-black px-2 py-1.5 font-mono text-[12px] text-white outline-none placeholder:text-white/35",
3805
- onKeyDown: (event) => {
3806
- if (event.key === "Escape") {
3807
- event.preventDefault();
3808
- event.stopPropagation();
3809
- onClose();
3810
- return;
3811
- }
3812
- if (event.key === "ArrowDown") {
3813
- event.preventDefault();
3814
- setActive((prev) => Math.min(matches.length - 1, prev + 1));
3815
- return;
3816
- }
3817
- if (event.key === "ArrowUp") {
3818
- event.preventDefault();
3819
- setActive((prev) => Math.max(0, prev - 1));
3820
- return;
3821
- }
3822
- if (event.key === "Enter") {
3823
- event.preventDefault();
3824
- event.stopPropagation();
3825
- runAt(active);
3826
- }
3827
- }
3828
- }
3829
- ),
3830
- /* @__PURE__ */ jsx("ul", { "data-unsys-canvas-command-picker-list": true, className: "max-h-56 overflow-y-auto py-1", children: matches.length ? matches.map((command, index) => /* @__PURE__ */ jsx(
3831
- PickerRow,
3832
- {
3833
- command,
3834
- active: index === active,
3835
- onRun: () => onRun(command.id)
3836
- },
3837
- command.id
3838
- )) : /* @__PURE__ */ jsx("li", { className: "px-2 py-2 font-mono text-[11px] text-white/45", children: "No matching commands" }) })
3839
- ]
3840
- }
3670
+ function unsysCanvasContextMenuIsForSelection(list) {
3671
+ return !list.querySelector(
3672
+ `[data-testid="${UNSYS_CANVAS_CONTEXT_MENU_SELECTORS.canvasOnlyTestId}"]`
3841
3673
  );
3842
3674
  }
3843
- function PickerRow({
3844
- command,
3845
- active,
3846
- onRun
3847
- }) {
3848
- const shortcut = unsysCanvasCommandShortcutLabel(command.shortcut);
3849
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
3850
- "button",
3851
- {
3852
- type: "button",
3853
- "data-unsys-canvas-command-picker-row": command.id,
3854
- "data-active": active ? "true" : "false",
3855
- onClick: onRun,
3856
- className: `flex w-full items-center gap-2 px-2 py-1.5 text-left font-mono text-[11px] ${active ? "bg-white text-neutral-950" : "text-white hover:bg-white/10"}`,
3857
- children: [
3858
- /* @__PURE__ */ jsx(CommandMark, { id: command.id, label: command.label, className: "h-3.5 w-3.5 shrink-0" }),
3859
- /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: command.label }),
3860
- shortcut ? /* @__PURE__ */ jsx("kbd", { className: "shrink-0 text-[10px] opacity-55", children: shortcut }) : null
3861
- ]
3862
- }
3863
- ) });
3675
+ var SECTION_ATTR = "data-unsys-canvas-context-section";
3676
+ var ROW_ATTR = "data-unsys-canvas-context-command";
3677
+ function buildSection(doc, entries, onRun) {
3678
+ const S = UNSYS_CANVAS_CONTEXT_MENU_SELECTORS;
3679
+ const nodes = [];
3680
+ const header = doc.createElement("li");
3681
+ header.setAttribute(SECTION_ATTR, "header");
3682
+ header.textContent = UNSYS_CANVAS_CONTEXT_MENU_LABEL;
3683
+ header.style.cssText = "padding:0.25rem 1.25rem;font-size:0.65rem;letter-spacing:0.08em;text-transform:uppercase;opacity:0.55;pointer-events:none;";
3684
+ nodes.push(header);
3685
+ for (const entry of entries) {
3686
+ const li = doc.createElement("li");
3687
+ li.setAttribute(SECTION_ATTR, "item");
3688
+ li.setAttribute("data-testid", `unsys-canvas-command-${entry.id}`);
3689
+ const button = doc.createElement("button");
3690
+ button.type = "button";
3691
+ button.className = S.item;
3692
+ button.setAttribute(ROW_ATTR, entry.id);
3693
+ if (entry.title) button.title = entry.title;
3694
+ const label = doc.createElement("div");
3695
+ label.className = S.label;
3696
+ label.textContent = entry.label;
3697
+ const kbd = doc.createElement("kbd");
3698
+ kbd.className = S.shortcut;
3699
+ kbd.textContent = entry.shortcut;
3700
+ button.append(label, kbd);
3701
+ li.append(button);
3702
+ li.addEventListener("click", (event) => {
3703
+ event.preventDefault();
3704
+ event.stopPropagation();
3705
+ onRun(entry.id);
3706
+ });
3707
+ nodes.push(li);
3708
+ }
3709
+ const hr = doc.createElement("hr");
3710
+ hr.setAttribute(SECTION_ATTR, "separator");
3711
+ hr.className = S.separator;
3712
+ nodes.push(hr);
3713
+ return nodes;
3714
+ }
3715
+ function refitPopover(list, host) {
3716
+ const popover = list.closest(UNSYS_CANVAS_CONTEXT_MENU_SELECTORS.popover);
3717
+ if (!popover) return;
3718
+ const pad = 10;
3719
+ const bounds = host.getBoundingClientRect();
3720
+ const rect = popover.getBoundingClientRect();
3721
+ const room = bounds.height - pad * 2;
3722
+ if (rect.height > room) {
3723
+ popover.style.maxHeight = `${room}px`;
3724
+ popover.style.overflowY = "auto";
3725
+ popover.style.top = `${pad}px`;
3726
+ return;
3727
+ }
3728
+ const overflow = rect.bottom - (bounds.bottom - pad);
3729
+ if (overflow > 0) {
3730
+ const top = Number.parseFloat(popover.style.top) || 0;
3731
+ popover.style.top = `${Math.max(pad, top - overflow)}px`;
3732
+ }
3864
3733
  }
3865
- function UnsysCanvasCommandPickerAffordance({
3866
- visible,
3867
- left,
3868
- top,
3869
- onOpen
3870
- }) {
3871
- if (!visible) return null;
3872
- return /* @__PURE__ */ jsx(
3873
- "button",
3874
- {
3875
- type: "button",
3876
- "data-unsys-canvas-command-picker-affordance": true,
3877
- "aria-label": UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3878
- title: UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3879
- className: "pointer-events-auto absolute z-[60] flex h-6 w-6 items-center justify-center border border-white/50 bg-black font-mono text-[11px] text-white hover:border-white",
3880
- style: { left, top },
3881
- onMouseDown: (event) => event.preventDefault(),
3882
- onClick: onOpen,
3883
- children: "/"
3734
+ function installUnsysCanvasContextMenu(options) {
3735
+ const { host } = options;
3736
+ const doc = host.ownerDocument;
3737
+ const ObserverCtor = doc.defaultView?.MutationObserver ?? globalThis.MutationObserver;
3738
+ if (!ObserverCtor) return () => {
3739
+ };
3740
+ const inject = () => {
3741
+ const lists = host.querySelectorAll(UNSYS_CANVAS_CONTEXT_MENU_SELECTORS.list);
3742
+ for (const list of lists) {
3743
+ if (list.querySelector(`[${SECTION_ATTR}]`)) continue;
3744
+ if (!options.canRun() || !unsysCanvasContextMenuIsForSelection(list)) continue;
3745
+ const entries = options.getEntries();
3746
+ if (!entries.length) continue;
3747
+ const nodes = buildSection(doc, entries, (id) => {
3748
+ options.closeMenu();
3749
+ options.onRun(id);
3750
+ });
3751
+ list.prepend(...nodes);
3752
+ refitPopover(list, host);
3884
3753
  }
3885
- );
3754
+ };
3755
+ const observer = new ObserverCtor(inject);
3756
+ observer.observe(host, { childList: true, subtree: true });
3757
+ inject();
3758
+ return () => observer.disconnect();
3886
3759
  }
3887
3760
 
3888
3761
  // src/lib/session-branch-model.ts
@@ -4403,6 +4276,99 @@ function unsysCanvasWithLiveTransparentFill(scene) {
4403
4276
  };
4404
4277
  }
4405
4278
 
4279
+ // src/lib/work-canvas/command-errors.ts
4280
+ var MODEL_KIND_LABEL = {
4281
+ ask: "Ask",
4282
+ check: "Check",
4283
+ "selective-compress": "Compress",
4284
+ "suggest-insight": "Suggest insight",
4285
+ "clear-overlaps": "Clear overlaps",
4286
+ declutter: "Declutter"
4287
+ };
4288
+ function unsysCanvasCommandDisplayName(commandId) {
4289
+ const id = String(commandId || "").trim();
4290
+ if (!id || id === "ask") return "Ask";
4291
+ const catalog = UNSYS_CANVAS_COMMANDS.find((command) => command.id === id);
4292
+ if (catalog) return catalog.label;
4293
+ return MODEL_KIND_LABEL[id] ?? id;
4294
+ }
4295
+ function inferApiName(text, explicit) {
4296
+ const given = String(explicit || "").trim();
4297
+ if (given) return given;
4298
+ const lower = text.toLowerCase();
4299
+ if (lower.includes("openai")) return "OpenAI";
4300
+ if (lower.includes("anthropic") || lower.includes("claude")) return "Anthropic";
4301
+ return "xAI";
4302
+ }
4303
+ function unsysCanvasErrorHttpStatus(text) {
4304
+ const labeled = text.match(/\b(?:status|code|HTTP)\s*[:=]?\s*(\d{3})\b/i);
4305
+ if (labeled) return Number(labeled[1]);
4306
+ const parens = text.match(/\((\d{3})\)/);
4307
+ if (parens) return Number(parens[1]);
4308
+ const bare = text.match(/\b([1-9]\d{2})\b/);
4309
+ if (!bare) return null;
4310
+ const status = Number(bare[1]);
4311
+ return status >= 400 && status <= 599 ? status : null;
4312
+ }
4313
+ function statusReason(status, text) {
4314
+ if (status === 401 || status === 403) return "Check the API key.";
4315
+ if (status === 429) return "The API is rate-limiting requests.";
4316
+ if (status === 402) return "The API account has no credit.";
4317
+ if (status >= 500) return "The API had a server error.";
4318
+ const cut = text.replace(/^[^:]*:\s*/, "").replace(/\(\d{3}\)/g, "").replace(/\b(?:status|code|HTTP)\s*[:=]?\s*\d{3}\b/gi, "").replace(/\s+/g, " ").trim();
4319
+ return cut && cut.length < 180 ? cut : null;
4320
+ }
4321
+ function formatUnsysCanvasApiError(input) {
4322
+ const api = inferApiName(`${input.apiName || ""} ${input.baseUrl || ""}`, input.apiName);
4323
+ const status = input.status != null && Number.isFinite(Number(input.status)) ? Number(input.status) : null;
4324
+ if (status === 401 || status === 403) {
4325
+ return `the ${api} API returned ${status}. Check the API key.`;
4326
+ }
4327
+ if (status) {
4328
+ const reason2 = String(input.reason || "").trim();
4329
+ return reason2 ? `the ${api} API returned ${status} (${reason2}).` : `the ${api} API returned ${status}.`;
4330
+ }
4331
+ const reason = String(input.reason || "").trim();
4332
+ return reason ? `the ${api} API failed (${reason}).` : `the ${api} API failed.`;
4333
+ }
4334
+ function formatUnsysCanvasUnparseableReply(commandId) {
4335
+ const name = unsysCanvasCommandDisplayName(commandId);
4336
+ return `${name} couldn't use the model reply because it wasn't valid.`;
4337
+ }
4338
+ function formatUnsysCanvasCommandError(error, input) {
4339
+ const name = unsysCanvasCommandDisplayName(input?.commandId);
4340
+ const raw = error instanceof Error ? error.message : String(error ?? "");
4341
+ const text = raw.replace(/\s+/g, " ").trim();
4342
+ const lower = text.toLowerCase();
4343
+ const api = inferApiName(text, input?.apiName);
4344
+ const status = unsysCanvasErrorHttpStatus(text);
4345
+ if (/no api key|no xai api key|missing api key/i.test(text)) {
4346
+ return `${name} couldn't run: no ${api} API key. Check the API key.`;
4347
+ }
4348
+ if (!text) {
4349
+ return `${name} couldn't run: the ${api} API failed.`;
4350
+ }
4351
+ if (status === 401 || status === 403 || /unauthorized|invalid api key|incorrect api key/i.test(text)) {
4352
+ return `${name} couldn't run: the ${api} API returned ${status ?? 401}. Check the API key.`;
4353
+ }
4354
+ if (/timed? ?out|aborted|aborterror/i.test(lower)) {
4355
+ return `${name} couldn't run: the ${api} API timed out.`;
4356
+ }
4357
+ if (/empty reply|not valid|unparseable|could not parse|couldn't parse|invalid json|isn't valid/i.test(
4358
+ lower
4359
+ )) {
4360
+ return formatUnsysCanvasUnparseableReply(input?.commandId);
4361
+ }
4362
+ if (status) {
4363
+ const reason = statusReason(status, text);
4364
+ return `${name} couldn't run: ${formatUnsysCanvasApiError({ apiName: api, status, reason })}`;
4365
+ }
4366
+ if (/api failed|canvas model failed|failed to generate/i.test(lower)) {
4367
+ return `${name} couldn't run: ${formatUnsysCanvasApiError({ apiName: api, reason: text })}`;
4368
+ }
4369
+ return `${name} couldn't run: ${text}`;
4370
+ }
4371
+
4406
4372
  // src/lib/work-canvas/work-canvas-xai.ts
4407
4373
  var UNSYS_CANVAS_CONTEXT_TEXT_MAX = 220;
4408
4374
  var UNSYS_CANVAS_CONTEXT_MAX_MARKS = 24;
@@ -4412,7 +4378,7 @@ function unsysCanvasXaiNeedsBoardContext(kind) {
4412
4378
  function unsysCanvasXaiMaxTokens(kind) {
4413
4379
  if (kind === "concepts") return 220;
4414
4380
  if (kind === "simplify") return 280;
4415
- if (kind === "pretty") return 520;
4381
+ if (kind === "pretty") return 1600;
4416
4382
  if (kind === "refactor" || kind === "check" || kind === "suggest-insight") return 400;
4417
4383
  if (kind === "selective-compress" || kind === "clear-overlaps" || kind === "declutter") return 360;
4418
4384
  return 800;
@@ -4600,9 +4566,16 @@ function unsysCanvasSceneVisiblyChanged(before, after) {
4600
4566
  }
4601
4567
  return false;
4602
4568
  }
4603
- function unsysCanvasAskFallback(kind) {
4604
- if (!kind || kind === "ask") return "Learn more failed. Try again.";
4605
- return `${kind} failed. Try again.`;
4569
+ function applyUnsysCanvasCommandErrorNotice(input) {
4570
+ const text = String(input.message || "").trim();
4571
+ if (!text) return serializeUnsysCanvasScene(input.live);
4572
+ return withUnsysCanvasAutoLayout(
4573
+ mergeUnsysCanvasTurnOntoLiveWorkCanvas(
4574
+ input.live,
4575
+ { text },
4576
+ { fallbackOrigin: input.fallbackOrigin, reserved: input.reserved }
4577
+ )
4578
+ );
4606
4579
  }
4607
4580
  function applyUnsysCanvasAskReply(input) {
4608
4581
  const live = serializeUnsysCanvasScene(input.live);
@@ -4647,6 +4620,9 @@ function applyUnsysCanvasAskReply(input) {
4647
4620
  elements: input.payload.elements
4648
4621
  });
4649
4622
  if (placed.placed) next = placed.scene;
4623
+ else if (text || normalizeExtraSkeletons(input.payload.elements).length) {
4624
+ next = merge(text);
4625
+ }
4650
4626
  } else if (kind === "concepts") {
4651
4627
  const labels = unsysCanvasConceptLabels(source, {
4652
4628
  text: input.payload.text,
@@ -4661,8 +4637,17 @@ function applyUnsysCanvasAskReply(input) {
4661
4637
  next = merge(stripLearnerFacingWrappers(String(input.payload.text || "").trim()));
4662
4638
  }
4663
4639
  if (unsysCanvasSceneVisiblyChanged(live, next)) return withUnsysCanvasAutoLayout(next);
4664
- const fallback = stripLearnerFacingWrappers(String(input.payload.text || "").trim()) || unsysCanvasAskFallback(kind);
4665
- return withUnsysCanvasAutoLayout(merge(fallback));
4640
+ const recoverable = stripLearnerFacingWrappers(String(input.payload.text || "").trim());
4641
+ if (recoverable || normalizeExtraSkeletons(input.payload.elements).length) {
4642
+ const recovered = merge(recoverable);
4643
+ if (unsysCanvasSceneVisiblyChanged(live, recovered)) return withUnsysCanvasAutoLayout(recovered);
4644
+ }
4645
+ return applyUnsysCanvasCommandErrorNotice({
4646
+ live,
4647
+ message: formatUnsysCanvasUnparseableReply(kind),
4648
+ fallbackOrigin: input.fallbackOrigin,
4649
+ reserved: input.reserved
4650
+ });
4666
4651
  }
4667
4652
  function applyUnsysCanvasPositionEdits(scene, selectedElements, reply) {
4668
4653
  const current = serializeUnsysCanvasScene(scene);
@@ -4842,7 +4827,7 @@ function defaultBuildPrompt(commandId, context) {
4842
4827
  timeoutMs: unsysCanvasXaiFetchTimeout(kind)
4843
4828
  };
4844
4829
  }
4845
- var MODEL_KIND_LABEL = {
4830
+ var MODEL_KIND_LABEL2 = {
4846
4831
  ask: "Ask",
4847
4832
  check: "Check",
4848
4833
  "selective-compress": "Compress",
@@ -4853,8 +4838,8 @@ var MODEL_KIND_LABEL = {
4853
4838
  function hiddenModelDef(id) {
4854
4839
  return {
4855
4840
  id,
4856
- label: MODEL_KIND_LABEL[id] ?? id,
4857
- tooltip: MODEL_KIND_LABEL[id] ?? id,
4841
+ label: MODEL_KIND_LABEL2[id] ?? id,
4842
+ tooltip: MODEL_KIND_LABEL2[id] ?? id,
4858
4843
  shortcut: "",
4859
4844
  needsSelection: id !== "ask",
4860
4845
  boardOnly: false,
@@ -5131,7 +5116,7 @@ function createUnsysCanvasXaiBrowserRunner(options) {
5131
5116
  return async (request) => {
5132
5117
  const apiKey = String(await options.getApiKey() || "").trim();
5133
5118
  if (!apiKey) {
5134
- throw new Error("No API key.");
5119
+ throw new Error("No xAI API key.");
5135
5120
  }
5136
5121
  const baseURL = String(await options.getBaseUrl?.() || "").replace(/\/+$/, "") || "https://api.x.ai/v1";
5137
5122
  const model = typeof options.model === "function" ? options.model(request.commandId) : options.model || "grok-4.7";
@@ -5164,7 +5149,15 @@ function createUnsysCanvasXaiBrowserRunner(options) {
5164
5149
  if (!response.ok) {
5165
5150
  const err = data.error;
5166
5151
  const message = typeof err === "string" ? err : err && typeof err === "object" && "message" in err ? String(err.message || "") : "";
5167
- throw new Error(message.trim() || `Canvas model failed (${response.status})`);
5152
+ const apiName = /x\.ai/i.test(baseURL) ? "xAI" : "model";
5153
+ throw new Error(
5154
+ formatUnsysCanvasApiError({
5155
+ apiName,
5156
+ status: response.status,
5157
+ reason: message.trim(),
5158
+ baseUrl: baseURL
5159
+ })
5160
+ );
5168
5161
  }
5169
5162
  const text = choiceContent(data).trim();
5170
5163
  if (!text) throw new Error("Canvas chat returned an empty reply.");
@@ -5190,7 +5183,7 @@ function createUnsysCanvasModelProxyRunner(options) {
5190
5183
  const data = await response.json().catch(() => ({}));
5191
5184
  if (!response.ok) {
5192
5185
  const err = asRecord2(data.error);
5193
- const message = err && typeof err.message === "string" && err.message || (typeof data.error === "string" ? data.error : "") || `Canvas model failed (${response.status})`;
5186
+ const message = err && typeof err.message === "string" && err.message || (typeof data.error === "string" ? data.error : "") || `the model API returned ${response.status}`;
5194
5187
  throw new Error(message);
5195
5188
  }
5196
5189
  const raw = typeof data.raw === "string" && data.raw.trim() ? data.raw : typeof data.message === "string" ? data.message : "";
@@ -6876,9 +6869,51 @@ function useWorkCanvasCommands(input) {
6876
6869
  "[ExcalidrawCanvas] Ask XAI failed:",
6877
6870
  err instanceof Error ? err.message : String(err)
6878
6871
  );
6879
- const fallback = unsysCanvasAskFallback(askInput.kind);
6872
+ const message = formatUnsysCanvasCommandError(err, { commandId: askInput.kind });
6880
6873
  await enqueueCanvasAskApply(() => {
6881
- applyReply({ text: fallback });
6874
+ const live = liveWorkCanvasScene(api);
6875
+ const liveChip = thinkingChipsRef.current.find((chip) => chip.turnId === turnId);
6876
+ const placeAt = liveChip ? { x: liveChip.x, y: liveChip.y } : origin;
6877
+ const next = applyUnsysCanvasCommandErrorNotice({
6878
+ live,
6879
+ message,
6880
+ fallbackOrigin: placeAt,
6881
+ reserved: reservedThinkingOrigins(turnId)
6882
+ });
6883
+ const addedIds = new Set(unsysCanvasAddedElementIds(live, next));
6884
+ const added = next.elements.filter((el) => addedIds.has(el.id) && !el.isDeleted);
6885
+ const reveal = unsysCanvasRevealScroll(added, api.getAppState() ?? live.appState);
6886
+ commitScene(
6887
+ api,
6888
+ {
6889
+ elements: next.elements,
6890
+ appState: {
6891
+ selectedElementIds: Object.fromEntries(added.map((el) => [el.id, true])),
6892
+ ...reveal ?? {}
6893
+ },
6894
+ ...next.files ? { files: next.files } : {}
6895
+ },
6896
+ { applyingRemote: applyingRemoteRef }
6897
+ );
6898
+ canvasEventCollectorRef.current.syncWithoutEmit({
6899
+ elements: next.elements,
6900
+ appState: api.getAppState() ?? {},
6901
+ files: api.getFiles() ?? {}
6902
+ });
6903
+ emitCanvasEventsRef.current(
6904
+ canvasEventCollectorRef.current.commandComplete(askInput.kind ?? "ask", {
6905
+ inputs: unsysCanvasCommandEventInputs({
6906
+ commandId: String(askInput.kind || "ask"),
6907
+ selectedElements: askInput.selectedElements,
6908
+ prompt: askInput.prompt
6909
+ }),
6910
+ outputs: {
6911
+ ok: false,
6912
+ text: message,
6913
+ addedElementIds: [...addedIds]
6914
+ }
6915
+ })
6916
+ );
6882
6917
  });
6883
6918
  return false;
6884
6919
  } finally {
@@ -8424,11 +8459,7 @@ function ExcalidrawCanvas({
8424
8459
  const [isLoaded, setIsLoaded] = useState(false);
8425
8460
  const [canvasApiReady, setCanvasApiReady] = useState(false);
8426
8461
  const [commandText, setCommandText] = useState("");
8427
- const [slashBarOpen, setSlashBarOpen] = useState(false);
8428
- const [pickerPos, setPickerPos] = useState({ left: 24, top: 24 });
8429
- const commandInputRef = useRef(null);
8430
- const lastPointerHostRef = useRef({ x: 24, y: 24 });
8431
- const pickerSelectedRef = useRef([]);
8462
+ const contextMenuSelectedRef = useRef([]);
8432
8463
  const selectionWasActiveRef = useRef(false);
8433
8464
  const [askInFlight, setAskInFlight] = useState(0);
8434
8465
  const lastReplaceNonceRef = useRef(null);
@@ -8798,7 +8829,6 @@ function ExcalidrawCanvas({
8798
8829
  const active = Boolean(onAskRef.current) && unsysCanvasPromptMode(appState?.selectedElementIds ?? {}) === "commands";
8799
8830
  if (selectionWasActiveRef.current && !active) {
8800
8831
  setCommandText("");
8801
- setSlashBarOpen(false);
8802
8832
  }
8803
8833
  selectionWasActiveRef.current = active;
8804
8834
  setCanvasSelectionActive((prev) => prev === active ? prev : active);
@@ -8881,30 +8911,10 @@ function ExcalidrawCanvas({
8881
8911
  emitCanvasEventsRef.current(canvasEventCollectorRef.current.laser(payload));
8882
8912
  }
8883
8913
  });
8884
- const openCommandPickerAt = useCallback(
8885
- (x, y) => {
8886
- const host = canvasHostRef.current;
8887
- const width = host?.clientWidth ?? 320;
8888
- const height = host?.clientHeight ?? 240;
8889
- setPickerPos({
8890
- left: Math.max(8, Math.min(Math.round(x), width - 272)),
8891
- top: Math.max(8, Math.min(Math.round(y), height - 220))
8892
- });
8893
- pickerSelectedRef.current = selectedCanvasElements();
8894
- setCommandText("");
8895
- setSlashBarOpen(true);
8896
- },
8897
- [selectedCanvasElements]
8898
- );
8899
8914
  useEffect(() => {
8900
8915
  const onKey = (event) => {
8901
8916
  const target = event.target;
8902
8917
  const typingInField = target?.tagName === "INPUT" || target?.tagName === "TEXTAREA" || Boolean(target?.isContentEditable);
8903
- if (slashBarOpen && event.key === "Escape" && !typingInField) {
8904
- event.preventDefault();
8905
- setSlashBarOpen(false);
8906
- return;
8907
- }
8908
8918
  if (typingInField) return;
8909
8919
  const letter = unsysCanvasCommandShortcutKeyFromEvent(event);
8910
8920
  const key = String(event.key || "").toLowerCase();
@@ -8913,7 +8923,7 @@ function ExcalidrawCanvas({
8913
8923
  const kind = event.shiftKey ? "redo" : "undo";
8914
8924
  emitCanvasEventsRef.current(canvasEventCollectorRef.current.history(kind, { key }));
8915
8925
  }
8916
- if (letter && !slashBarOpen) {
8926
+ if (letter) {
8917
8927
  const command = unsysCanvasCommandByShortcut(letter, markModeRef.current, extraCommands);
8918
8928
  if (command) {
8919
8929
  event.preventDefault();
@@ -8921,34 +8931,35 @@ function ExcalidrawCanvas({
8921
8931
  return;
8922
8932
  }
8923
8933
  }
8924
- if (!unsysCanvasSlashKeyOpensBar({
8925
- key: event.key,
8926
- selectionActive: canvasSelectionActive,
8927
- typingInField
8928
- })) {
8929
- return;
8930
- }
8931
- event.preventDefault();
8932
- openCommandPickerAt(lastPointerHostRef.current.x, lastPointerHostRef.current.y);
8933
8934
  };
8934
8935
  window.addEventListener("keydown", onKey);
8935
8936
  return () => window.removeEventListener("keydown", onKey);
8936
- }, [
8937
- canvasSelectionActive,
8938
- extraCommands,
8939
- handleQuickActionRef,
8940
- openCommandPickerAt,
8941
- slashBarOpen
8942
- ]);
8937
+ }, [extraCommands, handleQuickActionRef]);
8938
+ const viewModeEnabledRef = useRef(viewModeEnabled);
8939
+ viewModeEnabledRef.current = viewModeEnabled;
8940
+ const extraCommandsForMenuRef = useRef(extraCommands);
8941
+ extraCommandsForMenuRef.current = extraCommands;
8943
8942
  useEffect(() => {
8944
- if (!unsysCanvasSlashBarOpen({
8945
- selectionActive: canvasSelectionActive,
8946
- slashIntent: slashBarOpen
8947
- })) {
8948
- return;
8949
- }
8950
- commandInputRef.current?.focus();
8951
- }, [canvasSelectionActive, slashBarOpen]);
8943
+ const host = canvasHostRef.current;
8944
+ if (!host || !isLoaded) return;
8945
+ return installUnsysCanvasContextMenu({
8946
+ host,
8947
+ getEntries: () => unsysCanvasContextMenuEntries(extraCommandsForMenuRef.current),
8948
+ canRun: () => {
8949
+ if (!onAskRef.current || viewModeEnabledRef.current) return false;
8950
+ const selected = selectedCanvasElements();
8951
+ contextMenuSelectedRef.current = selected;
8952
+ return selected.length > 0;
8953
+ },
8954
+ onRun: (id) => {
8955
+ const selected = contextMenuSelectedRef.current;
8956
+ handleQuickActionRef.current(id, selected.length ? selected : void 0);
8957
+ },
8958
+ closeMenu: () => {
8959
+ excalidrawAPIRef.current?.updateScene({ appState: { contextMenu: null } });
8960
+ }
8961
+ });
8962
+ }, [handleQuickActionRef, isLoaded, selectedCanvasElements]);
8952
8963
  useEffect(() => {
8953
8964
  if (applyElementsNonce == null || applyElementsNonce === lastApplyNonceRef.current) return;
8954
8965
  pendingApplyRef.current = {
@@ -9266,19 +9277,6 @@ function ExcalidrawCanvas({
9266
9277
  className: "relative min-h-0 flex-1",
9267
9278
  "data-unsys-canvas-host": true,
9268
9279
  style: { backgroundColor: sidebarStyle.canvas.background },
9269
- onMouseMove: (event) => {
9270
- const rect = event.currentTarget.getBoundingClientRect();
9271
- lastPointerHostRef.current = {
9272
- x: event.clientX - rect.left,
9273
- y: event.clientY - rect.top
9274
- };
9275
- },
9276
- onContextMenu: (event) => {
9277
- if (!canvasSelectionActive) return;
9278
- event.preventDefault();
9279
- const rect = event.currentTarget.getBoundingClientRect();
9280
- openCommandPickerAt(event.clientX - rect.left, event.clientY - rect.top);
9281
- },
9282
9280
  children: [
9283
9281
  isLoaded && /* @__PURE__ */ jsx(UnsysExcalidrawErrorBoundary, { children: /* @__PURE__ */ jsx(
9284
9282
  UnsysExcalidrawMount,
@@ -9346,7 +9344,6 @@ function ExcalidrawCanvas({
9346
9344
  askInFlight,
9347
9345
  canvasSelectionActive,
9348
9346
  submitCommand,
9349
- slashBarOpen,
9350
9347
  commandText,
9351
9348
  setCommandText,
9352
9349
  handleQuickAction,
@@ -9364,56 +9361,7 @@ function ExcalidrawCanvas({
9364
9361
  selectedMarkTexts: selectedCanvasElements().map((element) => element.text || "").filter((text) => text.trim()),
9365
9362
  markSpeech: dictateTranscript || ""
9366
9363
  }
9367
- ),
9368
- (() => {
9369
- const selected = selectedCanvasElements();
9370
- const hostRect = unsysCanvasSelectionHostRect(
9371
- selected,
9372
- excalidrawAPIRef.current?.getAppState?.() ?? {}
9373
- );
9374
- const pickerOpen = unsysCanvasSlashBarOpen({
9375
- selectionActive: canvasSelectionActive,
9376
- slashIntent: slashBarOpen
9377
- });
9378
- return /* @__PURE__ */ jsxs(Fragment, { children: [
9379
- /* @__PURE__ */ jsx(
9380
- UnsysCanvasCommandPickerAffordance,
9381
- {
9382
- visible: canvasSelectionActive && !pickerOpen && Boolean(hostRect),
9383
- left: Math.round((hostRect?.right ?? 0) + 6),
9384
- top: Math.round(hostRect?.top ?? 0),
9385
- onOpen: () => openCommandPickerAt(
9386
- (hostRect?.right ?? lastPointerHostRef.current.x) + 8,
9387
- hostRect?.top ?? lastPointerHostRef.current.y
9388
- )
9389
- }
9390
- ),
9391
- /* @__PURE__ */ jsx(
9392
- UnsysCanvasCommandPicker,
9393
- {
9394
- open: pickerOpen,
9395
- left: pickerPos.left,
9396
- top: pickerPos.top,
9397
- query: commandText,
9398
- extras: extraCommands,
9399
- onQueryChange: setCommandText,
9400
- onClose: () => {
9401
- setSlashBarOpen(false);
9402
- setCommandText("");
9403
- },
9404
- onRun: (id) => {
9405
- const selectedForRun = pickerSelectedRef.current;
9406
- setSlashBarOpen(false);
9407
- setCommandText("");
9408
- handleQuickActionRef.current(
9409
- id,
9410
- selectedForRun.length ? selectedForRun : void 0
9411
- );
9412
- }
9413
- }
9414
- )
9415
- ] });
9416
- })()
9364
+ )
9417
9365
  ]
9418
9366
  }
9419
9367
  )
@@ -9434,6 +9382,53 @@ function ExtraCommandsProvider({
9434
9382
  function useExtraCommands() {
9435
9383
  return useContext(ExtraCommandsContext);
9436
9384
  }
9385
+ var UNSYS_CANVAS_COMMAND_RAIL_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 whitespace-nowrap rounded-none border border-white/45 bg-black px-1.5 py-2 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
9386
+ var UNSYS_CANVAS_COMMAND_SIDEBAR_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 overflow-hidden whitespace-nowrap rounded-none border border-white/35 bg-black px-1.5 py-1.5 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
9387
+ var UNSYS_CANVAS_COMMAND_SIDEBAR_MARK_CLASS = "h-3.5 w-3.5 shrink-0";
9388
+ var UNSYS_CANVAS_COMMAND_STRIPE_CLASS = "pointer-events-auto relative flex h-10 w-10 shrink-0 items-center justify-center rounded-none border border-white/35 bg-black text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
9389
+ var UNSYS_CANVAS_COMMAND_STRIPE_MARK_CLASS = "h-4 w-4 shrink-0";
9390
+ var ICON_PATHS = {
9391
+ focus: "M8 2v2.5M8 11.5V14M2 8h2.5M11.5 8H14M8 5.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z",
9392
+ next: "M2 8h9M8 4.5l4.5 3.5L8 11.5M13.5 3.5v9",
9393
+ simplify: "M3 4h10M3 8h7M3 12h4",
9394
+ breakdown: "M2 6.5h4v3H2zM10 2.5h4v3h-4zM10 10.5h4v3h-4zM6 8h4M10 8V4M10 8v6.5",
9395
+ concepts: "M2 2.5h4v3H2zM10 2.5h4v3h-4zM6 10.5h4v3H6zM4 5.5v5M12 5.5v5M8 8.5v2",
9396
+ define: "M3 2.5h10v11H3zM5.5 5.5h5M5.5 8h7M5.5 10.5h4",
9397
+ answer: "M3 3h10v7H8l-3 3v-3H3z",
9398
+ draw: "M10.5 2.5l3 3-8 8H2.5v-3zM9 4l3 3",
9399
+ refactor: "M4 3h5v2H6.5A4.5 4.5 0 1 1 3 10M12 13H7v-2h2.5A4.5 4.5 0 1 1 13 6",
9400
+ pretty: "M2.5 2.5h11v11H2.5zM5 6h6M5 8.5h6M5 11h4",
9401
+ picker: "M3 4.5h10M3 8h7M3 11.5h4",
9402
+ dictate: "M8 2.5a2 2 0 0 1 2 2V8a2 2 0 1 1-4 0V4.5a2 2 0 0 1 2-2zM5 8.5a3 3 0 0 0 6 0M8 11.5V14",
9403
+ pointer: "M4.2 8.2a3.6 3.6 0 1 1 3.6-3.6l5.8 5.8a2.2 2.2 0 0 1-3.1 3.1zM9.4 9.4l2.1 2.1M7 7.2l1.3 1.3M4.8 4.8l1.8 1.8",
9404
+ commit: "M3 8h10M10 5l3 3-3 3",
9405
+ "rail-expand": "M6 3l5 5-5 5",
9406
+ "rail-collapse": "M10 3L5 8l5 5",
9407
+ boards: "M2.5 3.5h4.5v4.5H2.5zM9 3.5h4.5v4.5H9zM2.5 10h4.5v3H2.5zM9 10h4.5v3H9z",
9408
+ save: "M3 8.5V13h10V8.5M8 2.5v8M5 8l3 3 3-3"
9409
+ };
9410
+ function CommandMark({
9411
+ id,
9412
+ className = "h-3.5 w-3.5"
9413
+ }) {
9414
+ const d = ICON_PATHS[id] ?? ICON_PATHS.simplify;
9415
+ return /* @__PURE__ */ jsx(
9416
+ "svg",
9417
+ {
9418
+ viewBox: "0 0 16 16",
9419
+ className,
9420
+ fill: "none",
9421
+ stroke: "currentColor",
9422
+ strokeWidth: 1.4,
9423
+ strokeLinecap: "round",
9424
+ strokeLinejoin: "round",
9425
+ "aria-hidden": true,
9426
+ "data-unsys-canvas-command-mark": id,
9427
+ "data-command-icon": id,
9428
+ children: /* @__PURE__ */ jsx("path", { d })
9429
+ }
9430
+ );
9431
+ }
9437
9432
  function dictateButtonClass(kind, square, wide, plate, iconOnly) {
9438
9433
  const pressed = kind === "idle" ? " aria-pressed:bg-white aria-pressed:text-neutral-950" : "";
9439
9434
  if (iconOnly) return `${UNSYS_CANVAS_COMMAND_STRIPE_CLASS}${pressed}`;
@@ -9689,16 +9684,16 @@ function CanvasCommandCheatsheet({
9689
9684
  /* @__PURE__ */ jsxs(
9690
9685
  "li",
9691
9686
  {
9692
- "data-unsys-canvas-command-cheatsheet-row": "picker",
9687
+ "data-unsys-canvas-command-cheatsheet-row": "context-menu",
9693
9688
  className: "flex items-start gap-2 border border-white/20 px-2 py-2",
9694
9689
  children: [
9695
- /* @__PURE__ */ jsx(CommandMark, { id: "picker", label: UNSYS_CANVAS_COMMAND_PICKER_LABEL, className: "mt-0.5 h-4 w-4 shrink-0" }),
9690
+ /* @__PURE__ */ jsx(CommandMark, { id: "picker", label: UNSYS_CANVAS_CONTEXT_MENU_ROW_LABEL, className: "mt-0.5 h-4 w-4 shrink-0" }),
9696
9691
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
9697
9692
  /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
9698
- /* @__PURE__ */ jsx("span", { className: "font-mono text-[12px] font-semibold", children: UNSYS_CANVAS_COMMAND_PICKER_LABEL }),
9699
- /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-baseline gap-1.5 font-mono text-[10px] text-white/55", children: /* @__PURE__ */ jsx("kbd", { "data-shortcut-apple": UNSYS_CANVAS_COMMAND_PICKER_SHORTCUT, children: UNSYS_CANVAS_COMMAND_PICKER_SHORTCUT }) })
9693
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[12px] font-semibold", children: UNSYS_CANVAS_CONTEXT_MENU_ROW_LABEL }),
9694
+ /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-baseline gap-1.5 font-mono text-[10px] text-white/55", children: /* @__PURE__ */ jsx("kbd", { children: UNSYS_CANVAS_CONTEXT_MENU_ROW_HINT }) })
9700
9695
  ] }),
9701
- /* @__PURE__ */ jsx("p", { className: "mt-1 font-mono text-[11px] leading-snug text-white/70", children: UNSYS_CANVAS_COMMAND_PICKER_TOOLTIP })
9696
+ /* @__PURE__ */ jsx("p", { className: "mt-1 font-mono text-[11px] leading-snug text-white/70", children: UNSYS_CANVAS_CONTEXT_MENU_ROW_TOOLTIP })
9702
9697
  ] })
9703
9698
  ]
9704
9699
  }
@@ -9758,7 +9753,7 @@ function CanvasCommandCheatsheet({
9758
9753
  }
9759
9754
 
9760
9755
  // src/lib/session-instructions.ts
9761
- var CANVAS_HELP = "Write and draw on the board. Select marks, then run a command. / opens the command picker. Dictate places a Work note from speech. The pointer laser can Simplify, Concepts, Subdivide, Do/run, Refactor, or Pretty.";
9756
+ var CANVAS_HELP = "Write and draw on the board. Select marks, then run a command from the right-click menu. Dictate places a Work note from speech. The pointer laser can Simplify, Concepts, Subdivide, Do/run, Refactor, or Pretty.";
9762
9757
  var SESSION_INSTRUCTIONS = {
9763
9758
  board: CANVAS_HELP
9764
9759
  };