js-draw 0.0.10 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Editor.d.ts +2 -2
- package/dist/src/Editor.js +17 -7
- package/dist/src/EditorImage.d.ts +15 -7
- package/dist/src/EditorImage.js +46 -37
- package/dist/src/Pointer.d.ts +3 -2
- package/dist/src/Pointer.js +12 -3
- package/dist/src/SVGLoader.d.ts +6 -2
- package/dist/src/SVGLoader.js +20 -8
- package/dist/src/Viewport.d.ts +4 -0
- package/dist/src/Viewport.js +51 -0
- package/dist/src/components/AbstractComponent.d.ts +9 -2
- package/dist/src/components/AbstractComponent.js +14 -0
- package/dist/src/components/SVGGlobalAttributesObject.d.ts +1 -1
- package/dist/src/components/SVGGlobalAttributesObject.js +1 -1
- package/dist/src/components/Stroke.d.ts +1 -1
- package/dist/src/components/Stroke.js +1 -1
- package/dist/src/components/UnknownSVGObject.d.ts +1 -1
- package/dist/src/components/UnknownSVGObject.js +1 -1
- package/dist/src/components/builders/ArrowBuilder.d.ts +1 -1
- package/dist/src/components/builders/FreehandLineBuilder.d.ts +1 -1
- package/dist/src/components/builders/FreehandLineBuilder.js +1 -1
- package/dist/src/components/builders/LineBuilder.d.ts +1 -1
- package/dist/src/components/builders/RectangleBuilder.d.ts +1 -1
- package/dist/src/components/builders/types.d.ts +1 -1
- package/dist/src/geometry/Mat33.js +3 -0
- package/dist/src/geometry/Path.d.ts +1 -1
- package/dist/src/geometry/Path.js +102 -69
- package/dist/src/geometry/Rect2.d.ts +1 -0
- package/dist/src/geometry/Rect2.js +47 -9
- package/dist/src/{Display.d.ts → rendering/Display.d.ts} +5 -2
- package/dist/src/{Display.js → rendering/Display.js} +34 -4
- package/dist/src/rendering/caching/CacheRecord.d.ts +19 -0
- package/dist/src/rendering/caching/CacheRecord.js +52 -0
- package/dist/src/rendering/caching/CacheRecordManager.d.ts +11 -0
- package/dist/src/rendering/caching/CacheRecordManager.js +31 -0
- package/dist/src/rendering/caching/RenderingCache.d.ts +12 -0
- package/dist/src/rendering/caching/RenderingCache.js +42 -0
- package/dist/src/rendering/caching/RenderingCacheNode.d.ts +28 -0
- package/dist/src/rendering/caching/RenderingCacheNode.js +301 -0
- package/dist/src/rendering/caching/testUtils.d.ts +9 -0
- package/dist/src/rendering/caching/testUtils.js +20 -0
- package/dist/src/rendering/caching/types.d.ts +21 -0
- package/dist/src/rendering/caching/types.js +1 -0
- package/dist/src/rendering/{AbstractRenderer.d.ts → renderers/AbstractRenderer.d.ts} +20 -9
- package/dist/src/rendering/{AbstractRenderer.js → renderers/AbstractRenderer.js} +37 -3
- package/dist/src/rendering/{CanvasRenderer.d.ts → renderers/CanvasRenderer.d.ts} +10 -5
- package/dist/src/rendering/{CanvasRenderer.js → renderers/CanvasRenderer.js} +60 -20
- package/dist/src/rendering/{DummyRenderer.d.ts → renderers/DummyRenderer.d.ts} +9 -5
- package/dist/src/rendering/{DummyRenderer.js → renderers/DummyRenderer.js} +35 -4
- package/dist/src/rendering/{SVGRenderer.d.ts → renderers/SVGRenderer.d.ts} +7 -5
- package/dist/src/rendering/{SVGRenderer.js → renderers/SVGRenderer.js} +35 -18
- package/dist/src/testing/createEditor.js +1 -1
- package/dist/src/toolbar/HTMLToolbar.d.ts +2 -1
- package/dist/src/toolbar/HTMLToolbar.js +165 -154
- package/dist/src/toolbar/icons.d.ts +10 -0
- package/dist/src/toolbar/icons.js +180 -0
- package/dist/src/toolbar/localization.d.ts +4 -1
- package/dist/src/toolbar/localization.js +4 -1
- package/dist/src/toolbar/types.d.ts +4 -0
- package/dist/src/tools/PanZoom.d.ts +9 -6
- package/dist/src/tools/PanZoom.js +30 -21
- package/dist/src/tools/Pen.js +8 -3
- package/dist/src/tools/SelectionTool.js +9 -24
- package/dist/src/tools/ToolController.d.ts +5 -6
- package/dist/src/tools/ToolController.js +8 -10
- package/dist/src/tools/localization.d.ts +1 -0
- package/dist/src/tools/localization.js +1 -0
- package/dist/src/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/Editor.ts +19 -8
- package/src/EditorImage.test.ts +2 -2
- package/src/EditorImage.ts +58 -42
- package/src/Pointer.ts +13 -4
- package/src/SVGLoader.ts +36 -10
- package/src/Viewport.ts +68 -0
- package/src/components/AbstractComponent.ts +21 -2
- package/src/components/SVGGlobalAttributesObject.ts +2 -2
- package/src/components/Stroke.ts +2 -2
- package/src/components/UnknownSVGObject.ts +2 -2
- package/src/components/builders/ArrowBuilder.ts +1 -1
- package/src/components/builders/FreehandLineBuilder.ts +2 -2
- package/src/components/builders/LineBuilder.ts +1 -1
- package/src/components/builders/RectangleBuilder.ts +1 -1
- package/src/components/builders/types.ts +1 -1
- package/src/geometry/Mat33.ts +3 -0
- package/src/geometry/Path.fromString.test.ts +94 -4
- package/src/geometry/Path.toString.test.ts +12 -2
- package/src/geometry/Path.ts +107 -71
- package/src/geometry/Rect2.test.ts +47 -8
- package/src/geometry/Rect2.ts +57 -9
- package/src/{Display.ts → rendering/Display.ts} +39 -6
- package/src/rendering/caching/CacheRecord.test.ts +49 -0
- package/src/rendering/caching/CacheRecord.ts +73 -0
- package/src/rendering/caching/CacheRecordManager.ts +45 -0
- package/src/rendering/caching/RenderingCache.test.ts +44 -0
- package/src/rendering/caching/RenderingCache.ts +63 -0
- package/src/rendering/caching/RenderingCacheNode.ts +378 -0
- package/src/rendering/caching/testUtils.ts +35 -0
- package/src/rendering/caching/types.ts +39 -0
- package/src/rendering/{AbstractRenderer.ts → renderers/AbstractRenderer.ts} +57 -9
- package/src/rendering/{CanvasRenderer.ts → renderers/CanvasRenderer.ts} +74 -25
- package/src/rendering/renderers/DummyRenderer.test.ts +43 -0
- package/src/rendering/{DummyRenderer.ts → renderers/DummyRenderer.ts} +50 -7
- package/src/rendering/{SVGRenderer.ts → renderers/SVGRenderer.ts} +39 -23
- package/src/testing/createEditor.ts +1 -1
- package/src/toolbar/HTMLToolbar.ts +199 -170
- package/src/toolbar/icons.ts +203 -0
- package/src/toolbar/localization.ts +9 -2
- package/src/toolbar/toolbar.css +21 -8
- package/src/toolbar/types.ts +5 -0
- package/src/tools/PanZoom.ts +37 -27
- package/src/tools/Pen.ts +7 -3
- package/src/tools/SelectionTool.test.ts +1 -1
- package/src/tools/SelectionTool.ts +12 -33
- package/src/tools/ToolController.ts +3 -5
- package/src/tools/localization.ts +2 -0
- package/src/types.ts +10 -3
- package/tsconfig.json +1 -0
- package/dist/__mocks__/coloris.d.ts +0 -2
- package/dist/__mocks__/coloris.js +0 -5
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
export interface ToolbarLocalization {
|
4
|
+
anyDevicePanning: string;
|
5
|
+
touchPanning: string;
|
4
6
|
outlinedRectanglePen: string;
|
5
7
|
filledRectanglePen: string;
|
6
8
|
linePen: string;
|
@@ -11,7 +13,7 @@ export interface ToolbarLocalization {
|
|
11
13
|
pen: string;
|
12
14
|
eraser: string;
|
13
15
|
select: string;
|
14
|
-
|
16
|
+
handTool: string;
|
15
17
|
thicknessLabel: string;
|
16
18
|
resizeImageToSelection: string;
|
17
19
|
deleteSelection: string;
|
@@ -20,13 +22,14 @@ export interface ToolbarLocalization {
|
|
20
22
|
|
21
23
|
dropdownShown: (toolName: string)=>string;
|
22
24
|
dropdownHidden: (toolName: string)=>string;
|
25
|
+
zoomLevel: (zoomPercentage: number)=> string;
|
23
26
|
}
|
24
27
|
|
25
28
|
export const defaultToolbarLocalization: ToolbarLocalization = {
|
26
29
|
pen: 'Pen',
|
27
30
|
eraser: 'Eraser',
|
28
31
|
select: 'Select',
|
29
|
-
|
32
|
+
handTool: 'Pan',
|
30
33
|
thicknessLabel: 'Thickness: ',
|
31
34
|
colorLabel: 'Color: ',
|
32
35
|
resizeImageToSelection: 'Resize image to selection',
|
@@ -35,6 +38,9 @@ export const defaultToolbarLocalization: ToolbarLocalization = {
|
|
35
38
|
redo: 'Redo',
|
36
39
|
selectObjectType: 'Object type: ',
|
37
40
|
|
41
|
+
touchPanning: 'Touchscreen panning',
|
42
|
+
anyDevicePanning: 'Any device panning',
|
43
|
+
|
38
44
|
freehandPen: 'Freehand',
|
39
45
|
arrowPen: 'Arrow',
|
40
46
|
linePen: 'Line',
|
@@ -43,4 +49,5 @@ export const defaultToolbarLocalization: ToolbarLocalization = {
|
|
43
49
|
|
44
50
|
dropdownShown: (toolName) => `Dropdown for ${toolName} shown`,
|
45
51
|
dropdownHidden: (toolName) => `Dropdown for ${toolName} hidden`,
|
52
|
+
zoomLevel: (zoomPercent: number) => `Zoom: ${zoomPercent}%`,
|
46
53
|
};
|
package/src/toolbar/toolbar.css
CHANGED
@@ -32,6 +32,7 @@
|
|
32
32
|
|
33
33
|
min-width: 40px;
|
34
34
|
max-width: 70px;
|
35
|
+
width: min-content;
|
35
36
|
font-size: 11pt;
|
36
37
|
|
37
38
|
cursor: pointer;
|
@@ -49,16 +50,12 @@
|
|
49
50
|
box-shadow: 0px 2px 4px var(--primary-foreground-color);
|
50
51
|
}
|
51
52
|
|
52
|
-
.toolbar-root button {
|
53
|
-
height: auto;
|
54
|
-
}
|
55
|
-
|
56
53
|
.toolbar-root button:disabled {
|
57
54
|
cursor: inherit;
|
58
55
|
filter: opacity(0.5);
|
59
56
|
}
|
60
57
|
|
61
|
-
.toolbar-
|
58
|
+
.toolbar-root .toolbar-icon {
|
62
59
|
flex-shrink: 1;
|
63
60
|
min-width: 30px;
|
64
61
|
}
|
@@ -68,11 +65,11 @@
|
|
68
65
|
color: var(--secondary-foreground-color);
|
69
66
|
}
|
70
67
|
|
71
|
-
.toolbar-toolContainer:not(.selected) .toolbar-showHideDropdownIcon {
|
68
|
+
.toolbar-toolContainer:not(.selected):not(.dropdownShowable) .toolbar-showHideDropdownIcon {
|
72
69
|
display: none;
|
73
70
|
}
|
74
71
|
|
75
|
-
.toolbar-toolContainer
|
72
|
+
.toolbar-toolContainer .toolbar-showHideDropdownIcon {
|
76
73
|
height: 10px;
|
77
74
|
transition: transform 0.5s ease;
|
78
75
|
}
|
@@ -81,7 +78,8 @@
|
|
81
78
|
transform: rotate(180deg);
|
82
79
|
}
|
83
80
|
|
84
|
-
.toolbar-dropdown.hidden,
|
81
|
+
.toolbar-dropdown.hidden,
|
82
|
+
.toolbar-toolContainer:not(.selected):not(.dropdownShowable) > .toolbar-dropdown {
|
85
83
|
display: none;
|
86
84
|
}
|
87
85
|
|
@@ -98,6 +96,7 @@
|
|
98
96
|
.toolbar-buttonGroup {
|
99
97
|
display: flex;
|
100
98
|
flex-direction: row;
|
99
|
+
justify-content: center;
|
101
100
|
}
|
102
101
|
|
103
102
|
.toolbar-closeColorPickerOverlay {
|
@@ -120,3 +119,17 @@
|
|
120
119
|
margin-left: 0;
|
121
120
|
margin-right: 0;
|
122
121
|
}
|
122
|
+
|
123
|
+
.toolbar-root .toolbar-zoomLevelEditor {
|
124
|
+
display: flex;
|
125
|
+
flex-direction: row;
|
126
|
+
}
|
127
|
+
|
128
|
+
.toolbar-root .toolbar-zoomLevelEditor .zoomDisplay {
|
129
|
+
flex-grow: 1;
|
130
|
+
}
|
131
|
+
|
132
|
+
.toolbar-root .toolbar-zoomLevelEditor button {
|
133
|
+
width: min-content;
|
134
|
+
height: min-content;
|
135
|
+
}
|
package/src/toolbar/types.ts
CHANGED
package/src/tools/PanZoom.ts
CHANGED
@@ -4,7 +4,7 @@ import Mat33 from '../geometry/Mat33';
|
|
4
4
|
import { Point2, Vec2 } from '../geometry/Vec2';
|
5
5
|
import Vec3 from '../geometry/Vec3';
|
6
6
|
import Pointer, { PointerDevice } from '../Pointer';
|
7
|
-
import { KeyPressEvent, PointerEvt, WheelEvt } from '../types';
|
7
|
+
import { EditorEventType, KeyPressEvent, PointerEvt, WheelEvt } from '../types';
|
8
8
|
import { Viewport } from '../Viewport';
|
9
9
|
import BaseTool from './BaseTool';
|
10
10
|
import { ToolType } from './ToolController';
|
@@ -17,18 +17,14 @@ interface PinchData {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
export enum PanZoomMode {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
TwoFingerGestures = 0x1 << 1,
|
25
|
-
|
26
|
-
// / Handle gestures from any device, rather than just touch
|
27
|
-
AnyDevice = 0x1 << 2,
|
20
|
+
OneFingerTouchGestures = 0x1,
|
21
|
+
TwoFingerTouchGestures = 0x1 << 1,
|
22
|
+
RightClickDrags = 0x1 << 2,
|
23
|
+
SinglePointerGestures = 0x1 << 3,
|
28
24
|
}
|
29
25
|
|
30
26
|
export default class PanZoom extends BaseTool {
|
31
|
-
public readonly kind: ToolType.PanZoom
|
27
|
+
public readonly kind: ToolType.PanZoom = ToolType.PanZoom;
|
32
28
|
private transform: Viewport.ViewportTransform|null = null;
|
33
29
|
|
34
30
|
private lastAngle: number;
|
@@ -37,10 +33,6 @@ export default class PanZoom extends BaseTool {
|
|
37
33
|
|
38
34
|
public constructor(private editor: Editor, private mode: PanZoomMode, description: string) {
|
39
35
|
super(editor.notifier, description);
|
40
|
-
|
41
|
-
if (mode === PanZoomMode.OneFingerGestures) {
|
42
|
-
this.kind = ToolType.TouchPanZoom;
|
43
|
-
}
|
44
36
|
}
|
45
37
|
|
46
38
|
// Returns information about the pointers in a gesture
|
@@ -54,25 +46,28 @@ export default class PanZoom extends BaseTool {
|
|
54
46
|
return { canvasCenter, screenCenter, angle, dist };
|
55
47
|
}
|
56
48
|
|
57
|
-
private
|
58
|
-
return
|
59
|
-
pointer => pointer.device === PointerDevice.Touch
|
60
|
-
);
|
49
|
+
private allPointersAreOfType(pointers: Pointer[], kind: PointerDevice) {
|
50
|
+
return pointers.every(pointer => pointer.device === kind);
|
61
51
|
}
|
62
52
|
|
63
|
-
public onPointerDown({ allPointers }: PointerEvt): boolean {
|
53
|
+
public onPointerDown({ allPointers: pointers }: PointerEvt): boolean {
|
64
54
|
let handlingGesture = false;
|
65
55
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
const allAreTouch = this.allPointersAreOfType(pointers, PointerDevice.Touch);
|
57
|
+
const isRightClick = this.allPointersAreOfType(pointers, PointerDevice.RightButtonMouse);
|
58
|
+
|
59
|
+
if (allAreTouch && pointers.length === 2 && this.mode & PanZoomMode.TwoFingerTouchGestures) {
|
60
|
+
const { screenCenter, angle, dist } = this.computePinchData(pointers[0], pointers[1]);
|
70
61
|
this.lastAngle = angle;
|
71
62
|
this.lastDist = dist;
|
72
63
|
this.lastScreenCenter = screenCenter;
|
73
64
|
handlingGesture = true;
|
74
|
-
} else if (
|
75
|
-
this.
|
65
|
+
} else if (pointers.length === 1 && (
|
66
|
+
(this.mode & PanZoomMode.OneFingerTouchGestures && allAreTouch)
|
67
|
+
|| (isRightClick && this.mode & PanZoomMode.RightClickDrags)
|
68
|
+
|| (this.mode & PanZoomMode.SinglePointerGestures)
|
69
|
+
)) {
|
70
|
+
this.lastScreenCenter = pointers[0].screenPos;
|
76
71
|
handlingGesture = true;
|
77
72
|
}
|
78
73
|
|
@@ -122,9 +117,9 @@ export default class PanZoom extends BaseTool {
|
|
122
117
|
this.transform ??= new Viewport.ViewportTransform(Mat33.identity);
|
123
118
|
|
124
119
|
const lastTransform = this.transform;
|
125
|
-
if (allPointers.length === 2
|
120
|
+
if (allPointers.length === 2) {
|
126
121
|
this.handleTwoFingerMove(allPointers);
|
127
|
-
} else if (allPointers.length === 1
|
122
|
+
} else if (allPointers.length === 1) {
|
128
123
|
this.handleOneFingerMove(allPointers[0]);
|
129
124
|
}
|
130
125
|
lastTransform.unapply(this.editor);
|
@@ -253,4 +248,19 @@ export default class PanZoom extends BaseTool {
|
|
253
248
|
|
254
249
|
return true;
|
255
250
|
}
|
251
|
+
|
252
|
+
public setMode(mode: PanZoomMode) {
|
253
|
+
if (mode !== this.mode) {
|
254
|
+
this.mode = mode;
|
255
|
+
|
256
|
+
this.editor.notifier.dispatch(EditorEventType.ToolUpdated, {
|
257
|
+
kind: EditorEventType.ToolUpdated,
|
258
|
+
tool: this,
|
259
|
+
});
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
public getMode(): PanZoomMode {
|
264
|
+
return this.mode;
|
265
|
+
}
|
256
266
|
}
|
package/src/tools/Pen.ts
CHANGED
@@ -91,9 +91,13 @@ export default class Pen extends BaseTool {
|
|
91
91
|
const stroke = this.builder.build();
|
92
92
|
this.previewStroke();
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
if (stroke.getBBox().area > 0) {
|
95
|
+
const canFlatten = true;
|
96
|
+
const action = new EditorImage.AddElementCommand(stroke, canFlatten);
|
97
|
+
this.editor.dispatch(action);
|
98
|
+
} else {
|
99
|
+
console.warn('Pen: Not adding empty stroke', stroke, 'to the canvas.');
|
100
|
+
}
|
97
101
|
}
|
98
102
|
this.builder = null;
|
99
103
|
this.editor.clearWetInk();
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import Color4 from '../Color4';
|
4
4
|
import Stroke from '../components/Stroke';
|
5
|
-
import { RenderingMode } from '../Display';
|
5
|
+
import { RenderingMode } from '../rendering/Display';
|
6
6
|
import Editor from '../Editor';
|
7
7
|
import EditorImage from '../EditorImage';
|
8
8
|
import Path from '../geometry/Path';
|
@@ -7,7 +7,6 @@ import Mat33 from '../geometry/Mat33';
|
|
7
7
|
import Rect2 from '../geometry/Rect2';
|
8
8
|
import { Point2, Vec2 } from '../geometry/Vec2';
|
9
9
|
import { EditorEventType, PointerEvt } from '../types';
|
10
|
-
import Viewport from '../Viewport';
|
11
10
|
import BaseTool from './BaseTool';
|
12
11
|
import { ToolType } from './ToolController';
|
13
12
|
|
@@ -120,7 +119,7 @@ const makeDraggable = (element: HTMLElement, onDrag: DragCallback, onDragEnd: Dr
|
|
120
119
|
};
|
121
120
|
|
122
121
|
// Maximum number of strokes to transform without a re-render.
|
123
|
-
const updateChunkSize =
|
122
|
+
const updateChunkSize = 100;
|
124
123
|
|
125
124
|
class Selection {
|
126
125
|
public region: Rect2;
|
@@ -341,10 +340,16 @@ class Selection {
|
|
341
340
|
this.selectedElems = this.editor.image.getElementsIntersectingRegion(this.region).filter(elem => {
|
342
341
|
if (this.region.containsRect(elem.getBBox())) {
|
343
342
|
return true;
|
344
|
-
} else if (this.region.getEdges().some(edge => elem.intersects(edge))) {
|
345
|
-
return true;
|
346
343
|
}
|
347
|
-
|
344
|
+
|
345
|
+
// Calculated bounding boxes can be slightly larger than their actual contents' bounding box.
|
346
|
+
// As such, test with more lines than just this' edges.
|
347
|
+
const testLines = [];
|
348
|
+
for (const subregion of this.region.divideIntoGrid(2, 2)) {
|
349
|
+
testLines.push(...subregion.getEdges());
|
350
|
+
}
|
351
|
+
|
352
|
+
return testLines.some(edge => elem.intersects(edge));
|
348
353
|
});
|
349
354
|
|
350
355
|
// Find the bounding box of all selected elements.
|
@@ -484,38 +489,12 @@ export default class SelectionTool extends BaseTool {
|
|
484
489
|
});
|
485
490
|
|
486
491
|
if (hasSelection) {
|
487
|
-
const visibleRect = this.editor.viewport.visibleRect;
|
488
|
-
const selectionRect = this.selectionBox.region;
|
489
|
-
|
490
492
|
this.editor.announceForAccessibility(
|
491
493
|
this.editor.localization.selectedElements(this.selectionBox.getSelectedItemCount())
|
492
494
|
);
|
493
495
|
|
494
|
-
|
495
|
-
|
496
|
-
Mat33.scaling2D(2 / 3, visibleRect.center)
|
497
|
-
);
|
498
|
-
|
499
|
-
// Ensure that the selection fits within the target
|
500
|
-
if (targetRect.w < selectionRect.w || targetRect.h < selectionRect.h) {
|
501
|
-
const multiplier = Math.max(
|
502
|
-
selectionRect.w / targetRect.w, selectionRect.h / targetRect.h
|
503
|
-
);
|
504
|
-
const visibleRectTransform = Mat33.scaling2D(multiplier, targetRect.topLeft);
|
505
|
-
const viewportContentTransform = visibleRectTransform.inverse();
|
506
|
-
|
507
|
-
(new Viewport.ViewportTransform(viewportContentTransform)).apply(this.editor);
|
508
|
-
}
|
509
|
-
|
510
|
-
// Ensure that the top left is visible
|
511
|
-
if (!targetRect.containsRect(selectionRect)) {
|
512
|
-
// target position - current position
|
513
|
-
const translation = selectionRect.center.minus(targetRect.center);
|
514
|
-
const visibleRectTransform = Mat33.translation(translation);
|
515
|
-
const viewportContentTransform = visibleRectTransform.inverse();
|
516
|
-
|
517
|
-
(new Viewport.ViewportTransform(viewportContentTransform)).apply(this.editor);
|
518
|
-
}
|
496
|
+
const selectionRect = this.selectionBox.region;
|
497
|
+
this.editor.viewport.zoomTo(selectionRect).apply(this.editor);
|
519
498
|
}
|
520
499
|
}
|
521
500
|
|
@@ -11,7 +11,6 @@ import { ToolLocalization } from './localization';
|
|
11
11
|
import UndoRedoShortcut from './UndoRedoShortcut';
|
12
12
|
|
13
13
|
export enum ToolType {
|
14
|
-
TouchPanZoom,
|
15
14
|
Pen,
|
16
15
|
Selection,
|
17
16
|
Eraser,
|
@@ -25,7 +24,7 @@ export default class ToolController {
|
|
25
24
|
|
26
25
|
public constructor(editor: Editor, localization: ToolLocalization) {
|
27
26
|
const primaryToolEnabledGroup = new ToolEnabledGroup();
|
28
|
-
const
|
27
|
+
const panZoomTool = new PanZoom(editor, PanZoomMode.TwoFingerTouchGestures | PanZoomMode.RightClickDrags, localization.touchPanTool);
|
29
28
|
const primaryPenTool = new Pen(editor, localization.penTool(1), { color: Color4.purple, thickness: 16 });
|
30
29
|
const primaryTools = [
|
31
30
|
new SelectionTool(editor, localization.selectionTool),
|
@@ -39,13 +38,12 @@ export default class ToolController {
|
|
39
38
|
new Pen(editor, localization.penTool(3), { color: Color4.ofRGBA(1, 1, 0, 0.5), thickness: 64 }),
|
40
39
|
];
|
41
40
|
this.tools = [
|
42
|
-
|
41
|
+
panZoomTool,
|
43
42
|
...primaryTools,
|
44
|
-
new PanZoom(editor, PanZoomMode.TwoFingerGestures | PanZoomMode.AnyDevice, localization.twoFingerPanZoomTool),
|
45
43
|
new UndoRedoShortcut(editor),
|
46
44
|
];
|
47
45
|
primaryTools.forEach(tool => tool.setToolGroup(primaryToolEnabledGroup));
|
48
|
-
|
46
|
+
panZoomTool.setEnabled(true);
|
49
47
|
primaryPenTool.setEnabled(true);
|
50
48
|
|
51
49
|
editor.notifier.on(EditorEventType.ToolEnabled, event => {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
export interface ToolLocalization {
|
3
|
+
RightClickDragPanTool: string;
|
3
4
|
penTool: (penId: number)=>string;
|
4
5
|
selectionTool: string;
|
5
6
|
eraserTool: string;
|
@@ -18,6 +19,7 @@ export const defaultToolLocalization: ToolLocalization = {
|
|
18
19
|
touchPanTool: 'Touch Panning',
|
19
20
|
twoFingerPanZoomTool: 'Panning and Zooming',
|
20
21
|
undoRedoTool: 'Undo/Redo',
|
22
|
+
RightClickDragPanTool: 'Right-click drag',
|
21
23
|
|
22
24
|
toolEnabledAnnouncement: (toolName) => `${toolName} enabled`,
|
23
25
|
toolDisabledAnnouncement: (toolName) => `${toolName} disabled`,
|
package/src/types.ts
CHANGED
@@ -134,11 +134,18 @@ export type OnProgressListener =
|
|
134
134
|
(amountProcessed: number, totalToProcess: number)=> Promise<void>|null;
|
135
135
|
|
136
136
|
export type ComponentAddedListener = (component: AbstractComponent)=> void;
|
137
|
+
|
138
|
+
// Called when a new estimate for the import/export rect has been generated. This can be called multiple times.
|
139
|
+
// Only the last call to this listener must be accurate.
|
140
|
+
// The import/export rect is also returned by [start].
|
141
|
+
export type OnDetermineExportRectListener = (exportRect: Rect2)=> void;
|
142
|
+
|
137
143
|
export interface ImageLoader {
|
138
|
-
// Returns the main region of the loaded image
|
139
144
|
start(
|
140
|
-
onAddComponent: ComponentAddedListener,
|
141
|
-
|
145
|
+
onAddComponent: ComponentAddedListener,
|
146
|
+
onProgressListener: OnProgressListener,
|
147
|
+
onDetermineExportRect?: OnDetermineExportRectListener,
|
148
|
+
): Promise<void>;
|
142
149
|
}
|
143
150
|
|
144
151
|
export interface StrokeDataPoint {
|
package/tsconfig.json
CHANGED