js-draw 0.15.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/translation.yml +56 -0
- package/CHANGELOG.md +13 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Color4.d.ts +1 -1
- package/dist/src/Color4.js +5 -1
- package/dist/src/Editor.d.ts +11 -2
- package/dist/src/Editor.js +66 -33
- package/dist/src/EditorImage.d.ts +28 -3
- package/dist/src/EditorImage.js +109 -18
- package/dist/src/EventDispatcher.d.ts +4 -3
- package/dist/src/SVGLoader.d.ts +1 -0
- package/dist/src/SVGLoader.js +15 -1
- package/dist/src/Viewport.d.ts +8 -3
- package/dist/src/Viewport.js +15 -8
- package/dist/src/components/AbstractComponent.d.ts +6 -1
- package/dist/src/components/AbstractComponent.js +15 -2
- package/dist/src/components/ImageBackground.d.ts +42 -0
- package/dist/src/components/ImageBackground.js +139 -0
- package/dist/src/components/ImageComponent.js +2 -0
- package/dist/src/components/builders/ArrowBuilder.d.ts +3 -1
- package/dist/src/components/builders/ArrowBuilder.js +43 -40
- package/dist/src/components/builders/LineBuilder.d.ts +3 -1
- package/dist/src/components/builders/LineBuilder.js +25 -28
- package/dist/src/components/builders/RectangleBuilder.js +1 -1
- package/dist/src/components/lib.d.ts +2 -1
- package/dist/src/components/lib.js +2 -1
- package/dist/src/components/localization.d.ts +2 -0
- package/dist/src/components/localization.js +2 -0
- package/dist/src/localizations/es.js +1 -1
- package/dist/src/math/Mat33.js +43 -5
- package/dist/src/math/Path.d.ts +5 -0
- package/dist/src/math/Path.js +80 -28
- package/dist/src/math/Vec3.js +1 -1
- package/dist/src/rendering/Display.js +1 -1
- package/dist/src/rendering/renderers/AbstractRenderer.d.ts +13 -1
- package/dist/src/rendering/renderers/AbstractRenderer.js +18 -3
- package/dist/src/rendering/renderers/CanvasRenderer.d.ts +2 -1
- package/dist/src/rendering/renderers/CanvasRenderer.js +12 -2
- package/dist/src/rendering/renderers/SVGRenderer.d.ts +1 -1
- package/dist/src/rendering/renderers/SVGRenderer.js +8 -2
- package/dist/src/testing/sendTouchEvent.d.ts +6 -0
- package/dist/src/testing/sendTouchEvent.js +26 -0
- package/dist/src/toolbar/HTMLToolbar.d.ts +25 -2
- package/dist/src/toolbar/HTMLToolbar.js +127 -15
- package/dist/src/toolbar/IconProvider.d.ts +2 -0
- package/dist/src/toolbar/IconProvider.js +45 -2
- package/dist/src/toolbar/localization.d.ts +5 -0
- package/dist/src/toolbar/localization.js +5 -0
- package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +3 -1
- package/dist/src/toolbar/widgets/ActionButtonWidget.js +5 -1
- package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +1 -1
- package/dist/src/toolbar/widgets/BaseToolWidget.js +2 -1
- package/dist/src/toolbar/widgets/BaseWidget.d.ts +7 -2
- package/dist/src/toolbar/widgets/BaseWidget.js +23 -1
- package/dist/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +19 -0
- package/dist/src/toolbar/widgets/DocumentPropertiesWidget.js +135 -0
- package/dist/src/toolbar/widgets/HandToolWidget.js +1 -1
- package/dist/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
- package/dist/src/toolbar/widgets/OverflowWidget.js +65 -0
- package/dist/src/toolbar/widgets/lib.d.ts +1 -0
- package/dist/src/toolbar/widgets/lib.js +1 -0
- package/dist/src/tools/Eraser.js +5 -2
- package/dist/src/tools/PanZoom.js +12 -0
- package/dist/src/tools/PasteHandler.js +2 -2
- package/dist/src/tools/SelectionTool/Selection.d.ts +2 -1
- package/dist/src/tools/SelectionTool/Selection.js +3 -2
- package/dist/src/tools/SelectionTool/SelectionTool.js +5 -1
- package/package.json +1 -1
- package/src/Color4.test.ts +6 -0
- package/src/Color4.ts +6 -1
- package/src/Editor.loadFrom.test.ts +24 -0
- package/src/Editor.ts +73 -39
- package/src/EditorImage.ts +136 -21
- package/src/EventDispatcher.ts +4 -1
- package/src/SVGLoader.ts +12 -1
- package/src/Viewport.ts +17 -7
- package/src/components/AbstractComponent.ts +17 -1
- package/src/components/ImageBackground.test.ts +35 -0
- package/src/components/ImageBackground.ts +176 -0
- package/src/components/ImageComponent.ts +2 -0
- package/src/components/builders/ArrowBuilder.ts +44 -41
- package/src/components/builders/LineBuilder.ts +26 -28
- package/src/components/builders/RectangleBuilder.ts +1 -1
- package/src/components/lib.ts +2 -0
- package/src/components/localization.ts +4 -0
- package/src/localizations/es.ts +8 -0
- package/src/math/Mat33.test.ts +47 -3
- package/src/math/Mat33.ts +47 -5
- package/src/math/Path.ts +87 -28
- package/src/math/Vec3.test.ts +4 -0
- package/src/math/Vec3.ts +1 -1
- package/src/rendering/Display.ts +1 -1
- package/src/rendering/renderers/AbstractRenderer.ts +20 -3
- package/src/rendering/renderers/CanvasRenderer.ts +17 -4
- package/src/rendering/renderers/DummyRenderer.test.ts +1 -2
- package/src/rendering/renderers/SVGRenderer.ts +8 -1
- package/src/testing/sendTouchEvent.ts +43 -0
- package/src/toolbar/HTMLToolbar.ts +164 -16
- package/src/toolbar/IconProvider.ts +47 -2
- package/src/toolbar/localization.ts +10 -0
- package/src/toolbar/toolbar.css +2 -0
- package/src/toolbar/widgets/ActionButtonWidget.ts +5 -0
- package/src/toolbar/widgets/BaseToolWidget.ts +3 -1
- package/src/toolbar/widgets/BaseWidget.ts +34 -2
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +185 -0
- package/src/toolbar/widgets/HandToolWidget.ts +1 -1
- package/src/toolbar/widgets/OverflowWidget.css +9 -0
- package/src/toolbar/widgets/OverflowWidget.ts +83 -0
- package/src/toolbar/widgets/lib.ts +2 -1
- package/src/tools/Eraser.test.ts +24 -1
- package/src/tools/Eraser.ts +6 -2
- package/src/tools/PanZoom.test.ts +267 -23
- package/src/tools/PanZoom.ts +15 -1
- package/src/tools/PasteHandler.ts +3 -2
- package/src/tools/SelectionTool/Selection.ts +3 -2
- package/src/tools/SelectionTool/SelectionTool.ts +6 -1
- package/src/types.ts +1 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
import Color4 from '../Color4';
|
2
|
+
import Editor from '../Editor';
|
3
|
+
import EditorImage, { EditorImageEventType } from '../EditorImage';
|
4
|
+
import { DispatcherEventListener } from '../EventDispatcher';
|
5
|
+
import SerializableCommand from '../commands/SerializableCommand';
|
6
|
+
import LineSegment2 from '../math/LineSegment2';
|
7
|
+
import Mat33 from '../math/Mat33';
|
8
|
+
import Rect2 from '../math/Rect2';
|
9
|
+
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
10
|
+
import AbstractComponent from './AbstractComponent';
|
11
|
+
import { ImageComponentLocalization } from './localization';
|
12
|
+
import RestyleableComponent, { ComponentStyle, createRestyleComponentCommand } from './RestylableComponent';
|
13
|
+
|
14
|
+
export enum BackgroundType {
|
15
|
+
SolidColor,
|
16
|
+
None,
|
17
|
+
}
|
18
|
+
|
19
|
+
export const imageBackgroundCSSClassName = 'js-draw-image-background';
|
20
|
+
|
21
|
+
// Represents the background of an image in the editor.
|
22
|
+
export default class ImageBackground extends AbstractComponent implements RestyleableComponent {
|
23
|
+
protected contentBBox: Rect2;
|
24
|
+
private viewportSizeChangeListener: DispatcherEventListener|null = null;
|
25
|
+
|
26
|
+
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
27
|
+
readonly isRestylableComponent: true = true;
|
28
|
+
|
29
|
+
public constructor(
|
30
|
+
private backgroundType: BackgroundType, private mainColor: Color4
|
31
|
+
) {
|
32
|
+
super('image-background', 0);
|
33
|
+
this.contentBBox = Rect2.empty;
|
34
|
+
}
|
35
|
+
|
36
|
+
public getStyle(): ComponentStyle {
|
37
|
+
let color: Color4|undefined = this.mainColor;
|
38
|
+
|
39
|
+
if (this.backgroundType === BackgroundType.None) {
|
40
|
+
color = undefined;
|
41
|
+
}
|
42
|
+
|
43
|
+
return {
|
44
|
+
color,
|
45
|
+
};
|
46
|
+
}
|
47
|
+
|
48
|
+
public updateStyle(style: ComponentStyle): SerializableCommand {
|
49
|
+
return createRestyleComponentCommand(this.getStyle(), style, this);
|
50
|
+
}
|
51
|
+
|
52
|
+
// @internal
|
53
|
+
public forceStyle(style: ComponentStyle, editor: Editor | null): void {
|
54
|
+
const fill = style.color;
|
55
|
+
|
56
|
+
if (!fill) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
this.mainColor = fill;
|
61
|
+
if (fill.eq(Color4.transparent)) {
|
62
|
+
this.backgroundType = BackgroundType.None;
|
63
|
+
} else {
|
64
|
+
this.backgroundType = BackgroundType.SolidColor;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (editor) {
|
68
|
+
editor.image.queueRerenderOf(this);
|
69
|
+
editor.queueRerender();
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
public onAddToImage(image: EditorImage) {
|
74
|
+
if (this.viewportSizeChangeListener) {
|
75
|
+
console.warn('onAddToImage called when background is already in an image');
|
76
|
+
this.onRemoveFromImage();
|
77
|
+
}
|
78
|
+
|
79
|
+
this.viewportSizeChangeListener = image.notifier.on(
|
80
|
+
EditorImageEventType.ExportViewportChanged, () => {
|
81
|
+
this.recomputeBBox(image);
|
82
|
+
});
|
83
|
+
this.recomputeBBox(image);
|
84
|
+
}
|
85
|
+
|
86
|
+
public onRemoveFromImage(): void {
|
87
|
+
this.viewportSizeChangeListener?.remove();
|
88
|
+
this.viewportSizeChangeListener = null;
|
89
|
+
}
|
90
|
+
|
91
|
+
private recomputeBBox(image: EditorImage) {
|
92
|
+
const importExportRect = image.getImportExportViewport().visibleRect;
|
93
|
+
if (!this.contentBBox.eq(importExportRect)) {
|
94
|
+
this.contentBBox = importExportRect;
|
95
|
+
|
96
|
+
// Re-render this if already added to the EditorImage.
|
97
|
+
image.queueRerenderOf(this);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
public render(canvas: AbstractRenderer, visibleRect?: Rect2) {
|
102
|
+
if (this.backgroundType === BackgroundType.None) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
canvas.startObject(this.contentBBox);
|
106
|
+
|
107
|
+
if (this.backgroundType === BackgroundType.SolidColor) {
|
108
|
+
// If the rectangle for this region contains the visible rect,
|
109
|
+
// we can fill the entire visible rectangle (which may be more efficient than
|
110
|
+
// filling the entire region for this.)
|
111
|
+
if (visibleRect) {
|
112
|
+
const intersection = visibleRect.intersection(this.contentBBox);
|
113
|
+
if (intersection) {
|
114
|
+
canvas.fillRect(intersection, this.mainColor);
|
115
|
+
}
|
116
|
+
} else {
|
117
|
+
canvas.fillRect(this.contentBBox, this.mainColor);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
canvas.endObject(this.getLoadSaveData(), [ imageBackgroundCSSClassName ]);
|
122
|
+
}
|
123
|
+
|
124
|
+
public intersects(lineSegment: LineSegment2): boolean {
|
125
|
+
return this.contentBBox.getEdges().some(edge => edge.intersects(lineSegment));
|
126
|
+
}
|
127
|
+
|
128
|
+
public isSelectable(): boolean {
|
129
|
+
return false;
|
130
|
+
}
|
131
|
+
|
132
|
+
public isBackground(): boolean {
|
133
|
+
return true;
|
134
|
+
}
|
135
|
+
|
136
|
+
protected serializeToJSON() {
|
137
|
+
return {
|
138
|
+
mainColor: this.mainColor.toHexString(),
|
139
|
+
backgroundType: this.backgroundType,
|
140
|
+
};
|
141
|
+
}
|
142
|
+
|
143
|
+
protected applyTransformation(_affineTransfm: Mat33) {
|
144
|
+
// Do nothing — it doesn't make sense to transform the background.
|
145
|
+
}
|
146
|
+
|
147
|
+
public description(localizationTable: ImageComponentLocalization) {
|
148
|
+
if (this.backgroundType === BackgroundType.SolidColor) {
|
149
|
+
return localizationTable.filledBackgroundWithColor(this.mainColor.toString());
|
150
|
+
} else {
|
151
|
+
return localizationTable.emptyBackground;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
protected createClone(): AbstractComponent {
|
156
|
+
return new ImageBackground(this.backgroundType, this.mainColor);
|
157
|
+
}
|
158
|
+
|
159
|
+
// @internal
|
160
|
+
public static deserializeFromJSON(json: any) {
|
161
|
+
if (typeof json === 'string') {
|
162
|
+
json = JSON.parse(json);
|
163
|
+
}
|
164
|
+
|
165
|
+
if (typeof json.mainColor !== 'string') {
|
166
|
+
throw new Error('Error deserializing — mainColor must be of type string.');
|
167
|
+
}
|
168
|
+
|
169
|
+
const backgroundType = json.backgroundType === BackgroundType.SolidColor ? BackgroundType.SolidColor : BackgroundType.None;
|
170
|
+
const mainColor = Color4.fromHex(json.mainColor);
|
171
|
+
|
172
|
+
return new ImageBackground(backgroundType, mainColor);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
AbstractComponent.registerComponent('image-background', ImageBackground.deserializeFromJSON);
|
@@ -88,7 +88,9 @@ export default class ImageComponent extends AbstractComponent {
|
|
88
88
|
}
|
89
89
|
|
90
90
|
public render(canvas: AbstractRenderer, _visibleRect?: Rect2): void {
|
91
|
+
canvas.startObject(this.contentBBox);
|
91
92
|
canvas.drawImage(this.image);
|
93
|
+
canvas.endObject(this.getLoadSaveData());
|
92
94
|
}
|
93
95
|
|
94
96
|
public getProportionalRenderingTime(): number {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PathCommandType } from '../../math/Path';
|
1
|
+
import Path, { PathCommandType } from '../../math/Path';
|
2
2
|
import Rect2 from '../../math/Rect2';
|
3
3
|
import AbstractRenderer from '../../rendering/renderers/AbstractRenderer';
|
4
4
|
import { StrokeDataPoint } from '../../types';
|
@@ -7,14 +7,14 @@ import AbstractComponent from '../AbstractComponent';
|
|
7
7
|
import Stroke from '../Stroke';
|
8
8
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
9
9
|
|
10
|
-
export const makeArrowBuilder: ComponentBuilderFactory = (initialPoint: StrokeDataPoint,
|
11
|
-
return new ArrowBuilder(initialPoint);
|
10
|
+
export const makeArrowBuilder: ComponentBuilderFactory = (initialPoint: StrokeDataPoint, viewport: Viewport) => {
|
11
|
+
return new ArrowBuilder(initialPoint, viewport);
|
12
12
|
};
|
13
13
|
|
14
14
|
export default class ArrowBuilder implements ComponentBuilder {
|
15
15
|
private endPoint: StrokeDataPoint;
|
16
16
|
|
17
|
-
public constructor(private readonly startPoint: StrokeDataPoint) {
|
17
|
+
public constructor(private readonly startPoint: StrokeDataPoint, private readonly viewport: Viewport) {
|
18
18
|
this.endPoint = startPoint;
|
19
19
|
}
|
20
20
|
|
@@ -28,10 +28,10 @@ export default class ArrowBuilder implements ComponentBuilder {
|
|
28
28
|
}
|
29
29
|
|
30
30
|
private buildPreview(): Stroke {
|
31
|
-
const
|
31
|
+
const lineStartPoint = this.startPoint.pos;
|
32
32
|
const endPoint = this.endPoint.pos;
|
33
|
-
const toEnd = endPoint.minus(
|
34
|
-
const arrowLength = endPoint.minus(
|
33
|
+
const toEnd = endPoint.minus(lineStartPoint).normalized();
|
34
|
+
const arrowLength = endPoint.minus(lineStartPoint).length();
|
35
35
|
|
36
36
|
// Ensure that the arrow tip is smaller than the arrow.
|
37
37
|
const arrowTipSize = Math.min(this.getLineWidth(), arrowLength / 2);
|
@@ -45,42 +45,45 @@ export default class ArrowBuilder implements ComponentBuilder {
|
|
45
45
|
const scaledStartNormal = lineNormal.times(startSize);
|
46
46
|
const scaledBaseNormal = lineNormal.times(endSize);
|
47
47
|
|
48
|
+
const path = new Path(arrowTipBase.minus(scaledBaseNormal), [
|
49
|
+
// Stem
|
50
|
+
{
|
51
|
+
kind: PathCommandType.LineTo,
|
52
|
+
point: lineStartPoint.minus(scaledStartNormal),
|
53
|
+
},
|
54
|
+
{
|
55
|
+
kind: PathCommandType.LineTo,
|
56
|
+
point: lineStartPoint.plus(scaledStartNormal),
|
57
|
+
},
|
58
|
+
{
|
59
|
+
kind: PathCommandType.LineTo,
|
60
|
+
point: arrowTipBase.plus(scaledBaseNormal),
|
61
|
+
},
|
62
|
+
|
63
|
+
// Head
|
64
|
+
{
|
65
|
+
kind: PathCommandType.LineTo,
|
66
|
+
point: arrowTipBase.plus(lineNormal.times(arrowTipSize).plus(scaledBaseNormal)),
|
67
|
+
},
|
68
|
+
{
|
69
|
+
kind: PathCommandType.LineTo,
|
70
|
+
point: endPoint.plus(toEnd.times(endSize)),
|
71
|
+
},
|
72
|
+
{
|
73
|
+
kind: PathCommandType.LineTo,
|
74
|
+
point: arrowTipBase.plus(lineNormal.times(-arrowTipSize).minus(scaledBaseNormal)),
|
75
|
+
},
|
76
|
+
{
|
77
|
+
kind: PathCommandType.LineTo,
|
78
|
+
point: arrowTipBase.minus(scaledBaseNormal),
|
79
|
+
},
|
80
|
+
// Round all points in the arrow (to remove unnecessary decimal places)
|
81
|
+
]).mapPoints(point => this.viewport.roundPoint(point));
|
82
|
+
|
48
83
|
const preview = new Stroke([
|
49
84
|
{
|
50
|
-
startPoint:
|
51
|
-
commands:
|
52
|
-
// Stem
|
53
|
-
{
|
54
|
-
kind: PathCommandType.LineTo,
|
55
|
-
point: startPoint.minus(scaledStartNormal),
|
56
|
-
},
|
57
|
-
{
|
58
|
-
kind: PathCommandType.LineTo,
|
59
|
-
point: startPoint.plus(scaledStartNormal),
|
60
|
-
},
|
61
|
-
{
|
62
|
-
kind: PathCommandType.LineTo,
|
63
|
-
point: arrowTipBase.plus(scaledBaseNormal),
|
64
|
-
},
|
65
|
-
|
66
|
-
// Head
|
67
|
-
{
|
68
|
-
kind: PathCommandType.LineTo,
|
69
|
-
point: arrowTipBase.plus(lineNormal.times(arrowTipSize).plus(scaledBaseNormal))
|
70
|
-
},
|
71
|
-
{
|
72
|
-
kind: PathCommandType.LineTo,
|
73
|
-
point: endPoint.plus(toEnd.times(endSize)),
|
74
|
-
},
|
75
|
-
{
|
76
|
-
kind: PathCommandType.LineTo,
|
77
|
-
point: arrowTipBase.plus(lineNormal.times(-arrowTipSize).minus(scaledBaseNormal)),
|
78
|
-
},
|
79
|
-
{
|
80
|
-
kind: PathCommandType.LineTo,
|
81
|
-
point: arrowTipBase.minus(scaledBaseNormal),
|
82
|
-
},
|
83
|
-
],
|
85
|
+
startPoint: path.startPoint,
|
86
|
+
commands: path.parts,
|
84
87
|
style: {
|
85
88
|
fill: this.startPoint.color,
|
86
89
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PathCommandType } from '../../math/Path';
|
1
|
+
import Path, { PathCommandType } from '../../math/Path';
|
2
2
|
import Rect2 from '../../math/Rect2';
|
3
3
|
import AbstractRenderer from '../../rendering/renderers/AbstractRenderer';
|
4
4
|
import { StrokeDataPoint } from '../../types';
|
@@ -7,14 +7,14 @@ import AbstractComponent from '../AbstractComponent';
|
|
7
7
|
import Stroke from '../Stroke';
|
8
8
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
9
9
|
|
10
|
-
export const makeLineBuilder: ComponentBuilderFactory = (initialPoint: StrokeDataPoint,
|
11
|
-
return new LineBuilder(initialPoint);
|
10
|
+
export const makeLineBuilder: ComponentBuilderFactory = (initialPoint: StrokeDataPoint, viewport: Viewport) => {
|
11
|
+
return new LineBuilder(initialPoint, viewport);
|
12
12
|
};
|
13
13
|
|
14
14
|
export default class LineBuilder implements ComponentBuilder {
|
15
15
|
private endPoint: StrokeDataPoint;
|
16
16
|
|
17
|
-
public constructor(private readonly startPoint: StrokeDataPoint) {
|
17
|
+
public constructor(private readonly startPoint: StrokeDataPoint, private readonly viewport: Viewport) {
|
18
18
|
this.endPoint = startPoint;
|
19
19
|
}
|
20
20
|
|
@@ -35,31 +35,29 @@ export default class LineBuilder implements ComponentBuilder {
|
|
35
35
|
const scaledStartNormal = lineNormal.times(startSize);
|
36
36
|
const scaledEndNormal = lineNormal.times(endSize);
|
37
37
|
|
38
|
-
const
|
38
|
+
const strokeStartPoint = startPoint.minus(scaledStartNormal);
|
39
|
+
|
40
|
+
const path = new Path(strokeStartPoint, [
|
41
|
+
{
|
42
|
+
kind: PathCommandType.LineTo,
|
43
|
+
point: startPoint.plus(scaledStartNormal),
|
44
|
+
},
|
45
|
+
{
|
46
|
+
kind: PathCommandType.LineTo,
|
47
|
+
point: endPoint.plus(scaledEndNormal),
|
48
|
+
},
|
39
49
|
{
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
kind: PathCommandType.LineTo,
|
52
|
-
point: endPoint.minus(scaledEndNormal),
|
53
|
-
},
|
54
|
-
{
|
55
|
-
kind: PathCommandType.LineTo,
|
56
|
-
point: startPoint.minus(scaledStartNormal),
|
57
|
-
},
|
58
|
-
],
|
59
|
-
style: {
|
60
|
-
fill: this.startPoint.color,
|
61
|
-
}
|
62
|
-
}
|
50
|
+
kind: PathCommandType.LineTo,
|
51
|
+
point: endPoint.minus(scaledEndNormal),
|
52
|
+
},
|
53
|
+
{
|
54
|
+
kind: PathCommandType.LineTo,
|
55
|
+
point: startPoint.minus(scaledStartNormal),
|
56
|
+
},
|
57
|
+
]).mapPoints(point => this.viewport.roundPoint(point));
|
58
|
+
|
59
|
+
const preview = new Stroke([
|
60
|
+
path.toRenderable({ fill: this.startPoint.color })
|
63
61
|
]);
|
64
62
|
|
65
63
|
return preview;
|
@@ -49,7 +49,7 @@ export default class RectangleBuilder implements ComponentBuilder {
|
|
49
49
|
).transformedBy(
|
50
50
|
// Rotate the canvas rectangle so that its rotation matches the screen
|
51
51
|
rotationMat
|
52
|
-
);
|
52
|
+
).mapPoints(point => this.viewport.roundPoint(point));
|
53
53
|
|
54
54
|
const preview = new Stroke([
|
55
55
|
path.toRenderable({
|
package/src/components/lib.ts
CHANGED
@@ -9,6 +9,7 @@ import Stroke from './Stroke';
|
|
9
9
|
import TextComponent from './TextComponent';
|
10
10
|
import ImageComponent from './ImageComponent';
|
11
11
|
import RestyleableComponent, { createRestyleComponentCommand } from './RestylableComponent';
|
12
|
+
import ImageBackground from './ImageBackground';
|
12
13
|
|
13
14
|
export {
|
14
15
|
Stroke,
|
@@ -18,5 +19,6 @@ export {
|
|
18
19
|
|
19
20
|
TextComponent,
|
20
21
|
Stroke as StrokeComponent,
|
22
|
+
ImageBackground as BackgroundComponent,
|
21
23
|
ImageComponent,
|
22
24
|
};
|
@@ -4,6 +4,8 @@ export interface ImageComponentLocalization {
|
|
4
4
|
imageNode: (description: string)=> string;
|
5
5
|
stroke: string;
|
6
6
|
svgObject: string;
|
7
|
+
emptyBackground: string;
|
8
|
+
filledBackgroundWithColor: (color: string)=> string;
|
7
9
|
|
8
10
|
restyledElements: string;
|
9
11
|
}
|
@@ -13,6 +15,8 @@ export const defaultComponentLocalization: ImageComponentLocalization = {
|
|
13
15
|
stroke: 'Stroke',
|
14
16
|
svgObject: 'SVG Object',
|
15
17
|
restyledElements: 'Restyled elements',
|
18
|
+
emptyBackground: 'Empty background',
|
19
|
+
filledBackgroundWithColor: (color) => `Filled background (${color})`,
|
16
20
|
text: (text) => `Text object: ${text}`,
|
17
21
|
imageNode: (description: string) => `Image: ${description}`,
|
18
22
|
};
|
package/src/localizations/es.ts
CHANGED
@@ -57,10 +57,18 @@ const localization: EditorLocalization = {
|
|
57
57
|
eraserTool: 'Borrador',
|
58
58
|
textTool: 'Texto',
|
59
59
|
enterTextToInsert: 'Entra texto',
|
60
|
+
textSize: 'Tamaño',
|
60
61
|
rerenderAsText: 'Redibuja la pantalla al texto',
|
62
|
+
lockRotation: 'Bloquea rotación',
|
61
63
|
image: 'Imagen',
|
62
64
|
imageSize: (size: number, units: string) => `Tamaño del imagen: ${size} ${units}`,
|
63
65
|
imageLoadError: (message: string)=> `Error cargando imagen: ${message}`,
|
66
|
+
toggleOverflow: 'Más',
|
67
|
+
|
68
|
+
documentProperties: 'Fondo',
|
69
|
+
imageWidthOption: 'Ancho: ',
|
70
|
+
imageHeightOption: 'Alto: ',
|
71
|
+
backgroundColor: 'Color de fondo: '
|
64
72
|
};
|
65
73
|
|
66
74
|
export default localization;
|
package/src/math/Mat33.test.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import Mat33 from './Mat33';
|
2
|
-
import { Vec2 } from './Vec2';
|
2
|
+
import { Point2, Vec2 } from './Vec2';
|
3
3
|
import Vec3 from './Vec3';
|
4
4
|
|
5
5
|
|
@@ -72,7 +72,7 @@ describe('Mat33 tests', () => {
|
|
72
72
|
});
|
73
73
|
|
74
74
|
it('90 degree z-rotation matricies should rotate 90 degrees counter clockwise', () => {
|
75
|
-
const fuzz = 0.
|
75
|
+
const fuzz = 0.001;
|
76
76
|
|
77
77
|
const M = Mat33.zRotation(Math.PI / 2);
|
78
78
|
const rotated = M.transformVec2(Vec2.unitX);
|
@@ -80,6 +80,18 @@ describe('Mat33 tests', () => {
|
|
80
80
|
expect(M.transformVec2(rotated)).objEq(Vec2.unitX.times(-1), fuzz);
|
81
81
|
});
|
82
82
|
|
83
|
+
it('z-rotation matricies should preserve the given origin', () => {
|
84
|
+
const testPairs: Array<[number, Vec2]> = [
|
85
|
+
[ Math.PI / 2, Vec2.zero ],
|
86
|
+
[ -Math.PI / 2, Vec2.zero ],
|
87
|
+
[ -Math.PI / 2, Vec2.of(10, 10) ],
|
88
|
+
];
|
89
|
+
|
90
|
+
for (const [ angle, center ] of testPairs) {
|
91
|
+
expect(Mat33.zRotation(angle, center).transformVec2(center)).objEq(center);
|
92
|
+
}
|
93
|
+
});
|
94
|
+
|
83
95
|
it('translation matricies should translate Vec2s', () => {
|
84
96
|
const fuzz = 0.01;
|
85
97
|
|
@@ -118,7 +130,7 @@ describe('Mat33 tests', () => {
|
|
118
130
|
|
119
131
|
const starterTransform = new Mat33(
|
120
132
|
-0.2588190451025205, -0.9659258262890688, 923.7645204565603,
|
121
|
-
0.9659258262890688,
|
133
|
+
0.9659258262890688, -0.2588190451025205, -49.829447083761465,
|
122
134
|
0, 0, 1
|
123
135
|
);
|
124
136
|
expect(starterTransform.invertable()).toBe(true);
|
@@ -140,6 +152,38 @@ describe('Mat33 tests', () => {
|
|
140
152
|
).objEq(Vec2.unitX, fuzz);
|
141
153
|
});
|
142
154
|
|
155
|
+
it('z-rotation matrix inverses should undo the z-rotation', () => {
|
156
|
+
const testCases: Array<[ number, Point2 ]> = [
|
157
|
+
[ Math.PI / 2, Vec2.zero ],
|
158
|
+
[ Math.PI, Vec2.of(1, 1) ],
|
159
|
+
[ -Math.PI, Vec2.of(1, 1) ],
|
160
|
+
[ -Math.PI * 2, Vec2.of(1, 1) ],
|
161
|
+
[ -Math.PI * 2, Vec2.of(123, 456) ],
|
162
|
+
[ -Math.PI / 4, Vec2.of(123, 456) ],
|
163
|
+
[ 0.1, Vec2.of(1, 2) ],
|
164
|
+
];
|
165
|
+
|
166
|
+
const fuzz = 0.00001;
|
167
|
+
for (const [ angle, center ] of testCases) {
|
168
|
+
const mat = Mat33.zRotation(angle, center);
|
169
|
+
expect(mat.inverse().rightMul(mat)).objEq(Mat33.identity, fuzz);
|
170
|
+
expect(mat.rightMul(mat.inverse())).objEq(Mat33.identity, fuzz);
|
171
|
+
}
|
172
|
+
});
|
173
|
+
|
174
|
+
it('z-rotation should preserve given origin', () => {
|
175
|
+
const testCases: Array<[ number, Point2 ]> = [
|
176
|
+
[ 6.205048847547065, Vec2.of(75.16363373235318, 104.29870408043762) ],
|
177
|
+
[ 1.234, Vec2.of(-56, 789) ],
|
178
|
+
[ -Math.PI, Vec2.of(-56, 789) ],
|
179
|
+
[ -Math.PI / 2, Vec2.of(-0.001, 1.0002) ],
|
180
|
+
];
|
181
|
+
|
182
|
+
for (const [angle, rotationOrigin] of testCases) {
|
183
|
+
expect(Mat33.zRotation(angle, rotationOrigin).transformVec2(rotationOrigin)).objEq(rotationOrigin);
|
184
|
+
}
|
185
|
+
});
|
186
|
+
|
143
187
|
it('should correctly apply a mapping to all components', () => {
|
144
188
|
expect(
|
145
189
|
new Mat33(
|
package/src/math/Mat33.ts
CHANGED
@@ -240,11 +240,49 @@ export default class Mat33 {
|
|
240
240
|
}
|
241
241
|
|
242
242
|
public toString(): string {
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
243
|
+
let result = '';
|
244
|
+
const maxColumnLens = [ 0, 0, 0 ];
|
245
|
+
|
246
|
+
// Determine the longest item in each column so we can pad the others to that
|
247
|
+
// length.
|
248
|
+
for (const row of this.rows) {
|
249
|
+
for (let i = 0; i < 3; i++) {
|
250
|
+
maxColumnLens[i] = Math.max(maxColumnLens[0], `${row.at(i)}`.length);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
for (let i = 0; i < 3; i++) {
|
255
|
+
if (i === 0) {
|
256
|
+
result += '⎡ ';
|
257
|
+
} else if (i === 1) {
|
258
|
+
result += '⎢ ';
|
259
|
+
} else {
|
260
|
+
result += '⎣ ';
|
261
|
+
}
|
262
|
+
|
263
|
+
// Add each component of the ith row (after padding it)
|
264
|
+
for (let j = 0; j < 3; j++) {
|
265
|
+
const val = this.rows[i].at(j).toString();
|
266
|
+
|
267
|
+
let padding = '';
|
268
|
+
for (let i = val.length; i < maxColumnLens[j]; i++) {
|
269
|
+
padding += ' ';
|
270
|
+
}
|
271
|
+
|
272
|
+
result += val + ', ' + padding;
|
273
|
+
}
|
274
|
+
|
275
|
+
if (i === 0) {
|
276
|
+
result += ' ⎤';
|
277
|
+
} else if (i === 1) {
|
278
|
+
result += ' ⎥';
|
279
|
+
} else {
|
280
|
+
result += ' ⎦';
|
281
|
+
}
|
282
|
+
result += '\n';
|
283
|
+
}
|
284
|
+
|
285
|
+
return result.trimEnd();
|
248
286
|
}
|
249
287
|
|
250
288
|
/**
|
@@ -302,6 +340,10 @@ export default class Mat33 {
|
|
302
340
|
}
|
303
341
|
|
304
342
|
public static zRotation(radians: number, center: Point2 = Vec2.zero): Mat33 {
|
343
|
+
if (radians === 0) {
|
344
|
+
return Mat33.identity;
|
345
|
+
}
|
346
|
+
|
305
347
|
const cos = Math.cos(radians);
|
306
348
|
const sin = Math.sin(radians);
|
307
349
|
|