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/dist/src/Editor.d.ts
CHANGED
@@ -4,12 +4,12 @@ import { InputEvtType, EditorNotifier, ImageLoader } from './types';
|
|
4
4
|
import Command from './commands/Command';
|
5
5
|
import UndoRedoHistory from './UndoRedoHistory';
|
6
6
|
import Viewport from './Viewport';
|
7
|
-
import { Point2 } from './
|
7
|
+
import { Point2 } from './math/Vec2';
|
8
8
|
import HTMLToolbar from './toolbar/HTMLToolbar';
|
9
9
|
import { RenderablePathSpec } from './rendering/renderers/AbstractRenderer';
|
10
10
|
import Display, { RenderingMode } from './rendering/Display';
|
11
11
|
import Pointer from './Pointer';
|
12
|
-
import Rect2 from './
|
12
|
+
import Rect2 from './math/Rect2';
|
13
13
|
import { EditorLocalization } from './localization';
|
14
14
|
export interface EditorSettings {
|
15
15
|
renderingMode: RenderingMode;
|
@@ -31,11 +31,13 @@ export declare class Editor {
|
|
31
31
|
notifier: EditorNotifier;
|
32
32
|
private loadingWarning;
|
33
33
|
private accessibilityAnnounceArea;
|
34
|
+
private accessibilityControlArea;
|
34
35
|
private settings;
|
35
36
|
constructor(parent: HTMLElement, settings?: Partial<EditorSettings>);
|
36
37
|
getRootElement(): HTMLElement;
|
37
38
|
showLoadingWarning(fractionLoaded: number): void;
|
38
39
|
hideLoadingWarning(): void;
|
40
|
+
private previousAccessibilityAnnouncement;
|
39
41
|
announceForAccessibility(message: string): void;
|
40
42
|
addToolbar(defaultLayout?: boolean): HTMLToolbar;
|
41
43
|
private registerListeners;
|
package/dist/src/Editor.js
CHANGED
@@ -14,24 +14,25 @@ import Command from './commands/Command';
|
|
14
14
|
import UndoRedoHistory from './UndoRedoHistory';
|
15
15
|
import Viewport from './Viewport';
|
16
16
|
import EventDispatcher from './EventDispatcher';
|
17
|
-
import { Vec2 } from './
|
18
|
-
import Vec3 from './
|
17
|
+
import { Vec2 } from './math/Vec2';
|
18
|
+
import Vec3 from './math/Vec3';
|
19
19
|
import HTMLToolbar from './toolbar/HTMLToolbar';
|
20
20
|
import Display, { RenderingMode } from './rendering/Display';
|
21
21
|
import SVGRenderer from './rendering/renderers/SVGRenderer';
|
22
22
|
import Color4 from './Color4';
|
23
23
|
import SVGLoader from './SVGLoader';
|
24
24
|
import Pointer from './Pointer';
|
25
|
-
import Mat33 from './
|
25
|
+
import Mat33 from './math/Mat33';
|
26
26
|
import getLocalizationTable from './localizations/getLocalizationTable';
|
27
27
|
export class Editor {
|
28
28
|
constructor(parent, settings = {}) {
|
29
29
|
var _a, _b, _c, _d;
|
30
|
+
this.previousAccessibilityAnnouncement = '';
|
30
31
|
this.announceUndoCallback = (command) => {
|
31
|
-
this.announceForAccessibility(this.localization.undoAnnouncement(command.description(this.localization)));
|
32
|
+
this.announceForAccessibility(this.localization.undoAnnouncement(command.description(this, this.localization)));
|
32
33
|
};
|
33
34
|
this.announceRedoCallback = (command) => {
|
34
|
-
this.announceForAccessibility(this.localization.redoAnnouncement(command.description(this.localization)));
|
35
|
+
this.announceForAccessibility(this.localization.redoAnnouncement(command.description(this, this.localization)));
|
35
36
|
};
|
36
37
|
this.rerenderQueued = false;
|
37
38
|
this.localization = Object.assign(Object.assign({}, getLocalizationTable()), settings.localization);
|
@@ -51,14 +52,21 @@ export class Editor {
|
|
51
52
|
this.loadingWarning.classList.add('loadingMessage');
|
52
53
|
this.loadingWarning.ariaLive = 'polite';
|
53
54
|
this.container.appendChild(this.loadingWarning);
|
55
|
+
this.accessibilityControlArea = document.createElement('textarea');
|
56
|
+
this.accessibilityControlArea.setAttribute('placeholder', this.localization.accessibilityInputInstructions);
|
57
|
+
this.accessibilityControlArea.style.opacity = '0';
|
58
|
+
this.accessibilityControlArea.style.width = '0';
|
59
|
+
this.accessibilityControlArea.style.height = '0';
|
60
|
+
this.accessibilityControlArea.style.position = 'absolute';
|
54
61
|
this.accessibilityAnnounceArea = document.createElement('div');
|
55
|
-
this.accessibilityAnnounceArea.
|
62
|
+
this.accessibilityAnnounceArea.setAttribute('aria-live', 'assertive');
|
56
63
|
this.accessibilityAnnounceArea.className = 'accessibilityAnnouncement';
|
57
64
|
this.container.appendChild(this.accessibilityAnnounceArea);
|
58
65
|
this.renderingRegion.style.touchAction = 'none';
|
59
66
|
this.renderingRegion.className = 'imageEditorRenderArea';
|
67
|
+
this.renderingRegion.appendChild(this.accessibilityControlArea);
|
60
68
|
this.renderingRegion.setAttribute('tabIndex', '0');
|
61
|
-
this.renderingRegion.
|
69
|
+
this.renderingRegion.setAttribute('alt', '');
|
62
70
|
this.notifier = new EventDispatcher();
|
63
71
|
this.importExportViewport = new Viewport(this.notifier);
|
64
72
|
this.viewport = new Viewport(this.notifier);
|
@@ -105,7 +113,12 @@ export class Editor {
|
|
105
113
|
this.announceForAccessibility(this.localization.doneLoading);
|
106
114
|
}
|
107
115
|
announceForAccessibility(message) {
|
116
|
+
// Force re-announcing an announcement if announced again.
|
117
|
+
if (message === this.previousAccessibilityAnnouncement) {
|
118
|
+
message = message + '. ';
|
119
|
+
}
|
108
120
|
this.accessibilityAnnounceArea.innerText = message;
|
121
|
+
this.previousAccessibilityAnnouncement = message;
|
109
122
|
}
|
110
123
|
addToolbar(defaultLayout = true) {
|
111
124
|
const toolbar = new HTMLToolbar(this, this.container, this.localization);
|
@@ -237,12 +250,19 @@ export class Editor {
|
|
237
250
|
});
|
238
251
|
this.queueRerender();
|
239
252
|
});
|
253
|
+
this.accessibilityControlArea.addEventListener('input', () => {
|
254
|
+
this.accessibilityControlArea.value = '';
|
255
|
+
});
|
240
256
|
}
|
241
257
|
// Adds event listners for keypresses to [elem] and forwards those events to the
|
242
258
|
// editor.
|
243
259
|
handleKeyEventsFrom(elem) {
|
244
260
|
elem.addEventListener('keydown', evt => {
|
245
|
-
if (
|
261
|
+
if (evt.key === 't' || evt.key === 'T') {
|
262
|
+
evt.preventDefault();
|
263
|
+
this.display.rerenderAsText();
|
264
|
+
}
|
265
|
+
else if (this.toolController.dispatchInputEvent({
|
246
266
|
kind: InputEvtType.KeyPressEvent,
|
247
267
|
key: evt.key,
|
248
268
|
ctrlKey: evt.ctrlKey,
|
@@ -272,7 +292,7 @@ export class Editor {
|
|
272
292
|
else {
|
273
293
|
command.apply(this);
|
274
294
|
}
|
275
|
-
this.announceForAccessibility(command.description(this.localization));
|
295
|
+
this.announceForAccessibility(command.description(this, this.localization));
|
276
296
|
}
|
277
297
|
// Dispatches a command without announcing it. By default, does not add to history.
|
278
298
|
dispatchNoAnnounce(command, addToHistory = false) {
|
@@ -449,7 +469,7 @@ export class Editor {
|
|
449
469
|
viewport.resetTransform(origTransform);
|
450
470
|
editor.queueRerender();
|
451
471
|
}
|
452
|
-
description(localizationTable) {
|
472
|
+
description(_editor, localizationTable) {
|
453
473
|
return localizationTable.resizeOutputCommand(imageRect);
|
454
474
|
}
|
455
475
|
};
|
@@ -2,7 +2,7 @@ import AbstractRenderer from './rendering/renderers/AbstractRenderer';
|
|
2
2
|
import Command from './commands/Command';
|
3
3
|
import Viewport from './Viewport';
|
4
4
|
import AbstractComponent from './components/AbstractComponent';
|
5
|
-
import Rect2 from './
|
5
|
+
import Rect2 from './math/Rect2';
|
6
6
|
import RenderingCache from './rendering/caching/RenderingCache';
|
7
7
|
export declare const sortLeavesByZIndex: (leaves: Array<ImageNode>) => void;
|
8
8
|
export default class EditorImage {
|
package/dist/src/EditorImage.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
var _a;
|
2
2
|
import AbstractComponent from './components/AbstractComponent';
|
3
|
-
import Rect2 from './
|
3
|
+
import Rect2 from './math/Rect2';
|
4
4
|
import SerializableCommand from './commands/SerializableCommand';
|
5
5
|
export const sortLeavesByZIndex = (leaves) => {
|
6
6
|
leaves.sort((a, b) => a.getContent().getZIndex() - b.getContent().getZIndex());
|
@@ -83,7 +83,7 @@ EditorImage.AddElementCommand = (_a = class extends SerializableCommand {
|
|
83
83
|
container === null || container === void 0 ? void 0 : container.remove();
|
84
84
|
editor.queueRerender();
|
85
85
|
}
|
86
|
-
description(localization) {
|
86
|
+
description(editor, localization) {
|
87
87
|
return localization.addElementAction(this.element.description(localization));
|
88
88
|
}
|
89
89
|
serializeToString() {
|
package/dist/src/Pointer.d.ts
CHANGED
package/dist/src/Pointer.js
CHANGED
package/dist/src/SVGLoader.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import Rect2 from './
|
1
|
+
import Rect2 from './math/Rect2';
|
2
2
|
import { ComponentAddedListener, ImageLoader, OnDetermineExportRectListener, OnProgressListener } from './types';
|
3
3
|
export declare const defaultSVGViewRect: Rect2;
|
4
4
|
export declare const svgAttributesDataKey = "svgAttrs";
|
package/dist/src/SVGLoader.js
CHANGED
@@ -12,10 +12,10 @@ import Stroke from './components/Stroke';
|
|
12
12
|
import SVGGlobalAttributesObject from './components/SVGGlobalAttributesObject';
|
13
13
|
import Text from './components/Text';
|
14
14
|
import UnknownSVGObject from './components/UnknownSVGObject';
|
15
|
-
import Mat33 from './
|
16
|
-
import Path from './
|
17
|
-
import Rect2 from './
|
18
|
-
import { Vec2 } from './
|
15
|
+
import Mat33 from './math/Mat33';
|
16
|
+
import Path from './math/Path';
|
17
|
+
import Rect2 from './math/Rect2';
|
18
|
+
import { Vec2 } from './math/Vec2';
|
19
19
|
// Size of a loaded image if no size is specified.
|
20
20
|
export const defaultSVGViewRect = new Rect2(0, 0, 500, 500);
|
21
21
|
// Key to retrieve unrecognised attributes from an AbstractComponent
|
@@ -171,8 +171,16 @@ export default class SVGLoader {
|
|
171
171
|
if (transformProperty === '' || transformProperty === 'none') {
|
172
172
|
transformProperty = elem.style.transform || 'none';
|
173
173
|
}
|
174
|
-
// Compute transform matrix
|
175
|
-
|
174
|
+
// Compute transform matrix. Prefer the actual .style.transform
|
175
|
+
// to the computed stylesheet -- in some browsers, the computedStyles version
|
176
|
+
// can have lower precision.
|
177
|
+
let transform;
|
178
|
+
try {
|
179
|
+
transform = Mat33.fromCSSMatrix(elem.style.transform);
|
180
|
+
}
|
181
|
+
catch (_e) {
|
182
|
+
transform = Mat33.fromCSSMatrix(transformProperty);
|
183
|
+
}
|
176
184
|
const supportedAttrs = [];
|
177
185
|
const elemX = elem.getAttribute('x');
|
178
186
|
const elemY = elem.getAttribute('y');
|
package/dist/src/Viewport.d.ts
CHANGED
@@ -1,31 +1,16 @@
|
|
1
1
|
import Command from './commands/Command';
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import Rect2 from './geometry/Rect2';
|
6
|
-
import { Point2, Vec2 } from './geometry/Vec2';
|
2
|
+
import Mat33 from './math/Mat33';
|
3
|
+
import Rect2 from './math/Rect2';
|
4
|
+
import { Point2, Vec2 } from './math/Vec2';
|
7
5
|
import { StrokeDataPoint } from './types';
|
8
6
|
import { EditorNotifier } from './types';
|
9
7
|
declare type PointDataType<T extends Point2 | StrokeDataPoint | number> = T extends Point2 ? Point2 : number;
|
8
|
+
export declare abstract class ViewportTransform extends Command {
|
9
|
+
abstract readonly transform: Mat33;
|
10
|
+
}
|
10
11
|
export declare class Viewport {
|
11
12
|
private notifier;
|
12
|
-
static ViewportTransform
|
13
|
-
new (transform: Mat33): {
|
14
|
-
readonly "__#679@#inverseTransform": Mat33;
|
15
|
-
readonly transform: Mat33;
|
16
|
-
apply(editor: Editor): void;
|
17
|
-
unapply(editor: Editor): void;
|
18
|
-
description(localizationTable: CommandLocalization): string;
|
19
|
-
onDrop(_editor: Editor): void;
|
20
|
-
};
|
21
|
-
union(a: Command, b: Command): Command;
|
22
|
-
readonly empty: {
|
23
|
-
description(_localizationTable: import("./localization").EditorLocalization): string;
|
24
|
-
apply(_editor: Editor): void;
|
25
|
-
unapply(_editor: Editor): void;
|
26
|
-
onDrop(_editor: Editor): void;
|
27
|
-
};
|
28
|
-
};
|
13
|
+
private static ViewportTransform;
|
29
14
|
private transform;
|
30
15
|
private inverseTransform;
|
31
16
|
private screenRect;
|
@@ -34,6 +19,7 @@ export declare class Viewport {
|
|
34
19
|
get visibleRect(): Rect2;
|
35
20
|
screenToCanvas(screenPoint: Point2): Point2;
|
36
21
|
canvasToScreen(canvasPoint: Point2): Point2;
|
22
|
+
static transformBy(transform: Mat33): ViewportTransform;
|
37
23
|
resetTransform(newTransform?: Mat33): void;
|
38
24
|
get screenToCanvasTransform(): Mat33;
|
39
25
|
get canvasToScreenTransform(): Mat33;
|
@@ -45,7 +31,4 @@ export declare class Viewport {
|
|
45
31
|
roundPoint(point: Point2): Point2;
|
46
32
|
zoomTo(toMakeVisible: Rect2, allowZoomIn?: boolean, allowZoomOut?: boolean): Command;
|
47
33
|
}
|
48
|
-
export declare namespace Viewport {
|
49
|
-
type ViewportTransform = typeof Viewport.ViewportTransform.prototype;
|
50
|
-
}
|
51
34
|
export default Viewport;
|
package/dist/src/Viewport.js
CHANGED
@@ -11,11 +11,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
11
11
|
};
|
12
12
|
var _inverseTransform, _a;
|
13
13
|
import Command from './commands/Command';
|
14
|
-
import Mat33 from './
|
15
|
-
import Rect2 from './
|
16
|
-
import { Vec2 } from './
|
17
|
-
import Vec3 from './
|
14
|
+
import Mat33 from './math/Mat33';
|
15
|
+
import Rect2 from './math/Rect2';
|
16
|
+
import { Vec2 } from './math/Vec2';
|
17
|
+
import Vec3 from './math/Vec3';
|
18
18
|
import { EditorEventType } from './types';
|
19
|
+
export class ViewportTransform extends Command {
|
20
|
+
}
|
19
21
|
export class Viewport {
|
20
22
|
constructor(notifier) {
|
21
23
|
this.notifier = notifier;
|
@@ -35,7 +37,10 @@ export class Viewport {
|
|
35
37
|
canvasToScreen(canvasPoint) {
|
36
38
|
return this.transform.transformVec2(canvasPoint);
|
37
39
|
}
|
38
|
-
|
40
|
+
static transformBy(transform) {
|
41
|
+
return new Viewport.ViewportTransform(transform);
|
42
|
+
}
|
43
|
+
// Updates the transformation directly. Using transformBy is preferred.
|
39
44
|
// [newTransform] should map from canvas coordinates to screen coordinates.
|
40
45
|
resetTransform(newTransform = Mat33.identity) {
|
41
46
|
const oldTransform = this.transform;
|
@@ -132,7 +137,7 @@ export class Viewport {
|
|
132
137
|
}
|
133
138
|
}
|
134
139
|
// Command that translates/scales the viewport.
|
135
|
-
Viewport.ViewportTransform = (_a = class extends
|
140
|
+
Viewport.ViewportTransform = (_a = class extends ViewportTransform {
|
136
141
|
constructor(transform) {
|
137
142
|
super();
|
138
143
|
this.transform = transform;
|
@@ -149,13 +154,13 @@ Viewport.ViewportTransform = (_a = class extends Command {
|
|
149
154
|
viewport.resetTransform(viewport.transform.rightMul(__classPrivateFieldGet(this, _inverseTransform, "f")));
|
150
155
|
editor.queueRerender();
|
151
156
|
}
|
152
|
-
description(localizationTable) {
|
157
|
+
description(editor, localizationTable) {
|
153
158
|
const result = [];
|
154
159
|
// Describe the transformation's affect on the viewport (note that transformation transforms
|
155
160
|
// the **elements** within the viewport). Assumes the transformation only does rotation/scale/translation.
|
156
|
-
const origVec =
|
161
|
+
const origVec = editor.viewport.visibleRect.center;
|
157
162
|
const linearTransformedVec = this.transform.transformVec3(Vec2.unitX);
|
158
|
-
const affineTransformedVec = this.transform.transformVec2(
|
163
|
+
const affineTransformedVec = this.transform.transformVec2(origVec);
|
159
164
|
const scale = linearTransformedVec.magnitude();
|
160
165
|
const rotation = 180 / Math.PI * linearTransformedVec.angle();
|
161
166
|
const translation = affineTransformedVec.minus(origVec);
|
@@ -175,7 +180,7 @@ Viewport.ViewportTransform = (_a = class extends Command {
|
|
175
180
|
else if (translation.x < -minTranslation) {
|
176
181
|
result.push(localizationTable.movedRight);
|
177
182
|
}
|
178
|
-
if (translation.y < minTranslation) {
|
183
|
+
if (translation.y < -minTranslation) {
|
179
184
|
result.push(localizationTable.movedDown);
|
180
185
|
}
|
181
186
|
else if (translation.y > minTranslation) {
|
@@ -4,10 +4,10 @@ export declare abstract class Command {
|
|
4
4
|
abstract apply(editor: Editor): void;
|
5
5
|
abstract unapply(editor: Editor): void;
|
6
6
|
onDrop(_editor: Editor): void;
|
7
|
-
abstract description(localizationTable: EditorLocalization): string;
|
7
|
+
abstract description(editor: Editor, localizationTable: EditorLocalization): string;
|
8
8
|
static union(a: Command, b: Command): Command;
|
9
9
|
static readonly empty: {
|
10
|
-
description(_localizationTable: EditorLocalization): string;
|
10
|
+
description(_editor: Editor, _localizationTable: EditorLocalization): string;
|
11
11
|
apply(_editor: Editor): void;
|
12
12
|
unapply(_editor: Editor): void;
|
13
13
|
onDrop(_editor: Editor): void;
|
@@ -11,9 +11,9 @@ export class Command {
|
|
11
11
|
b.unapply(editor);
|
12
12
|
a.unapply(editor);
|
13
13
|
}
|
14
|
-
description(localizationTable) {
|
15
|
-
const aDescription = a.description(localizationTable);
|
16
|
-
const bDescription = b.description(localizationTable);
|
14
|
+
description(editor, localizationTable) {
|
15
|
+
const aDescription = a.description(editor, localizationTable);
|
16
|
+
const bDescription = b.description(editor, localizationTable);
|
17
17
|
if (aDescription === bDescription) {
|
18
18
|
return aDescription;
|
19
19
|
}
|
@@ -23,7 +23,7 @@ export class Command {
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
Command.empty = new class extends Command {
|
26
|
-
description(_localizationTable) { return ''; }
|
26
|
+
description(_editor, _localizationTable) { return ''; }
|
27
27
|
apply(_editor) { }
|
28
28
|
unapply(_editor) { }
|
29
29
|
};
|
@@ -9,6 +9,6 @@ export default class Duplicate extends SerializableCommand {
|
|
9
9
|
constructor(toDuplicate: AbstractComponent[]);
|
10
10
|
apply(editor: Editor): void;
|
11
11
|
unapply(editor: Editor): void;
|
12
|
-
description(localizationTable: EditorLocalization): string;
|
12
|
+
description(_editor: Editor, localizationTable: EditorLocalization): string;
|
13
13
|
protected serializeToString(): string;
|
14
14
|
}
|
@@ -14,7 +14,7 @@ export default class Duplicate extends SerializableCommand {
|
|
14
14
|
unapply(editor) {
|
15
15
|
this.reverse.apply(editor);
|
16
16
|
}
|
17
|
-
description(localizationTable) {
|
17
|
+
description(_editor, localizationTable) {
|
18
18
|
var _a;
|
19
19
|
if (this.duplicates.length === 0) {
|
20
20
|
return localizationTable.duplicatedNoElements;
|
@@ -9,6 +9,6 @@ export default class Erase extends SerializableCommand {
|
|
9
9
|
apply(editor: Editor): void;
|
10
10
|
unapply(editor: Editor): void;
|
11
11
|
onDrop(editor: Editor): void;
|
12
|
-
description(localizationTable: EditorLocalization): string;
|
12
|
+
description(_editor: Editor, localizationTable: EditorLocalization): string;
|
13
13
|
protected serializeToString(): string;
|
14
14
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import Command from '../commands/Command';
|
2
|
-
import LineSegment2 from '../
|
3
|
-
import Mat33 from '../
|
4
|
-
import Rect2 from '../
|
2
|
+
import LineSegment2 from '../math/LineSegment2';
|
3
|
+
import Mat33 from '../math/Mat33';
|
4
|
+
import Rect2 from '../math/Rect2';
|
5
5
|
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
6
6
|
import { ImageComponentLocalization } from './localization';
|
7
7
|
declare type LoadSaveData = (string[] | Record<symbol, string | number>);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
var _a;
|
2
2
|
import SerializableCommand from '../commands/SerializableCommand';
|
3
3
|
import EditorImage from '../EditorImage';
|
4
|
-
import Mat33 from '../
|
4
|
+
import Mat33 from '../math/Mat33';
|
5
5
|
export default class AbstractComponent {
|
6
6
|
constructor(
|
7
7
|
// A unique identifier for the type of component
|
@@ -132,7 +132,7 @@ AbstractComponent.TransformElementCommand = (_a = class extends SerializableComm
|
|
132
132
|
this.updateTransform(editor, this.affineTransfm.inverse());
|
133
133
|
editor.queueRerender();
|
134
134
|
}
|
135
|
-
description(localizationTable) {
|
135
|
+
description(_editor, localizationTable) {
|
136
136
|
return localizationTable.transformedElements(1);
|
137
137
|
}
|
138
138
|
serializeToString() {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import LineSegment2 from '../
|
2
|
-
import Mat33 from '../
|
3
|
-
import Rect2 from '../
|
1
|
+
import LineSegment2 from '../math/LineSegment2';
|
2
|
+
import Mat33 from '../math/Mat33';
|
3
|
+
import Rect2 from '../math/Rect2';
|
4
4
|
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
5
5
|
import AbstractComponent from './AbstractComponent';
|
6
6
|
import { ImageComponentLocalization } from './localization';
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import LineSegment2 from '../
|
2
|
-
import Mat33 from '../
|
3
|
-
import Path from '../
|
4
|
-
import Rect2 from '../
|
1
|
+
import LineSegment2 from '../math/LineSegment2';
|
2
|
+
import Mat33 from '../math/Mat33';
|
3
|
+
import Path from '../math/Path';
|
4
|
+
import Rect2 from '../math/Rect2';
|
5
5
|
import AbstractRenderer, { RenderablePathSpec } from '../rendering/renderers/AbstractRenderer';
|
6
6
|
import AbstractComponent from './AbstractComponent';
|
7
7
|
import { ImageComponentLocalization } from './localization';
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import Path from '../
|
2
|
-
import Rect2 from '../
|
1
|
+
import Path from '../math/Path';
|
2
|
+
import Rect2 from '../math/Rect2';
|
3
3
|
import { styleFromJSON, styleToJSON } from '../rendering/RenderingStyle';
|
4
4
|
import AbstractComponent from './AbstractComponent';
|
5
5
|
export default class Stroke extends AbstractComponent {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import LineSegment2 from '../
|
2
|
-
import Mat33 from '../
|
3
|
-
import Rect2 from '../
|
1
|
+
import LineSegment2 from '../math/LineSegment2';
|
2
|
+
import Mat33 from '../math/Mat33';
|
3
|
+
import Rect2 from '../math/Rect2';
|
4
4
|
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
5
5
|
import RenderingStyle from '../rendering/RenderingStyle';
|
6
6
|
import AbstractComponent from './AbstractComponent';
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import LineSegment2 from '../
|
2
|
-
import Mat33 from '../
|
3
|
-
import Rect2 from '../
|
1
|
+
import LineSegment2 from '../math/LineSegment2';
|
2
|
+
import Mat33 from '../math/Mat33';
|
3
|
+
import Rect2 from '../math/Rect2';
|
4
4
|
import { styleFromJSON, styleToJSON } from '../rendering/RenderingStyle';
|
5
5
|
import AbstractComponent from './AbstractComponent';
|
6
6
|
const componentTypeId = 'text';
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import LineSegment2 from '../
|
2
|
-
import Mat33 from '../
|
3
|
-
import Rect2 from '../
|
1
|
+
import LineSegment2 from '../math/LineSegment2';
|
2
|
+
import Mat33 from '../math/Mat33';
|
3
|
+
import Rect2 from '../math/Rect2';
|
4
4
|
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
5
5
|
import AbstractComponent from './AbstractComponent';
|
6
6
|
import { ImageComponentLocalization } from './localization';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import AbstractRenderer from '../../rendering/renderers/AbstractRenderer';
|
2
|
-
import Rect2 from '../../
|
2
|
+
import Rect2 from '../../math/Rect2';
|
3
3
|
import Stroke from '../Stroke';
|
4
4
|
import { StrokeDataPoint } from '../../types';
|
5
5
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
@@ -8,7 +8,11 @@ export default class FreehandLineBuilder implements ComponentBuilder {
|
|
8
8
|
private startPoint;
|
9
9
|
private minFitAllowed;
|
10
10
|
private maxFitAllowed;
|
11
|
-
private
|
11
|
+
private isFirstSegment;
|
12
|
+
private pathStartConnector;
|
13
|
+
private mostRecentConnector;
|
14
|
+
private upperSegments;
|
15
|
+
private lowerSegments;
|
12
16
|
private buffer;
|
13
17
|
private lastPoint;
|
14
18
|
private lastExitingVec;
|
@@ -20,7 +24,8 @@ export default class FreehandLineBuilder implements ComponentBuilder {
|
|
20
24
|
constructor(startPoint: StrokeDataPoint, minFitAllowed: number, maxFitAllowed: number);
|
21
25
|
getBBox(): Rect2;
|
22
26
|
private getRenderingStyle;
|
23
|
-
private
|
27
|
+
private previewPath;
|
28
|
+
private previewStroke;
|
24
29
|
preview(renderer: AbstractRenderer): void;
|
25
30
|
build(): Stroke;
|
26
31
|
private roundPoint;
|