@hankchen/canvas-editor-react 0.0.0-stage → 1.0.1

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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -2
  3. package/dist/DropdownMenu-CCvv55NI.js +967 -0
  4. package/dist/PanelIcon-cQ-hx-Ky.js +87 -0
  5. package/dist/Tooltip-BAFJN0xP.js +815 -0
  6. package/dist/canvas/AlignFloatBar.d.ts +6 -0
  7. package/dist/canvas/CanvasSurface.d.ts +13 -0
  8. package/dist/canvas/ContextMenu.d.ts +14 -0
  9. package/dist/canvas/EditOverlayToolbar.d.ts +30 -0
  10. package/dist/canvas/FindBar.d.ts +13 -0
  11. package/dist/canvas/GuidesOverlay.d.ts +19 -0
  12. package/dist/canvas/Ruler.d.ts +32 -0
  13. package/dist/canvas/TextEditingOverlay.d.ts +22 -0
  14. package/dist/canvas/createBand.d.ts +6 -0
  15. package/dist/canvas/findHighlight.d.ts +12 -0
  16. package/dist/canvas/gizmo.d.ts +24 -0
  17. package/dist/canvas/guideSnap.d.ts +5 -0
  18. package/dist/canvas/index.d.ts +24 -0
  19. package/dist/canvas/resizeHandles.d.ts +3 -0
  20. package/dist/canvas/scheduler.d.ts +2 -0
  21. package/dist/canvas/useDpr.d.ts +9 -0
  22. package/dist/canvas/useFindSession.d.ts +12 -0
  23. package/dist/canvas/useTextEditing.d.ts +90 -0
  24. package/dist/canvas-jJ7OaUvZ.js +2171 -0
  25. package/dist/canvas.js +2 -0
  26. package/dist/chevron-down-D0_YGxvV.js +359 -0
  27. package/dist/createLucideIcon-CLd1sc0f.js +140 -0
  28. package/dist/index.d.ts +19 -0
  29. package/dist/index.js +16 -0
  30. package/dist/layer-panel/LayerPanel.d.ts +6 -0
  31. package/dist/layer-panel/TemplateTableForm.d.ts +10 -0
  32. package/dist/layer-panel/addMenu.d.ts +68 -0
  33. package/dist/layer-panel/index.d.ts +11 -0
  34. package/dist/layer-panel/useLayerPanel.d.ts +12 -0
  35. package/dist/layer-panel-DIfOb40N.js +779 -0
  36. package/dist/layer-panel.js +2 -0
  37. package/dist/mergeKey--xr8gdWl.js +694 -0
  38. package/dist/property-panel/PropertyField.d.ts +39 -0
  39. package/dist/property-panel/PropertyPanel.d.ts +5 -0
  40. package/dist/property-panel/controlStyles.d.ts +17 -0
  41. package/dist/property-panel/controls.d.ts +42 -0
  42. package/dist/property-panel/fieldSchema.d.ts +142 -0
  43. package/dist/property-panel/fields/AlignField.d.ts +3 -0
  44. package/dist/property-panel/fields/AnchorDisclosureField.d.ts +3 -0
  45. package/dist/property-panel/fields/BooleanField.d.ts +3 -0
  46. package/dist/property-panel/fields/BorderField.d.ts +3 -0
  47. package/dist/property-panel/fields/BorderWidthInput.d.ts +9 -0
  48. package/dist/property-panel/fields/ColorField.d.ts +3 -0
  49. package/dist/property-panel/fields/FontField.d.ts +3 -0
  50. package/dist/property-panel/fields/ImageSrcField.d.ts +3 -0
  51. package/dist/property-panel/fields/NumberField.d.ts +3 -0
  52. package/dist/property-panel/fields/PaddingField.d.ts +3 -0
  53. package/dist/property-panel/fields/PairField.d.ts +3 -0
  54. package/dist/property-panel/fields/ResourceValueField.d.ts +3 -0
  55. package/dist/property-panel/fields/RowsPathField.d.ts +3 -0
  56. package/dist/property-panel/fields/SelectField.d.ts +3 -0
  57. package/dist/property-panel/fields/ShorthandModeButton.d.ts +7 -0
  58. package/dist/property-panel/fields/TextField.d.ts +3 -0
  59. package/dist/property-panel/fields/TextareaField.d.ts +3 -0
  60. package/dist/property-panel/fields/ValueTypeSegmented.d.ts +8 -0
  61. package/dist/property-panel/fields/index.d.ts +18 -0
  62. package/dist/property-panel/fields/intrinsicSize.d.ts +9 -0
  63. package/dist/property-panel/imageUpload.d.ts +11 -0
  64. package/dist/property-panel/index.d.ts +14 -0
  65. package/dist/property-panel/shorthand.d.ts +28 -0
  66. package/dist/property-panel/usePropertyPanel.d.ts +67 -0
  67. package/dist/property-panel/useShorthandMode.d.ts +17 -0
  68. package/dist/property-panel-DD45Myee.js +1861 -0
  69. package/dist/property-panel.js +3 -0
  70. package/dist/resourceTemplate-B4QRWGq7.js +33 -0
  71. package/dist/shared/DropdownMenu.d.ts +18 -0
  72. package/dist/shared/ExpressionCompletionPopup.d.ts +11 -0
  73. package/dist/shared/ExpressionPathPicker.d.ts +23 -0
  74. package/dist/shared/HelpDialog.d.ts +10 -0
  75. package/dist/shared/PanelIcon.d.ts +11 -0
  76. package/dist/shared/Tooltip.d.ts +11 -0
  77. package/dist/shared/completion.d.ts +73 -0
  78. package/dist/shared/completionAnchor.d.ts +28 -0
  79. package/dist/shared/editableTarget.d.ts +14 -0
  80. package/dist/shared/expressionContext.d.ts +22 -0
  81. package/dist/shared/fontPicker.d.ts +13 -0
  82. package/dist/shared/index.d.ts +42 -0
  83. package/dist/shared/mergeKey.d.ts +2 -0
  84. package/dist/shared/pathPickerModel.d.ts +24 -0
  85. package/dist/shared/popupPosition.d.ts +41 -0
  86. package/dist/shared/resourceTemplate.d.ts +7 -0
  87. package/dist/shared/rowsPathPickerSource.d.ts +15 -0
  88. package/dist/shared/shortcutsHelp.d.ts +30 -0
  89. package/dist/shared/uploadFile.d.ts +2 -0
  90. package/dist/shared/useCnTheme.d.ts +11 -0
  91. package/dist/shared/useDataSourceSchema.d.ts +10 -0
  92. package/dist/shared/useDoc.d.ts +2 -0
  93. package/dist/shared/useDocumentExchange.d.ts +21 -0
  94. package/dist/shared/useDropdownMenu.d.ts +163 -0
  95. package/dist/shared/useExpressionCompletion.d.ts +35 -0
  96. package/dist/shared/useExpressionDiagnostics.d.ts +29 -0
  97. package/dist/shared/useHistory.d.ts +6 -0
  98. package/dist/shared/useSelection.d.ts +2 -0
  99. package/dist/shared/useShortcuts.d.ts +2 -0
  100. package/dist/shared/useShortcutsHelp.d.ts +8 -0
  101. package/dist/shared/useTransientFeedback.d.ts +9 -0
  102. package/dist/shared/useViewport.d.ts +2 -0
  103. package/dist/shared-QI04Xk-a.js +236 -0
  104. package/dist/shared.js +9 -0
  105. package/dist/status-bar/StatusBar.d.ts +14 -0
  106. package/dist/status-bar/index.d.ts +9 -0
  107. package/dist/status-bar/layerGeometryLabel.d.ts +13 -0
  108. package/dist/status-bar/layerPathLabel.d.ts +2 -0
  109. package/dist/status-bar-Bt3TonDm.js +181 -0
  110. package/dist/status-bar.js +2 -0
  111. package/dist/style.css +2 -0
  112. package/dist/theme.css +420 -0
  113. package/dist/useDoc-B2LXNJV7.js +32 -0
  114. package/dist/useViewport-DXtOHYgJ.js +18 -0
  115. package/package.json +83 -3
