@hankchen/canvas-editor-react 0.0.0-stage → 1.0.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.
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,967 @@
1
+ import { t as e } from "./PanelIcon-cQ-hx-Ky.js";
2
+ import { useCallback as t, useEffect as n, useLayoutEffect as r, useRef as i, useState as a, useSyncExternalStore as o } from "react";
3
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
4
+ //#region ../canvas-editor/src/session/shortcuts.ts
5
+ var l = {
6
+ armCreateText: "TextLayer",
7
+ armCreateTable: "TableLayer",
8
+ armCreateQrCode: "QrCodeLayer",
9
+ armCreateImage: "ImageLayer"
10
+ }, u = [
11
+ {
12
+ combo: {
13
+ key: "z",
14
+ mod: !0,
15
+ shift: !1
16
+ },
17
+ action: "undo",
18
+ label: "撤销",
19
+ group: "history"
20
+ },
21
+ {
22
+ combo: {
23
+ key: "z",
24
+ mod: !0,
25
+ shift: !0
26
+ },
27
+ action: "redo",
28
+ label: "重做",
29
+ group: "history"
30
+ },
31
+ {
32
+ combo: {
33
+ key: "y",
34
+ mod: !0,
35
+ shift: !1
36
+ },
37
+ action: "redo",
38
+ label: "重做",
39
+ group: "history"
40
+ },
41
+ {
42
+ combo: {
43
+ key: "c",
44
+ mod: !0,
45
+ shift: !1
46
+ },
47
+ action: "copy",
48
+ label: "复制",
49
+ group: "clipboard"
50
+ },
51
+ {
52
+ combo: {
53
+ key: "v",
54
+ mod: !0,
55
+ shift: !1
56
+ },
57
+ action: "paste",
58
+ label: "粘贴",
59
+ group: "clipboard"
60
+ },
61
+ {
62
+ combo: {
63
+ key: "d",
64
+ mod: !0,
65
+ shift: !1
66
+ },
67
+ action: "duplicate",
68
+ label: "创建副本",
69
+ group: "clipboard"
70
+ },
71
+ {
72
+ combo: {
73
+ key: "c",
74
+ mod: !0,
75
+ shift: !1,
76
+ alt: !0,
77
+ code: "KeyC"
78
+ },
79
+ action: "copyStyle",
80
+ label: "复制样式",
81
+ group: "clipboard"
82
+ },
83
+ {
84
+ combo: {
85
+ key: "v",
86
+ mod: !0,
87
+ shift: !1,
88
+ alt: !0,
89
+ code: "KeyV"
90
+ },
91
+ action: "pasteStyle",
92
+ label: "粘贴样式",
93
+ group: "clipboard"
94
+ },
95
+ {
96
+ combo: {
97
+ key: "delete",
98
+ mod: !1,
99
+ shift: !1
100
+ },
101
+ action: "delete",
102
+ label: "删除图层",
103
+ group: "layer"
104
+ },
105
+ {
106
+ combo: {
107
+ key: "backspace",
108
+ mod: !1,
109
+ shift: !1
110
+ },
111
+ action: "delete",
112
+ label: "删除图层",
113
+ group: "layer"
114
+ },
115
+ {
116
+ combo: {
117
+ key: "f2",
118
+ mod: !1,
119
+ shift: !1
120
+ },
121
+ action: "rename",
122
+ label: "重命名图层",
123
+ group: "layer"
124
+ },
125
+ {
126
+ combo: {
127
+ key: "f",
128
+ mod: !0,
129
+ shift: !1
130
+ },
131
+ action: "findReplace",
132
+ label: "查找替换",
133
+ group: "text"
134
+ },
135
+ {
136
+ combo: {
137
+ key: "r",
138
+ mod: !1,
139
+ shift: !0
140
+ },
141
+ action: "toggleRulers",
142
+ label: "标尺显隐",
143
+ group: "view"
144
+ },
145
+ {
146
+ combo: {
147
+ key: "l",
148
+ mod: !0,
149
+ shift: !0
150
+ },
151
+ action: "toggleLayerLock",
152
+ label: "锁定/解锁图层",
153
+ group: "layer"
154
+ },
155
+ {
156
+ combo: {
157
+ key: "h",
158
+ mod: !0,
159
+ shift: !0
160
+ },
161
+ action: "toggleLayerVisibility",
162
+ label: "显示/隐藏图层",
163
+ group: "layer"
164
+ },
165
+ {
166
+ combo: {
167
+ key: "]",
168
+ mod: !0,
169
+ shift: !1
170
+ },
171
+ action: "bringForward",
172
+ label: "前移一层",
173
+ group: "layer"
174
+ },
175
+ {
176
+ combo: {
177
+ key: "[",
178
+ mod: !0,
179
+ shift: !1
180
+ },
181
+ action: "sendBackward",
182
+ label: "后移一层",
183
+ group: "layer"
184
+ },
185
+ {
186
+ combo: {
187
+ key: "]",
188
+ mod: !0,
189
+ shift: !1,
190
+ alt: !0,
191
+ code: "BracketRight"
192
+ },
193
+ action: "bringToFront",
194
+ label: "置顶",
195
+ group: "layer"
196
+ },
197
+ {
198
+ combo: {
199
+ key: "[",
200
+ mod: !0,
201
+ shift: !1,
202
+ alt: !0,
203
+ code: "BracketLeft"
204
+ },
205
+ action: "sendToBack",
206
+ label: "置底",
207
+ group: "layer"
208
+ },
209
+ {
210
+ combo: {
211
+ key: "arrowup",
212
+ mod: !1,
213
+ shift: !1
214
+ },
215
+ action: "nudgeUp",
216
+ label: "微调上移",
217
+ group: "layer"
218
+ },
219
+ {
220
+ combo: {
221
+ key: "arrowdown",
222
+ mod: !1,
223
+ shift: !1
224
+ },
225
+ action: "nudgeDown",
226
+ label: "微调下移",
227
+ group: "layer"
228
+ },
229
+ {
230
+ combo: {
231
+ key: "arrowleft",
232
+ mod: !1,
233
+ shift: !1
234
+ },
235
+ action: "nudgeLeft",
236
+ label: "微调左移",
237
+ group: "layer"
238
+ },
239
+ {
240
+ combo: {
241
+ key: "arrowright",
242
+ mod: !1,
243
+ shift: !1
244
+ },
245
+ action: "nudgeRight",
246
+ label: "微调右移",
247
+ group: "layer"
248
+ },
249
+ {
250
+ combo: {
251
+ key: "arrowup",
252
+ mod: !1,
253
+ shift: !0
254
+ },
255
+ action: "nudgeUpCoarse",
256
+ label: "大步上移",
257
+ group: "layer"
258
+ },
259
+ {
260
+ combo: {
261
+ key: "arrowdown",
262
+ mod: !1,
263
+ shift: !0
264
+ },
265
+ action: "nudgeDownCoarse",
266
+ label: "大步下移",
267
+ group: "layer"
268
+ },
269
+ {
270
+ combo: {
271
+ key: "arrowleft",
272
+ mod: !1,
273
+ shift: !0
274
+ },
275
+ action: "nudgeLeftCoarse",
276
+ label: "大步左移",
277
+ group: "layer"
278
+ },
279
+ {
280
+ combo: {
281
+ key: "arrowright",
282
+ mod: !1,
283
+ shift: !0
284
+ },
285
+ action: "nudgeRightCoarse",
286
+ label: "大步右移",
287
+ group: "layer"
288
+ },
289
+ {
290
+ combo: {
291
+ key: "tab",
292
+ mod: !1,
293
+ shift: !1
294
+ },
295
+ action: "selectNextLayer",
296
+ label: "循环选下一层",
297
+ group: "layer"
298
+ },
299
+ {
300
+ combo: {
301
+ key: "tab",
302
+ mod: !1,
303
+ shift: !0
304
+ },
305
+ action: "selectPrevLayer",
306
+ label: "循环选上一层",
307
+ group: "layer"
308
+ },
309
+ {
310
+ combo: {
311
+ key: "t",
312
+ mod: !1,
313
+ shift: !1,
314
+ code: "KeyT"
315
+ },
316
+ action: "armCreateText",
317
+ label: "画拉建文本层",
318
+ group: "layer"
319
+ },
320
+ {
321
+ combo: {
322
+ key: "g",
323
+ mod: !1,
324
+ shift: !1,
325
+ code: "KeyG"
326
+ },
327
+ action: "armCreateTable",
328
+ label: "画拉建表格",
329
+ group: "layer"
330
+ },
331
+ {
332
+ combo: {
333
+ key: "q",
334
+ mod: !1,
335
+ shift: !1,
336
+ code: "KeyQ"
337
+ },
338
+ action: "armCreateQrCode",
339
+ label: "画拉建二维码",
340
+ group: "layer"
341
+ },
342
+ {
343
+ combo: {
344
+ key: "i",
345
+ mod: !1,
346
+ shift: !1,
347
+ code: "KeyI"
348
+ },
349
+ action: "armCreateImage",
350
+ label: "画拉建图片",
351
+ group: "layer"
352
+ },
353
+ {
354
+ combo: {
355
+ key: "0",
356
+ mod: !0,
357
+ shift: !1
358
+ },
359
+ action: "zoomReset",
360
+ label: "缩放复位 100%",
361
+ group: "view"
362
+ },
363
+ {
364
+ combo: {
365
+ key: "1",
366
+ mod: !1,
367
+ shift: !0,
368
+ code: "Digit1"
369
+ },
370
+ action: "fitToSurface",
371
+ label: "适应画布",
372
+ group: "view"
373
+ },
374
+ {
375
+ combo: {
376
+ key: "2",
377
+ mod: !1,
378
+ shift: !0,
379
+ code: "Digit2"
380
+ },
381
+ action: "fitToSelection",
382
+ label: "适应选区",
383
+ group: "view"
384
+ },
385
+ {
386
+ combo: {
387
+ key: "/",
388
+ mod: !0,
389
+ shift: !1
390
+ },
391
+ action: "helpShortcuts",
392
+ label: "快捷键帮助",
393
+ group: "help"
394
+ }
395
+ ];
396
+ function d(e, t = u) {
397
+ if (e.composing || e.editing || e.editableTarget) return null;
398
+ let n = e.key.toLowerCase(), r = e.alt ?? !1;
399
+ for (let i of t) if ((i.combo.code === void 0 ? i.combo.key === n : i.combo.code === e.code) && i.combo.mod === e.mod && i.combo.shift === e.shift && (i.combo.alt ?? !1) === r) return i.action;
400
+ return null;
401
+ }
402
+ //#endregion
403
+ //#region src/shared/editableTarget.ts
404
+ function f(e) {
405
+ if (!(e instanceof HTMLElement)) return !1;
406
+ if (e.isContentEditable) return !0;
407
+ let t = e.tagName;
408
+ return t === "INPUT" || t === "TEXTAREA" || t === "SELECT" || t === "BUTTON";
409
+ }
410
+ function p(e) {
411
+ if (!(e instanceof HTMLElement)) return !1;
412
+ if (e.isContentEditable) return !0;
413
+ let t = e.tagName;
414
+ return t === "INPUT" || t === "TEXTAREA" || t === "SELECT";
415
+ }
416
+ //#endregion
417
+ //#region src/shared/useTransientFeedback.ts
418
+ var m = 4e3, h = "", g = null, _ = /* @__PURE__ */ new Set();
419
+ function v(e) {
420
+ if (h !== e) {
421
+ h = e;
422
+ for (let e of _) e();
423
+ }
424
+ }
425
+ function y() {
426
+ g !== null && (clearTimeout(g), g = null);
427
+ }
428
+ function b(e) {
429
+ return _.add(e), () => _.delete(e);
430
+ }
431
+ var x = () => h;
432
+ function S() {
433
+ return {
434
+ message: o(b, x),
435
+ show: (e) => {
436
+ y(), v(e), g = setTimeout(() => {
437
+ v(""), g = null;
438
+ }, m);
439
+ },
440
+ clear: () => {
441
+ y(), v("");
442
+ }
443
+ };
444
+ }
445
+ //#endregion
446
+ //#region src/shared/shortcutsHelp.ts
447
+ var C = [
448
+ "history",
449
+ "clipboard",
450
+ "layer",
451
+ "text",
452
+ "view",
453
+ "help"
454
+ ], w = {
455
+ history: "历史",
456
+ clipboard: "剪贴板",
457
+ layer: "图层",
458
+ text: "文本",
459
+ view: "视图",
460
+ help: "帮助"
461
+ }, T = {
462
+ arrowup: "↑",
463
+ arrowdown: "↓",
464
+ arrowleft: "←",
465
+ arrowright: "→",
466
+ backspace: "⌫",
467
+ delete: "Del",
468
+ escape: "Esc",
469
+ tab: "Tab",
470
+ f2: "F2"
471
+ };
472
+ function E(e, t) {
473
+ let n = e.key, r = /^[a-z]$/.test(n) ? n.toUpperCase() : T[n] ?? n;
474
+ if (t === "mac") {
475
+ let t = "";
476
+ return e.alt && (t += "⌥"), e.shift && (t += "⇧"), e.mod && (t += "⌘"), t + r;
477
+ }
478
+ let i = [];
479
+ return e.mod && i.push("Ctrl"), e.shift && i.push("Shift"), e.alt && i.push("Alt"), i.push(r), i.join("+");
480
+ }
481
+ function D(e, t) {
482
+ let n = u.find((t) => t.action === e);
483
+ return n ? E(n.combo, t) : "";
484
+ }
485
+ var O = "画拉或点击落层,Esc 取消";
486
+ function k() {
487
+ let e = globalThis.navigator;
488
+ return /mac/i.test(`${e?.userAgentData?.platform ?? ""} ${e?.platform ?? ""} ${e?.userAgent ?? ""}`) ? "mac" : "win";
489
+ }
490
+ //#endregion
491
+ //#region src/shared/useDataSourceSchema.ts
492
+ var A = "先绑定数据源";
493
+ function j(e) {
494
+ let n = t((t) => e.subscribe((e) => {
495
+ e.scope === "ui" && e.branch === "dataSourceSchema" && t();
496
+ }), [e]), r = t(() => e.store.ui.dataSourceSchema, [e]);
497
+ return o(n, r);
498
+ }
499
+ function M(e) {
500
+ let n = t((t) => e.subscribe((e) => {
501
+ e.scope === "ui" && e.branch === "dataSourceSchema" && t();
502
+ }), [e]), r = t(() => e.store.ui.dataSourceSchemaRejection, [e]);
503
+ return o(n, r);
504
+ }
505
+ //#endregion
506
+ //#region src/shared/useDropdownMenu.ts
507
+ function N(e) {
508
+ return e !== "separator" && "kind" in e && e.kind === "submenu";
509
+ }
510
+ function P(e) {
511
+ let [r, i] = a(!1);
512
+ return n(() => {
513
+ if (!r) return;
514
+ function t(t) {
515
+ let n = e.containerRef.current, r = t.target;
516
+ n !== null && r instanceof Node && n.contains(r) || i(!1);
517
+ }
518
+ function n(e) {
519
+ e.key === "Escape" && i(!1);
520
+ }
521
+ return window.addEventListener("pointerdown", t), window.addEventListener("keydown", n), () => {
522
+ window.removeEventListener("pointerdown", t), window.removeEventListener("keydown", n);
523
+ };
524
+ }, [r, e.containerRef]), {
525
+ open: r,
526
+ toggle: t(() => i((e) => !e), []),
527
+ openMenu: t(() => i(!0), []),
528
+ closeMenu: t(() => i(!1), [])
529
+ };
530
+ }
531
+ function F(e, t, n) {
532
+ let r = e.length;
533
+ if (r === 0) return -1;
534
+ if (n === "Home" || n === "End") {
535
+ for (let t = 0; t < r; t++) {
536
+ let i = n === "Home" ? t : r - 1 - t;
537
+ if (e[i] === !0) return i;
538
+ }
539
+ return -1;
540
+ }
541
+ let i = n === "ArrowDown" ? 1 : -1, a = t === -1 ? i === 1 ? -1 : r : t;
542
+ for (let t = 0; t < r; t++) if (a = (a + i + r) % r, e[a] === !0) return a;
543
+ return -1;
544
+ }
545
+ function I(e, t) {
546
+ return t.type === "close" || t.target === void 0 ? null : t.type === "open" ? t.target : e === t.target ? null : t.target;
547
+ }
548
+ function ee(e) {
549
+ let { anchor: t, flyoutWidth: n, flyoutHeight: r, viewportWidth: i, viewportHeight: a } = e, o = e.gap ?? 6, s = e.margin ?? 2, c = n > 0 && t.right + o + n > i - s ? "left" : "right", l = c === "right" ? t.right + o : t.left - o - n;
550
+ n > 0 && (l = Math.max(s, Math.min(l, i - s - n)));
551
+ let u = t.top;
552
+ return r > 0 && (u = Math.max(s, Math.min(u, a - s - r))), {
553
+ left: l,
554
+ top: u,
555
+ side: c
556
+ };
557
+ }
558
+ function te(e) {
559
+ return e === "ArrowDown" || e === "ArrowUp" || e === "Home" || e === "End" ? {
560
+ type: "move",
561
+ key: e
562
+ } : e === "ArrowLeft" || e === "Escape" ? { type: "close" } : e === "Enter" || e === " " ? { type: "activate" } : e === "Tab" ? { type: "close-menu" } : { type: "none" };
563
+ }
564
+ function L(e, t) {
565
+ return e.find((e) => e.hasAttribute("disabled") === !1) ?? t;
566
+ }
567
+ function ne(e) {
568
+ return e?.closest("[data-dropdown-submenu-host]")?.querySelector("[data-dropdown-submenu-arrow]") ?? null;
569
+ }
570
+ function re(e) {
571
+ return e;
572
+ }
573
+ //#endregion
574
+ //#region src/shared/DropdownMenu.tsx
575
+ var R = 6, z = 2, B = {
576
+ left: 0,
577
+ top: 0,
578
+ side: "right"
579
+ };
580
+ function V({ label: n, items: o, title: l, direction: u = "down", onClosed: d, trigger: p, body: m }) {
581
+ let h = i(null), g = i(null), _ = i(null), { open: v, toggle: y, closeMenu: b } = P({ containerRef: h }), [x, S] = a(null), [C, w] = a(B), T = i(null), [E, D] = a({
582
+ left: 0,
583
+ edge: "top",
584
+ offset: 0
585
+ }), O = i(v);
586
+ O.current = v;
587
+ let k = i(!1);
588
+ r(() => {
589
+ if (v) {
590
+ k.current = !0;
591
+ return;
592
+ }
593
+ k.current !== !1 && (k.current = !1, S(null), d?.());
594
+ }, [v, d]);
595
+ let A = t((e) => {
596
+ g.current = e;
597
+ }, []), j = t(() => {
598
+ re(g.current)?.focus();
599
+ }, []), M = t(() => o.filter((e) => e !== "separator"), [o]);
600
+ function V() {
601
+ return Array.from(_.current?.querySelectorAll("[data-dropdown-item]") ?? []);
602
+ }
603
+ function H() {
604
+ return M().filter(N);
605
+ }
606
+ function ie() {
607
+ return Array.from(_.current?.querySelectorAll("[data-dropdown-submenu-host]") ?? []);
608
+ }
609
+ function U() {
610
+ return _.current?.querySelector("[data-dropdown-submenu]") ?? null;
611
+ }
612
+ function W() {
613
+ return Array.from(U()?.querySelectorAll("[data-dropdown-submenu-item]") ?? []);
614
+ }
615
+ let ae = t((e) => {
616
+ let t = _.current;
617
+ if (t === null) return;
618
+ let n = V(), r = F(n.map((e) => e.hasAttribute("disabled") === !1), document.activeElement instanceof HTMLElement ? n.indexOf(document.activeElement) : -1, e);
619
+ if (r === -1) {
620
+ t.focus();
621
+ return;
622
+ }
623
+ n[r]?.focus();
624
+ }, []), G = t((e) => {
625
+ e.run(), (N(e) !== !1 || e.keepsOpen !== !0) && (b(), j());
626
+ }, [b, j]);
627
+ function oe(e) {
628
+ let t = M()[V().indexOf(e)];
629
+ t !== void 0 && t.disabled !== !0 && G(t);
630
+ }
631
+ function se(e) {
632
+ let t = x;
633
+ if (t === null) return;
634
+ let n = W(), r = t.children.filter((e) => e !== "separator")[n.indexOf(e)];
635
+ r !== void 0 && r.disabled !== !0 && G(r);
636
+ }
637
+ let ce = t((e) => {
638
+ let t = U();
639
+ if (t === null) return;
640
+ let n = W(), r = F(n.map((e) => e.hasAttribute("disabled") === !1), document.activeElement instanceof HTMLElement ? n.indexOf(document.activeElement) : -1, e);
641
+ if (r === -1) {
642
+ t.focus();
643
+ return;
644
+ }
645
+ n[r]?.focus();
646
+ }, []), K = t(() => {
647
+ let e = ne(document.activeElement instanceof HTMLElement ? document.activeElement : null);
648
+ S(null), e?.focus();
649
+ }, []), q = t(() => {
650
+ if (O.current === !1) return;
651
+ let e = _.current;
652
+ e !== null && L(V(), e).focus();
653
+ }, []), J = t(() => {
654
+ if (O.current === !1) {
655
+ let e = g.current?.getBoundingClientRect();
656
+ e && D(u === "up" ? {
657
+ left: e.left,
658
+ edge: "bottom",
659
+ offset: window.innerHeight - e.top + R
660
+ } : {
661
+ left: e.left,
662
+ edge: "top",
663
+ offset: e.bottom + R
664
+ });
665
+ } else j();
666
+ y();
667
+ }, [
668
+ u,
669
+ j,
670
+ y
671
+ ]);
672
+ r(() => {
673
+ if (v === !1) return;
674
+ let e = _.current?.getBoundingClientRect();
675
+ e && D((t) => ({
676
+ left: Math.max(z, Math.min(t.left, window.innerWidth - e.width - z)),
677
+ edge: t.edge,
678
+ offset: Math.max(z, Math.min(t.offset, window.innerHeight - e.height - z))
679
+ })), q();
680
+ }, [v, q]);
681
+ function le(e) {
682
+ let t = e.key, n = e.target;
683
+ if (n instanceof HTMLElement && n.matches("[data-dropdown-submenu-item]")) {
684
+ let r = te(t);
685
+ if (r.type === "move") {
686
+ e.preventDefault(), ce(r.key);
687
+ return;
688
+ }
689
+ if (r.type === "close") {
690
+ e.preventDefault(), K();
691
+ return;
692
+ }
693
+ if (r.type === "activate") {
694
+ e.preventDefault(), se(n);
695
+ return;
696
+ }
697
+ if (r.type === "close-menu") {
698
+ b(), j();
699
+ return;
700
+ }
701
+ return;
702
+ }
703
+ if (t === "Escape") {
704
+ if (x !== null) {
705
+ K();
706
+ return;
707
+ }
708
+ b(), j();
709
+ return;
710
+ }
711
+ if (t === "Tab") {
712
+ if (n instanceof HTMLElement && n.matches("[data-dropdown-item]") === !1 && f(n)) return;
713
+ b(), j();
714
+ return;
715
+ }
716
+ if (t === "Enter" || t === " ") {
717
+ n instanceof HTMLElement && n.matches("[data-dropdown-item]") && (e.preventDefault(), oe(n));
718
+ return;
719
+ }
720
+ if (t === "ArrowDown" || t === "ArrowUp" || t === "Home" || t === "End") {
721
+ if (n instanceof HTMLElement && n.matches("[data-dropdown-item]") === !1 && f(n)) return;
722
+ e.preventDefault(), ae(t);
723
+ return;
724
+ }
725
+ if (t === "ArrowRight") {
726
+ let t = n instanceof HTMLElement ? n.closest("[data-dropdown-submenu-host]") : null;
727
+ if (t !== null) {
728
+ let n = H()[ie().indexOf(t)];
729
+ n !== void 0 && (e.preventDefault(), ue(n, t));
730
+ }
731
+ }
732
+ }
733
+ let Y = i(null);
734
+ function ue(e, t) {
735
+ e.disabled !== !0 && (Y.current = e, S(I(x, {
736
+ type: "open",
737
+ target: e
738
+ })), X(t.querySelector("[data-dropdown-submenu-arrow]")));
739
+ }
740
+ let X = t((e) => {
741
+ if (e === null) return;
742
+ let t = e.getBoundingClientRect();
743
+ T.current = {
744
+ top: t.top,
745
+ bottom: t.bottom,
746
+ left: t.left,
747
+ right: t.right
748
+ }, w({
749
+ left: t.right + 6,
750
+ top: t.top,
751
+ side: "right"
752
+ });
753
+ }, []);
754
+ r(() => {
755
+ if (x === null) return;
756
+ let e = T.current, t = U(), n = t?.getBoundingClientRect();
757
+ e !== null && t !== null && n !== void 0 && n.width !== 0 && w(ee({
758
+ anchor: e,
759
+ flyoutWidth: n.width,
760
+ flyoutHeight: n.height,
761
+ viewportWidth: window.innerWidth,
762
+ viewportHeight: window.innerHeight
763
+ }));
764
+ }, [x]), r(() => {
765
+ if (x === null) return;
766
+ let e = Y.current;
767
+ if (e === null || x !== e) {
768
+ Y.current = null;
769
+ return;
770
+ }
771
+ if (Y.current = null, O.current === !1) return;
772
+ let t = U();
773
+ t !== null && L(W(), t).focus();
774
+ }, [x]);
775
+ function Z(e) {
776
+ return e.currentTarget instanceof HTMLElement ? e.currentTarget : null;
777
+ }
778
+ function de(e, t) {
779
+ t.disabled !== !0 && (S(I(x, {
780
+ type: "open",
781
+ target: t
782
+ })), X(Z(e)));
783
+ }
784
+ function fe(e, t) {
785
+ t.disabled !== !0 && (S(I(x, {
786
+ type: "toggle",
787
+ target: t
788
+ })), X(Z(e)));
789
+ }
790
+ function pe() {
791
+ S(null);
792
+ }
793
+ let Q = t((e) => {
794
+ if (e.key === "ArrowDown") {
795
+ if (e.preventDefault(), O.current === !1) {
796
+ J();
797
+ return;
798
+ }
799
+ q();
800
+ }
801
+ }, [q, J]), $ = {
802
+ open: v,
803
+ toggle: J,
804
+ closeMenu: b,
805
+ triggerRef: A,
806
+ onKeydown: Q
807
+ };
808
+ return /* @__PURE__ */ c("div", {
809
+ ref: h,
810
+ className: "cn-dropdown",
811
+ onMouseLeave: pe,
812
+ children: [p === void 0 ? /* @__PURE__ */ c("button", {
813
+ ref: A,
814
+ type: "button",
815
+ className: "cn-dropdown__trigger",
816
+ "data-dropdown-trigger": !0,
817
+ "aria-haspopup": "menu",
818
+ "aria-expanded": v,
819
+ title: l ?? n,
820
+ onClick: J,
821
+ onKeyDown: Q,
822
+ children: [n, /* @__PURE__ */ s("span", {
823
+ className: "cn-dropdown__caret",
824
+ "aria-hidden": "true",
825
+ children: "▾"
826
+ })]
827
+ }) : p($), v && /* @__PURE__ */ c("div", {
828
+ ref: _,
829
+ className: "cn-dropdown__menu",
830
+ role: "menu",
831
+ "aria-label": n,
832
+ "data-dropdown-menu": !0,
833
+ tabIndex: -1,
834
+ style: E.edge === "top" ? {
835
+ left: `${E.left}px`,
836
+ top: `${E.offset}px`
837
+ } : {
838
+ left: `${E.left}px`,
839
+ bottom: `${E.offset}px`
840
+ },
841
+ onKeyDown: (e) => {
842
+ e.stopPropagation(), le(e);
843
+ },
844
+ children: [o.map((t, n) => {
845
+ if (t === "separator") return /* @__PURE__ */ s("div", {
846
+ className: "cn-dropdown__separator",
847
+ role: "separator",
848
+ "data-dropdown-separator": !0,
849
+ "aria-hidden": "true"
850
+ }, n);
851
+ if (N(t)) {
852
+ let e = x === t;
853
+ return /* @__PURE__ */ c("div", {
854
+ className: "cn-dropdown__submenu-host",
855
+ "data-dropdown-submenu-host": !0,
856
+ children: [
857
+ /* @__PURE__ */ c("button", {
858
+ type: "button",
859
+ role: "menuitem",
860
+ className: "cn-dropdown__item cn-dropdown__submenu-main",
861
+ "data-dropdown-item": !0,
862
+ tabIndex: -1,
863
+ disabled: t.disabled,
864
+ title: t.title,
865
+ ...t.dataAttrs,
866
+ onClick: () => G(t),
867
+ children: [/* @__PURE__ */ s("span", {
868
+ className: "cn-dropdown__item-label",
869
+ children: t.label
870
+ }), t.shortcut !== void 0 && /* @__PURE__ */ s("span", {
871
+ className: "cn-dropdown__shortcut",
872
+ children: t.shortcut
873
+ })]
874
+ }),
875
+ /* @__PURE__ */ s("button", {
876
+ type: "button",
877
+ className: "cn-dropdown__submenu-arrow",
878
+ "data-dropdown-submenu-arrow": !0,
879
+ tabIndex: -1,
880
+ disabled: t.disabled,
881
+ title: t.title,
882
+ "aria-haspopup": "menu",
883
+ "aria-expanded": e,
884
+ onClick: (e) => fe(e, t),
885
+ onMouseEnter: (e) => de(e, t),
886
+ children: /* @__PURE__ */ s("span", {
887
+ "aria-hidden": "true",
888
+ children: "▸"
889
+ })
890
+ }),
891
+ e && /* @__PURE__ */ s("div", {
892
+ className: C.side === "left" ? "cn-dropdown__submenu cn-dropdown__submenu--left" : "cn-dropdown__submenu",
893
+ role: "menu",
894
+ "aria-label": t.label,
895
+ "data-dropdown-submenu": !0,
896
+ tabIndex: -1,
897
+ style: {
898
+ left: `${C.left}px`,
899
+ top: `${C.top}px`
900
+ },
901
+ children: t.children.map((e, t) => e === "separator" ? /* @__PURE__ */ s("div", {
902
+ className: "cn-dropdown__separator",
903
+ role: "separator",
904
+ "data-dropdown-submenu-separator": !0,
905
+ "aria-hidden": "true"
906
+ }, t) : /* @__PURE__ */ c("button", {
907
+ type: "button",
908
+ role: "menuitem",
909
+ className: "cn-dropdown__item",
910
+ "data-dropdown-submenu-item": !0,
911
+ tabIndex: -1,
912
+ disabled: e.disabled,
913
+ title: e.title,
914
+ ...e.dataAttrs,
915
+ onClick: () => G(e),
916
+ children: [/* @__PURE__ */ s("span", {
917
+ className: "cn-dropdown__item-label",
918
+ children: e.label
919
+ }), e.shortcut !== void 0 && /* @__PURE__ */ s("span", {
920
+ className: "cn-dropdown__shortcut",
921
+ children: e.shortcut
922
+ })]
923
+ }, t))
924
+ })
925
+ ]
926
+ }, n);
927
+ }
928
+ let r = "checked" in t;
929
+ return /* @__PURE__ */ c("button", {
930
+ type: "button",
931
+ role: r ? "menuitemradio" : "menuitem",
932
+ "aria-checked": r ? t.checked : void 0,
933
+ className: "cn-dropdown__item",
934
+ "data-dropdown-item": !0,
935
+ tabIndex: -1,
936
+ disabled: t.disabled,
937
+ title: t.title,
938
+ ...t.dataAttrs,
939
+ onClick: () => G(t),
940
+ children: [
941
+ t.icon === void 0 ? /* @__PURE__ */ s("span", {
942
+ className: "cn-dropdown__item-label",
943
+ children: t.label
944
+ }) : /* @__PURE__ */ c("span", {
945
+ className: "cn-dropdown__item-lead",
946
+ children: [/* @__PURE__ */ s(e, { icon: t.icon }), /* @__PURE__ */ s("span", {
947
+ className: "cn-dropdown__item-label",
948
+ children: t.label
949
+ })]
950
+ }),
951
+ t.shortcut !== void 0 && /* @__PURE__ */ s("span", {
952
+ className: "cn-dropdown__shortcut",
953
+ children: t.shortcut
954
+ }),
955
+ r && t.checked === !0 && /* @__PURE__ */ s("span", {
956
+ className: "cn-dropdown__check",
957
+ "aria-hidden": "true",
958
+ children: "✓"
959
+ })
960
+ ]
961
+ }, n);
962
+ }), m !== void 0 && m($)]
963
+ })]
964
+ });
965
+ }
966
+ //#endregion
967
+ export { d as _, M as a, C as c, E as d, S as f, u as g, l as h, j as i, k as l, p as m, P as n, O as o, f as p, A as r, w as s, V as t, D as u };