js-draw 0.1.11 → 0.1.12
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 +7 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Editor.d.ts +4 -2
- package/dist/src/Editor.js +30 -10
- package/dist/src/EditorImage.d.ts +1 -1
- package/dist/src/EditorImage.js +2 -2
- package/dist/src/Pointer.d.ts +1 -1
- package/dist/src/Pointer.js +1 -1
- package/dist/src/SVGLoader.d.ts +1 -1
- package/dist/src/SVGLoader.js +14 -6
- package/dist/src/Viewport.d.ts +8 -25
- package/dist/src/Viewport.js +15 -10
- package/dist/src/commands/Command.d.ts +2 -2
- package/dist/src/commands/Command.js +4 -4
- package/dist/src/commands/Duplicate.d.ts +1 -1
- package/dist/src/commands/Duplicate.js +1 -1
- package/dist/src/commands/Erase.d.ts +1 -1
- package/dist/src/commands/Erase.js +1 -1
- package/dist/src/commands/localization.d.ts +1 -1
- package/dist/src/components/AbstractComponent.d.ts +3 -3
- package/dist/src/components/AbstractComponent.js +2 -2
- package/dist/src/components/SVGGlobalAttributesObject.d.ts +3 -3
- package/dist/src/components/SVGGlobalAttributesObject.js +1 -1
- package/dist/src/components/Stroke.d.ts +4 -4
- package/dist/src/components/Stroke.js +2 -2
- package/dist/src/components/Text.d.ts +3 -3
- package/dist/src/components/Text.js +3 -3
- package/dist/src/components/UnknownSVGObject.d.ts +3 -3
- package/dist/src/components/UnknownSVGObject.js +1 -1
- package/dist/src/components/builders/ArrowBuilder.d.ts +1 -1
- package/dist/src/components/builders/ArrowBuilder.js +1 -1
- package/dist/src/components/builders/FreehandLineBuilder.d.ts +8 -3
- package/dist/src/components/builders/FreehandLineBuilder.js +142 -71
- package/dist/src/components/builders/LineBuilder.d.ts +1 -1
- package/dist/src/components/builders/LineBuilder.js +1 -1
- package/dist/src/components/builders/RectangleBuilder.d.ts +1 -1
- package/dist/src/components/builders/RectangleBuilder.js +3 -3
- package/dist/src/components/builders/types.d.ts +1 -1
- package/dist/src/localization.d.ts +1 -0
- package/dist/src/localization.js +5 -1
- package/dist/src/localizations/es.js +1 -1
- package/dist/src/{geometry → math}/LineSegment2.d.ts +0 -0
- package/dist/src/{geometry → math}/LineSegment2.js +0 -0
- package/dist/src/{geometry → math}/Mat33.d.ts +0 -0
- package/dist/src/{geometry → math}/Mat33.js +0 -0
- package/dist/src/{geometry → math}/Path.d.ts +2 -1
- package/dist/src/{geometry → math}/Path.js +58 -51
- package/dist/src/{geometry → math}/Rect2.d.ts +0 -0
- package/dist/src/{geometry → math}/Rect2.js +0 -0
- package/dist/src/{geometry → math}/Vec2.d.ts +0 -0
- package/dist/src/{geometry → math}/Vec2.js +0 -0
- package/dist/src/{geometry → math}/Vec3.d.ts +1 -1
- package/dist/src/{geometry → math}/Vec3.js +1 -1
- package/dist/src/math/rounding.d.ts +3 -0
- package/dist/src/math/rounding.js +120 -0
- package/dist/src/rendering/Display.d.ts +3 -1
- package/dist/src/rendering/Display.js +16 -10
- package/dist/src/rendering/caching/CacheRecord.d.ts +2 -2
- package/dist/src/rendering/caching/CacheRecord.js +1 -1
- package/dist/src/rendering/caching/CacheRecordManager.d.ts +1 -1
- package/dist/src/rendering/caching/RenderingCache.js +1 -1
- package/dist/src/rendering/caching/RenderingCacheNode.d.ts +2 -1
- package/dist/src/rendering/caching/RenderingCacheNode.js +18 -7
- package/dist/src/rendering/caching/testUtils.js +1 -1
- package/dist/src/rendering/caching/types.d.ts +1 -1
- package/dist/src/rendering/localization.d.ts +2 -0
- package/dist/src/rendering/localization.js +2 -0
- package/dist/src/rendering/renderers/AbstractRenderer.d.ts +4 -4
- package/dist/src/rendering/renderers/AbstractRenderer.js +2 -2
- package/dist/src/rendering/renderers/CanvasRenderer.d.ts +4 -4
- package/dist/src/rendering/renderers/CanvasRenderer.js +1 -1
- package/dist/src/rendering/renderers/DummyRenderer.d.ts +4 -4
- package/dist/src/rendering/renderers/DummyRenderer.js +1 -1
- package/dist/src/rendering/renderers/SVGRenderer.d.ts +3 -3
- package/dist/src/rendering/renderers/SVGRenderer.js +8 -2
- package/dist/src/rendering/renderers/TextOnlyRenderer.d.ts +5 -3
- package/dist/src/rendering/renderers/TextOnlyRenderer.js +13 -3
- package/dist/src/toolbar/icons.d.ts +3 -0
- package/dist/src/toolbar/icons.js +142 -132
- package/dist/src/toolbar/localization.d.ts +2 -1
- package/dist/src/toolbar/localization.js +2 -1
- package/dist/src/toolbar/makeColorInput.js +2 -1
- package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +13 -0
- package/dist/src/toolbar/widgets/ActionButtonWidget.js +21 -0
- package/dist/src/toolbar/widgets/BaseWidget.js +2 -0
- package/dist/src/toolbar/widgets/HandToolWidget.js +3 -3
- package/dist/src/toolbar/widgets/SelectionWidget.d.ts +0 -1
- package/dist/src/toolbar/widgets/SelectionWidget.js +23 -30
- package/dist/src/tools/Eraser.js +1 -1
- package/dist/src/tools/PanZoom.d.ts +1 -1
- package/dist/src/tools/PanZoom.js +24 -14
- package/dist/src/tools/SelectionTool.d.ts +3 -3
- package/dist/src/tools/SelectionTool.js +6 -6
- package/dist/src/tools/TextTool.js +1 -1
- package/dist/src/types.d.ts +4 -4
- package/package.json +1 -1
- package/src/Editor.ts +34 -12
- package/src/EditorImage.test.ts +2 -4
- package/src/EditorImage.ts +2 -2
- package/src/Pointer.ts +1 -1
- package/src/SVGLoader.ts +14 -6
- package/src/Viewport.ts +19 -17
- package/src/commands/Command.ts +5 -5
- package/src/commands/Duplicate.ts +1 -1
- package/src/commands/Erase.ts +1 -1
- package/src/commands/localization.ts +1 -1
- package/src/components/AbstractComponent.ts +4 -4
- package/src/components/SVGGlobalAttributesObject.ts +3 -3
- package/src/components/Stroke.test.ts +3 -5
- package/src/components/Stroke.ts +4 -4
- package/src/components/Text.test.ts +2 -2
- package/src/components/Text.ts +3 -3
- package/src/components/UnknownSVGObject.ts +3 -3
- package/src/components/builders/ArrowBuilder.ts +2 -2
- package/src/components/builders/FreehandLineBuilder.ts +190 -80
- package/src/components/builders/LineBuilder.ts +2 -2
- package/src/components/builders/RectangleBuilder.ts +3 -3
- package/src/components/builders/types.ts +1 -1
- package/src/localization.ts +6 -0
- package/src/localizations/es.ts +2 -1
- package/src/{geometry → math}/LineSegment2.test.ts +0 -0
- package/src/{geometry → math}/LineSegment2.ts +0 -0
- package/src/{geometry → math}/Mat33.test.ts +0 -0
- package/src/{geometry → math}/Mat33.ts +0 -0
- package/src/{geometry → math}/Path.fromString.test.ts +0 -0
- package/src/{geometry → math}/Path.test.ts +0 -0
- package/src/{geometry → math}/Path.toString.test.ts +11 -2
- package/src/{geometry → math}/Path.ts +60 -57
- package/src/{geometry → math}/Rect2.test.ts +0 -0
- package/src/{geometry → math}/Rect2.ts +0 -0
- package/src/{geometry → math}/Vec2.test.ts +0 -0
- package/src/{geometry → math}/Vec2.ts +0 -0
- package/src/{geometry → math}/Vec3.test.ts +0 -0
- package/src/{geometry → math}/Vec3.ts +2 -2
- package/src/math/rounding.test.ts +40 -0
- package/src/math/rounding.ts +145 -0
- package/src/rendering/Display.ts +18 -10
- package/src/rendering/caching/CacheRecord.test.ts +2 -2
- package/src/rendering/caching/CacheRecord.ts +2 -2
- package/src/rendering/caching/CacheRecordManager.ts +1 -1
- package/src/rendering/caching/RenderingCache.test.ts +3 -3
- package/src/rendering/caching/RenderingCache.ts +1 -1
- package/src/rendering/caching/RenderingCacheNode.ts +23 -7
- package/src/rendering/caching/testUtils.ts +1 -1
- package/src/rendering/caching/types.ts +1 -1
- package/src/rendering/localization.ts +4 -0
- package/src/rendering/renderers/AbstractRenderer.ts +4 -4
- package/src/rendering/renderers/CanvasRenderer.ts +4 -4
- package/src/rendering/renderers/DummyRenderer.test.ts +2 -2
- package/src/rendering/renderers/DummyRenderer.ts +4 -4
- package/src/rendering/renderers/SVGRenderer.ts +10 -4
- package/src/rendering/renderers/TextOnlyRenderer.ts +17 -6
- package/src/toolbar/icons.ts +157 -137
- package/src/toolbar/localization.ts +4 -2
- package/src/toolbar/makeColorInput.ts +2 -1
- package/src/toolbar/toolbar.css +1 -1
- package/src/toolbar/widgets/ActionButtonWidget.ts +31 -0
- package/src/toolbar/widgets/BaseWidget.ts +2 -0
- package/src/toolbar/widgets/HandToolWidget.ts +3 -3
- package/src/toolbar/widgets/SelectionWidget.ts +46 -41
- package/src/tools/Eraser.ts +2 -2
- package/src/tools/PanZoom.ts +28 -16
- package/src/tools/SelectionTool.test.ts +2 -4
- package/src/tools/SelectionTool.ts +6 -6
- package/src/tools/TextTool.ts +2 -2
- package/src/tools/UndoRedoShortcut.test.ts +1 -1
- package/src/types.ts +4 -4
package/src/tools/PanZoom.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
2
|
import { Editor } from '../Editor';
|
3
|
-
import Mat33 from '../
|
4
|
-
import { Point2, Vec2 } from '../
|
5
|
-
import Vec3 from '../
|
3
|
+
import Mat33 from '../math/Mat33';
|
4
|
+
import { Point2, Vec2 } from '../math/Vec2';
|
5
|
+
import Vec3 from '../math/Vec3';
|
6
6
|
import Pointer, { PointerDevice } from '../Pointer';
|
7
7
|
import { EditorEventType, KeyPressEvent, PointerEvt, WheelEvt } from '../types';
|
8
|
-
import { Viewport } from '../Viewport';
|
8
|
+
import { Viewport, ViewportTransform } from '../Viewport';
|
9
9
|
import BaseTool from './BaseTool';
|
10
10
|
import { ToolType } from './ToolController';
|
11
11
|
|
@@ -27,7 +27,7 @@ export enum PanZoomMode {
|
|
27
27
|
|
28
28
|
export default class PanZoom extends BaseTool {
|
29
29
|
public readonly kind: ToolType.PanZoom = ToolType.PanZoom;
|
30
|
-
private transform:
|
30
|
+
private transform: ViewportTransform|null = null;
|
31
31
|
|
32
32
|
private lastAngle: number;
|
33
33
|
private lastDist: number;
|
@@ -74,7 +74,7 @@ export default class PanZoom extends BaseTool {
|
|
74
74
|
}
|
75
75
|
|
76
76
|
if (handlingGesture) {
|
77
|
-
this.transform ??=
|
77
|
+
this.transform ??= Viewport.transformBy(Mat33.identity);
|
78
78
|
this.editor.display.setDraftMode(true);
|
79
79
|
}
|
80
80
|
|
@@ -100,14 +100,14 @@ export default class PanZoom extends BaseTool {
|
|
100
100
|
this.lastScreenCenter = screenCenter;
|
101
101
|
this.lastDist = dist;
|
102
102
|
this.lastAngle = angle;
|
103
|
-
this.transform =
|
103
|
+
this.transform = Viewport.transformBy(
|
104
104
|
this.transform!.transform.rightMul(transformUpdate)
|
105
105
|
);
|
106
106
|
}
|
107
107
|
|
108
108
|
private handleOneFingerMove(pointer: Pointer) {
|
109
109
|
const delta = this.getCenterDelta(pointer.screenPos);
|
110
|
-
this.transform =
|
110
|
+
this.transform = Viewport.transformBy(
|
111
111
|
this.transform!.transform.rightMul(
|
112
112
|
Mat33.translation(delta)
|
113
113
|
)
|
@@ -116,7 +116,7 @@ export default class PanZoom extends BaseTool {
|
|
116
116
|
}
|
117
117
|
|
118
118
|
public onPointerMove({ allPointers }: PointerEvt): void {
|
119
|
-
this.transform ??=
|
119
|
+
this.transform ??= Viewport.transformBy(Mat33.identity);
|
120
120
|
|
121
121
|
const lastTransform = this.transform;
|
122
122
|
if (allPointers.length === 2) {
|
@@ -146,21 +146,25 @@ export default class PanZoom extends BaseTool {
|
|
146
146
|
|
147
147
|
// Applies [transformUpdate] to the editor. This stacks on top of the
|
148
148
|
// current transformation, if it exists.
|
149
|
-
private updateTransform(transformUpdate: Mat33) {
|
149
|
+
private updateTransform(transformUpdate: Mat33, announce: boolean = false) {
|
150
150
|
let newTransform = transformUpdate;
|
151
151
|
if (this.transform) {
|
152
152
|
newTransform = this.transform.transform.rightMul(transformUpdate);
|
153
153
|
}
|
154
154
|
|
155
155
|
this.transform?.unapply(this.editor);
|
156
|
-
this.transform =
|
156
|
+
this.transform = Viewport.transformBy(newTransform);
|
157
157
|
this.transform.apply(this.editor);
|
158
|
+
|
159
|
+
if (announce) {
|
160
|
+
this.editor.announceForAccessibility(this.transform.description(this.editor, this.editor.localization));
|
161
|
+
}
|
158
162
|
}
|
159
163
|
|
160
164
|
public onWheel({ delta, screenPos }: WheelEvt): boolean {
|
161
165
|
// Reset the transformation -- wheel events are individual events, so we don't
|
162
166
|
// need to unapply/reapply.
|
163
|
-
this.transform =
|
167
|
+
this.transform = Viewport.transformBy(Mat33.identity);
|
164
168
|
|
165
169
|
const canvasPos = this.editor.viewport.screenToCanvas(screenPos);
|
166
170
|
const toCanvas = this.editor.viewport.screenToCanvasTransform;
|
@@ -176,7 +180,7 @@ export default class PanZoom extends BaseTool {
|
|
176
180
|
).rightMul(
|
177
181
|
Mat33.translation(translation)
|
178
182
|
);
|
179
|
-
this.updateTransform(transformUpdate);
|
183
|
+
this.updateTransform(transformUpdate, true);
|
180
184
|
|
181
185
|
return true;
|
182
186
|
}
|
@@ -187,7 +191,7 @@ export default class PanZoom extends BaseTool {
|
|
187
191
|
}
|
188
192
|
|
189
193
|
// No need to keep the same the transform for keyboard events.
|
190
|
-
this.transform =
|
194
|
+
this.transform = Viewport.transformBy(Mat33.identity);
|
191
195
|
|
192
196
|
let translation = Vec2.zero;
|
193
197
|
let scale = 1;
|
@@ -205,10 +209,12 @@ export default class PanZoom extends BaseTool {
|
|
205
209
|
case 'ArrowRight':
|
206
210
|
translation = Vec2.of(1, 0);
|
207
211
|
break;
|
212
|
+
case 'q':
|
208
213
|
case 'k':
|
209
214
|
case 'ArrowUp':
|
210
215
|
translation = Vec2.of(0, -1);
|
211
216
|
break;
|
217
|
+
case 'e':
|
212
218
|
case 'j':
|
213
219
|
case 'ArrowDown':
|
214
220
|
translation = Vec2.of(0, 1);
|
@@ -231,13 +237,19 @@ export default class PanZoom extends BaseTool {
|
|
231
237
|
|
232
238
|
// For each keypress,
|
233
239
|
translation = translation.times(30); // Move at most 30 units
|
234
|
-
rotation *= Math.PI / 8; // Rotate at
|
240
|
+
rotation *= Math.PI / 8; // Rotate at least a sixteenth of a rotation
|
235
241
|
|
236
242
|
// Transform the canvas, not the viewport:
|
237
243
|
translation = translation.times(-1);
|
238
244
|
rotation = rotation * -1;
|
239
245
|
scale = 1 / scale;
|
240
246
|
|
247
|
+
// Work around an issue that seems to be related to rotation matricies losing precision on inversion.
|
248
|
+
// TODO: Figure out why and implement a better solution.
|
249
|
+
if (rotation !== 0) {
|
250
|
+
rotation += 0.0001;
|
251
|
+
}
|
252
|
+
|
241
253
|
const toCanvas = this.editor.viewport.screenToCanvasTransform;
|
242
254
|
|
243
255
|
// Transform without translating (treat toCanvas as a linear instead of
|
@@ -253,7 +265,7 @@ export default class PanZoom extends BaseTool {
|
|
253
265
|
)).rightMul(Mat33.translation(
|
254
266
|
translation
|
255
267
|
));
|
256
|
-
this.updateTransform(transformUpdate);
|
268
|
+
this.updateTransform(transformUpdate, true);
|
257
269
|
|
258
270
|
return true;
|
259
271
|
}
|
@@ -1,11 +1,9 @@
|
|
1
|
-
/* @jest-environment jsdom */
|
2
|
-
|
3
1
|
import Color4 from '../Color4';
|
4
2
|
import Stroke from '../components/Stroke';
|
5
3
|
import Editor from '../Editor';
|
6
4
|
import EditorImage from '../EditorImage';
|
7
|
-
import Path from '../
|
8
|
-
import { Vec2 } from '../
|
5
|
+
import Path from '../math/Path';
|
6
|
+
import { Vec2 } from '../math/Vec2';
|
9
7
|
import { InputEvtType } from '../types';
|
10
8
|
import SelectionTool from './SelectionTool';
|
11
9
|
import { ToolType } from './ToolController';
|
@@ -3,10 +3,10 @@ import Duplicate from '../commands/Duplicate';
|
|
3
3
|
import Erase from '../commands/Erase';
|
4
4
|
import AbstractComponent from '../components/AbstractComponent';
|
5
5
|
import Editor from '../Editor';
|
6
|
-
import Mat33 from '../
|
6
|
+
import Mat33 from '../math/Mat33';
|
7
7
|
// import Mat33 from "../geometry/Mat33";
|
8
|
-
import Rect2 from '../
|
9
|
-
import { Point2, Vec2 } from '../
|
8
|
+
import Rect2 from '../math/Rect2';
|
9
|
+
import { Point2, Vec2 } from '../math/Vec2';
|
10
10
|
import { EditorLocalization } from '../localization';
|
11
11
|
import { EditorEventType, KeyPressEvent, KeyUpEvent, PointerEvt } from '../types';
|
12
12
|
import Viewport from '../Viewport';
|
@@ -310,7 +310,7 @@ class Selection {
|
|
310
310
|
this.selection.updateUI();
|
311
311
|
}
|
312
312
|
|
313
|
-
public description(localizationTable: EditorLocalization) {
|
313
|
+
public description(_editor: Editor, localizationTable: EditorLocalization) {
|
314
314
|
return localizationTable.transformedElements(this.currentTransfmCommands.length);
|
315
315
|
}
|
316
316
|
};
|
@@ -460,7 +460,7 @@ class Selection {
|
|
460
460
|
const closestPoint = visibleRect.getClosestPointOnBoundaryTo(this.region.center);
|
461
461
|
const delta = this.region.center.minus(closestPoint);
|
462
462
|
this.editor.dispatchNoAnnounce(
|
463
|
-
|
463
|
+
Viewport.transformBy(Mat33.translation(delta.times(-1))), false
|
464
464
|
);
|
465
465
|
}
|
466
466
|
}
|
@@ -671,7 +671,7 @@ export default class SelectionTool extends BaseTool {
|
|
671
671
|
|
672
672
|
if (enabled) {
|
673
673
|
this.handleOverlay.tabIndex = 0;
|
674
|
-
this.handleOverlay.
|
674
|
+
this.handleOverlay.setAttribute('aria-label', this.editor.localization.selectionToolKeyboardShortcuts);
|
675
675
|
} else {
|
676
676
|
this.handleOverlay.tabIndex = -1;
|
677
677
|
}
|
package/src/tools/TextTool.ts
CHANGED
@@ -2,8 +2,8 @@ import Color4 from '../Color4';
|
|
2
2
|
import Text, { TextStyle } from '../components/Text';
|
3
3
|
import Editor from '../Editor';
|
4
4
|
import EditorImage from '../EditorImage';
|
5
|
-
import Mat33 from '../
|
6
|
-
import { Vec2 } from '../
|
5
|
+
import Mat33 from '../math/Mat33';
|
6
|
+
import { Vec2 } from '../math/Vec2';
|
7
7
|
import { PointerDevice } from '../Pointer';
|
8
8
|
import { EditorEventType, PointerEvt } from '../types';
|
9
9
|
import BaseTool from './BaseTool';
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import Color4 from '../Color4';
|
4
4
|
import Stroke from '../components/Stroke';
|
5
5
|
import EditorImage from '../EditorImage';
|
6
|
-
import Path from '../
|
6
|
+
import Path from '../math/Path';
|
7
7
|
import createEditor from '../testing/createEditor';
|
8
8
|
import { InputEvtType } from '../types';
|
9
9
|
|
package/src/types.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
// Types related to the image editor
|
2
2
|
|
3
3
|
import EventDispatcher from './EventDispatcher';
|
4
|
-
import Mat33 from './
|
5
|
-
import { Point2, Vec2 } from './
|
6
|
-
import Vec3 from './
|
4
|
+
import Mat33 from './math/Mat33';
|
5
|
+
import { Point2, Vec2 } from './math/Vec2';
|
6
|
+
import Vec3 from './math/Vec3';
|
7
7
|
import BaseTool from './tools/BaseTool';
|
8
8
|
import AbstractComponent from './components/AbstractComponent';
|
9
|
-
import Rect2 from './
|
9
|
+
import Rect2 from './math/Rect2';
|
10
10
|
import Pointer from './Pointer';
|
11
11
|
import Color4 from './Color4';
|
12
12
|
|