@lvl99dotcom/paintcanvas 0.3.1 → 0.4.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 +1 -1
- package/dist/lib/brushes/StrokeEngine/index.d.ts +2 -2
- package/dist/lib/brushes/StrokeEngine/index.js +26 -28
- package/dist/lib/classes/BrushSettings/index.d.ts +24 -0
- package/dist/lib/classes/BrushSettings/index.js +35 -1
- package/dist/lib/classes/KeyboardShortcuts/index.d.ts +17 -6
- package/dist/lib/classes/KeyboardShortcuts/index.js +81 -18
- package/dist/lib/classes/PaintCanvas/index.d.ts +77 -27
- package/dist/lib/classes/PaintCanvas/index.js +141 -41
- package/dist/lib/classes/PaintCanvas/tool.d.ts +15 -0
- package/dist/lib/classes/PaintCanvas/tool.js +18 -0
- package/dist/lib/classes/Palette/index.d.ts +58 -0
- package/dist/lib/classes/Palette/index.js +92 -0
- package/dist/lib/classes/SettingsAutosave/index.d.ts +52 -0
- package/dist/lib/classes/SettingsAutosave/index.js +96 -0
- package/dist/lib/classes/ShortcutSettings/index.d.ts +63 -0
- package/dist/lib/classes/ShortcutSettings/index.js +110 -0
- package/dist/lib/palette/index.d.ts +49 -0
- package/dist/lib/palette/index.js +82 -0
- package/dist/lib/palette/schema.d.ts +45 -0
- package/dist/lib/palette/schema.js +41 -0
- package/dist/lib/rendering/cursors/index.d.ts +2 -0
- package/dist/lib/rendering/cursors/index.js +3 -1
- package/dist/lib/rendering/sample/index.js +3 -2
- package/dist/lib/settings/index.d.ts +63 -0
- package/dist/lib/settings/index.js +91 -0
- package/dist/lib/settings/schema.d.ts +150 -0
- package/dist/lib/settings/schema.js +102 -0
- package/dist/lib/storage/index.d.ts +36 -5
- package/dist/lib/storage/index.js +87 -29
- package/dist/lib/utils/colour/index.d.ts +72 -0
- package/dist/lib/utils/colour/index.js +154 -0
- package/dist/lib/utils/shortcuts/index.d.ts +174 -11
- package/dist/lib/utils/shortcuts/index.js +391 -145
- package/dist/lib/validation/validators.generated.d.ts +5 -0
- package/dist/lib/validation/validators.generated.js +872 -1
- package/dist/locales/en-GB.js +87 -1
- package/dist/locales/en-US.js +87 -1
- package/dist/locales/fr.js +87 -1
- package/dist/locales/ja.js +87 -1
- package/dist/locales/ko.js +87 -1
- package/dist/locales/zh-Hans.js +87 -1
- package/dist/locales/zh-Hant.js +87 -1
- package/dist/package.js +1 -1
- package/dist/ui/elements/PaintCanvas/index.d.ts +49 -47
- package/dist/ui/elements/PaintCanvas/index.js +121 -171
- package/dist/ui/elements/PaintCanvas/style.js +1 -1
- package/dist/ui/elements/PcAppSettings/index.d.ts +59 -0
- package/dist/ui/elements/PcAppSettings/index.js +222 -0
- package/dist/ui/elements/PcCanvas/index.d.ts +1 -1
- package/dist/ui/elements/PcCanvas/index.js +7 -5
- package/dist/ui/elements/PcColourPair/index.d.ts +43 -0
- package/dist/ui/elements/PcColourPair/index.js +125 -0
- package/dist/ui/elements/PcContextMenu/index.d.ts +70 -33
- package/dist/ui/elements/PcContextMenu/index.js +128 -97
- package/dist/ui/elements/PcLayerItem/index.d.ts +13 -34
- package/dist/ui/elements/PcLayerItem/index.js +39 -91
- package/dist/ui/elements/PcLayerItem/style.js +1 -1
- package/dist/ui/elements/PcMenu/index.d.ts +93 -0
- package/dist/ui/elements/PcMenu/index.js +204 -0
- package/dist/ui/elements/PcPane/index.d.ts +118 -0
- package/dist/ui/elements/PcPane/index.js +357 -0
- package/dist/ui/elements/PcPanel/index.d.ts +26 -8
- package/dist/ui/elements/PcPanel/index.js +76 -8
- package/dist/ui/elements/{PcBrushMenu → PcPanelBrushes}/index.d.ts +20 -6
- package/dist/ui/elements/{PcBrushMenu → PcPanelBrushes}/index.js +18 -14
- package/dist/ui/elements/PcPanelBrushes/style.js +3 -0
- package/dist/ui/elements/PcPanelColours/index.d.ts +171 -0
- package/dist/ui/elements/PcPanelColours/index.js +650 -0
- package/dist/ui/elements/PcPanelColours/style.js +3 -0
- package/dist/ui/elements/{PcLayersMenu → PcPanelLayers}/index.d.ts +17 -4
- package/dist/ui/elements/{PcLayersMenu → PcPanelLayers}/index.js +17 -10
- package/dist/ui/elements/PcPanelLayers/style.js +3 -0
- package/dist/ui/elements/PcShortcutSettings/index.d.ts +69 -0
- package/dist/ui/elements/PcShortcutSettings/index.js +273 -0
- package/dist/ui/elements/PcToolSettings/index.js +2 -1
- package/dist/ui/elements/PcToolbar/index.d.ts +47 -12
- package/dist/ui/elements/PcToolbar/index.js +77 -56
- package/dist/ui/elements/PcToolbar/style.js +1 -1
- package/dist/ui/index.d.ts +7 -1
- package/dist/ui/index.js +8 -2
- package/dist/ui/tokens/index.js +3 -1
- package/locales/en-GB.json +87 -1
- package/locales/en-US.json +87 -1
- package/locales/fr.json +87 -1
- package/locales/ja.json +87 -1
- package/locales/ko.json +87 -1
- package/locales/zh-Hans.json +87 -1
- package/locales/zh-Hant.json +87 -1
- package/package.json +1 -1
- package/dist/ui/elements/PcBrushMenu/style.js +0 -3
- package/dist/ui/elements/PcLayersMenu/style.js +0 -3
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { Tool } from "../../classes/PaintCanvas";
|
|
1
|
+
import { Tool } from "../../classes/PaintCanvas/tool";
|
|
2
2
|
/** Actions that keyboard shortcuts trigger */
|
|
3
3
|
export type ShortcutAction = {
|
|
4
4
|
type: "tool";
|
|
5
5
|
tool: Tool;
|
|
6
|
+
} | {
|
|
7
|
+
type: "pan";
|
|
6
8
|
} | {
|
|
7
9
|
type: "brush-smaller";
|
|
8
10
|
} | {
|
|
9
11
|
type: "brush-bigger";
|
|
12
|
+
} | {
|
|
13
|
+
type: "brush-less-opaque";
|
|
14
|
+
} | {
|
|
15
|
+
type: "brush-more-opaque";
|
|
10
16
|
} | {
|
|
11
17
|
type: "toggle-interface";
|
|
12
18
|
} | {
|
|
13
19
|
type: "select-all";
|
|
20
|
+
} | {
|
|
21
|
+
type: "invert-selection";
|
|
14
22
|
} | {
|
|
15
23
|
type: "deselect";
|
|
16
24
|
} | {
|
|
@@ -31,21 +39,124 @@ export type ShortcutAction = {
|
|
|
31
39
|
type: "cancel";
|
|
32
40
|
} | {
|
|
33
41
|
type: "commit";
|
|
42
|
+
} | {
|
|
43
|
+
type: "fill-foreground";
|
|
44
|
+
} | {
|
|
45
|
+
type: "fill-background";
|
|
46
|
+
} | {
|
|
47
|
+
type: "swap-colours";
|
|
48
|
+
} | {
|
|
49
|
+
type: "zoom-in";
|
|
50
|
+
} | {
|
|
51
|
+
type: "zoom-out";
|
|
52
|
+
} | {
|
|
53
|
+
type: "reset-zoom";
|
|
54
|
+
} | {
|
|
55
|
+
type: "layer-opacity";
|
|
56
|
+
opacity: number;
|
|
34
57
|
};
|
|
35
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* A key combination. `cmd` is the Command key on Apple devices and Ctrl elsewhere; `ctrl` is the Control key on Apple
|
|
60
|
+
* devices only (elsewhere Ctrl is `cmd`).
|
|
61
|
+
*/
|
|
36
62
|
export interface KeyCombo {
|
|
37
|
-
/** Lowercase `KeyboardEvent.key` value */
|
|
63
|
+
/** Lowercase `KeyboardEvent.key` value, e.g. `a`, `[`, `backspace` or ` ` (Space) */
|
|
38
64
|
key: string;
|
|
39
65
|
cmd?: boolean;
|
|
66
|
+
ctrl?: boolean;
|
|
40
67
|
shift?: boolean;
|
|
41
68
|
alt?: boolean;
|
|
42
69
|
}
|
|
70
|
+
/** A key combination and the action it runs */
|
|
43
71
|
export interface Shortcut extends KeyCombo {
|
|
44
72
|
action: ShortcutAction;
|
|
45
73
|
}
|
|
46
|
-
/**
|
|
74
|
+
/** Groups shortcuts are listed in, e.g. in the keyboard shortcuts settings */
|
|
75
|
+
export type ShortcutGroup = "tools" | "brushes" | "masking" | "fills" | "viewport" | "layers" | "clipboard" | "history" | "general";
|
|
76
|
+
/** A keyboard shortcut action and its default key combinations */
|
|
77
|
+
export interface ShortcutDefinition {
|
|
78
|
+
/** Names the action, e.g. to save its key combination and to translate its name (`paintCanvas.shortcuts.<id>`) */
|
|
79
|
+
id: string;
|
|
80
|
+
group: ShortcutGroup;
|
|
81
|
+
action: ShortcutAction;
|
|
82
|
+
/** Default key combinations (a configurable action has one) */
|
|
83
|
+
combos: readonly KeyCombo[];
|
|
84
|
+
/** Whether users can change or remove its key combination */
|
|
85
|
+
configurable: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** ID of the action run while its key is held: pan, returning to the last tool when released */
|
|
88
|
+
export declare const HOLD_TO_PAN = "pan";
|
|
89
|
+
/** Every keyboard shortcut action, in the order they are listed */
|
|
90
|
+
export declare const SHORTCUT_DEFINITIONS: readonly ShortcutDefinition[];
|
|
91
|
+
/** The actions users can change the key combinations of */
|
|
92
|
+
export declare const CONFIGURABLE_SHORTCUTS: readonly ShortcutDefinition[];
|
|
93
|
+
/** The actions whose key combinations can't be changed */
|
|
94
|
+
export declare const FIXED_SHORTCUTS: readonly ShortcutDefinition[];
|
|
95
|
+
/** The key combination of each configurable action, by ID (null when it has none) */
|
|
96
|
+
export type ShortcutBindings = Record<string, KeyCombo | null>;
|
|
97
|
+
/**
|
|
98
|
+
* A key combination with only the modifiers that are on, e.g. to compare or save it.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* normaliseCombo({ key: "s", cmd: true, shift: false }); // { key: "s", cmd: true }
|
|
102
|
+
*/
|
|
103
|
+
export declare const normaliseCombo: ({ key, cmd, ctrl, shift, alt, }: KeyCombo) => KeyCombo;
|
|
104
|
+
/**
|
|
105
|
+
* Whether two key combinations are the same.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* sameCombo({ key: "s", cmd: true }, { key: "s", cmd: true, shift: false }); // true
|
|
109
|
+
*/
|
|
110
|
+
export declare const sameCombo: (a: KeyCombo, b: KeyCombo) => boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Keep a valid key combination from an untrusted value (e.g. stored or imported). Undefined if it isn't one.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* sanitiseCombo({ key: "s", cmd: true, extra: 1 }); // { key: "s", cmd: true }
|
|
116
|
+
* sanitiseCombo({ key: "" }); // undefined
|
|
117
|
+
*/
|
|
118
|
+
export declare const sanitiseCombo: (input: unknown) => KeyCombo | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* The default key combination of each configurable action.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* defaultShortcutBindings()["tool-brush"]; // { key: "b" }
|
|
124
|
+
*/
|
|
125
|
+
export declare const defaultShortcutBindings: () => ShortcutBindings;
|
|
126
|
+
/**
|
|
127
|
+
* The fixed action that uses a key combination, if any.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* fixedShortcutFor({ key: "z", cmd: true })?.id; // "undo"
|
|
131
|
+
*/
|
|
132
|
+
export declare const fixedShortcutFor: (combo: KeyCombo) => ShortcutDefinition | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Keep valid key combinations from an untrusted value (e.g. stored or imported), using `defaults` for actions that are
|
|
135
|
+
* missing or invalid. `null` removes an action's key combination. A key combination a fixed action uses, or that an
|
|
136
|
+
* earlier action (in `SHORTCUT_DEFINITIONS` order) already has, is removed. Unknown actions are left out.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* sanitiseShortcutBindings({ "tool-brush": { key: "p" }, cut: null }, defaultShortcutBindings());
|
|
140
|
+
*/
|
|
141
|
+
export declare const sanitiseShortcutBindings: (input: unknown, defaults: ShortcutBindings) => ShortcutBindings;
|
|
142
|
+
/**
|
|
143
|
+
* The shortcuts to match key presses against: the configurable actions' key combinations (except the hold-to-pan key,
|
|
144
|
+
* which acts while held) and the fixed ones.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* shortcutsFor(defaultShortcutBindings()).find((s) => s.key === "b")?.action; // { type: "tool", tool: Tool.Brush }
|
|
148
|
+
*/
|
|
149
|
+
export declare const shortcutsFor: (bindings: ShortcutBindings) => Shortcut[];
|
|
150
|
+
/** All keyboard shortcuts with their default key combinations */
|
|
47
151
|
export declare const SHORTCUTS: readonly Shortcut[];
|
|
48
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* Whether a platform (`navigator.platform` by default) is an Apple device, where "cmd" is the Command key.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* isApplePlatform("MacIntel"); // true
|
|
157
|
+
* isApplePlatform("Win32"); // false
|
|
158
|
+
*/
|
|
159
|
+
export declare const isApplePlatform: (platform?: string) => boolean;
|
|
49
160
|
/**
|
|
50
161
|
* The symbol for the "cmd" key in shortcut labels: ⌘ on Apple devices, ^ (Control) elsewhere.
|
|
51
162
|
*
|
|
@@ -54,17 +165,69 @@ export declare const SHORTCUTS: readonly Shortcut[];
|
|
|
54
165
|
* cmdSymbol("Win32"); // "^"
|
|
55
166
|
*/
|
|
56
167
|
export declare const cmdSymbol: (platform?: string) => string;
|
|
57
|
-
export declare const HOLD_TO_PAN_KEY = " ";
|
|
58
|
-
/** The parts of a keyboard event used to match shortcuts */
|
|
59
|
-
export type KeyEventLike = Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey" | "shiftKey" | "altKey">;
|
|
60
168
|
/**
|
|
61
|
-
*
|
|
169
|
+
* A short label for a key combination, e.g. for menus: modifier symbols (^ Control, ⌥ Alt, ⇧ Shift, then ⌘ for "cmd" on
|
|
170
|
+
* Apple devices or ^ elsewhere), then the key as a symbol or in uppercase.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* shortcutLabel({ key: "z", cmd: true, shift: true }, "MacIntel"); // "⇧⌘Z"
|
|
174
|
+
* shortcutLabel({ key: "backspace", alt: true }, "Win32"); // "⌥⌫"
|
|
175
|
+
*/
|
|
176
|
+
export declare const shortcutLabel: (combo: KeyCombo, platform?: string) => string;
|
|
177
|
+
/**
|
|
178
|
+
* A key combination as an `aria-keyshortcuts` value, so screen readers can announce it.
|
|
62
179
|
*
|
|
63
180
|
* @example
|
|
64
|
-
*
|
|
181
|
+
* ariaKeyShortcut({ key: "s", cmd: true }, "MacIntel"); // "Meta+S"
|
|
182
|
+
* ariaKeyShortcut({ key: "backspace", alt: true }, "Win32"); // "Alt+Backspace"
|
|
183
|
+
*/
|
|
184
|
+
export declare const ariaKeyShortcut: (combo: KeyCombo, platform?: string) => string;
|
|
185
|
+
/** The parts of a keyboard event used to read key combinations */
|
|
186
|
+
export type KeyEventLike = Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey" | "shiftKey" | "altKey"> & Partial<Pick<KeyboardEvent, "code" | "isComposing" | "getModifierState">>;
|
|
187
|
+
/**
|
|
188
|
+
* The key combination of a key press, matching keyboards with different layouts:
|
|
189
|
+
* - Keys are matched by the character they type, so letters follow the key's label (e.g. `a` on a French keyboard).
|
|
190
|
+
* - Digits and symbols ignore Shift and AltGr/Option, which are often needed to type them (e.g. `<` and `[` on a
|
|
191
|
+
* German keyboard).
|
|
192
|
+
* - When a key types a character that isn't basic Latin (another alphabet, or Option on macOS), or is a dead key, the
|
|
193
|
+
* physical key is used instead (e.g. `a` for `ф`, and `alt g` for Option+G typing `©`).
|
|
194
|
+
* - `=` counts as `+`, so `cmd +` works with or without Shift.
|
|
195
|
+
*
|
|
196
|
+
* `cmd` is Command on Apple devices and Ctrl elsewhere; `ctrl` is Control on Apple devices. Undefined while composing
|
|
197
|
+
* text (e.g. with an input method), for modifier keys alone, and for the Windows key elsewhere.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* comboFromEvent({ key: "Z", metaKey: true, ctrlKey: false, shiftKey: true, altKey: false }, "MacIntel");
|
|
201
|
+
* // { key: "z", cmd: true, shift: true }
|
|
202
|
+
*/
|
|
203
|
+
export declare const comboFromEvent: (event: KeyEventLike, platform?: string) => KeyCombo | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Find the action for a key press (see `comboFromEvent`). Modifier keys must match exactly.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* matchShortcut({ key: "Z", metaKey: true, ctrlKey: false, shiftKey: true, altKey: false }, SHORTCUTS, "MacIntel");
|
|
65
209
|
* // { type: "redo" }
|
|
66
210
|
*/
|
|
67
|
-
export declare const matchShortcut: (event: KeyEventLike, shortcuts?: readonly Shortcut[]) => ShortcutAction | undefined;
|
|
211
|
+
export declare const matchShortcut: (event: KeyEventLike, shortcuts?: readonly Shortcut[], platform?: string) => ShortcutAction | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* The modifier keys held during a key press, as a key combination without a key (e.g. to show them while recording a
|
|
214
|
+
* key combination). Read like `comboFromEvent`: `cmd` is Command on Apple devices and Ctrl elsewhere.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* heldModifiers({ key: "Shift", metaKey: true, ctrlKey: false, shiftKey: true, altKey: false }, "MacIntel");
|
|
218
|
+
* // { key: "", cmd: true, shift: true }
|
|
219
|
+
*/
|
|
220
|
+
export declare const heldModifiers: (event: KeyEventLike, platform?: string) => KeyCombo;
|
|
221
|
+
/**
|
|
222
|
+
* A key combination as words, e.g. for a text field: modifiers in the order shift, alt, cmd, ctrl, then the key
|
|
223
|
+
* (Space as `space`). "cmd" is written `ctrl` except on Apple devices.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* comboText({ key: "g", shift: true, alt: true, cmd: true, ctrl: true }, "MacIntel"); // "shift alt cmd ctrl g"
|
|
227
|
+
* comboText({ key: "s", cmd: true }, "Win32"); // "ctrl s"
|
|
228
|
+
* comboText({ key: "", shift: true }, "MacIntel"); // "shift" (modifiers only)
|
|
229
|
+
*/
|
|
230
|
+
export declare const comboText: (combo: KeyCombo, platform?: string) => string;
|
|
68
231
|
/**
|
|
69
232
|
* Check if a key press happened while typing in a text field, where shortcuts must not apply.
|
|
70
233
|
*
|