@edv4h/usketch-core 2.4.12 → 2.6.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/dist/create-app.d.ts +17 -1
- package/dist/create-app.d.ts.map +1 -1
- package/dist/create-app.js +51 -4
- package/dist/create-app.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/keymap-storage.d.ts +36 -0
- package/dist/keymap-storage.d.ts.map +1 -0
- package/dist/keymap-storage.js +137 -0
- package/dist/keymap-storage.js.map +1 -0
- package/dist/keymap-ui.d.ts +72 -0
- package/dist/keymap-ui.d.ts.map +1 -0
- package/dist/keymap-ui.js +193 -0
- package/dist/keymap-ui.js.map +1 -0
- package/dist/keymap.d.ts +78 -0
- package/dist/keymap.d.ts.map +1 -0
- package/dist/keymap.js +463 -0
- package/dist/keymap.js.map +1 -0
- package/dist/selection-handle-registry.d.ts +12 -0
- package/dist/selection-handle-registry.d.ts.map +1 -0
- package/dist/selection-handle-registry.js +51 -0
- package/dist/selection-handle-registry.js.map +1 -0
- package/dist/shape-registry.d.ts.map +1 -1
- package/dist/shape-registry.js +40 -0
- package/dist/shape-registry.js.map +1 -1
- package/dist/shortcut-registry.d.ts +10 -1
- package/dist/shortcut-registry.d.ts.map +1 -1
- package/dist/shortcut-registry.js +42 -41
- package/dist/shortcut-registry.js.map +1 -1
- package/dist/tool-shortcut-bridge.d.ts +14 -0
- package/dist/tool-shortcut-bridge.d.ts.map +1 -0
- package/dist/tool-shortcut-bridge.js +33 -0
- package/dist/tool-shortcut-bridge.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { codeToKey, normalizeCombo } from "./keymap.js";
|
|
2
|
+
const MODIFIERS = new Set(["mod", "ctrl", "meta", "shift", "alt"]);
|
|
3
|
+
const detectMac = () => typeof navigator !== "undefined" &&
|
|
4
|
+
/Mac|iPhone|iPad|iPod/.test(navigator.userAgentData?.platform ??
|
|
5
|
+
navigator.platform ??
|
|
6
|
+
"");
|
|
7
|
+
const KEY_LABELS = {
|
|
8
|
+
space: "Space",
|
|
9
|
+
escape: "Esc",
|
|
10
|
+
enter: "Enter",
|
|
11
|
+
tab: "Tab",
|
|
12
|
+
backspace: "Backspace",
|
|
13
|
+
delete: "Delete",
|
|
14
|
+
arrowup: "↑",
|
|
15
|
+
arrowdown: "↓",
|
|
16
|
+
arrowleft: "←",
|
|
17
|
+
arrowright: "→",
|
|
18
|
+
pageup: "PageUp",
|
|
19
|
+
pagedown: "PageDown",
|
|
20
|
+
home: "Home",
|
|
21
|
+
end: "End",
|
|
22
|
+
};
|
|
23
|
+
const MAC_KEY_LABELS = {
|
|
24
|
+
enter: "↩",
|
|
25
|
+
backspace: "⌫",
|
|
26
|
+
delete: "⌦",
|
|
27
|
+
escape: "⎋",
|
|
28
|
+
tab: "⇥",
|
|
29
|
+
};
|
|
30
|
+
const keyLabel = (key, isMac) => (isMac ? MAC_KEY_LABELS[key] : undefined) ??
|
|
31
|
+
KEY_LABELS[key] ??
|
|
32
|
+
(key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1));
|
|
33
|
+
/**
|
|
34
|
+
* A combo for display: `"Mod+Shift+Z"` → `⇧⌘Z` on macOS (Apple's ⌃⌥⇧⌘ order) and
|
|
35
|
+
* `Ctrl+Shift+Z` elsewhere. `Shift+/` is shown as `?`.
|
|
36
|
+
*/
|
|
37
|
+
export function formatCombo(combo, options = {}) {
|
|
38
|
+
const isMac = options.isMac ?? detectMac();
|
|
39
|
+
const tokens = new Set(normalizeCombo(combo).split("+").filter(Boolean));
|
|
40
|
+
if (tokens.size === 2 && tokens.has("shift") && tokens.has("/"))
|
|
41
|
+
return "?";
|
|
42
|
+
const key = [...tokens].find((t) => !MODIFIERS.has(t));
|
|
43
|
+
const ctrl = tokens.has("ctrl") || (!isMac && tokens.has("mod"));
|
|
44
|
+
const cmd = tokens.has("meta") || (isMac && tokens.has("mod"));
|
|
45
|
+
const label = key ? keyLabel(key, isMac) : "";
|
|
46
|
+
if (isMac) {
|
|
47
|
+
return ((ctrl ? "⌃" : "") +
|
|
48
|
+
(tokens.has("alt") ? "⌥" : "") +
|
|
49
|
+
(tokens.has("shift") ? "⇧" : "") +
|
|
50
|
+
(cmd ? "⌘" : "") +
|
|
51
|
+
label);
|
|
52
|
+
}
|
|
53
|
+
const parts = [];
|
|
54
|
+
if (ctrl)
|
|
55
|
+
parts.push("Ctrl");
|
|
56
|
+
if (cmd)
|
|
57
|
+
parts.push("Meta");
|
|
58
|
+
if (tokens.has("alt"))
|
|
59
|
+
parts.push("Alt");
|
|
60
|
+
if (tokens.has("shift"))
|
|
61
|
+
parts.push("Shift");
|
|
62
|
+
if (label)
|
|
63
|
+
parts.push(label);
|
|
64
|
+
return parts.join("+");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A held key (`KeyboardEvent.code`) for display: `"KeyW"` → `W`, `"ShiftLeft"` →
|
|
68
|
+
* `Left Shift` (`Left ⇧` on macOS).
|
|
69
|
+
*/
|
|
70
|
+
export function formatKeyCode(code, options = {}) {
|
|
71
|
+
const key = codeToKey(code);
|
|
72
|
+
const label = formatCombo(key, options);
|
|
73
|
+
const side = /^(?:Shift|Control|Alt|Meta|OS)(Left|Right)$/.exec(code)?.[1];
|
|
74
|
+
if (!side)
|
|
75
|
+
return label;
|
|
76
|
+
const sides = options.sides ?? { left: "Left ", right: "Right " };
|
|
77
|
+
return `${side === "Left" ? sides.left : sides.right}${label}`;
|
|
78
|
+
}
|
|
79
|
+
/** {@link formatCombo} or {@link formatKeyCode}, by the binding's kind. */
|
|
80
|
+
export function formatBindingKey(kind, key, options = {}) {
|
|
81
|
+
return kind === "hold" ? formatKeyCode(key, options) : formatCombo(key, options);
|
|
82
|
+
}
|
|
83
|
+
/** Browser / OS shortcuts a page can't (or shouldn't) take over. */
|
|
84
|
+
export const DEFAULT_RESERVED_COMBOS = [
|
|
85
|
+
"Mod+W",
|
|
86
|
+
"Mod+T",
|
|
87
|
+
"Mod+N",
|
|
88
|
+
"Mod+Q",
|
|
89
|
+
"Mod+R",
|
|
90
|
+
"Escape",
|
|
91
|
+
"Tab",
|
|
92
|
+
];
|
|
93
|
+
/**
|
|
94
|
+
* Whether a viewer may not bind `combo` (a `"press"` combo): modifier-only or several
|
|
95
|
+
* keys at once, a bare key when `allowBareKeys` is false, or one of `reserved`.
|
|
96
|
+
*/
|
|
97
|
+
export function isReservedCombo(combo, options = {}) {
|
|
98
|
+
const canonical = normalizeCombo(combo);
|
|
99
|
+
const tokens = canonical.split("+").filter(Boolean);
|
|
100
|
+
const keys = tokens.filter((t) => !MODIFIERS.has(t));
|
|
101
|
+
if (keys.length !== 1)
|
|
102
|
+
return true;
|
|
103
|
+
if (options.allowBareKeys === false && keys.length === tokens.length)
|
|
104
|
+
return true;
|
|
105
|
+
const reserved = options.reserved ?? DEFAULT_RESERVED_COMBOS;
|
|
106
|
+
return reserved.some((r) => normalizeCombo(r) === canonical);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The combo to store when a viewer presses a key to rebind a `"press"` binding, in
|
|
110
|
+
* {@link normalizeCombo} form (platform-independent: the accelerator becomes `mod`).
|
|
111
|
+
* Shifted symbols / digits are read by physical key (`Shift+1`, not `Shift+!`).
|
|
112
|
+
* Returns null while only modifiers are down.
|
|
113
|
+
*/
|
|
114
|
+
export function comboFromKeyEvent(event, options = {}) {
|
|
115
|
+
const mode = options.mod ?? "platform";
|
|
116
|
+
const isMac = options.isMac ?? detectMac();
|
|
117
|
+
const tokens = [];
|
|
118
|
+
if (mode === "either") {
|
|
119
|
+
if (event.ctrlKey || event.metaKey)
|
|
120
|
+
tokens.push("mod");
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const accel = isMac ? event.metaKey : event.ctrlKey;
|
|
124
|
+
const other = isMac ? event.ctrlKey : event.metaKey;
|
|
125
|
+
if (accel)
|
|
126
|
+
tokens.push("mod");
|
|
127
|
+
if (other)
|
|
128
|
+
tokens.push(isMac ? "ctrl" : "meta");
|
|
129
|
+
}
|
|
130
|
+
if (event.shiftKey)
|
|
131
|
+
tokens.push("shift");
|
|
132
|
+
if (event.altKey)
|
|
133
|
+
tokens.push("alt");
|
|
134
|
+
const raw = (event.key ?? "").toLowerCase();
|
|
135
|
+
if (["control", "meta", "shift", "alt", "os", "altgraph", ""].includes(raw))
|
|
136
|
+
return null;
|
|
137
|
+
const code = event.code ?? "";
|
|
138
|
+
const physical = code ? codeToKey(code) : "";
|
|
139
|
+
const usePhysical = physical &&
|
|
140
|
+
physical !== code.toLowerCase() &&
|
|
141
|
+
(event.shiftKey || event.altKey || !/^[a-z0-9]$/.test(raw));
|
|
142
|
+
tokens.push(usePhysical ? physical : raw === " " ? "space" : raw);
|
|
143
|
+
return normalizeCombo(tokens.join("+"));
|
|
144
|
+
}
|
|
145
|
+
/** Bindings (other than `exceptId`) that use `key`, as the keymap's overlap check sees it. */
|
|
146
|
+
export function bindingsUsingKey(keymap, key, kind = "press", exceptId) {
|
|
147
|
+
const token = keymap.normalizeKey(key, kind);
|
|
148
|
+
return keymap
|
|
149
|
+
.getAll()
|
|
150
|
+
.filter((b) => b.id !== exceptId && b.keys.some((k) => keymap.normalizeKey(k, b.kind) === token));
|
|
151
|
+
}
|
|
152
|
+
/** Bind `key` to `id` for the viewer (see {@link AssignKeyOptions}). */
|
|
153
|
+
export function assignKey(keymap, id, key, options = {}) {
|
|
154
|
+
const binding = keymap.get(id);
|
|
155
|
+
if (!binding?.customizable)
|
|
156
|
+
return { ok: false, stolenFrom: [], sharedWith: [] };
|
|
157
|
+
const token = keymap.normalizeKey(key, binding.kind);
|
|
158
|
+
const same = (k, kind) => keymap.normalizeKey(k, kind) === token;
|
|
159
|
+
const stolenFrom = [];
|
|
160
|
+
const sharedWith = [];
|
|
161
|
+
for (const other of bindingsUsingKey(keymap, key, binding.kind, id)) {
|
|
162
|
+
if (options.steal && other.customizable) {
|
|
163
|
+
keymap.setKeys(other.id, other.keys.filter((k) => !same(k, other.kind)));
|
|
164
|
+
stolenFrom.push(other.id);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
sharedWith.push(other.id);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// One entry per key: drop an older copy, then put the key in its slot (or last).
|
|
171
|
+
const slot = options.slot;
|
|
172
|
+
const keys = binding.keys.map((k, i) => (i === slot ? null : k));
|
|
173
|
+
const kept = keys.filter((k) => k !== null && !same(k, binding.kind));
|
|
174
|
+
const at = slot !== undefined && slot >= 0 && slot < binding.keys.length
|
|
175
|
+
? keys.slice(0, slot).filter((k) => k !== null && !same(k, binding.kind)).length
|
|
176
|
+
: kept.length;
|
|
177
|
+
kept.splice(at, 0, key);
|
|
178
|
+
keymap.setKeys(id, kept);
|
|
179
|
+
return { ok: true, stolenFrom, sharedWith };
|
|
180
|
+
}
|
|
181
|
+
/** Remove `key` from `id` for the viewer. Returns false when nothing changed. */
|
|
182
|
+
export function unassignKey(keymap, id, key) {
|
|
183
|
+
const binding = keymap.get(id);
|
|
184
|
+
if (!binding?.customizable)
|
|
185
|
+
return false;
|
|
186
|
+
const token = keymap.normalizeKey(key, binding.kind);
|
|
187
|
+
const keys = binding.keys.filter((k) => keymap.normalizeKey(k, binding.kind) !== token);
|
|
188
|
+
if (keys.length === binding.keys.length)
|
|
189
|
+
return false;
|
|
190
|
+
keymap.setKeys(id, keys);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=keymap-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keymap-ui.js","sourceRoot":"","sources":["../src/keymap-ui.ts"],"names":[],"mappings":"AAKA,OAAO,EAAqB,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,E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,CAAC"}
|
package/dist/keymap.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { KeyBindingSpec, KeyConflict, KeyConflictPolicy, KeyGate, Keymap } from "@edv4h/usketch-shared";
|
|
2
|
+
/**
|
|
3
|
+
* How the `Mod` token (and the Cmd / Ctrl keys) match:
|
|
4
|
+
* - `"platform"` (default): `Mod` is Cmd on macOS and Ctrl elsewhere; Cmd and Ctrl are
|
|
5
|
+
* different keys (on a Mac, `Ctrl+Z` is not `Mod+Z`).
|
|
6
|
+
* - `"either"`: Cmd and Ctrl are the same key everywhere, and `Mod` is that key.
|
|
7
|
+
*/
|
|
8
|
+
export type ModKeyMode = "platform" | "either";
|
|
9
|
+
/** Options for matching combos against keydowns. */
|
|
10
|
+
export interface ComboOptions {
|
|
11
|
+
/** Default `"platform"`. */
|
|
12
|
+
mod?: ModKeyMode;
|
|
13
|
+
/** Whether to treat the platform as macOS. Default: detected from `navigator`. */
|
|
14
|
+
isMac?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The canonical, platform-independent form of a `"+"`-joined combo: lower-case,
|
|
18
|
+
* order-independent, aliases folded (`Cmd` → `meta`, `Option` → `alt`, `Spacebar` →
|
|
19
|
+
* `space` …), and `?` expanded to `shift+/`. `Mod` is kept as `mod`, so the result is
|
|
20
|
+
* the same on every platform (safe to store, e.g. as a rebinding).
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeCombo(combo: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* The key a `KeyboardEvent.code` stands for on a US layout, in {@link normalizeCombo}
|
|
25
|
+
* form (`"KeyW"` → `"w"`, `"Digit1"` → `"1"`, `"ShiftLeft"` → `"shift"`, `"ArrowUp"` →
|
|
26
|
+
* `"arrowup"`). Used for physical-key matching and to compare held-key bindings with
|
|
27
|
+
* shortcut combos when looking for overlaps.
|
|
28
|
+
*/
|
|
29
|
+
export declare function codeToKey(code: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* The combos a keydown can match, resolved for `options` (see {@link ComboOptions}).
|
|
32
|
+
* The first is from `KeyboardEvent.key` (follows the layout: `"q"` on AZERTY's A key).
|
|
33
|
+
* When Shift / Alt is held or the key is not a plain letter / digit, the physical key
|
|
34
|
+
* (`KeyboardEvent.code`) is added too, so `Shift+1` matches although `key` is `"!"`, and
|
|
35
|
+
* `Mod+Shift+]` matches although `key` is `"}"`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function eventToCombos(event: KeyboardEvent, options?: ComboOptions): string[];
|
|
38
|
+
/** The main combo a keydown produces (its `key`-based form; see {@link eventToCombos}). */
|
|
39
|
+
export declare function eventToCombo(event: KeyboardEvent, options?: ComboOptions): string;
|
|
40
|
+
/** Who a registration is attributed to (see {@link KeymapInternal.registerFor}). */
|
|
41
|
+
export interface KeymapOwner {
|
|
42
|
+
pluginId?: string;
|
|
43
|
+
/** Position in the plugin list; omit (or −1) for host / core. */
|
|
44
|
+
index?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface CreateKeymapOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Host defaults by binding id: replace a plugin's default keys (`null` = unbound by
|
|
49
|
+
* default). The viewer's {@link Keymap.setKeys} still wins over these.
|
|
50
|
+
*/
|
|
51
|
+
keys?: Readonly<Record<string, readonly string[] | null>>;
|
|
52
|
+
/** The viewer's saved rebindings to start from (as {@link Keymap.getOverrides} returns). */
|
|
53
|
+
overrides?: Readonly<Record<string, readonly string[] | null>>;
|
|
54
|
+
/** Who gets a key several active bindings share (default `"first"`); see {@link KeyConflictPolicy}. */
|
|
55
|
+
conflictPolicy?: KeyConflictPolicy;
|
|
56
|
+
/** How `Mod` / Cmd / Ctrl match (default `"platform"`); see {@link ModKeyMode}. */
|
|
57
|
+
mod?: ModKeyMode;
|
|
58
|
+
/** Treat the platform as macOS (default: detected). */
|
|
59
|
+
isMac?: boolean;
|
|
60
|
+
/** The host's gate; see {@link Keymap.setGate}. */
|
|
61
|
+
gate?: KeyGate | null;
|
|
62
|
+
}
|
|
63
|
+
export interface KeymapInternal extends Keymap {
|
|
64
|
+
/** Register on behalf of a plugin (createApp's scoped `ctx.keymap` calls this). */
|
|
65
|
+
registerFor(owner: KeymapOwner, spec: KeyBindingSpec): () => void;
|
|
66
|
+
}
|
|
67
|
+
export declare function createKeymap(options?: CreateKeymapOptions): KeymapInternal;
|
|
68
|
+
/**
|
|
69
|
+
* The keymap as one plugin sees it: `register` is attributed to `owner`, and the
|
|
70
|
+
* internal `registerFor` is not reachable (explicit members, not a spread).
|
|
71
|
+
*/
|
|
72
|
+
export declare function scopeKeymap(keymap: KeymapInternal, owner: KeymapOwner): Keymap;
|
|
73
|
+
/**
|
|
74
|
+
* Human-readable list of overlaps, for a dev-time console warning. `markWinner` puts ▶
|
|
75
|
+
* on the binding that gets the key when all of them act (`"first"` / `"last"` policies).
|
|
76
|
+
*/
|
|
77
|
+
export declare function describeConflicts(conflicts: readonly KeyConflict[], markWinner?: boolean): string;
|
|
78
|
+
//# sourceMappingURL=keymap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keymap.d.ts","sourceRoot":"","sources":["../src/keymap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,MAAM,EACN,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE/C,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC5B,4BAA4B;IAC5B,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AA4BD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBpD;AAkCD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9C;AAOD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