@@ -0,0 +1,163 @@
1
+ import { KeyboardEvent as ReactKeyboardEvent, RefObject } from 'react';
2
+ import { LucideIcon } from 'lucide-react';
3
+ /** 菜单项:shortcut 为纯展示键位后缀(右侧灰字,字符串由调用方传入,底座不做
4
+ * 平台检测);title 承载置灰原因(「置灰 + title」统一先例);keepsOpen 项分发
5
+ * 后菜单留场(面板+模板表表单交换特例);dataAttrs 透传 data-* 目验/测试钩子
6
+ * (状态栏 data-zoom-*、面板 data-add-layer 同缝);icon/checked 为可选扩展——
7
+ * icon 为 Lucide 组件引用(消费方按名 import 保 tree-shake),经 PanelIcon 渲染
8
+ * 于 label 前同一左组;checked 字段在场即换 role=menuitemradio + aria-checked
9
+ * (true 项右侧 ✓),未带字段维持 role=menuitem。 */
10
+ export interface DropdownMenuItem {
11
+ label: string;
12
+ title?: string;
13
+ disabled?: boolean;
14
+ shortcut?: string;
15
+ keepsOpen?: boolean;
16
+ dataAttrs?: Readonly<Record<string, string>>;
17
+ /** 可选图标(Lucide 组件引用,经 PanelIcon 缺省档渲染——封装不引 lucide
18
+ * 运行时,摇树按消费方 import 走);缺省零渲染 */
19
+ icon?: LucideIcon;
20
+ /** 勾选态:字段在场(含 false)即按 menuitemradio 渲染,aria-checked 随值、
21
+ * true 项右侧 ✓(aria-hidden 纯展示);未带字段维持 role=menuitem */
22
+ checked?: boolean;
23
+ run: () => void;
24
+ }
25
+ /**
26
+ * 两段式 submenu 条目:一级行渲染为左右两段命中区——主体(label + 可选 shortcut
27
+ * 灰字后缀)点击/Enter = run + 收菜单(直建语义,「保点一级直达」);右缘 ▸ 钮
28
+ * 悬停/点击唤出 children 二级浮层(预设项,title 承载归属说明)。children 收完整
29
+ * DropdownMenuEntry(容纳分隔符);dataAttrs 透传主体钮;keepsOpen 无此形态——
30
+ * 主体分发无条件收菜单。
31
+ */
32
+ export interface DropdownSubmenuEntry {
33
+ kind: 'submenu';
34
+ label: string;
35
+ title?: string;
36
+ disabled?: boolean;
37
+ shortcut?: string;
38
+ dataAttrs?: Readonly<Record<string, string>>;
39
+ /** 主体点击/Enter = 直建(run + 收整个菜单) */
40
+ run: () => void;
41
+ /** 预设二级条目(子项 run = 带 preset 直建,装配归宿主) */
42
+ children: readonly DropdownMenuEntry[];
43
+ }
44
+ /** submenu 形态判定(kind 字段只此形态持有,in 判定窄化联合) */
45
+ export declare function isSubmenuEntry(entry: DropdownMenuEntry): entry is DropdownSubmenuEntry;
46
+ /** 菜单条目 = 菜单项 | 两段式 submenu | 分隔符(成员间可插,排列▾/视图▾ 各需一段) */
47
+ export type DropdownMenuEntry = DropdownMenuItem | DropdownSubmenuEntry | 'separator';
48
+ export interface DropdownMenuController {
49
+ /** 菜单开合态(触发钮 aria-expanded 与菜单条件渲染同源) */
50
+ open: boolean;
51
+ toggle(): void;
52
+ openMenu(): void;
53
+ closeMenu(): void;
54
+ }
55
+ /**
56
+ * trigger / body 两个 render-prop 的受控 props(vue 版 #trigger/#body 插槽镜像):
57
+ * 自绘触发钮消费 open(驱动 aria-expanded)/toggle(点击开合,内含定位与焦点编
58
+ * 排)/triggerRef(元素记录,定位与回焦的前提)/onKeydown(↓ 开菜单);菜单体消
59
+ * 费 closeMenu(表单创建/取消自管收起)。a11y 两属性 aria-haspopup="menu"/
60
+ * aria-expanded 由消费方写在自绘钮上——底座保留 role="menu"/role="menuitem" 与
61
+ * 菜单 aria-label。
62
+ */
63
+ export interface DropdownMenuSlotProps {
64
+ open: boolean;
65
+ toggle(): void;
66
+ closeMenu(): void;
67
+ triggerRef(el: HTMLElement | null): void;
68
+ onKeydown(event: ReactKeyboardEvent<HTMLElement>): void;
69
+ }
70
+ export declare function useDropdownMenu(options: {
71
+ containerRef: RefObject<HTMLElement | null>;
72
+ }): DropdownMenuController;
73
+ /** 菜单内导航键:↑↓ 循环 + Home/End 首尾;左右键与 typeahead 不做 */
74
+ export type MenuFocusKey = 'ArrowDown' | 'ArrowUp' | 'Home' | 'End';
75
+ /**
76
+ * 菜单键盘导航落点(纯函数):enabled 与菜单项 DOM 序对齐的启用位标志,current
77
+ * 为现焦点项下标(焦点不在项上——菜单根本兜——传 -1),返回落点下标。置灰项
78
+ * 跳过;↑↓ 循环(末项 ↓ 绕首、首项 ↑ 绕尾),current=-1 时 ↓ 落首个启用项、
79
+ * ↑ 落末个;全置灰返回 -1,调用方回焦菜单根。
80
+ */
81
+ export declare function nextEnabledItemIndex(enabled: readonly boolean[], current: number, key: MenuFocusKey): number;
82
+ /** 二级开合动作(指针门控的语义输入):open = ▸ 悬停/键盘 →(恒开指定行);
83
+ * toggle = ▸ 点击(同行翻转、异行换开);close = 移出菜单/菜单随收/子项分发 */
84
+ export interface SubmenuToggleAction<T> {
85
+ type: 'open' | 'toggle' | 'close';
86
+ /** open/toggle 的目标条目(close 时无意义,恒 null) */
87
+ target?: T;
88
+ }
89
+ /**
90
+ * 二级开合切换(纯函数):单开不变量——任一时刻至多一行二级在场。open 换开
91
+ * (异行收旧开新、同行保持)、toggle 同行翻转(已开收、未开开)、close 全关。
92
+ */
93
+ export declare function nextOpenSubmenu<T>(current: T | null, action: SubmenuToggleAction<T>): T | null;
94
+ /** 二级浮层锚点盒(触发行 ▸ 的视口坐标,getBoundingClientRect 同形四轴) */
95
+ export interface SubmenuAnchorBox {
96
+ top: number;
97
+ bottom: number;
98
+ left: number;
99
+ right: number;
100
+ }
101
+ /** 二级浮层落点(视口坐标,fixed 直用);side = 弹出侧(右缘放不下翻左) */
102
+ export interface SubmenuPlacement {
103
+ left: number;
104
+ top: number;
105
+ side: 'right' | 'left';
106
+ }
107
+ /** 二级浮层与触发行的屏幕间隙(px,主菜单 MENU_GAP_PX 同值语义) */
108
+ export declare const SUBMENU_GAP_PX = 6;
109
+ /** 二级浮层与视口边缘的最小留白(px,主菜单 VIEWPORT_MARGIN_PX 同值语义) */
110
+ export declare const SUBMENU_VIEWPORT_MARGIN_PX = 2;
111
+ /**
112
+ * 二级浮层定位(纯函数):默认弹触发行右侧(左缘 = 行右缘 + 间隙、顶缘对齐行
113
+ * 顶缘);右缘放不下翻左侧(右缘 = 行左缘 − 间隙);水平/垂直都钳位进视口。
114
+ * 宽/高度量不到(0——首帧未渲染/降级)按「放得下/不移动」处理,不误翻转不误
115
+ * 收口(首帧锚点直用,渲染后调用方补量钳位)。纯几何、零 DOM、Node 可测。
116
+ */
117
+ export declare function placeSubmenuInViewport(options: {
118
+ anchor: SubmenuAnchorBox;
119
+ flyoutWidth: number;
120
+ flyoutHeight: number;
121
+ viewportWidth: number;
122
+ viewportHeight: number;
123
+ /** 触发行与浮层的间隙;缺省 SUBMENU_GAP_PX */
124
+ gap?: number;
125
+ /** 视口留白;缺省 SUBMENU_VIEWPORT_MARGIN_PX */
126
+ margin?: number;
127
+ }): SubmenuPlacement;
128
+ /**
129
+ * 二级浮层键盘动作(纯函数):焦点在二级浮层子项上时的按键决策——↑↓/Home/End
130
+ * 推进(落点仍归 nextEnabledItemIndex)、←/Esc 收二级(菜单留场,两段收的第一
131
+ * 段)、Enter/Space 激活焦点子项(带 preset 直建)、Tab 收整个菜单(沿现状,
132
+ * 不 preventDefault 由调用方保证)、其余 none(模态吞掉)。
133
+ */
134
+ export type SubmenuKeyAction = {
135
+ type: 'none';
136
+ } | {
137
+ type: 'move';
138
+ key: MenuFocusKey;
139
+ } | {
140
+ type: 'close';
141
+ } | {
142
+ type: 'activate';
143
+ } | {
144
+ type: 'close-menu';
145
+ };
146
+ export declare function submenuKeyAction(key: string): SubmenuKeyAction;
147
+ /**
148
+ * 开焦点落点(纯函数):条目 DOM 序首个启用项(无 disabled 属性),全置灰或空
149
+ * 清单回落容器根(菜单根/二级浮层根 tabindex=-1 可编程聚焦)。菜单开时入菜单
150
+ * 与二级键盘开入首项共用同一判定。
151
+ */
152
+ export declare function focusTargetOnOpen(items: readonly HTMLElement[], container: HTMLElement): HTMLElement;
153
+ /**
154
+ * 收二级回焦落点(纯函数):焦点在两段式行宿主内 → 该行 ▸ 钮(APG「关子菜单
155
+ * 回父项」惯例);焦点不在行内(防御路径)→ null = 不迁焦(只收不追焦)。
156
+ */
157
+ export declare function focusTargetOnSubmenuClose(active: HTMLElement | null): HTMLElement | null;
158
+ /**
159
+ * 收菜单回焦落点(纯函数):触发钮元素在场 → 回焦该钮(APG menu button 惯例,
160
+ * 幸免菜单条件渲染卸载时焦点坠 body);#trigger 自绘钮未接 triggerRef 的退化 →
161
+ * null = 不迁焦。哪些收起路回焦(点外收不回焦等)的编排归呈现件。
162
+ */
163
+ export declare function focusTargetOnMenuClose(trigger: HTMLElement | null): HTMLElement | null;
@@ -0,0 +1,35 @@
1
+ import { CompletionItem, CompletionSource } from './completion';
2
+ /** 浮层呈现态(传给 ExpressionCompletionPopup 的 state prop) */
3
+ export interface ExpressionCompletionState {
4
+ open: boolean;
5
+ items: readonly CompletionItem[];
6
+ activeIndex: number;
7
+ /** 视口坐标(fixed 定位;光标下缘 + 间隙) */
8
+ top: number;
9
+ left: number;
10
+ }
11
+ export declare function useExpressionCompletion(options: {
12
+ /** 表达式态开关(静态态恒闭);每次渲染以最新闭包读数(latest-props ref) */
13
+ enabled: () => boolean;
14
+ /** 候选源(纯函数注入缝,见 completion.ts) */
15
+ resolve: CompletionSource;
16
+ /** 浮层根元素(可选;在场时按其量宽做视口右缘收口) */
17
+ popupEl?: () => HTMLElement | null;
18
+ /**
19
+ * `{{` 自动配对门(可选):与 enabled 分离——表达式态未注入 schema 也配对
20
+ * (配对防的是未闭合静默错,不依赖候选声明);缺省回落 enabled。
21
+ */
22
+ pairing?: () => boolean;
23
+ /**
24
+ * 锚点测量缩放(可选):宿主整体在 CSS transform scale 系时传呈现缩放,
25
+ * mirror 布局偏移按其折算;缺省 1(面板侧宿主无变换,行为不变)。
26
+ */
27
+ scale?: () => number;
28
+ }): {
29
+ /** 呈现态快照,传给浮层组件 */
30
+ popup: ExpressionCompletionState;
31
+ /** 接受高亮项(或指定项);浮层点选经此回接 */
32
+ accept: (index?: number) => void;
33
+ /** 宿主输入元素回调 ref(控件 ref 直接连线;换绑/卸绑经同一入口) */
34
+ targetRef: (node: HTMLTextAreaElement | HTMLInputElement | null) => void;
35
+ };
@@ -0,0 +1,29 @@
1
+ import { ExpressionFragmentDiagnostic } from '@hankchen/canvas-editor';
2
+ /** 诊断汇总文案:多处取首条 kind 带计数;无诊断返回空串 */
3
+ export declare function expressionDiagnosticHint(diagnostics: readonly ExpressionFragmentDiagnostic[]): string;
4
+ /**
5
+ * 资源字段绑定门引导(resource-expression-single-ref 呈现面):资源字段表达式态
6
+ * 未注入数据源声明 → 选择器无菜单(引用以声明为门)——弱提示行说明缺席原因。
7
+ */
8
+ export declare const RESOURCE_BINDING_HINT = "\u7ED1\u5B9A\u6570\u636E\u6E90\u540E\u53EF\u9009\u62E9\u5B57\u6BB5";
9
+ /**
10
+ * 资源单值门的提示文案(ADR 0020 呈现面):门是内容引用约束,不是语法错——
11
+ * 不走「表达式语法错误」框架,按修复通道在场与否给动作指引(菜单点选是资源面
12
+ * 唯一写入口);违例 kind(拼接/函数/字面残留)只进诊断面,呈现统一按通道分流。
13
+ */
14
+ export declare function resourceDiagnosticHint(hasSource: boolean): string;
15
+ /** React hook 的宿主元素接绑形态(vue 版 target Ref 的对位):回调 ref 直连 */
16
+ export type ExpressionInputRef = (node: HTMLTextAreaElement | HTMLInputElement | null) => void;
17
+ export declare function useExpressionDiagnostics(options: {
18
+ /** 表达式态开关(静态态恒空);每次渲染以最新闭包读数(latest-props ref) */
19
+ enabled: () => boolean;
20
+ /** 诊断值的外部读数(宿主把 value 写进来,如非受控宿主的程序化同步面) */
21
+ getValue?: () => string;
22
+ }): {
23
+ /** 全部片段结构错诊断(模板坐标);关闭态恒空 */
24
+ diagnostics: readonly ExpressionFragmentDiagnostic[];
25
+ /** 程序化写值后的显式同步(初值注入等不走 input 事件的路径调用) */
26
+ refresh: () => void;
27
+ /** 宿主输入元素回调 ref(控件 ref 直接连线;换绑/卸绑经同一入口) */
28
+ targetRef: ExpressionInputRef;
29
+ };
@@ -0,0 +1,6 @@
1
+ import { EditorSession } from '@hankchen/canvas-editor';
2
+ export interface HistoryAvailability {
3
+ canUndo: boolean;
4
+ canRedo: boolean;
5
+ }
6
+ export declare function useHistory(editor: EditorSession): HistoryAvailability;
@@ -0,0 +1,2 @@
1
+ import { EditorSession, LayerPath } from '@hankchen/canvas-editor';
2
+ export declare function useSelection(editor: EditorSession): LayerPath | null;
@@ -0,0 +1,2 @@
1
+ import { EditorSession } from '@hankchen/canvas-editor';
2
+ export declare function useShortcuts(editor: EditorSession): void;
@@ -0,0 +1,8 @@
1
+ export interface ShortcutsHelp {
2
+ /** 面板开合态(单例共享,双入口同源) */
3
+ open: boolean;
4
+ show(): void;
5
+ close(): void;
6
+ toggle(): void;
7
+ }
8
+ export declare function useShortcutsHelp(): ShortcutsHelp;
@@ -0,0 +1,9 @@
1
+ export interface TransientFeedback {
2
+ /** 当前瞬时文案(空串 = 无) */
3
+ readonly message: string;
4
+ /** 显示一条瞬时反馈(替换前一条并重置驻留计时) */
5
+ show(text: string): void;
6
+ /** 立即清除当前文案(取消驻留计时) */
7
+ clear(): void;
8
+ }
9
+ export declare function useTransientFeedback(): TransientFeedback;
@@ -0,0 +1,2 @@
1
+ import { EditorSession, Viewport } from '@hankchen/canvas-editor';
2
+ export declare function useViewport(editor: EditorSession): Viewport;
@@ -0,0 +1,236 @@
1
+ import { _ as e, c as t, d as n, f as r, g as i, h as a, l as o, o as s, p as c, s as l } from "./DropdownMenu-CCvv55NI.js";
2
+ import { n as u, t as d } from "./useDoc-B2LXNJV7.js";
3
+ import { useCallback as f, useEffect as p, useRef as m, useSyncExternalStore as h } from "react";
4
+ import { createPortal as g } from "react-dom";
5
+ import { jsx as _, jsxs as v } from "react/jsx-runtime";
6
+ //#region src/shared/HelpDialog.tsx
7
+ var y = [
8
+ {
9
+ gesture: "Ctrl/⌘ + 滚轮",
10
+ text: "缩放画布(以指针为中心,5%–800%)"
11
+ },
12
+ {
13
+ gesture: "空格拖动",
14
+ text: "平移画布(中键拖拽、左键拖空白同效)"
15
+ },
16
+ {
17
+ gesture: "面板菜单 / T·G·Q·I",
18
+ text: "画拉建层:点层型或按键武装 → 画布拖拽定落位与尺寸(位移小于死区 = 点击兜底缺省尺寸)→ 自动选中、文本直打;Esc 取消"
19
+ },
20
+ {
21
+ gesture: "双击",
22
+ text: "就地编辑文本"
23
+ },
24
+ {
25
+ gesture: "Esc",
26
+ text: "退出编辑 / 解除武装 / 关闭弹层 / 选择逐级升级(格→行→表)"
27
+ },
28
+ {
29
+ gesture: "方向键",
30
+ text: "微调选中图层 1px(按住 Shift 大步 10px)"
31
+ },
32
+ {
33
+ gesture: "Tab / ⇧Tab",
34
+ text: "在根图层间循环选层(跳过隐藏与锁定)"
35
+ }
36
+ ];
37
+ function b({ bindings: e = i, platform: r }) {
38
+ let { open: a, close: s } = u(), c = r ?? o();
39
+ if (p(() => {
40
+ if (a === !1) return;
41
+ function e(e) {
42
+ e.key === "Escape" && s();
43
+ }
44
+ return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
45
+ }, [a, s]), a === !1) return null;
46
+ let d = t.map((t) => ({
47
+ group: t,
48
+ label: l[t],
49
+ bindings: e.filter((e) => e.group === t)
50
+ })).filter((e) => e.bindings.length > 0);
51
+ return g(/* @__PURE__ */ _("div", {
52
+ className: "cn-help",
53
+ "data-help-overlay": !0,
54
+ onPointerDown: (e) => {
55
+ e.target === e.currentTarget && s();
56
+ },
57
+ children: /* @__PURE__ */ v("div", {
58
+ className: "cn-help__panel",
59
+ role: "dialog",
60
+ "aria-modal": "true",
61
+ "aria-label": "快捷键帮助",
62
+ "data-help-dialog": !0,
63
+ children: [/* @__PURE__ */ v("header", {
64
+ className: "cn-help__header",
65
+ children: [/* @__PURE__ */ _("h2", {
66
+ className: "cn-help__title",
67
+ children: "快捷键"
68
+ }), /* @__PURE__ */ _("button", {
69
+ type: "button",
70
+ className: "cn-help__close",
71
+ "data-help-close": !0,
72
+ "aria-label": "关闭快捷键帮助",
73
+ onClick: s,
74
+ children: "✕"
75
+ })]
76
+ }), /* @__PURE__ */ v("div", {
77
+ className: "cn-help__body",
78
+ children: [d.map((e) => /* @__PURE__ */ v("section", {
79
+ className: "cn-help__section",
80
+ "data-help-group": e.group,
81
+ children: [/* @__PURE__ */ _("h3", {
82
+ className: "cn-help__section-title",
83
+ children: e.label
84
+ }), /* @__PURE__ */ _("ul", {
85
+ className: "cn-help__list",
86
+ children: e.bindings.map((e) => /* @__PURE__ */ v("li", {
87
+ className: "cn-help__row",
88
+ "data-help-shortcut": !0,
89
+ children: [/* @__PURE__ */ _("span", {
90
+ className: "cn-help__label",
91
+ children: e.label
92
+ }), /* @__PURE__ */ _("kbd", {
93
+ className: "cn-help__keys",
94
+ children: n(e.combo, c)
95
+ })]
96
+ }, `${e.action}:${e.combo.key}`))
97
+ })]
98
+ }, e.group)), /* @__PURE__ */ v("section", {
99
+ className: "cn-help__section",
100
+ "data-help-interactions": !0,
101
+ children: [/* @__PURE__ */ _("h3", {
102
+ className: "cn-help__section-title",
103
+ children: "内置交互"
104
+ }), /* @__PURE__ */ _("ul", {
105
+ className: "cn-help__list",
106
+ children: y.map((e) => /* @__PURE__ */ v("li", {
107
+ className: "cn-help__row",
108
+ "data-help-interaction": !0,
109
+ children: [/* @__PURE__ */ _("span", {
110
+ className: "cn-help__label",
111
+ children: e.text
112
+ }), /* @__PURE__ */ _("kbd", {
113
+ className: "cn-help__keys",
114
+ children: e.gesture
115
+ })]
116
+ }, e.gesture))
117
+ })]
118
+ })]
119
+ })]
120
+ })
121
+ }), document.body);
122
+ }
123
+ //#endregion
124
+ //#region src/shared/useDocumentExchange.ts
125
+ function x(e, t) {
126
+ let n = d(e), r = m(t);
127
+ return p(() => {
128
+ r.current = t;
129
+ }), {
130
+ doc: n,
131
+ loadDocument: f((t) => {
132
+ let n = r.current.decode(t);
133
+ return e.openDocument(n), n;
134
+ }, [e]),
135
+ extractDocument: f(() => {
136
+ let t = e.store.doc;
137
+ return t === null ? null : r.current.encode(t);
138
+ }, [e])
139
+ };
140
+ }
141
+ //#endregion
142
+ //#region src/shared/useHistory.ts
143
+ function S(e) {
144
+ let t = f((t) => e.subscribe((e) => {
145
+ e.scope === "doc" && t();
146
+ }), [e]), n = f(() => e.store.canUndo, [e]), r = f(() => e.store.canRedo, [e]);
147
+ return {
148
+ canUndo: h(t, n),
149
+ canRedo: h(t, r)
150
+ };
151
+ }
152
+ //#endregion
153
+ //#region src/shared/useCnTheme.ts
154
+ var C = "data-cn-theme", w = "dark", T = /* @__PURE__ */ new Set();
155
+ function E() {
156
+ for (let e of T) e();
157
+ }
158
+ function D(e) {
159
+ return T.add(e), () => T.delete(e);
160
+ }
161
+ var O = () => w;
162
+ function k(e) {
163
+ return e === "light" || e === "dark";
164
+ }
165
+ function A(e) {
166
+ try {
167
+ let t = localStorage.getItem(e);
168
+ return k(t) ? t : null;
169
+ } catch {
170
+ return null;
171
+ }
172
+ }
173
+ function j(e, t) {
174
+ try {
175
+ localStorage.setItem(e, t);
176
+ } catch {}
177
+ }
178
+ function M(e) {
179
+ e.setAttribute(C, w);
180
+ }
181
+ function N(e) {
182
+ let t = e?.storageKey, n = e?.target ?? (() => document.documentElement);
183
+ if (t !== void 0) {
184
+ let e = A(t);
185
+ e !== null && e !== w && (w = e, queueMicrotask(E));
186
+ }
187
+ let r = () => {
188
+ let e = n();
189
+ e !== null && M(e);
190
+ };
191
+ r();
192
+ let i = (e) => {
193
+ w = e, E(), r(), t !== void 0 && j(t, e);
194
+ };
195
+ return {
196
+ theme: h(D, O),
197
+ set: i,
198
+ toggle: () => {
199
+ i(w === "dark" ? "light" : "dark");
200
+ }
201
+ };
202
+ }
203
+ //#endregion
204
+ //#region src/shared/useShortcuts.ts
205
+ var P = new Set(Object.keys(a));
206
+ function F(t) {
207
+ let n = u(), i = r();
208
+ p(() => {
209
+ let r = (r) => {
210
+ let a = e({
211
+ key: r.key,
212
+ mod: r.ctrlKey || r.metaKey,
213
+ shift: r.shiftKey,
214
+ alt: r.altKey,
215
+ code: r.code,
216
+ composing: r.isComposing || r.keyCode === 229,
217
+ editing: t.store.ui.editing !== null,
218
+ editableTarget: c(r.target)
219
+ });
220
+ if (a !== null) {
221
+ if (r.preventDefault(), a === "helpShortcuts") {
222
+ n.toggle();
223
+ return;
224
+ }
225
+ t.executeShortcut(a), P.has(a) && i.show(s);
226
+ }
227
+ };
228
+ return window.addEventListener("keydown", r), () => window.removeEventListener("keydown", r);
229
+ }, [
230
+ t,
231
+ n,
232
+ i
233
+ ]);
234
+ }
235
+ //#endregion
236
+ export { b as a, x as i, N as n, S as r, F as t };
package/dist/shared.js ADDED
@@ -0,0 +1,9 @@
1
+ import { t as e } from "./PanelIcon-cQ-hx-Ky.js";
2
+ import { a as t, c as n, i as r, n as i, o as a, r as o, s, t as c } from "./Tooltip-BAFJN0xP.js";
3
+ import { n as l, t as u } from "./resourceTemplate-B4QRWGq7.js";
4
+ import { a as d, f, i as p, l as m, n as h, o as g, p as _, r as v, t as y, u as b } from "./DropdownMenu-CCvv55NI.js";
5
+ import { a as x, c as S, d as C, f as w, l as T, m as E, n as D, p as O, r as k, s as A, t as j, u as M } from "./mergeKey--xr8gdWl.js";
6
+ import { n as N, t as P } from "./useViewport-DXtOHYgJ.js";
7
+ import { n as F } from "./useDoc-B2LXNJV7.js";
8
+ import { a as I, i as L, n as R, r as z, t as B } from "./shared-QI04Xk-a.js";
9
+ export { g as ARM_LAYER_CREATE_HINT, v as DATA_SOURCE_GATE_HINT, y as DropdownMenu, O as ExpressionCompletionPopup, i as ExpressionPathPicker, D as FONT_PICKER_KEY, I as HelpDialog, o as POPUP_GAP, r as POPUP_MARGIN, e as PanelIcon, c as Tooltip, M as applyCompletion, u as attachResourceTemplate, m as detectShortcutPlatform, C as expressionCompletionSource, x as expressionDiagnosticHint, w as expressionFieldContext, k as injectFontPicker, _ as isEditableEventTarget, T as measureCursorAnchor, a as pathPickerEntries, t as placePopupInViewport, s as rowsPathPickerSource, n as rowsPathValueDrifts, j as selectionFieldMergeKey, b as shortcutActionLabel, l as stripResourceTemplate, E as uploadFileFromDom, R as useCnTheme, p as useDataSourceSchema, d as useDataSourceSchemaRejection, L as useDocumentExchange, h as useDropdownMenu, S as useExpressionCompletion, A as useExpressionDiagnostics, z as useHistory, N as useSelection, B as useShortcuts, F as useShortcutsHelp, f as useTransientFeedback, P as useViewport };
@@ -0,0 +1,14 @@
1
+ import { ReactNode } from 'react';
2
+ import { EditorSession } from '@hankchen/canvas-editor';
3
+ export interface StatusBarProps {
4
+ editor: EditorSession;
5
+ /** 宿主注入的物化在途计数(Materializer 住渲染端包,宿主订阅后传入);0 隐藏 */
6
+ pendingCount?: number;
7
+ /** 宿主注入的资源状态文案(资源就绪/物化中 N/失败 N 项);空串隐藏 */
8
+ resourceNote?: string;
9
+ /** 宿主注入的保存态;未接线(undefined)隐藏 */
10
+ saveState?: 'dirty' | 'clean';
11
+ /** 宿主注入的瞬时反馈文案(保存/打开/导出/上传/schema 动作结果与错误);空串隐藏 */
12
+ feedback?: string;
13
+ }
14
+ export declare function StatusBar({ editor, pendingCount, resourceNote, saveState, feedback }: StatusBarProps): ReactNode;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 状态栏域出口(vue 包 status-bar/index.ts 同源镜像):全壳读数归口——缩放/选中
3
+ * 路径/坐标尺寸/物化进行数/schema 声明态/保存态/瞬时反馈。物化计数与资源/保存/
4
+ * 反馈文案经宿主注入(红线禁直连 browser-renderer),坐标与 schema 段组件内部
5
+ * 直读内核切片。图层路径/坐标展示格式化随段导出。
6
+ */
7
+ export { formatLayerPath } from './layerPathLabel';
8
+ export { formatLayerGeometry } from './layerGeometryLabel';
9
+ export { StatusBar } from './StatusBar';
@@ -0,0 +1,13 @@
1
+ import { Anchor } from '@hankchen/canvas-editor';
2
+ /** 坐标段入参的最小结构:文档 position(LayerPosition 的 position 字段子集) */
3
+ export interface GeometryPosition {
4
+ readonly x: number;
5
+ readonly y: number;
6
+ readonly anchor: Anchor;
7
+ }
8
+ /** 坐标段入参的最小结构:解析盒(LayerBox 子集,只消费宽高) */
9
+ export interface GeometryBox {
10
+ readonly width: number;
11
+ readonly height: number;
12
+ }
13
+ export declare function formatLayerGeometry(position: GeometryPosition, box: GeometryBox): string;
@@ -0,0 +1,2 @@
1
+ import { LayerPath } from '@hankchen/canvas-editor';
2
+ export declare function formatLayerPath(path: LayerPath): string;