@pixerate/editor 0.22.0 → 0.24.0
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/README.md +175 -2
- package/THIRD_PARTY_NOTICES.md +139 -0
- package/dist/agent/index.cjs +87 -111
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +70 -211
- package/dist/agent/index.d.ts +70 -211
- package/dist/agent/index.js +78 -102
- package/dist/agent/index.js.map +1 -1
- package/dist/arrangeShortcuts-B8O3f8-P.d.cts +184 -0
- package/dist/arrangeShortcuts-sLlD2rSX.d.ts +184 -0
- package/dist/canvas/index.cjs +2075 -86
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +608 -186
- package/dist/canvas/index.d.ts +608 -186
- package/dist/canvas/index.js +2060 -71
- package/dist/canvas/index.js.map +1 -1
- package/dist/chunk-26BVFKHU.cjs +453 -0
- package/dist/chunk-26BVFKHU.cjs.map +1 -0
- package/dist/chunk-2H7ZHPEJ.js +762 -0
- package/dist/chunk-2H7ZHPEJ.js.map +1 -0
- package/dist/{chunk-DENSCKFC.js → chunk-3CN2WD3X.js} +1730 -189
- package/dist/chunk-3CN2WD3X.js.map +1 -0
- package/dist/{chunk-JJDLPEWL.js → chunk-3LV6RRPH.js} +2 -2
- package/dist/{chunk-MJZBNWG7.js → chunk-5S3Z4PPF.js} +78 -557
- package/dist/chunk-5S3Z4PPF.js.map +1 -0
- package/dist/chunk-664LQYFJ.js +115 -0
- package/dist/chunk-664LQYFJ.js.map +1 -0
- package/dist/chunk-7DWMJCAT.js +453 -0
- package/dist/chunk-7DWMJCAT.js.map +1 -0
- package/dist/chunk-ARRTP33I.js +101 -0
- package/dist/chunk-ARRTP33I.js.map +1 -0
- package/dist/chunk-CPOKFNBG.cjs +101 -0
- package/dist/chunk-CPOKFNBG.cjs.map +1 -0
- package/dist/{chunk-AA4ZEVCC.cjs → chunk-D27YFC46.cjs} +101 -580
- package/dist/chunk-D27YFC46.cjs.map +1 -0
- package/dist/chunk-D6FH2YAX.cjs +131 -0
- package/dist/chunk-D6FH2YAX.cjs.map +1 -0
- package/dist/{chunk-4SUNJZWB.cjs → chunk-FD4LPFAE.cjs} +48 -200
- package/dist/chunk-FD4LPFAE.cjs.map +1 -0
- package/dist/chunk-FODNLX5N.js +749 -0
- package/dist/chunk-FODNLX5N.js.map +1 -0
- package/dist/{chunk-OYXSKQFR.js → chunk-FPENXAEJ.js} +35 -187
- package/dist/chunk-FPENXAEJ.js.map +1 -0
- package/dist/chunk-G2I4QJOT.cjs +762 -0
- package/dist/chunk-G2I4QJOT.cjs.map +1 -0
- package/dist/chunk-HLIMTC6N.js +1 -0
- package/dist/chunk-HLIMTC6N.js.map +1 -0
- package/dist/{chunk-QGHGJ56O.js → chunk-ITBSKI26.js} +1483 -19
- package/dist/chunk-ITBSKI26.js.map +1 -0
- package/dist/{chunk-6M3BCTBD.cjs → chunk-MA2F5KHF.cjs} +470 -242
- package/dist/chunk-MA2F5KHF.cjs.map +1 -0
- package/dist/{chunk-SAZRENEZ.cjs → chunk-MCSJFWAO.cjs} +1733 -192
- package/dist/chunk-MCSJFWAO.cjs.map +1 -0
- package/dist/chunk-MKA3AHLV.cjs +256 -0
- package/dist/chunk-MKA3AHLV.cjs.map +1 -0
- package/dist/chunk-OLZJXL4R.cjs +749 -0
- package/dist/chunk-OLZJXL4R.cjs.map +1 -0
- package/dist/chunk-OXSV64JX.js +689 -0
- package/dist/chunk-OXSV64JX.js.map +1 -0
- package/dist/chunk-P3RQ5UJE.cjs +689 -0
- package/dist/chunk-P3RQ5UJE.cjs.map +1 -0
- package/dist/chunk-P6ODPZ4W.js +256 -0
- package/dist/chunk-P6ODPZ4W.js.map +1 -0
- package/dist/chunk-PGNZKFQS.js +685 -0
- package/dist/chunk-PGNZKFQS.js.map +1 -0
- package/dist/chunk-PL4JB3BF.cjs +1 -0
- package/dist/chunk-PL4JB3BF.cjs.map +1 -0
- package/dist/{chunk-GVSMRPHB.cjs → chunk-SBCZ6RN5.cjs} +1568 -104
- package/dist/chunk-SBCZ6RN5.cjs.map +1 -0
- package/dist/{chunk-CL37JGFW.cjs → chunk-SML64VJG.cjs} +4 -4
- package/dist/{chunk-CL37JGFW.cjs.map → chunk-SML64VJG.cjs.map} +1 -1
- package/dist/chunk-TNNJXF46.cjs +115 -0
- package/dist/chunk-TNNJXF46.cjs.map +1 -0
- package/dist/chunk-U5HZSFCS.js +131 -0
- package/dist/chunk-U5HZSFCS.js.map +1 -0
- package/dist/{chunk-RU52I7QO.js → chunk-U5KWZU4X.js} +388 -160
- package/dist/chunk-U5KWZU4X.js.map +1 -0
- package/dist/chunk-XNORY7M6.cjs +685 -0
- package/dist/chunk-XNORY7M6.cjs.map +1 -0
- package/dist/commands/index.cjs +860 -0
- package/dist/commands/index.cjs.map +1 -0
- package/dist/commands/index.d.cts +244 -0
- package/dist/commands/index.d.ts +244 -0
- package/dist/commands/index.js +860 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/comment-store-BEMgVlAA.d.cts +135 -0
- package/dist/comment-store-BEMgVlAA.d.ts +135 -0
- package/dist/compare/index.cjs +15 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +58 -0
- package/dist/compare/index.d.ts +58 -0
- package/dist/compare/index.js +15 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/{controller-B7GIybc4.d.cts → controller-BhLLAoi8.d.cts} +119 -5
- package/dist/{controller-B7GIybc4.d.ts → controller-BhLLAoi8.d.ts} +119 -5
- package/dist/documents-BQjzJNe2.d.ts +76 -0
- package/dist/documents-KRTPhvst.d.cts +76 -0
- package/dist/extensions/index.cjs +53 -5
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +7 -3
- package/dist/extensions/index.d.ts +7 -3
- package/dist/extensions/index.js +52 -4
- package/dist/generation/index.cjs +1373 -0
- package/dist/generation/index.cjs.map +1 -0
- package/dist/generation/index.d.cts +554 -0
- package/dist/generation/index.d.ts +554 -0
- package/dist/generation/index.js +1373 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/grammar/index.cjs +48 -3
- package/dist/grammar/index.cjs.map +1 -1
- package/dist/grammar/index.d.cts +322 -100
- package/dist/grammar/index.d.ts +322 -100
- package/dist/grammar/index.js +54 -9
- package/dist/history/index.cjs +12 -2
- package/dist/history/index.cjs.map +1 -1
- package/dist/history/index.d.cts +211 -7
- package/dist/history/index.d.ts +211 -7
- package/dist/history/index.js +13 -3
- package/dist/image-editor/index.cjs +2244 -38
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +742 -4
- package/dist/image-editor/index.d.ts +742 -4
- package/dist/image-editor/index.js +2222 -16
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-CCr_z9kF.d.cts → index-BhJBSm2d.d.cts} +370 -4
- package/dist/{index-Ck6ajwXh.d.ts → index-fJrlkJCd.d.ts} +370 -4
- package/dist/index.cjs +193 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -48
- package/dist/index.d.ts +17 -48
- package/dist/index.js +198 -103
- package/dist/index.js.map +1 -1
- package/dist/migrate-iTlm3a8h.d.cts +112 -0
- package/dist/migrate-iTlm3a8h.d.ts +112 -0
- package/dist/persistence/index.cjs +676 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +347 -0
- package/dist/persistence/index.d.ts +347 -0
- package/dist/persistence/index.js +676 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/registry-BDe-vlv3.d.ts +171 -0
- package/dist/registry-D32LpIc4.d.cts +354 -0
- package/dist/registry-DnzpgY27.d.cts +171 -0
- package/dist/registry-evKTP4ls.d.ts +354 -0
- package/dist/schema-DYDGdYL9.d.cts +41 -0
- package/dist/schema-DYDGdYL9.d.ts +41 -0
- package/dist/serializers/index.cjs +4 -3
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +2 -1
- package/dist/serializers/index.d.ts +2 -1
- package/dist/serializers/index.js +3 -2
- package/dist/sourcemap-C8AH3MBQ.d.cts +91 -0
- package/dist/sourcemap-DA1Evhrv.d.ts +91 -0
- package/dist/spreadsheet/index.cjs +53 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +247 -18
- package/dist/spreadsheet/index.d.ts +247 -18
- package/dist/spreadsheet/index.js +58 -8
- package/dist/{tokens-CyLZmIei.d.cts → tokens-D7yXvUU6.d.cts} +15 -2
- package/dist/{tokens-CyLZmIei.d.ts → tokens-D7yXvUU6.d.ts} +15 -2
- package/dist/{track-changes-BSF58RK0.d.cts → track-changes-BK5sVf4_.d.cts} +18 -136
- package/dist/{track-changes-BSF58RK0.d.ts → track-changes-CDjCrwKe.d.ts} +18 -136
- package/dist/{types-CJ4U-HHI.d.ts → types-DX4Mh4SL.d.cts} +1 -1
- package/dist/{types-CJ4U-HHI.d.cts → types-DX4Mh4SL.d.ts} +1 -1
- package/dist/types-GT5a5YAX.d.cts +86 -0
- package/dist/types-GT5a5YAX.d.ts +86 -0
- package/package.json +23 -2
- package/dist/chunk-2TWGLC5K.cjs +0 -262
- package/dist/chunk-2TWGLC5K.cjs.map +0 -1
- package/dist/chunk-4SUNJZWB.cjs.map +0 -1
- package/dist/chunk-6M3BCTBD.cjs.map +0 -1
- package/dist/chunk-AA4ZEVCC.cjs.map +0 -1
- package/dist/chunk-AXV2ZW34.cjs +0 -118
- package/dist/chunk-AXV2ZW34.cjs.map +0 -1
- package/dist/chunk-B2ZRLN4S.js +0 -118
- package/dist/chunk-B2ZRLN4S.js.map +0 -1
- package/dist/chunk-DENSCKFC.js.map +0 -1
- package/dist/chunk-GVSMRPHB.cjs.map +0 -1
- package/dist/chunk-KAADNAPF.js +0 -262
- package/dist/chunk-KAADNAPF.js.map +0 -1
- package/dist/chunk-MJZBNWG7.js.map +0 -1
- package/dist/chunk-OYXSKQFR.js.map +0 -1
- package/dist/chunk-QGHGJ56O.js.map +0 -1
- package/dist/chunk-RU52I7QO.js.map +0 -1
- package/dist/chunk-SAZRENEZ.cjs.map +0 -1
- package/dist/types-BZgcDsC5.d.cts +0 -42
- package/dist/types-BZgcDsC5.d.ts +0 -42
- /package/dist/{chunk-JJDLPEWL.js.map → chunk-3LV6RRPH.js.map} +0 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/commands/chords.ts
|
|
2
|
+
var PLATFORMS = ["mac", "windows", "linux"];
|
|
3
|
+
function detectPlatform() {
|
|
4
|
+
const nav = typeof navigator !== "undefined" ? navigator : void 0;
|
|
5
|
+
const text = `${_nullishCoalesce(_optionalChain([nav, 'optionalAccess', _ => _.platform]), () => ( ""))} ${_nullishCoalesce(_optionalChain([nav, 'optionalAccess', _2 => _2.userAgent]), () => ( ""))}`;
|
|
6
|
+
if (/Mac|iPod|iPhone|iPad/.test(_optionalChain([nav, 'optionalAccess', _3 => _3.platform]) || _optionalChain([nav, 'optionalAccess', _4 => _4.userAgent]) || "")) return "mac";
|
|
7
|
+
if (/Win/.test(text)) return "windows";
|
|
8
|
+
return "linux";
|
|
9
|
+
}
|
|
10
|
+
var NAMED_KEYS = {
|
|
11
|
+
"[": "BracketLeft",
|
|
12
|
+
"]": "BracketRight",
|
|
13
|
+
"-": "Minus",
|
|
14
|
+
"=": "Equal",
|
|
15
|
+
plus: "Equal",
|
|
16
|
+
",": "Comma",
|
|
17
|
+
".": "Period",
|
|
18
|
+
"/": "Slash",
|
|
19
|
+
"\\": "Backslash",
|
|
20
|
+
";": "Semicolon",
|
|
21
|
+
"'": "Quote",
|
|
22
|
+
"`": "Backquote",
|
|
23
|
+
enter: "Enter",
|
|
24
|
+
return: "Enter",
|
|
25
|
+
"\u21A9": "Enter",
|
|
26
|
+
escape: "Escape",
|
|
27
|
+
esc: "Escape",
|
|
28
|
+
"\u238B": "Escape",
|
|
29
|
+
space: "Space",
|
|
30
|
+
spacebar: "Space",
|
|
31
|
+
" ": "Space",
|
|
32
|
+
tab: "Tab",
|
|
33
|
+
"\u21E5": "Tab",
|
|
34
|
+
backspace: "Backspace",
|
|
35
|
+
"\u232B": "Backspace",
|
|
36
|
+
delete: "Delete",
|
|
37
|
+
del: "Delete",
|
|
38
|
+
"\u2326": "Delete",
|
|
39
|
+
insert: "Insert",
|
|
40
|
+
home: "Home",
|
|
41
|
+
end: "End",
|
|
42
|
+
pageup: "PageUp",
|
|
43
|
+
pgup: "PageUp",
|
|
44
|
+
pagedown: "PageDown",
|
|
45
|
+
pgdn: "PageDown",
|
|
46
|
+
up: "ArrowUp",
|
|
47
|
+
arrowup: "ArrowUp",
|
|
48
|
+
"\u2191": "ArrowUp",
|
|
49
|
+
down: "ArrowDown",
|
|
50
|
+
arrowdown: "ArrowDown",
|
|
51
|
+
"\u2193": "ArrowDown",
|
|
52
|
+
left: "ArrowLeft",
|
|
53
|
+
arrowleft: "ArrowLeft",
|
|
54
|
+
"\u2190": "ArrowLeft",
|
|
55
|
+
right: "ArrowRight",
|
|
56
|
+
arrowright: "ArrowRight",
|
|
57
|
+
"\u2192": "ArrowRight",
|
|
58
|
+
bracketleft: "BracketLeft",
|
|
59
|
+
bracketright: "BracketRight",
|
|
60
|
+
minus: "Minus",
|
|
61
|
+
equal: "Equal",
|
|
62
|
+
comma: "Comma",
|
|
63
|
+
period: "Period",
|
|
64
|
+
slash: "Slash",
|
|
65
|
+
backslash: "Backslash",
|
|
66
|
+
semicolon: "Semicolon",
|
|
67
|
+
quote: "Quote",
|
|
68
|
+
backquote: "Backquote"
|
|
69
|
+
};
|
|
70
|
+
var CODE_TEXT = {
|
|
71
|
+
BracketLeft: "[",
|
|
72
|
+
BracketRight: "]",
|
|
73
|
+
Minus: "-",
|
|
74
|
+
Equal: "=",
|
|
75
|
+
Comma: ",",
|
|
76
|
+
Period: ".",
|
|
77
|
+
Slash: "/",
|
|
78
|
+
Backslash: "\\",
|
|
79
|
+
Semicolon: ";",
|
|
80
|
+
Quote: "'",
|
|
81
|
+
Backquote: "`",
|
|
82
|
+
ArrowUp: "Up",
|
|
83
|
+
ArrowDown: "Down",
|
|
84
|
+
ArrowLeft: "Left",
|
|
85
|
+
ArrowRight: "Right"
|
|
86
|
+
};
|
|
87
|
+
var MAC_KEY_GLYPHS = {
|
|
88
|
+
Backspace: "\u232B",
|
|
89
|
+
Delete: "\u2326",
|
|
90
|
+
Enter: "\u21A9",
|
|
91
|
+
Escape: "\u238B",
|
|
92
|
+
Tab: "\u21E5",
|
|
93
|
+
ArrowUp: "\u2191",
|
|
94
|
+
ArrowDown: "\u2193",
|
|
95
|
+
ArrowLeft: "\u2190",
|
|
96
|
+
ArrowRight: "\u2192",
|
|
97
|
+
PageUp: "Page Up",
|
|
98
|
+
PageDown: "Page Down",
|
|
99
|
+
Space: "Space"
|
|
100
|
+
};
|
|
101
|
+
var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
102
|
+
...Object.values(NAMED_KEYS),
|
|
103
|
+
"Enter",
|
|
104
|
+
"Escape",
|
|
105
|
+
"Space",
|
|
106
|
+
"Tab",
|
|
107
|
+
"Backspace",
|
|
108
|
+
"Delete",
|
|
109
|
+
"Insert",
|
|
110
|
+
"Home",
|
|
111
|
+
"End",
|
|
112
|
+
"PageUp",
|
|
113
|
+
"PageDown"
|
|
114
|
+
]);
|
|
115
|
+
function keyToCode(token) {
|
|
116
|
+
if (!token) return null;
|
|
117
|
+
if (/^[a-z]$/i.test(token)) return `Key${token.toUpperCase()}`;
|
|
118
|
+
if (/^[0-9]$/.test(token)) return `Digit${token}`;
|
|
119
|
+
if (/^f([1-9]|1[0-9]|2[0-4])$/i.test(token)) return token.toUpperCase();
|
|
120
|
+
if (/^Key[A-Z]$/.test(token) || /^Digit[0-9]$/.test(token) || /^Numpad\w+$/.test(token)) return token;
|
|
121
|
+
if (KNOWN_CODES.has(token)) return token;
|
|
122
|
+
return _nullishCoalesce(_nullishCoalesce(NAMED_KEYS[token], () => ( NAMED_KEYS[token.toLowerCase().replace(/[\s_]/g, "")])), () => ( null));
|
|
123
|
+
}
|
|
124
|
+
function codeToKeyText(code) {
|
|
125
|
+
if (/^Key[A-Z]$/.test(code)) return code.slice(3);
|
|
126
|
+
if (/^Digit[0-9]$/.test(code)) return code.slice(5);
|
|
127
|
+
return _nullishCoalesce(CODE_TEXT[code], () => ( code));
|
|
128
|
+
}
|
|
129
|
+
var GLYPH_MODIFIERS = { "\u2318": "Meta+", "\u2303": "Ctrl+", "\u2325": "Alt+", "\u21E7": "Shift+" };
|
|
130
|
+
function parseChord(text) {
|
|
131
|
+
const source = text.trim();
|
|
132
|
+
if (!source) throw new Error("Empty shortcut.");
|
|
133
|
+
let expanded = "";
|
|
134
|
+
for (const ch of source) expanded += _nullishCoalesce(GLYPH_MODIFIERS[ch], () => ( ch));
|
|
135
|
+
const parts = expanded.split("+").map((p) => p.trim()).filter(Boolean);
|
|
136
|
+
if (parts.length === 0) throw new Error(`"${text}" has no key.`);
|
|
137
|
+
const chord = { key: "" };
|
|
138
|
+
parts.forEach((part, index) => {
|
|
139
|
+
const low = part.toLowerCase();
|
|
140
|
+
const isLast = index === parts.length - 1;
|
|
141
|
+
if (low === "mod" || low === "cmdorctrl" || low === "commandorcontrol" || low === "primary") chord.mod = true;
|
|
142
|
+
else if (low === "ctrl" || low === "control" || low === "ctl") chord.ctrl = true;
|
|
143
|
+
else if (low === "meta" || low === "cmd" || low === "command" || low === "super" || low === "win") chord.meta = true;
|
|
144
|
+
else if (low === "alt" || low === "option" || low === "opt") chord.alt = true;
|
|
145
|
+
else if (low === "shift") chord.shift = true;
|
|
146
|
+
else if (isLast) {
|
|
147
|
+
const code = keyToCode(part);
|
|
148
|
+
if (!code) throw new Error(`Unknown key "${part}" in shortcut "${text}".`);
|
|
149
|
+
chord.key = code;
|
|
150
|
+
} else throw new Error(`Unknown modifier "${part}" in shortcut "${text}".`);
|
|
151
|
+
});
|
|
152
|
+
if (!chord.key) throw new Error(`"${text}" has no key.`);
|
|
153
|
+
return chord;
|
|
154
|
+
}
|
|
155
|
+
function chordToString(chord) {
|
|
156
|
+
const parts = [];
|
|
157
|
+
if (chord.mod) parts.push("Mod");
|
|
158
|
+
if (chord.ctrl) parts.push("Ctrl");
|
|
159
|
+
if (chord.meta) parts.push("Meta");
|
|
160
|
+
if (chord.alt) parts.push("Alt");
|
|
161
|
+
if (chord.shift) parts.push("Shift");
|
|
162
|
+
parts.push(codeToKeyText(chord.key));
|
|
163
|
+
return parts.join("+");
|
|
164
|
+
}
|
|
165
|
+
function normalizeChord(text) {
|
|
166
|
+
return chordToString(parseChord(text));
|
|
167
|
+
}
|
|
168
|
+
var toChord = (chord) => typeof chord === "string" ? parseChord(chord) : chord;
|
|
169
|
+
function effectiveChord(chord, platform) {
|
|
170
|
+
const c = toChord(chord);
|
|
171
|
+
const mac = platform === "mac";
|
|
172
|
+
return {
|
|
173
|
+
key: c.key,
|
|
174
|
+
ctrl: !!c.ctrl || !mac && !!c.mod,
|
|
175
|
+
meta: !!c.meta || mac && !!c.mod,
|
|
176
|
+
alt: !!c.alt,
|
|
177
|
+
shift: !!c.shift
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function effectiveChordKey(chord, platform) {
|
|
181
|
+
const e = effectiveChord(chord, platform);
|
|
182
|
+
return [e.ctrl && "Ctrl", e.meta && "Meta", e.alt && "Alt", e.shift && "Shift", e.key].filter(Boolean).join("+");
|
|
183
|
+
}
|
|
184
|
+
function formatShortcut(chord, platform = detectPlatform()) {
|
|
185
|
+
let c;
|
|
186
|
+
try {
|
|
187
|
+
c = toChord(chord);
|
|
188
|
+
} catch (e2) {
|
|
189
|
+
return String(chord);
|
|
190
|
+
}
|
|
191
|
+
const e = effectiveChord(c, platform);
|
|
192
|
+
if (platform === "mac") {
|
|
193
|
+
const mods = `${e.ctrl ? "\u2303" : ""}${e.alt ? "\u2325" : ""}${e.shift ? "\u21E7" : ""}${e.meta ? "\u2318" : ""}`;
|
|
194
|
+
return mods + (_nullishCoalesce(MAC_KEY_GLYPHS[c.key], () => ( codeToKeyText(c.key))));
|
|
195
|
+
}
|
|
196
|
+
const parts = [];
|
|
197
|
+
if (e.ctrl) parts.push("Ctrl");
|
|
198
|
+
if (e.meta) parts.push(platform === "windows" ? "Win" : "Super");
|
|
199
|
+
if (e.alt) parts.push("Alt");
|
|
200
|
+
if (e.shift) parts.push("Shift");
|
|
201
|
+
const key = c.key === "PageUp" ? "Page Up" : c.key === "PageDown" ? "Page Down" : codeToKeyText(c.key);
|
|
202
|
+
parts.push(key);
|
|
203
|
+
return parts.join("+");
|
|
204
|
+
}
|
|
205
|
+
function eventCode(event) {
|
|
206
|
+
if (event.code) return event.code;
|
|
207
|
+
return _nullishCoalesce(_nullishCoalesce(codeFromKey(_nullishCoalesce(event.key, () => ( ""))), () => ( event.key)), () => ( ""));
|
|
208
|
+
}
|
|
209
|
+
function shortcutCode(event) {
|
|
210
|
+
const code = eventCode(event);
|
|
211
|
+
const key = _nullishCoalesce(event.key, () => ( ""));
|
|
212
|
+
if (!event.altKey && /^Key[A-Z]$/.test(code) && /^[a-z]$/i.test(key)) return `Key${key.toUpperCase()}`;
|
|
213
|
+
return code;
|
|
214
|
+
}
|
|
215
|
+
function codeFromKey(key) {
|
|
216
|
+
if (!key) return null;
|
|
217
|
+
if (key.length === 1) return /^[a-z0-9]$/i.test(key) || key in NAMED_KEYS ? keyToCode(key) : null;
|
|
218
|
+
return keyToCode(key);
|
|
219
|
+
}
|
|
220
|
+
function isEditableEventTarget(event) {
|
|
221
|
+
let target = _nullishCoalesce(event.target, () => ( null));
|
|
222
|
+
if (!target) target = typeof document !== "undefined" ? document.activeElement : null;
|
|
223
|
+
if (!target || typeof target.tagName !== "string") return false;
|
|
224
|
+
const tag = target.tagName.toUpperCase();
|
|
225
|
+
return !!(tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || target.isContentEditable || _optionalChain([target, 'access', _5 => _5.getAttribute, 'optionalCall', _6 => _6("contenteditable")]) === "true" || _optionalChain([target, 'access', _7 => _7.closest, 'optionalCall', _8 => _8('[contenteditable="true"]')]) || _optionalChain([target, 'access', _9 => _9.closest, 'optionalCall', _10 => _10(".ProseMirror")]));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/commands/shortcuts.ts
|
|
229
|
+
function toShortcutBindings(command, input, scope) {
|
|
230
|
+
if (input === void 0) return [];
|
|
231
|
+
const list = Array.isArray(input) ? input : [input];
|
|
232
|
+
return list.map(
|
|
233
|
+
(item) => typeof item === "string" ? { command, chord: item, ...scope ? { scope } : {} } : { ...item, command, ..._nullishCoalesce(item.scope, () => ( scope)) ? { scope: _nullishCoalesce(item.scope, () => ( scope)) } : {} }
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
var asList = (scopes) => scopes === void 0 ? [] : typeof scopes === "string" ? [scopes] : scopes;
|
|
237
|
+
var ShortcutMap = (_class = class {
|
|
238
|
+
__init() {this.defaults = []}
|
|
239
|
+
__init2() {this.overrides = /* @__PURE__ */ new Map()}
|
|
240
|
+
__init3() {this.listeners = /* @__PURE__ */ new Set()}
|
|
241
|
+
|
|
242
|
+
constructor(bindings = [], options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
243
|
+
this.options = options;
|
|
244
|
+
for (const binding of bindings) this.defaults.push(this.entry(binding, "default"));
|
|
245
|
+
}
|
|
246
|
+
get platform() {
|
|
247
|
+
return _nullishCoalesce(this.options.platform, () => ( detectPlatform()));
|
|
248
|
+
}
|
|
249
|
+
entry(binding, source) {
|
|
250
|
+
return { binding, chord: typeof binding.chord === "string" ? parseChord(binding.chord) : binding.chord, source };
|
|
251
|
+
}
|
|
252
|
+
changed() {
|
|
253
|
+
for (const listener of Array.from(this.listeners)) listener();
|
|
254
|
+
}
|
|
255
|
+
/** Subscribes to binding changes. Returns an unsubscribe function. */
|
|
256
|
+
subscribe(listener) {
|
|
257
|
+
this.listeners.add(listener);
|
|
258
|
+
return () => {
|
|
259
|
+
this.listeners.delete(listener);
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/** Adds default bindings (throws on invalid chord text). Returns a function removing them. */
|
|
263
|
+
bind(bindings) {
|
|
264
|
+
const added = (Array.isArray(bindings) ? bindings : [bindings]).map((b) => this.entry(b, "default"));
|
|
265
|
+
if (added.length === 0) return () => {
|
|
266
|
+
};
|
|
267
|
+
this.defaults.push(...added);
|
|
268
|
+
this.changed();
|
|
269
|
+
return () => {
|
|
270
|
+
const before = this.defaults.length;
|
|
271
|
+
this.defaults = this.defaults.filter((e) => !added.includes(e));
|
|
272
|
+
if (this.defaults.length !== before) this.changed();
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* User override for a command: replaces all of its default bindings with `chords`
|
|
277
|
+
* (an empty list unbinds it). Throws on invalid chord text.
|
|
278
|
+
*/
|
|
279
|
+
setOverride(command, chords) {
|
|
280
|
+
const list = Array.isArray(chords) ? chords : [chords];
|
|
281
|
+
const entries = list.map(
|
|
282
|
+
(item) => this.entry(
|
|
283
|
+
typeof item === "string" || !("chord" in item) ? { command, chord: item } : { ...item, command },
|
|
284
|
+
"override"
|
|
285
|
+
)
|
|
286
|
+
);
|
|
287
|
+
this.overrides.set(command, entries);
|
|
288
|
+
this.changed();
|
|
289
|
+
}
|
|
290
|
+
/** Removes a user override (the defaults apply again). */
|
|
291
|
+
clearOverride(command) {
|
|
292
|
+
if (this.overrides.delete(command)) this.changed();
|
|
293
|
+
}
|
|
294
|
+
/** User overrides as plain data (`{ command: ['Mod+K'] }`), e.g. to persist them. */
|
|
295
|
+
getOverrides() {
|
|
296
|
+
const out = {};
|
|
297
|
+
for (const [command, entries] of this.overrides) {
|
|
298
|
+
out[command] = entries.map((e) => chordToString(e.chord));
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
/** Restores overrides saved with `getOverrides` (replacing the current ones). */
|
|
303
|
+
setOverrides(overrides) {
|
|
304
|
+
this.overrides.clear();
|
|
305
|
+
for (const [command, chords] of Object.entries(overrides)) {
|
|
306
|
+
this.overrides.set(
|
|
307
|
+
command,
|
|
308
|
+
chords.map((chord) => this.entry({ command, chord }, "override"))
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
this.changed();
|
|
312
|
+
}
|
|
313
|
+
active(platform) {
|
|
314
|
+
const out = [];
|
|
315
|
+
for (const e of this.defaults) {
|
|
316
|
+
if (!this.overrides.has(e.binding.command)) out.push(e);
|
|
317
|
+
}
|
|
318
|
+
for (const entries of this.overrides.values()) out.push(...entries);
|
|
319
|
+
return out.filter((e) => !e.binding.platforms || e.binding.platforms.includes(platform));
|
|
320
|
+
}
|
|
321
|
+
/** Effective bindings on `platform` (defaults without overridden commands, plus overrides). */
|
|
322
|
+
bindings(platform = this.platform) {
|
|
323
|
+
return this.active(platform).map((e) => e.binding);
|
|
324
|
+
}
|
|
325
|
+
/** Canonical chord text bound to `command` on `platform` (first = primary). */
|
|
326
|
+
forCommand(command, platform = this.platform) {
|
|
327
|
+
return this.active(platform).filter((e) => e.binding.command === command).map((e) => chordToString(e.chord));
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* The command a keydown event runs, or `null`. Events from text inputs are ignored
|
|
331
|
+
* unless the binding (or `options`) allows them. Bindings in the active scopes
|
|
332
|
+
* (in order) win over global bindings; bindings in other scopes never match.
|
|
333
|
+
* Keys are matched by `event.code`, except that a letter key producing another Latin
|
|
334
|
+
* letter (AZERTY, QWERTZ, Dvorak) matches that letter when Alt is not held, so
|
|
335
|
+
* `Mod+Z` follows the Z label (see `shortcutCode`).
|
|
336
|
+
*/
|
|
337
|
+
resolve(event, options = {}) {
|
|
338
|
+
const platform = _nullishCoalesce(options.platform, () => ( this.platform));
|
|
339
|
+
const editable = isEditableEventTarget(event);
|
|
340
|
+
const scopes = asList(options.scopes);
|
|
341
|
+
const candidates = this.active(platform).filter(
|
|
342
|
+
(e) => !editable || (_nullishCoalesce(_nullishCoalesce(options.allowInEditable, () => ( e.binding.allowInEditable)), () => ( false)))
|
|
343
|
+
);
|
|
344
|
+
if (candidates.length === 0) return null;
|
|
345
|
+
const code = shortcutCode(event);
|
|
346
|
+
const matching = candidates.filter((e) => this.matches(e.chord, code, event, platform));
|
|
347
|
+
if (matching.length === 0) return null;
|
|
348
|
+
for (const scope of scopes) {
|
|
349
|
+
const found = matching.find((e) => e.binding.scope === scope);
|
|
350
|
+
if (found) return { command: found.binding.command, binding: found.binding };
|
|
351
|
+
}
|
|
352
|
+
const global = matching.find((e) => e.binding.scope === void 0);
|
|
353
|
+
if (global) return { command: global.binding.command, binding: global.binding };
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
matches(chord, code, event, platform) {
|
|
357
|
+
if (chord.key !== code) return false;
|
|
358
|
+
if (!!chord.alt !== !!event.altKey || !!chord.shift !== !!event.shiftKey) return false;
|
|
359
|
+
if (this.options.modifierMode === "either") {
|
|
360
|
+
return !!(chord.mod || chord.ctrl || chord.meta) === !!(event.ctrlKey || event.metaKey);
|
|
361
|
+
}
|
|
362
|
+
const e = effectiveChord(chord, platform);
|
|
363
|
+
return e.ctrl === !!event.ctrlKey && e.meta === !!event.metaKey;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Groups of bindings that share an effective chord in one scope on `platform`
|
|
367
|
+
* (e.g. `Mod+Y` and `Ctrl+Y` collide off macOS). A scoped binding shadowing a
|
|
368
|
+
* global one is not a conflict.
|
|
369
|
+
*/
|
|
370
|
+
findConflicts(platform = this.platform) {
|
|
371
|
+
const groups = /* @__PURE__ */ new Map();
|
|
372
|
+
for (const e of this.active(platform)) {
|
|
373
|
+
const chord = this.options.modifierMode === "either" ? eitherKey(e.chord) : effectiveChordKey(e.chord, platform);
|
|
374
|
+
const id = `${_nullishCoalesce(e.binding.scope, () => ( ""))}\0${chord}`;
|
|
375
|
+
const group = _nullishCoalesce(groups.get(id), () => ( { ...e.binding.scope ? { scope: e.binding.scope } : {}, chord, commands: [] }));
|
|
376
|
+
if (!group.commands.includes(e.binding.command)) group.commands.push(e.binding.command);
|
|
377
|
+
groups.set(id, group);
|
|
378
|
+
}
|
|
379
|
+
return [...groups.values()].filter((g) => g.commands.length > 1);
|
|
380
|
+
}
|
|
381
|
+
/** Conflicts on every platform, keyed by platform (only platforms with conflicts). */
|
|
382
|
+
findAllConflicts() {
|
|
383
|
+
const out = {};
|
|
384
|
+
for (const p of PLATFORMS) {
|
|
385
|
+
const conflicts = this.findConflicts(p);
|
|
386
|
+
if (conflicts.length) out[p] = conflicts;
|
|
387
|
+
}
|
|
388
|
+
return out;
|
|
389
|
+
}
|
|
390
|
+
}, _class);
|
|
391
|
+
function eitherKey(chord) {
|
|
392
|
+
return [(chord.mod || chord.ctrl || chord.meta) && "Mod", chord.alt && "Alt", chord.shift && "Shift", chord.key].filter(Boolean).join("+");
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/canvas/arrangeShortcuts.ts
|
|
396
|
+
var DEFAULT_ARRANGE_SHORTCUTS = [
|
|
397
|
+
{ action: "alignLeft", code: "KeyA", alt: true, label: "Alt+A" },
|
|
398
|
+
{ action: "alignCenter", code: "KeyH", alt: true, label: "Alt+H" },
|
|
399
|
+
{ action: "alignRight", code: "KeyD", alt: true, label: "Alt+D" },
|
|
400
|
+
{ action: "alignTop", code: "KeyW", alt: true, label: "Alt+W" },
|
|
401
|
+
{ action: "alignMiddle", code: "KeyV", alt: true, label: "Alt+V" },
|
|
402
|
+
{ action: "alignBottom", code: "KeyS", alt: true, label: "Alt+S" },
|
|
403
|
+
{ action: "distributeHorizontal", code: "KeyH", alt: true, shift: true, label: "Alt+Shift+H" },
|
|
404
|
+
{ action: "distributeVertical", code: "KeyV", alt: true, shift: true, label: "Alt+Shift+V" },
|
|
405
|
+
{ action: "lock", code: "KeyL", mod: true, label: "Mod+L" },
|
|
406
|
+
{ action: "unlock", code: "KeyL", mod: true, alt: true, label: "Mod+Alt+L" },
|
|
407
|
+
{ action: "bringForward", code: "BracketRight", mod: true, label: "Mod+]" },
|
|
408
|
+
{ action: "sendBackward", code: "BracketLeft", mod: true, label: "Mod+[" },
|
|
409
|
+
{ action: "bringToFront", code: "BracketRight", mod: true, alt: true, label: "Mod+Alt+]" },
|
|
410
|
+
{ action: "sendToBack", code: "BracketLeft", mod: true, alt: true, label: "Mod+Alt+[" },
|
|
411
|
+
{ action: "nextScene", code: "PageDown", label: "PageDown" },
|
|
412
|
+
{ action: "previousScene", code: "PageUp", label: "PageUp" }
|
|
413
|
+
];
|
|
414
|
+
var maps = /* @__PURE__ */ new WeakMap();
|
|
415
|
+
function arrangeShortcutMap(bindings) {
|
|
416
|
+
let map = maps.get(bindings);
|
|
417
|
+
if (!map) {
|
|
418
|
+
map = new ShortcutMap(
|
|
419
|
+
bindings.map((b) => ({
|
|
420
|
+
command: b.action,
|
|
421
|
+
chord: { key: b.code, mod: b.mod, alt: b.alt, shift: b.shift }
|
|
422
|
+
})),
|
|
423
|
+
{ modifierMode: "either" }
|
|
424
|
+
);
|
|
425
|
+
maps.set(bindings, map);
|
|
426
|
+
}
|
|
427
|
+
return map;
|
|
428
|
+
}
|
|
429
|
+
function matchArrangeShortcut(event, bindings = DEFAULT_ARRANGE_SHORTCUTS) {
|
|
430
|
+
return _nullishCoalesce(_optionalChain([arrangeShortcutMap, 'call', _11 => _11(bindings), 'access', _12 => _12.resolve, 'call', _13 => _13(event), 'optionalAccess', _14 => _14.command]), () => ( null));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
exports.PLATFORMS = PLATFORMS; exports.detectPlatform = detectPlatform; exports.keyToCode = keyToCode; exports.codeToKeyText = codeToKeyText; exports.parseChord = parseChord; exports.chordToString = chordToString; exports.normalizeChord = normalizeChord; exports.effectiveChord = effectiveChord; exports.effectiveChordKey = effectiveChordKey; exports.formatShortcut = formatShortcut; exports.eventCode = eventCode; exports.shortcutCode = shortcutCode; exports.codeFromKey = codeFromKey; exports.isEditableEventTarget = isEditableEventTarget; exports.toShortcutBindings = toShortcutBindings; exports.ShortcutMap = ShortcutMap; exports.DEFAULT_ARRANGE_SHORTCUTS = DEFAULT_ARRANGE_SHORTCUTS; exports.matchArrangeShortcut = matchArrangeShortcut;
|
|
453
|
+
//# sourceMappingURL=chunk-26BVFKHU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-26BVFKHU.cjs","../src/commands/chords.ts","../src/commands/shortcuts.ts","../src/canvas/arrangeShortcuts.ts"],"names":[],"mappings":"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A;AACD,MAAA;AACE,MAAA;AACR,IAAA;AACW,IAAA;AACZ,EAAA;AAAA;AAGA,EAAA;AAC4D,IAAA;AAChD,IAAA;AACJ,MAAA;AACF,MAAA;AACL,IAAA;AACO,IAAA;AACR,EAAA;AACD;AAES;AACC,EAAA;AAGV;AFyHgB;AACA;AGnWH;AACF,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACX;AAGa;AAEJ;AACE,EAAA;AACA,EAAA;AACC,IAAA;AACA,MAAA;AACR,QAAA;AACO,QAAA;AACN,MAAA;AACA,MAAA;AACH,IAAA;AACS,IAAA;AACV,EAAA;AACO,EAAA;AACR;AAOgB;AAIP,EAAA;AACT;AHyVgB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-26BVFKHU.cjs","sourcesContent":[null,"// Portions ported from filmcraft-main/crates/engine/src/shortcuts.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors). See THIRD_PARTY_NOTICES.md.\n\n/**\n * Keyboard chords in a platform-neutral notation.\n *\n * | token | macOS | Windows / Linux |\n * |---|---|---|\n * | `Mod` | ⌘ Command | Ctrl |\n * | `Ctrl` | ⌃ Control | Ctrl (same key as `Mod`: conflicts are reported) |\n * | `Meta` / `Cmd` | ⌘ Command | Win / Super |\n * | `Alt` / `Option` | ⌥ Option | Alt |\n * | `Shift` | ⇧ Shift | Shift |\n *\n * Keys are stored as `KeyboardEvent.code` values (`KeyZ`, `Digit1`, `BracketRight`,\n * `PageDown`), so Option/Alt chords work on macOS (where Option changes `event.key`).\n */\n\nexport type Platform = 'mac' | 'windows' | 'linux';\n\nexport const PLATFORMS: readonly Platform[] = ['mac', 'windows', 'linux'];\n\n/** A parsed chord. `mod` is the platform's primary modifier. */\nexport interface Chord {\n\t/** `KeyboardEvent.code` of the key, e.g. `KeyZ`. */\n\tkey: string;\n\tmod?: boolean;\n\tctrl?: boolean;\n\tmeta?: boolean;\n\talt?: boolean;\n\tshift?: boolean;\n}\n\n/** The modifiers a chord needs on one platform (`mod` resolved to `meta` or `ctrl`). */\nexport interface EffectiveChord {\n\tkey: string;\n\tctrl: boolean;\n\tmeta: boolean;\n\talt: boolean;\n\tshift: boolean;\n}\n\n/** The current platform from `navigator` (`linux` when unknown, e.g. in Node). */\nexport function detectPlatform(): Platform {\n\tconst nav = typeof navigator !== 'undefined' ? navigator : undefined;\n\tconst text = `${nav?.platform ?? ''} ${nav?.userAgent ?? ''}`;\n\tif (/Mac|iPod|iPhone|iPad/.test(nav?.platform || nav?.userAgent || '')) return 'mac';\n\tif (/Win/.test(text)) return 'windows';\n\treturn 'linux';\n}\n\n// Characters and names → `KeyboardEvent.code`.\nconst NAMED_KEYS: Record<string, string> = {\n\t'[': 'BracketLeft',\n\t']': 'BracketRight',\n\t'-': 'Minus',\n\t'=': 'Equal',\n\tplus: 'Equal',\n\t',': 'Comma',\n\t'.': 'Period',\n\t'/': 'Slash',\n\t'\\\\': 'Backslash',\n\t';': 'Semicolon',\n\t\"'\": 'Quote',\n\t'`': 'Backquote',\n\tenter: 'Enter',\n\treturn: 'Enter',\n\t'↩': 'Enter',\n\tescape: 'Escape',\n\tesc: 'Escape',\n\t'⎋': 'Escape',\n\tspace: 'Space',\n\tspacebar: 'Space',\n\t' ': 'Space',\n\ttab: 'Tab',\n\t'⇥': 'Tab',\n\tbackspace: 'Backspace',\n\t'⌫': 'Backspace',\n\tdelete: 'Delete',\n\tdel: 'Delete',\n\t'⌦': 'Delete',\n\tinsert: 'Insert',\n\thome: 'Home',\n\tend: 'End',\n\tpageup: 'PageUp',\n\tpgup: 'PageUp',\n\tpagedown: 'PageDown',\n\tpgdn: 'PageDown',\n\tup: 'ArrowUp',\n\tarrowup: 'ArrowUp',\n\t'↑': 'ArrowUp',\n\tdown: 'ArrowDown',\n\tarrowdown: 'ArrowDown',\n\t'↓': 'ArrowDown',\n\tleft: 'ArrowLeft',\n\tarrowleft: 'ArrowLeft',\n\t'←': 'ArrowLeft',\n\tright: 'ArrowRight',\n\tarrowright: 'ArrowRight',\n\t'→': 'ArrowRight',\n\tbracketleft: 'BracketLeft',\n\tbracketright: 'BracketRight',\n\tminus: 'Minus',\n\tequal: 'Equal',\n\tcomma: 'Comma',\n\tperiod: 'Period',\n\tslash: 'Slash',\n\tbackslash: 'Backslash',\n\tsemicolon: 'Semicolon',\n\tquote: 'Quote',\n\tbackquote: 'Backquote'\n};\n\nconst CODE_TEXT: Record<string, string> = {\n\tBracketLeft: '[',\n\tBracketRight: ']',\n\tMinus: '-',\n\tEqual: '=',\n\tComma: ',',\n\tPeriod: '.',\n\tSlash: '/',\n\tBackslash: '\\\\',\n\tSemicolon: ';',\n\tQuote: \"'\",\n\tBackquote: '`',\n\tArrowUp: 'Up',\n\tArrowDown: 'Down',\n\tArrowLeft: 'Left',\n\tArrowRight: 'Right'\n};\n\nconst MAC_KEY_GLYPHS: Record<string, string> = {\n\tBackspace: '⌫',\n\tDelete: '⌦',\n\tEnter: '↩',\n\tEscape: '⎋',\n\tTab: '⇥',\n\tArrowUp: '↑',\n\tArrowDown: '↓',\n\tArrowLeft: '←',\n\tArrowRight: '→',\n\tPageUp: 'Page Up',\n\tPageDown: 'Page Down',\n\tSpace: 'Space'\n};\n\nconst KNOWN_CODES = new Set([\n\t...Object.values(NAMED_KEYS),\n\t'Enter',\n\t'Escape',\n\t'Space',\n\t'Tab',\n\t'Backspace',\n\t'Delete',\n\t'Insert',\n\t'Home',\n\t'End',\n\t'PageUp',\n\t'PageDown'\n]);\n\n/** `KeyboardEvent.code` for a key token (`Z`, `1`, `]`, `PageDown`, `F5`, `KeyZ`), or `null`. */\nexport function keyToCode(token: string): string | null {\n\tif (!token) return null;\n\tif (/^[a-z]$/i.test(token)) return `Key${token.toUpperCase()}`;\n\tif (/^[0-9]$/.test(token)) return `Digit${token}`;\n\tif (/^f([1-9]|1[0-9]|2[0-4])$/i.test(token)) return token.toUpperCase();\n\tif (/^Key[A-Z]$/.test(token) || /^Digit[0-9]$/.test(token) || /^Numpad\\w+$/.test(token)) return token;\n\tif (KNOWN_CODES.has(token)) return token;\n\treturn NAMED_KEYS[token] ?? NAMED_KEYS[token.toLowerCase().replace(/[\\s_]/g, '')] ?? null;\n}\n\n/** Neutral text for a code: `KeyZ` → `Z`, `BracketRight` → `]`, `ArrowUp` → `Up`. */\nexport function codeToKeyText(code: string): string {\n\tif (/^Key[A-Z]$/.test(code)) return code.slice(3);\n\tif (/^Digit[0-9]$/.test(code)) return code.slice(5);\n\treturn CODE_TEXT[code] ?? code;\n}\n\nconst GLYPH_MODIFIERS: Record<string, string> = { '⌘': 'Meta+', '⌃': 'Ctrl+', '⌥': 'Alt+', '⇧': 'Shift+' };\n\n/**\n * Parses chord text (`Mod+Shift+Z`, `Alt+]`, `⌥⇧⌘K`, `CmdOrCtrl+K`). Throws on unknown\n * modifiers or keys. The last `+`-separated token is the key (`+` itself is `Plus`).\n */\nexport function parseChord(text: string): Chord {\n\tconst source = text.trim();\n\tif (!source) throw new Error('Empty shortcut.');\n\tlet expanded = '';\n\tfor (const ch of source) expanded += GLYPH_MODIFIERS[ch] ?? ch;\n\tconst parts = expanded\n\t\t.split('+')\n\t\t.map((p) => p.trim())\n\t\t.filter(Boolean);\n\tif (parts.length === 0) throw new Error(`\"${text}\" has no key.`);\n\tconst chord: Chord = { key: '' };\n\tparts.forEach((part, index) => {\n\t\tconst low = part.toLowerCase();\n\t\tconst isLast = index === parts.length - 1;\n\t\tif (low === 'mod' || low === 'cmdorctrl' || low === 'commandorcontrol' || low === 'primary') chord.mod = true;\n\t\telse if (low === 'ctrl' || low === 'control' || low === 'ctl') chord.ctrl = true;\n\t\telse if (low === 'meta' || low === 'cmd' || low === 'command' || low === 'super' || low === 'win') chord.meta = true;\n\t\telse if (low === 'alt' || low === 'option' || low === 'opt') chord.alt = true;\n\t\telse if (low === 'shift') chord.shift = true;\n\t\telse if (isLast) {\n\t\t\tconst code = keyToCode(part);\n\t\t\tif (!code) throw new Error(`Unknown key \"${part}\" in shortcut \"${text}\".`);\n\t\t\tchord.key = code;\n\t\t} else throw new Error(`Unknown modifier \"${part}\" in shortcut \"${text}\".`);\n\t});\n\tif (!chord.key) throw new Error(`\"${text}\" has no key.`);\n\treturn chord;\n}\n\n/** Canonical platform-neutral text: `Mod+Ctrl+Meta+Alt+Shift+<key>`. */\nexport function chordToString(chord: Chord): string {\n\tconst parts: string[] = [];\n\tif (chord.mod) parts.push('Mod');\n\tif (chord.ctrl) parts.push('Ctrl');\n\tif (chord.meta) parts.push('Meta');\n\tif (chord.alt) parts.push('Alt');\n\tif (chord.shift) parts.push('Shift');\n\tparts.push(codeToKeyText(chord.key));\n\treturn parts.join('+');\n}\n\n/** Canonical spelling of chord text (`shift+cmdorctrl+z` → `Mod+Shift+Z`). Throws when invalid. */\nexport function normalizeChord(text: string): string {\n\treturn chordToString(parseChord(text));\n}\n\nconst toChord = (chord: string | Chord): Chord => (typeof chord === 'string' ? parseChord(chord) : chord);\n\n/** The modifiers a chord needs on `platform`: `Mod` is ⌘ (meta) on macOS and Ctrl elsewhere. */\nexport function effectiveChord(chord: string | Chord, platform: Platform): EffectiveChord {\n\tconst c = toChord(chord);\n\tconst mac = platform === 'mac';\n\treturn {\n\t\tkey: c.key,\n\t\tctrl: !!c.ctrl || (!mac && !!c.mod),\n\t\tmeta: !!c.meta || (mac && !!c.mod),\n\t\talt: !!c.alt,\n\t\tshift: !!c.shift\n\t};\n}\n\n/** Identity of an effective chord, for conflict detection (`Ctrl+Shift+KeyZ`). */\nexport function effectiveChordKey(chord: string | Chord, platform: Platform): string {\n\tconst e = effectiveChord(chord, platform);\n\treturn [e.ctrl && 'Ctrl', e.meta && 'Meta', e.alt && 'Alt', e.shift && 'Shift', e.key].filter(Boolean).join('+');\n}\n\n/**\n * Display text: `⌥⇧⌘K` on macOS, `Ctrl+Alt+Shift+K` on Windows / Linux (`Meta` shows as\n * `Win` / `Super`). Invalid text is returned unchanged.\n */\nexport function formatShortcut(chord: string | Chord, platform: Platform = detectPlatform()): string {\n\tlet c: Chord;\n\ttry {\n\t\tc = toChord(chord);\n\t} catch {\n\t\treturn String(chord);\n\t}\n\tconst e = effectiveChord(c, platform);\n\tif (platform === 'mac') {\n\t\tconst mods = `${e.ctrl ? '⌃' : ''}${e.alt ? '⌥' : ''}${e.shift ? '⇧' : ''}${e.meta ? '⌘' : ''}`;\n\t\treturn mods + (MAC_KEY_GLYPHS[c.key] ?? codeToKeyText(c.key));\n\t}\n\tconst parts: string[] = [];\n\tif (e.ctrl) parts.push('Ctrl');\n\tif (e.meta) parts.push(platform === 'windows' ? 'Win' : 'Super');\n\tif (e.alt) parts.push('Alt');\n\tif (e.shift) parts.push('Shift');\n\tconst key = c.key === 'PageUp' ? 'Page Up' : c.key === 'PageDown' ? 'Page Down' : codeToKeyText(c.key);\n\tparts.push(key);\n\treturn parts.join('+');\n}\n\n/** Minimal keyboard event surface (DOM `KeyboardEvent` satisfies it). */\nexport interface KeyboardEventLike {\n\tkey?: string;\n\tcode?: string;\n\tctrlKey?: boolean;\n\tmetaKey?: boolean;\n\taltKey?: boolean;\n\tshiftKey?: boolean;\n\ttarget?: EventTarget | null | unknown;\n\tdefaultPrevented?: boolean;\n\tpreventDefault?: () => void;\n}\n\n/** `event.code`, or one derived from `event.key` for synthetic events without a code. */\nexport function eventCode(event: KeyboardEventLike): string {\n\tif (event.code) return event.code;\n\treturn codeFromKey(event.key ?? '') ?? event.key ?? '';\n}\n\n/**\n * The key code a shortcut event is matched by: `event.code` (layout-independent, so\n * Option/Alt chords work on macOS and punctuation chords follow the physical key),\n * except that a letter key producing a different Latin letter without Alt (AZERTY,\n * QWERTZ, Dvorak) uses the produced letter, as browsers and operating systems do.\n */\nexport function shortcutCode(event: KeyboardEventLike): string {\n\tconst code = eventCode(event);\n\tconst key = event.key ?? '';\n\tif (!event.altKey && /^Key[A-Z]$/.test(code) && /^[a-z]$/i.test(key)) return `Key${key.toUpperCase()}`;\n\treturn code;\n}\n\n/** The code a printable `event.key` names on a US layout (`z` → `KeyZ`, `]` → `BracketRight`). */\nexport function codeFromKey(key: string): string | null {\n\tif (!key) return null;\n\tif (key.length === 1) return /^[a-z0-9]$/i.test(key) || key in NAMED_KEYS ? keyToCode(key) : null;\n\treturn keyToCode(key);\n}\n\n/**\n * Whether a keyboard event comes from a text-entry element: `<input>`, `<textarea>`,\n * `<select>`, a `contenteditable` element (or a descendant) or a ProseMirror editor.\n * Falls back to `document.activeElement` when the event has no element target.\n */\nexport function isEditableEventTarget(event: { target?: unknown }): boolean {\n\ttype ElementLike = {\n\t\ttagName?: unknown;\n\t\tisContentEditable?: boolean;\n\t\tclosest?: (selector: string) => unknown;\n\t\tgetAttribute?: (name: string) => string | null;\n\t};\n\tlet target = (event.target ?? null) as ElementLike | null;\n\t// Window / document targets are not editable; without a target, check the focused element.\n\tif (!target) target = typeof document !== 'undefined' ? (document.activeElement as ElementLike | null) : null;\n\tif (!target || typeof target.tagName !== 'string') return false;\n\tconst tag = target.tagName.toUpperCase();\n\treturn !!(\n\t\ttag === 'INPUT' ||\n\t\ttag === 'TEXTAREA' ||\n\t\ttag === 'SELECT' ||\n\t\ttarget.isContentEditable ||\n\t\ttarget.getAttribute?.('contenteditable') === 'true' ||\n\t\ttarget.closest?.('[contenteditable=\"true\"]') ||\n\t\ttarget.closest?.('.ProseMirror')\n\t);\n}\n","// Portions ported from filmcraft-main/crates/engine/src/shortcuts.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors). See THIRD_PARTY_NOTICES.md.\nimport {\n\tchordToString,\n\tdetectPlatform,\n\teffectiveChord,\n\teffectiveChordKey,\n\tshortcutCode,\n\tisEditableEventTarget,\n\tparseChord,\n\tPLATFORMS,\n\ttype Chord,\n\ttype KeyboardEventLike,\n\ttype Platform\n} from './chords.js';\n\n/** One key binding: a chord that runs `command`, optionally only in one scope / on some platforms. */\nexport interface ShortcutBinding {\n\tcommand: string;\n\t/** Chord text (`Mod+Shift+Z`) or a parsed chord. */\n\tchord: string | Chord;\n\t/** Scope (e.g. `canvas`, `spreadsheet`); scoped bindings win over global ones. Omit for global. */\n\tscope?: string;\n\t/** Platforms the binding exists on (default: all). E.g. `Mod+Y` redo only off macOS. */\n\tplatforms?: readonly Platform[];\n\t/** Also fire while focus is in an input, textarea or contenteditable (default `false`). */\n\tallowInEditable?: boolean;\n}\n\n/** Shortcut declaration on a command: chord text, or an object for platform / scope specifics. */\nexport type ShortcutInput =\n\t| string\n\t| Omit<ShortcutBinding, 'command'>\n\t| ReadonlyArray<string | Omit<ShortcutBinding, 'command'>>;\n\n/** Expands a command's `shortcut` declaration into bindings. */\nexport function toShortcutBindings(command: string, input: ShortcutInput | undefined, scope?: string): ShortcutBinding[] {\n\tif (input === undefined) return [];\n\tconst list = (Array.isArray(input) ? input : [input]) as Array<string | Omit<ShortcutBinding, 'command'>>;\n\treturn list.map((item) =>\n\t\ttypeof item === 'string'\n\t\t\t? { command, chord: item, ...(scope ? { scope } : {}) }\n\t\t\t: { ...item, command, ...(item.scope ?? scope ? { scope: item.scope ?? scope } : {}) }\n\t);\n}\n\nexport interface ShortcutConflict {\n\t/** Scope shared by the bindings (`undefined` = global). */\n\tscope?: string;\n\t/** Effective chord, e.g. `Ctrl+KeyZ`. */\n\tchord: string;\n\t/** Commands bound to it (two or more). */\n\tcommands: string[];\n}\n\nexport interface ShortcutMatch {\n\tcommand: string;\n\tbinding: ShortcutBinding;\n}\n\nexport interface ShortcutResolveOptions {\n\t/** Active scopes, most specific first. Bindings in these scopes win over global ones. */\n\tscopes?: string | readonly string[];\n\t/** Resolve even when the event comes from a text input (default: per binding). */\n\tallowInEditable?: boolean;\n\t/** Override the map's platform. */\n\tplatform?: Platform;\n}\n\nexport interface ShortcutMapOptions {\n\t/** Platform used to resolve `Mod` (default: detected from `navigator` on every resolve). */\n\tplatform?: Platform;\n\t/**\n\t * `platform` (default): `Mod` means ⌘ on macOS and Ctrl elsewhere, exactly.\n\t * `either`: `Mod` (and `Ctrl` / `Meta`) match ⌘ or Ctrl on every platform.\n\t */\n\tmodifierMode?: 'platform' | 'either';\n}\n\ninterface Entry {\n\tbinding: ShortcutBinding;\n\tchord: Chord;\n\tsource: 'default' | 'override';\n}\n\nconst asList = (scopes: string | readonly string[] | undefined): readonly string[] =>\n\tscopes === undefined ? [] : typeof scopes === 'string' ? [scopes] : scopes;\n\n/**\n * Keyboard shortcuts as data: default bindings plus user overrides, resolved from\n * `KeyboardEvent`s by `event.code` (so Option/Alt chords work on macOS), with scopes\n * (scoped bindings win), conflict detection per platform and display formatting.\n */\nexport class ShortcutMap {\n\tprivate defaults: Entry[] = [];\n\tprivate overrides = new Map<string, Entry[]>();\n\tprivate readonly listeners = new Set<() => void>();\n\tprivate readonly options: ShortcutMapOptions;\n\n\tconstructor(bindings: readonly ShortcutBinding[] = [], options: ShortcutMapOptions = {}) {\n\t\tthis.options = options;\n\t\tfor (const binding of bindings) this.defaults.push(this.entry(binding, 'default'));\n\t}\n\n\tget platform(): Platform {\n\t\treturn this.options.platform ?? detectPlatform();\n\t}\n\n\tprivate entry(binding: ShortcutBinding, source: Entry['source']): Entry {\n\t\treturn { binding, chord: typeof binding.chord === 'string' ? parseChord(binding.chord) : binding.chord, source };\n\t}\n\n\tprivate changed() {\n\t\tfor (const listener of Array.from(this.listeners)) listener();\n\t}\n\n\t/** Subscribes to binding changes. Returns an unsubscribe function. */\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/** Adds default bindings (throws on invalid chord text). Returns a function removing them. */\n\tbind(bindings: ShortcutBinding | readonly ShortcutBinding[]): () => void {\n\t\tconst added = (Array.isArray(bindings) ? bindings : [bindings]).map((b) => this.entry(b as ShortcutBinding, 'default'));\n\t\tif (added.length === 0) return () => {};\n\t\tthis.defaults.push(...added);\n\t\tthis.changed();\n\t\treturn () => {\n\t\t\tconst before = this.defaults.length;\n\t\t\tthis.defaults = this.defaults.filter((e) => !added.includes(e));\n\t\t\tif (this.defaults.length !== before) this.changed();\n\t\t};\n\t}\n\n\t/**\n\t * User override for a command: replaces all of its default bindings with `chords`\n\t * (an empty list unbinds it). Throws on invalid chord text.\n\t */\n\tsetOverride(\n\t\tcommand: string,\n\t\tchords: string | Chord | ReadonlyArray<string | Chord | Omit<ShortcutBinding, 'command'>>\n\t): void {\n\t\tconst list = (Array.isArray(chords) ? chords : [chords]) as Array<string | Chord | Omit<ShortcutBinding, 'command'>>;\n\t\tconst entries = list.map((item) =>\n\t\t\tthis.entry(\n\t\t\t\ttypeof item === 'string' || !('chord' in item) ? { command, chord: item as string | Chord } : { ...item, command },\n\t\t\t\t'override'\n\t\t\t)\n\t\t);\n\t\tthis.overrides.set(command, entries);\n\t\tthis.changed();\n\t}\n\n\t/** Removes a user override (the defaults apply again). */\n\tclearOverride(command: string): void {\n\t\tif (this.overrides.delete(command)) this.changed();\n\t}\n\n\t/** User overrides as plain data (`{ command: ['Mod+K'] }`), e.g. to persist them. */\n\tgetOverrides(): Record<string, string[]> {\n\t\tconst out: Record<string, string[]> = {};\n\t\tfor (const [command, entries] of this.overrides) {\n\t\t\tout[command] = entries.map((e) => chordToString(e.chord));\n\t\t}\n\t\treturn out;\n\t}\n\n\t/** Restores overrides saved with `getOverrides` (replacing the current ones). */\n\tsetOverrides(overrides: Record<string, readonly string[]>): void {\n\t\tthis.overrides.clear();\n\t\tfor (const [command, chords] of Object.entries(overrides)) {\n\t\t\tthis.overrides.set(\n\t\t\t\tcommand,\n\t\t\t\tchords.map((chord) => this.entry({ command, chord }, 'override'))\n\t\t\t);\n\t\t}\n\t\tthis.changed();\n\t}\n\n\tprivate active(platform: Platform): Entry[] {\n\t\tconst out: Entry[] = [];\n\t\tfor (const e of this.defaults) {\n\t\t\tif (!this.overrides.has(e.binding.command)) out.push(e);\n\t\t}\n\t\tfor (const entries of this.overrides.values()) out.push(...entries);\n\t\treturn out.filter((e) => !e.binding.platforms || e.binding.platforms.includes(platform));\n\t}\n\n\t/** Effective bindings on `platform` (defaults without overridden commands, plus overrides). */\n\tbindings(platform: Platform = this.platform): ShortcutBinding[] {\n\t\treturn this.active(platform).map((e) => e.binding);\n\t}\n\n\t/** Canonical chord text bound to `command` on `platform` (first = primary). */\n\tforCommand(command: string, platform: Platform = this.platform): string[] {\n\t\treturn this.active(platform)\n\t\t\t.filter((e) => e.binding.command === command)\n\t\t\t.map((e) => chordToString(e.chord));\n\t}\n\n\t/**\n\t * The command a keydown event runs, or `null`. Events from text inputs are ignored\n\t * unless the binding (or `options`) allows them. Bindings in the active scopes\n\t * (in order) win over global bindings; bindings in other scopes never match.\n\t * Keys are matched by `event.code`, except that a letter key producing another Latin\n\t * letter (AZERTY, QWERTZ, Dvorak) matches that letter when Alt is not held, so\n\t * `Mod+Z` follows the Z label (see `shortcutCode`).\n\t */\n\tresolve(event: KeyboardEventLike, options: ShortcutResolveOptions = {}): ShortcutMatch | null {\n\t\tconst platform = options.platform ?? this.platform;\n\t\tconst editable = isEditableEventTarget(event);\n\t\tconst scopes = asList(options.scopes);\n\t\tconst candidates = this.active(platform).filter(\n\t\t\t(e) => !editable || (options.allowInEditable ?? e.binding.allowInEditable ?? false)\n\t\t);\n\t\tif (candidates.length === 0) return null;\n\t\tconst code = shortcutCode(event);\n\t\tconst matching = candidates.filter((e) => this.matches(e.chord, code, event, platform));\n\t\tif (matching.length === 0) return null;\n\t\tfor (const scope of scopes) {\n\t\t\tconst found = matching.find((e) => e.binding.scope === scope);\n\t\t\tif (found) return { command: found.binding.command, binding: found.binding };\n\t\t}\n\t\tconst global = matching.find((e) => e.binding.scope === undefined);\n\t\tif (global) return { command: global.binding.command, binding: global.binding };\n\t\treturn null;\n\t}\n\n\tprivate matches(chord: Chord, code: string, event: KeyboardEventLike, platform: Platform): boolean {\n\t\tif (chord.key !== code) return false;\n\t\tif (!!chord.alt !== !!event.altKey || !!chord.shift !== !!event.shiftKey) return false;\n\t\tif (this.options.modifierMode === 'either') {\n\t\t\treturn !!(chord.mod || chord.ctrl || chord.meta) === !!(event.ctrlKey || event.metaKey);\n\t\t}\n\t\tconst e = effectiveChord(chord, platform);\n\t\treturn e.ctrl === !!event.ctrlKey && e.meta === !!event.metaKey;\n\t}\n\n\t/**\n\t * Groups of bindings that share an effective chord in one scope on `platform`\n\t * (e.g. `Mod+Y` and `Ctrl+Y` collide off macOS). A scoped binding shadowing a\n\t * global one is not a conflict.\n\t */\n\tfindConflicts(platform: Platform = this.platform): ShortcutConflict[] {\n\t\tconst groups = new Map<string, ShortcutConflict>();\n\t\tfor (const e of this.active(platform)) {\n\t\t\tconst chord = this.options.modifierMode === 'either' ? eitherKey(e.chord) : effectiveChordKey(e.chord, platform);\n\t\t\tconst id = `${e.binding.scope ?? ''}\\u0000${chord}`;\n\t\t\tconst group = groups.get(id) ?? { ...(e.binding.scope ? { scope: e.binding.scope } : {}), chord, commands: [] };\n\t\t\tif (!group.commands.includes(e.binding.command)) group.commands.push(e.binding.command);\n\t\t\tgroups.set(id, group);\n\t\t}\n\t\treturn [...groups.values()].filter((g) => g.commands.length > 1);\n\t}\n\n\t/** Conflicts on every platform, keyed by platform (only platforms with conflicts). */\n\tfindAllConflicts(): Partial<Record<Platform, ShortcutConflict[]>> {\n\t\tconst out: Partial<Record<Platform, ShortcutConflict[]>> = {};\n\t\tfor (const p of PLATFORMS) {\n\t\t\tconst conflicts = this.findConflicts(p);\n\t\t\tif (conflicts.length) out[p] = conflicts;\n\t\t}\n\t\treturn out;\n\t}\n}\n\nfunction eitherKey(chord: Chord): string {\n\treturn [(chord.mod || chord.ctrl || chord.meta) && 'Mod', chord.alt && 'Alt', chord.shift && 'Shift', chord.key]\n\t\t.filter(Boolean)\n\t\t.join('+');\n}\n","import { ShortcutMap } from '../commands/shortcuts.js';\n\n/**\n * Canvas arrangement actions that have keyboard shortcuts.\n */\nexport type CanvasArrangeAction =\n\t| 'alignLeft'\n\t| 'alignCenter'\n\t| 'alignRight'\n\t| 'alignTop'\n\t| 'alignMiddle'\n\t| 'alignBottom'\n\t| 'distributeHorizontal'\n\t| 'distributeVertical'\n\t| 'lock'\n\t| 'unlock'\n\t| 'bringForward'\n\t| 'sendBackward'\n\t| 'bringToFront'\n\t| 'sendToBack'\n\t| 'nextScene'\n\t| 'previousScene';\n\nexport interface ArrangeShortcutBinding {\n\taction: CanvasArrangeAction;\n\t/** `KeyboardEvent.code` (layout- and Option-independent, e.g. `KeyA`, `BracketRight`). */\n\tcode: string;\n\tmod?: boolean;\n\talt?: boolean;\n\tshift?: boolean;\n\t/** Human readable label, e.g. for menus. `Mod` is ⌘ on macOS and Ctrl elsewhere. */\n\tlabel: string;\n}\n\n/**\n * Default bindings. Align/distribute follow Figma (Option/Alt + letter), layer order follows\n * the common `Mod+]` / `Mod+[` convention, lock follows Keynote/Freeform (`Mod+L`,\n * `Mod+Alt+L` to unlock) and scenes step with PageDown / PageUp.\n */\nexport const DEFAULT_ARRANGE_SHORTCUTS: readonly ArrangeShortcutBinding[] = [\n\t{ action: 'alignLeft', code: 'KeyA', alt: true, label: 'Alt+A' },\n\t{ action: 'alignCenter', code: 'KeyH', alt: true, label: 'Alt+H' },\n\t{ action: 'alignRight', code: 'KeyD', alt: true, label: 'Alt+D' },\n\t{ action: 'alignTop', code: 'KeyW', alt: true, label: 'Alt+W' },\n\t{ action: 'alignMiddle', code: 'KeyV', alt: true, label: 'Alt+V' },\n\t{ action: 'alignBottom', code: 'KeyS', alt: true, label: 'Alt+S' },\n\t{ action: 'distributeHorizontal', code: 'KeyH', alt: true, shift: true, label: 'Alt+Shift+H' },\n\t{ action: 'distributeVertical', code: 'KeyV', alt: true, shift: true, label: 'Alt+Shift+V' },\n\t{ action: 'lock', code: 'KeyL', mod: true, label: 'Mod+L' },\n\t{ action: 'unlock', code: 'KeyL', mod: true, alt: true, label: 'Mod+Alt+L' },\n\t{ action: 'bringForward', code: 'BracketRight', mod: true, label: 'Mod+]' },\n\t{ action: 'sendBackward', code: 'BracketLeft', mod: true, label: 'Mod+[' },\n\t{ action: 'bringToFront', code: 'BracketRight', mod: true, alt: true, label: 'Mod+Alt+]' },\n\t{ action: 'sendToBack', code: 'BracketLeft', mod: true, alt: true, label: 'Mod+Alt+[' },\n\t{ action: 'nextScene', code: 'PageDown', label: 'PageDown' },\n\t{ action: 'previousScene', code: 'PageUp', label: 'PageUp' }\n];\n\n// One ShortcutMap per bindings array. `either` keeps the historical behaviour: `Mod` matches ⌘ or Ctrl.\nconst maps = new WeakMap<readonly ArrangeShortcutBinding[], ShortcutMap>();\n\nfunction arrangeShortcutMap(bindings: readonly ArrangeShortcutBinding[]): ShortcutMap {\n\tlet map = maps.get(bindings);\n\tif (!map) {\n\t\tmap = new ShortcutMap(\n\t\t\tbindings.map((b) => ({\n\t\t\t\tcommand: b.action,\n\t\t\t\tchord: { key: b.code, mod: b.mod, alt: b.alt, shift: b.shift }\n\t\t\t})),\n\t\t\t{ modifierMode: 'either' }\n\t\t);\n\t\tmaps.set(bindings, map);\n\t}\n\treturn map;\n}\n\n/**\n * Resolves a keydown event to an arrange action, or `null`. Events from text inputs,\n * textareas, selects, contenteditable and ProseMirror are ignored (see `isEventFromTextInput`).\n * `Mod` is ⌘ or Ctrl. Built on the command system's `ShortcutMap` (matching `event.code`).\n */\nexport function matchArrangeShortcut(\n\tevent: KeyboardEvent,\n\tbindings: readonly ArrangeShortcutBinding[] = DEFAULT_ARRANGE_SHORTCUTS\n): CanvasArrangeAction | null {\n\treturn (arrangeShortcutMap(bindings).resolve(event)?.command as CanvasArrangeAction | undefined) ?? null;\n}\n"]}
|