js-draw 0.1.9 → 0.1.10
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/CHANGELOG.md +6 -0
- package/README.md +15 -3
- package/dist/bundle.js +1 -1
- package/dist/src/Editor.d.ts +1 -0
- package/dist/src/Editor.js +28 -15
- package/dist/src/UndoRedoHistory.js +3 -0
- package/dist/src/bundle/bundled.d.ts +2 -1
- package/dist/src/bundle/bundled.js +2 -1
- package/dist/src/geometry/LineSegment2.d.ts +1 -0
- package/dist/src/geometry/LineSegment2.js +16 -0
- package/dist/src/geometry/Rect2.d.ts +1 -0
- package/dist/src/geometry/Rect2.js +16 -0
- package/dist/src/localizations/en.d.ts +3 -0
- package/dist/src/localizations/en.js +4 -0
- package/dist/src/localizations/es.d.ts +3 -0
- package/dist/src/localizations/es.js +18 -0
- package/dist/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/src/localizations/getLocalizationTable.js +43 -0
- package/dist/src/toolbar/HTMLToolbar.js +5 -7
- package/dist/src/toolbar/icons.js +13 -13
- package/dist/src/toolbar/localization.d.ts +1 -0
- package/dist/src/toolbar/localization.js +1 -0
- package/dist/src/toolbar/widgets/BaseWidget.js +29 -0
- package/dist/src/tools/BaseTool.d.ts +2 -1
- package/dist/src/tools/BaseTool.js +3 -0
- package/dist/src/tools/PanZoom.d.ts +2 -1
- package/dist/src/tools/PanZoom.js +4 -0
- package/dist/src/tools/SelectionTool.d.ts +9 -2
- package/dist/src/tools/SelectionTool.js +131 -19
- package/dist/src/tools/ToolController.js +6 -2
- package/dist/src/tools/localization.d.ts +1 -0
- package/dist/src/tools/localization.js +1 -0
- package/dist/src/types.d.ts +8 -2
- package/dist/src/types.js +1 -0
- package/package.json +9 -1
- package/src/Editor.ts +31 -14
- package/src/UndoRedoHistory.ts +4 -0
- package/src/bundle/bundled.ts +2 -1
- package/src/geometry/LineSegment2.test.ts +15 -0
- package/src/geometry/LineSegment2.ts +20 -0
- package/src/geometry/Rect2.test.ts +20 -7
- package/src/geometry/Rect2.ts +19 -1
- package/src/localizations/en.ts +8 -0
- package/src/localizations/es.ts +60 -0
- package/src/localizations/getLocalizationTable.test.ts +27 -0
- package/src/localizations/getLocalizationTable.ts +53 -0
- package/src/toolbar/HTMLToolbar.ts +5 -8
- package/src/toolbar/icons.ts +13 -13
- package/src/toolbar/localization.ts +2 -0
- package/src/toolbar/toolbar.css +5 -0
- package/src/toolbar/widgets/BaseWidget.ts +34 -0
- package/src/tools/BaseTool.ts +5 -1
- package/src/tools/PanZoom.ts +6 -0
- package/src/tools/SelectionTool.test.ts +24 -1
- package/src/tools/SelectionTool.ts +158 -23
- package/src/tools/ToolController.ts +6 -2
- package/src/tools/localization.ts +2 -0
- package/src/types.ts +9 -1
- package/dist-test/test-dist-bundle.html +0 -42
package/dist/src/Editor.d.ts
CHANGED
@@ -37,6 +37,7 @@ export declare class Editor {
|
|
37
37
|
announceForAccessibility(message: string): void;
|
38
38
|
addToolbar(defaultLayout?: boolean): HTMLToolbar;
|
39
39
|
private registerListeners;
|
40
|
+
handleKeyEventsFrom(elem: HTMLElement): void;
|
40
41
|
dispatch(command: Command, addToHistory?: boolean): void;
|
41
42
|
dispatchNoAnnounce(command: Command, addToHistory?: boolean): void;
|
42
43
|
private asyncApplyOrUnapplyCommands;
|
package/dist/src/Editor.js
CHANGED
@@ -23,11 +23,10 @@ import Color4 from './Color4';
|
|
23
23
|
import SVGLoader from './SVGLoader';
|
24
24
|
import Pointer from './Pointer';
|
25
25
|
import Mat33 from './geometry/Mat33';
|
26
|
-
import
|
26
|
+
import getLocalizationTable from './localizations/getLocalizationTable';
|
27
27
|
export class Editor {
|
28
28
|
constructor(parent, settings = {}) {
|
29
29
|
var _a, _b;
|
30
|
-
this.localization = defaultEditorLocalization;
|
31
30
|
this.announceUndoCallback = (command) => {
|
32
31
|
this.announceForAccessibility(this.localization.undoAnnouncement(command.description(this.localization)));
|
33
32
|
};
|
@@ -35,7 +34,7 @@ export class Editor {
|
|
35
34
|
this.announceForAccessibility(this.localization.redoAnnouncement(command.description(this.localization)));
|
36
35
|
};
|
37
36
|
this.rerenderQueued = false;
|
38
|
-
this.localization = Object.assign(Object.assign({},
|
37
|
+
this.localization = Object.assign(Object.assign({}, getLocalizationTable()), settings.localization);
|
39
38
|
// Fill default settings.
|
40
39
|
this.settings = {
|
41
40
|
wheelEventsEnabled: (_a = settings.wheelEventsEnabled) !== null && _a !== void 0 ? _a : true,
|
@@ -176,18 +175,7 @@ export class Editor {
|
|
176
175
|
this.renderingRegion.addEventListener('pointercancel', evt => {
|
177
176
|
pointerEnd(evt);
|
178
177
|
});
|
179
|
-
this.renderingRegion
|
180
|
-
if (this.toolController.dispatchInputEvent({
|
181
|
-
kind: InputEvtType.KeyPressEvent,
|
182
|
-
key: evt.key,
|
183
|
-
ctrlKey: evt.ctrlKey,
|
184
|
-
})) {
|
185
|
-
evt.preventDefault();
|
186
|
-
}
|
187
|
-
else if (evt.key === 'Escape') {
|
188
|
-
this.renderingRegion.blur();
|
189
|
-
}
|
190
|
-
});
|
178
|
+
this.handleKeyEventsFrom(this.renderingRegion);
|
191
179
|
this.container.addEventListener('wheel', evt => {
|
192
180
|
let delta = Vec3.of(evt.deltaX, evt.deltaY, evt.deltaZ);
|
193
181
|
// Process wheel events if the ctrl key is down, even if disabled -- we do want to handle
|
@@ -234,6 +222,31 @@ export class Editor {
|
|
234
222
|
this.queueRerender();
|
235
223
|
});
|
236
224
|
}
|
225
|
+
// Adds event listners for keypresses to [elem] and forwards those events to the
|
226
|
+
// editor.
|
227
|
+
handleKeyEventsFrom(elem) {
|
228
|
+
elem.addEventListener('keydown', evt => {
|
229
|
+
if (this.toolController.dispatchInputEvent({
|
230
|
+
kind: InputEvtType.KeyPressEvent,
|
231
|
+
key: evt.key,
|
232
|
+
ctrlKey: evt.ctrlKey,
|
233
|
+
})) {
|
234
|
+
evt.preventDefault();
|
235
|
+
}
|
236
|
+
else if (evt.key === 'Escape') {
|
237
|
+
this.renderingRegion.blur();
|
238
|
+
}
|
239
|
+
});
|
240
|
+
elem.addEventListener('keyup', evt => {
|
241
|
+
if (this.toolController.dispatchInputEvent({
|
242
|
+
kind: InputEvtType.KeyUpEvent,
|
243
|
+
key: evt.key,
|
244
|
+
ctrlKey: evt.ctrlKey,
|
245
|
+
})) {
|
246
|
+
evt.preventDefault();
|
247
|
+
}
|
248
|
+
});
|
249
|
+
}
|
237
250
|
// Adds to history by default
|
238
251
|
dispatch(command, addToHistory = true) {
|
239
252
|
if (addToHistory) {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
// Main entrypoint for Webpack when building a bundle for release.
|
2
2
|
import '../styles';
|
3
3
|
import Editor from '../Editor';
|
4
|
+
import getLocalizationTable from '../localizations/getLocalizationTable';
|
4
5
|
export default Editor;
|
5
|
-
export { Editor };
|
6
|
+
export { Editor, getLocalizationTable };
|
@@ -97,4 +97,20 @@ export default class LineSegment2 {
|
|
97
97
|
t: resultT,
|
98
98
|
};
|
99
99
|
}
|
100
|
+
// Returns the closest point on this to [target]
|
101
|
+
closestPointTo(target) {
|
102
|
+
// Distance from P1 along this' direction.
|
103
|
+
const projectedDistFromP1 = target.minus(this.p1).dot(this.direction);
|
104
|
+
const projectedDistFromP2 = this.length - projectedDistFromP1;
|
105
|
+
const projection = this.p1.plus(this.direction.times(projectedDistFromP1));
|
106
|
+
if (projectedDistFromP1 > 0 && projectedDistFromP1 < this.length) {
|
107
|
+
return projection;
|
108
|
+
}
|
109
|
+
if (Math.abs(projectedDistFromP2) < Math.abs(projectedDistFromP1)) {
|
110
|
+
return this.p2;
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
return this.p1;
|
114
|
+
}
|
115
|
+
}
|
100
116
|
}
|
@@ -30,6 +30,7 @@ export default class Rect2 {
|
|
30
30
|
divideIntoGrid(columns: number, rows: number): Rect2[];
|
31
31
|
grownToPoint(point: Point2, margin?: number): Rect2;
|
32
32
|
grownBy(margin: number): Rect2;
|
33
|
+
getClosestPointOnBoundaryTo(target: Point2): import("./Vec3").default;
|
33
34
|
get corners(): Point2[];
|
34
35
|
get maxDimension(): number;
|
35
36
|
get topRight(): import("./Vec3").default;
|
@@ -25,6 +25,7 @@ export default class Rect2 {
|
|
25
25
|
translatedBy(vec) {
|
26
26
|
return new Rect2(vec.x + this.x, vec.y + this.y, this.w, this.h);
|
27
27
|
}
|
28
|
+
// Returns a copy of this with the given size (but same top-left).
|
28
29
|
resizedTo(size) {
|
29
30
|
return new Rect2(this.x, this.y, size.x, size.y);
|
30
31
|
}
|
@@ -109,6 +110,21 @@ export default class Rect2 {
|
|
109
110
|
grownBy(margin) {
|
110
111
|
return new Rect2(this.x - margin, this.y - margin, this.w + margin * 2, this.h + margin * 2);
|
111
112
|
}
|
113
|
+
getClosestPointOnBoundaryTo(target) {
|
114
|
+
const closestEdgePoints = this.getEdges().map(edge => {
|
115
|
+
return edge.closestPointTo(target);
|
116
|
+
});
|
117
|
+
let closest = null;
|
118
|
+
let closestDist = null;
|
119
|
+
for (const point of closestEdgePoints) {
|
120
|
+
const dist = point.minus(target).length();
|
121
|
+
if (closestDist === null || dist < closestDist) {
|
122
|
+
closest = point;
|
123
|
+
closestDist = dist;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
return closest;
|
127
|
+
}
|
112
128
|
get corners() {
|
113
129
|
return [
|
114
130
|
this.bottomRight,
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { defaultEditorLocalization } from '../localization';
|
2
|
+
// A partial Spanish localization.
|
3
|
+
const localization = Object.assign(Object.assign({}, defaultEditorLocalization), {
|
4
|
+
// Strings for the main editor interface
|
5
|
+
// (see src/localization.ts)
|
6
|
+
loading: (percentage) => `Cargando: ${percentage}%...`, imageEditor: 'Editor de dibujos', undoAnnouncement: (commandDescription) => `${commandDescription} fue deshecho`, redoAnnouncement: (commandDescription) => `${commandDescription} fue rehecho`, undo: 'Deshace', redo: 'Rehace',
|
7
|
+
// Strings for the toolbar
|
8
|
+
// (see src/toolbar/localization.ts)
|
9
|
+
pen: 'Lapiz', eraser: 'Borrador', select: 'Selecciona', thicknessLabel: 'Tamaño: ', colorLabel: 'Color: ', doneLoading: 'El cargado terminó', fontLabel: 'Fuente: ', anyDevicePanning: 'Mover la pantalla con todo dispotivo', touchPanning: 'Mover la pantalla con un dedo', touchPanTool: 'Instrumento de mover la pantalla con un dedo', outlinedRectanglePen: 'Rectángulo con nada más que un borde', filledRectanglePen: 'Rectángulo sin borde', linePen: 'Línea', arrowPen: 'Flecha', freehandPen: 'Dibuja sin restricción de forma', selectObjectType: 'Forma de dibuja:', handTool: 'Mover', resizeImageToSelection: 'Redimensionar la imagen a lo que está seleccionado', deleteSelection: 'Borra la selección', duplicateSelection: 'Duplica la selección', pickColorFronScreen: 'Selecciona un color de la pantalla', dropdownShown(toolName) {
|
10
|
+
return `Menú por ${toolName} es visible`;
|
11
|
+
}, dropdownHidden: function (toolName) {
|
12
|
+
return `Menú por ${toolName} fue ocultado`;
|
13
|
+
}, colorChangedAnnouncement: function (color) {
|
14
|
+
return `Color fue cambiado a ${color}`;
|
15
|
+
}, keyboardPanZoom: 'Mover la pantalla con el teclado', penTool: function (penId) {
|
16
|
+
return `Lapiz ${penId}`;
|
17
|
+
}, selectionTool: 'Selecciona', eraserTool: 'Borrador', textTool: 'Texto', enterTextToInsert: 'Entra texto', rerenderAsText: 'Redibuja la pantalla al texto' });
|
18
|
+
export default localization;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { defaultEditorLocalization } from '../localization';
|
2
|
+
import en from './en';
|
3
|
+
import es from './es';
|
4
|
+
const allLocales = {
|
5
|
+
en,
|
6
|
+
es,
|
7
|
+
};
|
8
|
+
// [locale]: A string in the format languageCode_Region or just languageCode. For example, en_US.
|
9
|
+
const languageFromLocale = (locale) => {
|
10
|
+
const matches = /^(\w+)[_-](\w+)$/.exec(locale);
|
11
|
+
if (!matches) {
|
12
|
+
// If not in languageCode_region format, the locale should be the
|
13
|
+
// languageCode. Return that.
|
14
|
+
return locale;
|
15
|
+
}
|
16
|
+
return matches[1];
|
17
|
+
};
|
18
|
+
const getLocalizationTable = (userLocales) => {
|
19
|
+
userLocales !== null && userLocales !== void 0 ? userLocales : (userLocales = navigator.languages);
|
20
|
+
let prevLanguage;
|
21
|
+
for (const locale of userLocales) {
|
22
|
+
const language = languageFromLocale(locale);
|
23
|
+
// If the specific localization of the language is not available, but
|
24
|
+
// a localization for the language is,
|
25
|
+
if (prevLanguage && language !== prevLanguage) {
|
26
|
+
if (prevLanguage in allLocales) {
|
27
|
+
return allLocales[prevLanguage];
|
28
|
+
}
|
29
|
+
}
|
30
|
+
// If the full locale (e.g. en_US) is available,
|
31
|
+
if (locale in allLocales) {
|
32
|
+
return allLocales[locale];
|
33
|
+
}
|
34
|
+
prevLanguage = language;
|
35
|
+
}
|
36
|
+
if (prevLanguage && prevLanguage in allLocales) {
|
37
|
+
return allLocales[prevLanguage];
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
return defaultEditorLocalization;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
export default getLocalizationTable;
|
@@ -108,13 +108,13 @@ export default class HTMLToolbar {
|
|
108
108
|
const undoRedoGroup = document.createElement('div');
|
109
109
|
undoRedoGroup.classList.add(`${toolbarCSSPrefix}buttonGroup`);
|
110
110
|
const undoButton = this.addActionButton({
|
111
|
-
label:
|
111
|
+
label: this.localizationTable.undo,
|
112
112
|
icon: makeUndoIcon()
|
113
113
|
}, () => {
|
114
114
|
this.editor.history.undo();
|
115
115
|
}, undoRedoGroup);
|
116
116
|
const redoButton = this.addActionButton({
|
117
|
-
label:
|
117
|
+
label: this.localizationTable.redo,
|
118
118
|
icon: makeRedoIcon(),
|
119
119
|
}, () => {
|
120
120
|
this.editor.history.redo();
|
@@ -157,11 +157,9 @@ export default class HTMLToolbar {
|
|
157
157
|
}
|
158
158
|
(new TextToolWidget(this.editor, tool, this.localizationTable)).addTo(this.container);
|
159
159
|
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
}
|
164
|
-
(new HandToolWidget(this.editor, tool, this.localizationTable)).addTo(this.container);
|
160
|
+
const panZoomTool = toolController.getMatchingTools(ToolType.PanZoom)[0];
|
161
|
+
if (panZoomTool && panZoomTool instanceof PanZoom) {
|
162
|
+
(new HandToolWidget(this.editor, panZoomTool, this.localizationTable)).addTo(this.container);
|
165
163
|
}
|
166
164
|
this.setupColorPickers();
|
167
165
|
}
|
@@ -3,11 +3,11 @@ import { Vec2 } from '../geometry/Vec2';
|
|
3
3
|
import SVGRenderer from '../rendering/renderers/SVGRenderer';
|
4
4
|
import Viewport from '../Viewport';
|
5
5
|
const svgNamespace = 'http://www.w3.org/2000/svg';
|
6
|
-
const
|
7
|
-
style='fill: var(--
|
6
|
+
const iconColorFill = `
|
7
|
+
style='fill: var(--icon-color);'
|
8
8
|
`;
|
9
|
-
const
|
10
|
-
style='fill: var(--
|
9
|
+
const iconColorStrokeFill = `
|
10
|
+
style='fill: var(--icon-color); stroke: var(--icon-color);'
|
11
11
|
`;
|
12
12
|
const checkerboardPatternDef = `
|
13
13
|
<pattern
|
@@ -31,7 +31,7 @@ export const makeRedoIcon = (mirror = false) => {
|
|
31
31
|
icon.innerHTML = `
|
32
32
|
<style>
|
33
33
|
.toolbar-svg-undo-redo-icon {
|
34
|
-
stroke: var(--
|
34
|
+
stroke: var(--icon-color);
|
35
35
|
stroke-width: 12;
|
36
36
|
stroke-linejoin: round;
|
37
37
|
stroke-linecap: round;
|
@@ -54,7 +54,7 @@ export const makeDropdownIcon = () => {
|
|
54
54
|
<g>
|
55
55
|
<path
|
56
56
|
d='M5,10 L50,90 L95,10 Z'
|
57
|
-
${
|
57
|
+
${iconColorFill}
|
58
58
|
/>
|
59
59
|
</g>
|
60
60
|
`;
|
@@ -69,7 +69,7 @@ export const makeEraserIcon = () => {
|
|
69
69
|
<rect x=10 y=50 width=80 height=30 rx=10 fill='pink' />
|
70
70
|
<rect
|
71
71
|
x=10 y=10 width=80 height=50
|
72
|
-
${
|
72
|
+
${iconColorFill}
|
73
73
|
/>
|
74
74
|
</g>
|
75
75
|
`;
|
@@ -116,7 +116,7 @@ export const makeHandToolIcon = () => {
|
|
116
116
|
|
117
117
|
fill='none'
|
118
118
|
style='
|
119
|
-
stroke: var(--
|
119
|
+
stroke: var(--icon-color);
|
120
120
|
stroke-width: 2;
|
121
121
|
'
|
122
122
|
/>
|
@@ -158,7 +158,7 @@ export const makeTouchPanningIcon = () => {
|
|
158
158
|
'
|
159
159
|
fill='none'
|
160
160
|
style='
|
161
|
-
stroke: var(--
|
161
|
+
stroke: var(--icon-color);
|
162
162
|
stroke-width: 2;
|
163
163
|
'
|
164
164
|
/>
|
@@ -222,7 +222,7 @@ export const makeAllDevicePanningIcon = () => {
|
|
222
222
|
'
|
223
223
|
fill='none'
|
224
224
|
style='
|
225
|
-
stroke: var(--
|
225
|
+
stroke: var(--icon-color);
|
226
226
|
stroke-width: 2;
|
227
227
|
'
|
228
228
|
/>
|
@@ -241,7 +241,7 @@ export const makeZoomIcon = () => {
|
|
241
241
|
textNode.style.textAlign = 'center';
|
242
242
|
textNode.style.textAnchor = 'middle';
|
243
243
|
textNode.style.fontSize = '55px';
|
244
|
-
textNode.style.fill = 'var(--
|
244
|
+
textNode.style.fill = 'var(--icon-color)';
|
245
245
|
textNode.style.fontFamily = 'monospace';
|
246
246
|
icon.appendChild(textNode);
|
247
247
|
};
|
@@ -282,7 +282,7 @@ export const makePenIcon = (tipThickness, color) => {
|
|
282
282
|
<!-- Pen grip -->
|
283
283
|
<path
|
284
284
|
d='M10,10 L90,10 L90,60 L${50 + halfThickness},80 L${50 - halfThickness},80 L10,60 Z'
|
285
|
-
${
|
285
|
+
${iconColorStrokeFill}
|
286
286
|
/>
|
287
287
|
</g>
|
288
288
|
<g>
|
@@ -348,7 +348,7 @@ export const makePipetteIcon = (color) => {
|
|
348
348
|
65,15 65,5 47,6
|
349
349
|
Z
|
350
350
|
`);
|
351
|
-
pipette.style.fill = 'var(--
|
351
|
+
pipette.style.fill = 'var(--icon-color)';
|
352
352
|
if (color) {
|
353
353
|
const defs = document.createElementNS(svgNamespace, 'defs');
|
354
354
|
defs.innerHTML = checkerboardPatternDef;
|
@@ -21,6 +21,7 @@ export interface ToolbarLocalization {
|
|
21
21
|
undo: string;
|
22
22
|
redo: string;
|
23
23
|
zoom: string;
|
24
|
+
selectionToolKeyboardShortcuts: string;
|
24
25
|
dropdownShown: (toolName: string) => string;
|
25
26
|
dropdownHidden: (toolName: string) => string;
|
26
27
|
zoomLevel: (zoomPercentage: number) => string;
|
@@ -14,6 +14,7 @@ export const defaultToolbarLocalization = {
|
|
14
14
|
redo: 'Redo',
|
15
15
|
selectObjectType: 'Object type: ',
|
16
16
|
pickColorFronScreen: 'Pick color from screen',
|
17
|
+
selectionToolKeyboardShortcuts: 'Selection tool: Use arrow keys to move selected items, lowercase/uppercase ‘i’ and ‘o’ to resize.',
|
17
18
|
touchPanning: 'Touchscreen panning',
|
18
19
|
anyDevicePanning: 'Any device panning',
|
19
20
|
freehandPen: 'Freehand',
|
@@ -10,6 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
11
|
};
|
12
12
|
var _BaseWidget_hasDropdown;
|
13
|
+
import { InputEvtType } from '../../types';
|
13
14
|
import { toolbarCSSPrefix } from '../HTMLToolbar';
|
14
15
|
import { makeDropdownIcon } from '../icons';
|
15
16
|
export default class BaseWidget {
|
@@ -44,6 +45,34 @@ export default class BaseWidget {
|
|
44
45
|
return true;
|
45
46
|
}
|
46
47
|
setupActionBtnClickListener(button) {
|
48
|
+
const clickTriggers = { enter: true, ' ': true, };
|
49
|
+
button.onkeydown = (evt) => {
|
50
|
+
let handled = false;
|
51
|
+
if (evt.key in clickTriggers) {
|
52
|
+
if (!this.disabled) {
|
53
|
+
this.handleClick();
|
54
|
+
handled = true;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
// If we didn't do anything with the event, send it to the editor.
|
58
|
+
if (!handled) {
|
59
|
+
this.editor.toolController.dispatchInputEvent({
|
60
|
+
kind: InputEvtType.KeyPressEvent,
|
61
|
+
key: evt.key,
|
62
|
+
ctrlKey: evt.ctrlKey,
|
63
|
+
});
|
64
|
+
}
|
65
|
+
};
|
66
|
+
button.onkeyup = evt => {
|
67
|
+
if (evt.key in clickTriggers) {
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
this.editor.toolController.dispatchInputEvent({
|
71
|
+
kind: InputEvtType.KeyUpEvent,
|
72
|
+
key: evt.key,
|
73
|
+
ctrlKey: evt.ctrlKey,
|
74
|
+
});
|
75
|
+
};
|
47
76
|
button.onclick = () => {
|
48
77
|
if (!this.disabled) {
|
49
78
|
this.handleClick();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PointerEvtListener, WheelEvt, PointerEvt, EditorNotifier, KeyPressEvent } from '../types';
|
1
|
+
import { PointerEvtListener, WheelEvt, PointerEvt, EditorNotifier, KeyPressEvent, KeyUpEvent } from '../types';
|
2
2
|
import { ToolType } from './ToolController';
|
3
3
|
import ToolEnabledGroup from './ToolEnabledGroup';
|
4
4
|
export default abstract class BaseTool implements PointerEvtListener {
|
@@ -14,6 +14,7 @@ export default abstract class BaseTool implements PointerEvtListener {
|
|
14
14
|
protected constructor(notifier: EditorNotifier, description: string);
|
15
15
|
onWheel(_event: WheelEvt): boolean;
|
16
16
|
onKeyPress(_event: KeyPressEvent): boolean;
|
17
|
+
onKeyUp(_event: KeyUpEvent): boolean;
|
17
18
|
setEnabled(enabled: boolean): void;
|
18
19
|
isEnabled(): boolean;
|
19
20
|
setToolGroup(group: ToolEnabledGroup): void;
|
@@ -14,7 +14,8 @@ export declare enum PanZoomMode {
|
|
14
14
|
OneFingerTouchGestures = 1,
|
15
15
|
TwoFingerTouchGestures = 2,
|
16
16
|
RightClickDrags = 4,
|
17
|
-
SinglePointerGestures = 8
|
17
|
+
SinglePointerGestures = 8,
|
18
|
+
Keyboard = 16
|
18
19
|
}
|
19
20
|
export default class PanZoom extends BaseTool {
|
20
21
|
private editor;
|
@@ -12,6 +12,7 @@ export var PanZoomMode;
|
|
12
12
|
PanZoomMode[PanZoomMode["TwoFingerTouchGestures"] = 2] = "TwoFingerTouchGestures";
|
13
13
|
PanZoomMode[PanZoomMode["RightClickDrags"] = 4] = "RightClickDrags";
|
14
14
|
PanZoomMode[PanZoomMode["SinglePointerGestures"] = 8] = "SinglePointerGestures";
|
15
|
+
PanZoomMode[PanZoomMode["Keyboard"] = 16] = "Keyboard";
|
15
16
|
})(PanZoomMode || (PanZoomMode = {}));
|
16
17
|
export default class PanZoom extends BaseTool {
|
17
18
|
constructor(editor, mode, description) {
|
@@ -133,6 +134,9 @@ export default class PanZoom extends BaseTool {
|
|
133
134
|
return true;
|
134
135
|
}
|
135
136
|
onKeyPress({ key }) {
|
137
|
+
if (!(this.mode & PanZoomMode.Keyboard)) {
|
138
|
+
return false;
|
139
|
+
}
|
136
140
|
let translation = Vec2.zero;
|
137
141
|
let scale = 1;
|
138
142
|
let rotation = 0;
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import Command from '../commands/Command';
|
2
2
|
import Editor from '../Editor';
|
3
|
+
import Mat33 from '../geometry/Mat33';
|
3
4
|
import Rect2 from '../geometry/Rect2';
|
4
5
|
import { Point2, Vec2 } from '../geometry/Vec2';
|
5
|
-
import { PointerEvt } from '../types';
|
6
|
+
import { KeyPressEvent, KeyUpEvent, PointerEvt } from '../types';
|
6
7
|
import BaseTool from './BaseTool';
|
7
8
|
import { ToolType } from './ToolController';
|
8
9
|
declare class Selection {
|
@@ -20,7 +21,8 @@ declare class Selection {
|
|
20
21
|
handleResizeCornerDrag(deltaPosition: Vec2): void;
|
21
22
|
handleRotateCircleDrag(offset: Vec2): void;
|
22
23
|
private computeTransformCommands;
|
23
|
-
|
24
|
+
transformPreview(transform: Mat33): void;
|
25
|
+
finalizeTransform(): void;
|
24
26
|
private static ApplyTransformationCommand;
|
25
27
|
private previewTransformCmds;
|
26
28
|
appendBackgroundBoxTo(elem: HTMLElement): void;
|
@@ -32,6 +34,7 @@ declare class Selection {
|
|
32
34
|
private recomputeBoxRotation;
|
33
35
|
getSelectedItemCount(): number;
|
34
36
|
updateUI(): void;
|
37
|
+
scrollTo(): void;
|
35
38
|
deleteSelectedObjects(): Command;
|
36
39
|
duplicateSelectedObjects(): Command;
|
37
40
|
}
|
@@ -45,8 +48,12 @@ export default class SelectionTool extends BaseTool {
|
|
45
48
|
onPointerDown(event: PointerEvt): boolean;
|
46
49
|
onPointerMove(event: PointerEvt): void;
|
47
50
|
private onGestureEnd;
|
51
|
+
private zoomToSelection;
|
48
52
|
onPointerUp(event: PointerEvt): void;
|
49
53
|
onGestureCancel(): void;
|
54
|
+
private static handleableKeys;
|
55
|
+
onKeyPress(event: KeyPressEvent): boolean;
|
56
|
+
onKeyUp(evt: KeyUpEvent): boolean;
|
50
57
|
setEnabled(enabled: boolean): void;
|
51
58
|
getSelection(): Selection | null;
|
52
59
|
clearSelection(): void;
|