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
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Bezier } from 'bezier-js';
|
2
|
-
import { Vec2 } from '../../
|
3
|
-
import Rect2 from '../../
|
4
|
-
import { PathCommandType } from '../../
|
5
|
-
import LineSegment2 from '../../
|
2
|
+
import { Vec2 } from '../../math/Vec2';
|
3
|
+
import Rect2 from '../../math/Rect2';
|
4
|
+
import { PathCommandType } from '../../math/Path';
|
5
|
+
import LineSegment2 from '../../math/LineSegment2';
|
6
6
|
import Stroke from '../Stroke';
|
7
7
|
import Viewport from '../../Viewport';
|
8
8
|
export const makeFreehandLineBuilder = (initialPoint, viewport) => {
|
@@ -24,9 +24,13 @@ export default class FreehandLineBuilder {
|
|
24
24
|
this.startPoint = startPoint;
|
25
25
|
this.minFitAllowed = minFitAllowed;
|
26
26
|
this.maxFitAllowed = maxFitAllowed;
|
27
|
+
this.isFirstSegment = true;
|
28
|
+
this.pathStartConnector = null;
|
29
|
+
this.mostRecentConnector = null;
|
27
30
|
this.currentCurve = null;
|
28
31
|
this.lastPoint = this.startPoint;
|
29
|
-
this.
|
32
|
+
this.upperSegments = [];
|
33
|
+
this.lowerSegments = [];
|
30
34
|
this.buffer = [this.startPoint.pos];
|
31
35
|
this.momentum = Vec2.zero;
|
32
36
|
this.currentCurve = null;
|
@@ -41,24 +45,81 @@ export default class FreehandLineBuilder {
|
|
41
45
|
fill: (_a = this.lastPoint.color) !== null && _a !== void 0 ? _a : null,
|
42
46
|
};
|
43
47
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
previewPath() {
|
49
|
+
var _a;
|
50
|
+
let upperPath;
|
51
|
+
let lowerPath;
|
52
|
+
let lowerToUpperCap;
|
53
|
+
let pathStartConnector;
|
54
|
+
if (this.currentCurve) {
|
55
|
+
const { upperCurve, lowerToUpperConnector, upperToLowerConnector, lowerCurve } = this.currentSegmentToPath();
|
56
|
+
upperPath = this.upperSegments.concat(upperCurve);
|
57
|
+
lowerPath = this.lowerSegments.concat(lowerCurve);
|
58
|
+
lowerToUpperCap = lowerToUpperConnector;
|
59
|
+
pathStartConnector = (_a = this.pathStartConnector) !== null && _a !== void 0 ? _a : upperToLowerConnector;
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
if (this.mostRecentConnector === null || this.pathStartConnector === null) {
|
63
|
+
return null;
|
64
|
+
}
|
65
|
+
upperPath = this.upperSegments.slice();
|
66
|
+
lowerPath = this.lowerSegments.slice();
|
67
|
+
lowerToUpperCap = this.mostRecentConnector;
|
68
|
+
pathStartConnector = this.pathStartConnector;
|
69
|
+
}
|
70
|
+
const startPoint = lowerPath[lowerPath.length - 1].endPoint;
|
71
|
+
return {
|
72
|
+
// Start at the end of the lower curve:
|
73
|
+
// Start point
|
74
|
+
// ↓
|
75
|
+
// __/ __/ ← Most recent points on this end
|
76
|
+
// /___ /
|
77
|
+
// ↑
|
78
|
+
// Oldest points
|
79
|
+
startPoint,
|
80
|
+
commands: [
|
81
|
+
// Move to the most recent point on the upperPath:
|
82
|
+
// ----→•
|
83
|
+
// __/ __/
|
84
|
+
// /___ /
|
85
|
+
lowerToUpperCap,
|
86
|
+
// Move to the beginning of the upperPath:
|
87
|
+
// __/ __/
|
88
|
+
// /___ /
|
89
|
+
// • ←-
|
90
|
+
...upperPath.reverse(),
|
91
|
+
// Move to the beginning of the lowerPath:
|
92
|
+
// __/ __/
|
93
|
+
// /___ /
|
94
|
+
// •
|
95
|
+
pathStartConnector,
|
96
|
+
// Move back to the start point:
|
97
|
+
// •
|
98
|
+
// __/ __/
|
99
|
+
// /___ /
|
100
|
+
...lowerPath,
|
101
|
+
],
|
102
|
+
style: this.getRenderingStyle(),
|
103
|
+
};
|
104
|
+
}
|
105
|
+
previewStroke() {
|
106
|
+
const pathPreview = this.previewPath();
|
107
|
+
if (pathPreview) {
|
108
|
+
return new Stroke([pathPreview]);
|
49
109
|
}
|
50
|
-
return
|
110
|
+
return null;
|
51
111
|
}
|
52
112
|
preview(renderer) {
|
53
|
-
|
54
|
-
|
113
|
+
const path = this.previewPath();
|
114
|
+
if (path) {
|
115
|
+
renderer.drawPath(path);
|
55
116
|
}
|
56
117
|
}
|
57
118
|
build() {
|
58
119
|
if (this.lastPoint) {
|
59
120
|
this.finalizeCurrentCurve();
|
60
121
|
}
|
61
|
-
return
|
122
|
+
return this.previewStroke();
|
62
123
|
}
|
63
124
|
roundPoint(point) {
|
64
125
|
return Viewport.roundPoint(point, this.minFitAllowed);
|
@@ -67,53 +128,61 @@ export default class FreehandLineBuilder {
|
|
67
128
|
// Case where no points have been added
|
68
129
|
if (!this.currentCurve) {
|
69
130
|
// Don't create a circle around the initial point if the stroke has more than one point.
|
70
|
-
if (this.
|
131
|
+
if (!this.isFirstSegment) {
|
71
132
|
return;
|
72
133
|
}
|
73
|
-
const width = Viewport.roundPoint(this.startPoint.width / 3, this.minFitAllowed);
|
134
|
+
const width = Viewport.roundPoint(this.startPoint.width / 3.5, this.minFitAllowed);
|
74
135
|
const center = this.roundPoint(this.startPoint.pos);
|
136
|
+
// Start on the right, cycle clockwise:
|
137
|
+
// |
|
138
|
+
// ----- ←
|
139
|
+
// |
|
140
|
+
const startPoint = this.startPoint.pos.plus(Vec2.of(width, 0));
|
75
141
|
// Draw a circle-ish shape around the start point
|
76
|
-
this.
|
77
|
-
|
142
|
+
this.lowerSegments.push({
|
143
|
+
kind: PathCommandType.QuadraticBezierTo,
|
144
|
+
controlPoint: center.plus(Vec2.of(width, width)),
|
145
|
+
// Bottom of the circle
|
78
146
|
// |
|
79
|
-
// -----
|
147
|
+
// -----
|
80
148
|
// |
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
controlPoint: center.plus(Vec2.of(-width, width)),
|
96
|
-
endPoint: center.plus(Vec2.of(-width, 0)),
|
97
|
-
},
|
98
|
-
{
|
99
|
-
kind: PathCommandType.QuadraticBezierTo,
|
100
|
-
controlPoint: center.plus(Vec2.of(-width, -width)),
|
101
|
-
endPoint: center.plus(Vec2.of(0, -width)),
|
102
|
-
},
|
103
|
-
{
|
104
|
-
kind: PathCommandType.QuadraticBezierTo,
|
105
|
-
controlPoint: center.plus(Vec2.of(width, -width)),
|
106
|
-
endPoint: center.plus(Vec2.of(width, 0)),
|
107
|
-
},
|
108
|
-
],
|
109
|
-
style: this.getRenderingStyle(),
|
149
|
+
// ↑
|
150
|
+
endPoint: center.plus(Vec2.of(0, width)),
|
151
|
+
}, {
|
152
|
+
kind: PathCommandType.QuadraticBezierTo,
|
153
|
+
controlPoint: center.plus(Vec2.of(-width, width)),
|
154
|
+
endPoint: center.plus(Vec2.of(-width, 0)),
|
155
|
+
}, {
|
156
|
+
kind: PathCommandType.QuadraticBezierTo,
|
157
|
+
controlPoint: center.plus(Vec2.of(-width, -width)),
|
158
|
+
endPoint: center.plus(Vec2.of(0, -width)),
|
159
|
+
}, {
|
160
|
+
kind: PathCommandType.QuadraticBezierTo,
|
161
|
+
controlPoint: center.plus(Vec2.of(width, -width)),
|
162
|
+
endPoint: center.plus(Vec2.of(width, 0)),
|
110
163
|
});
|
164
|
+
this.pathStartConnector = {
|
165
|
+
kind: PathCommandType.LineTo,
|
166
|
+
point: startPoint,
|
167
|
+
};
|
168
|
+
this.mostRecentConnector = this.pathStartConnector;
|
111
169
|
return;
|
112
170
|
}
|
113
|
-
this.
|
171
|
+
const { upperCurve, lowerToUpperConnector, upperToLowerConnector, lowerCurve } = this.currentSegmentToPath();
|
172
|
+
if (this.isFirstSegment) {
|
173
|
+
// We draw the upper path (reversed), then the lower path, so we need the
|
174
|
+
// upperToLowerConnector to join the two paths.
|
175
|
+
this.pathStartConnector = upperToLowerConnector;
|
176
|
+
this.isFirstSegment = false;
|
177
|
+
}
|
178
|
+
// With the most recent connector, we're joining the end of the lowerPath to the most recent
|
179
|
+
// upperPath:
|
180
|
+
this.mostRecentConnector = lowerToUpperConnector;
|
181
|
+
this.upperSegments.push(upperCurve);
|
182
|
+
this.lowerSegments.push(lowerCurve);
|
114
183
|
const lastPoint = this.buffer[this.buffer.length - 1];
|
115
184
|
this.lastExitingVec = Vec2.ofXY(this.currentCurve.points[2]).minus(Vec2.ofXY(this.currentCurve.points[1]));
|
116
|
-
console.assert(this.lastExitingVec.magnitude() !== 0);
|
185
|
+
console.assert(this.lastExitingVec.magnitude() !== 0, 'lastExitingVec has zero length!');
|
117
186
|
// Use the last two points to start a new curve (the last point isn't used
|
118
187
|
// in the current curve and we want connected curves to share end points)
|
119
188
|
this.buffer = [
|
@@ -121,6 +190,7 @@ export default class FreehandLineBuilder {
|
|
121
190
|
];
|
122
191
|
this.currentCurve = null;
|
123
192
|
}
|
193
|
+
// Returns [upper curve, connector, lower curve]
|
124
194
|
currentSegmentToPath() {
|
125
195
|
if (this.currentCurve == null) {
|
126
196
|
throw new Error('Invalid State: currentCurve is null!');
|
@@ -163,27 +233,28 @@ export default class FreehandLineBuilder {
|
|
163
233
|
if (upperBoundary.intersects(lowerBoundary).length > 0) {
|
164
234
|
halfVec = halfVec.times(2);
|
165
235
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
236
|
+
// Each starts at startPt ± startVec
|
237
|
+
const lowerCurve = {
|
238
|
+
kind: PathCommandType.QuadraticBezierTo,
|
239
|
+
controlPoint: this.roundPoint(controlPoint.plus(halfVec)),
|
240
|
+
endPoint: this.roundPoint(endPt.plus(endVec)),
|
241
|
+
};
|
242
|
+
// From the end of the upperCurve to the start of the lowerCurve:
|
243
|
+
const upperToLowerConnector = {
|
244
|
+
kind: PathCommandType.LineTo,
|
245
|
+
point: this.roundPoint(startPt.plus(startVec)),
|
246
|
+
};
|
247
|
+
// From the end of lowerCurve to the start of upperCurve:
|
248
|
+
const lowerToUpperConnector = {
|
249
|
+
kind: PathCommandType.LineTo,
|
250
|
+
point: this.roundPoint(endPt.minus(endVec))
|
251
|
+
};
|
252
|
+
const upperCurve = {
|
253
|
+
kind: PathCommandType.QuadraticBezierTo,
|
254
|
+
controlPoint: this.roundPoint(controlPoint.minus(halfVec)),
|
255
|
+
endPoint: this.roundPoint(startPt.minus(startVec)),
|
186
256
|
};
|
257
|
+
return { upperCurve, upperToLowerConnector, lowerToUpperConnector, lowerCurve };
|
187
258
|
}
|
188
259
|
// Compute the direction of the velocity at the end of this.buffer
|
189
260
|
computeExitingVec() {
|
@@ -205,7 +276,7 @@ export default class FreehandLineBuilder {
|
|
205
276
|
}
|
206
277
|
const threshold = Math.min(this.lastPoint.width, newPoint.width) / 4;
|
207
278
|
const shouldSnapToInitial = this.startPoint.pos.minus(newPoint.pos).magnitude() < threshold
|
208
|
-
&& this.
|
279
|
+
&& this.isFirstSegment;
|
209
280
|
// Snap to the starting point if the stroke is contained within a small ball centered
|
210
281
|
// at the starting point.
|
211
282
|
// This allows us to create a circle/dot at the start of the stroke.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import Mat33 from '../../
|
2
|
-
import Path from '../../
|
3
|
-
import Rect2 from '../../
|
1
|
+
import Mat33 from '../../math/Mat33';
|
2
|
+
import Path from '../../math/Path';
|
3
|
+
import Rect2 from '../../math/Rect2';
|
4
4
|
import Stroke from '../Stroke';
|
5
5
|
export const makeFilledRectangleBuilder = (initialPoint, viewport) => {
|
6
6
|
return new RectangleBuilder(initialPoint, true, viewport);
|
@@ -4,6 +4,7 @@ import { TextRendererLocalization } from './rendering/localization';
|
|
4
4
|
import { ToolbarLocalization } from './toolbar/localization';
|
5
5
|
import { ToolLocalization } from './tools/localization';
|
6
6
|
export interface EditorLocalization extends ToolbarLocalization, ToolLocalization, CommandLocalization, ImageComponentLocalization, TextRendererLocalization {
|
7
|
+
accessibilityInputInstructions: string;
|
7
8
|
undoAnnouncement: (actionDescription: string) => string;
|
8
9
|
redoAnnouncement: (actionDescription: string) => string;
|
9
10
|
doneLoading: string;
|
package/dist/src/localization.js
CHANGED
@@ -3,4 +3,8 @@ import { defaultComponentLocalization } from './components/localization';
|
|
3
3
|
import { defaultTextRendererLocalization } from './rendering/localization';
|
4
4
|
import { defaultToolbarLocalization } from './toolbar/localization';
|
5
5
|
import { defaultToolLocalization } from './tools/localization';
|
6
|
-
export const defaultEditorLocalization = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaultToolbarLocalization), defaultToolLocalization), defaultCommandLocalization), defaultComponentLocalization), defaultTextRendererLocalization), {
|
6
|
+
export const defaultEditorLocalization = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, defaultToolbarLocalization), defaultToolLocalization), defaultCommandLocalization), defaultComponentLocalization), defaultTextRendererLocalization), { accessibilityInputInstructions: [
|
7
|
+
'Press "t" to read the contents of the viewport as text.',
|
8
|
+
'Use the arrow keys to move the viewport, click and drag to draw strokes.',
|
9
|
+
'Press "w" to zoom in and "s" to zoom out.',
|
10
|
+
].join(' '), loading: (percentage) => `Loading ${percentage}%...`, imageEditor: 'Image Editor', doneLoading: 'Done loading', undoAnnouncement: (commandDescription) => `Undid ${commandDescription}`, redoAnnouncement: (commandDescription) => `Redid ${commandDescription}` });
|
@@ -6,7 +6,7 @@ const localization = Object.assign(Object.assign({}, defaultEditorLocalization),
|
|
6
6
|
loading: (percentage) => `Cargando: ${percentage}%...`, imageEditor: 'Editor de dibujos', undoAnnouncement: (commandDescription) => `${commandDescription} fue deshecho`, redoAnnouncement: (commandDescription) => `${commandDescription} fue rehecho`, undo: 'Deshace', redo: 'Rehace',
|
7
7
|
// Strings for the toolbar
|
8
8
|
// (see src/toolbar/localization.ts)
|
9
|
-
pen: 'Lapiz', eraser: 'Borrador', select: 'Selecciona', thicknessLabel: 'Tamaño: ', colorLabel: 'Color: ', doneLoading: 'El cargado terminó', fontLabel: 'Fuente: ', anyDevicePanning: 'Mover la pantalla con todo dispotivo', touchPanning: 'Mover la pantalla con un dedo', touchPanTool: 'Instrumento de mover la pantalla con un dedo', outlinedRectanglePen: 'Rectángulo con nada más que un borde', filledRectanglePen: 'Rectángulo sin borde', linePen: 'Línea', arrowPen: 'Flecha', freehandPen: 'Dibuja sin restricción de forma', selectObjectType: 'Forma de dibuja:', handTool: 'Mover', zoom: 'Zoom', resetView: 'Reiniciar vista', resizeImageToSelection: 'Redimensionar la imagen a lo que está seleccionado', deleteSelection: 'Borra la selección', duplicateSelection: 'Duplica la selección',
|
9
|
+
pen: 'Lapiz', eraser: 'Borrador', select: 'Selecciona', thicknessLabel: 'Tamaño: ', colorLabel: 'Color: ', doneLoading: 'El cargado terminó', fontLabel: 'Fuente: ', anyDevicePanning: 'Mover la pantalla con todo dispotivo', touchPanning: 'Mover la pantalla con un dedo', touchPanTool: 'Instrumento de mover la pantalla con un dedo', outlinedRectanglePen: 'Rectángulo con nada más que un borde', filledRectanglePen: 'Rectángulo sin borde', linePen: 'Línea', arrowPen: 'Flecha', freehandPen: 'Dibuja sin restricción de forma', selectObjectType: 'Forma de dibuja:', handTool: 'Mover', zoom: 'Zoom', resetView: 'Reiniciar vista', resizeImageToSelection: 'Redimensionar la imagen a lo que está seleccionado', deleteSelection: 'Borra la selección', duplicateSelection: 'Duplica la selección', pickColorFromScreen: 'Selecciona un color de la pantalla', clickToPickColorAnnouncement: 'Haga un clic en la pantalla para seleccionar un color', dropdownShown(toolName) {
|
10
10
|
return `Menú por ${toolName} es visible`;
|
11
11
|
}, dropdownHidden: function (toolName) {
|
12
12
|
return `Menú por ${toolName} fue ocultado`;
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -45,6 +45,7 @@ export default class Path {
|
|
45
45
|
get geometry(): Array<LineSegment2 | Bezier>;
|
46
46
|
static computeBBoxForSegment(startPoint: Point2, part: PathCommand): Rect2;
|
47
47
|
intersection(line: LineSegment2): IntersectionResult[];
|
48
|
+
mapPoints(mapping: (point: Point2) => Point2): Path;
|
48
49
|
transformedBy(affineTransfm: Mat33): Path;
|
49
50
|
union(other: Path | null): Path;
|
50
51
|
static fromRect(rect: Rect2, lineWidth?: number | null): Path;
|
@@ -52,7 +53,7 @@ export default class Path {
|
|
52
53
|
toRenderable(fill: RenderingStyle): RenderablePathSpec;
|
53
54
|
toString(): string;
|
54
55
|
serialize(): string;
|
55
|
-
static toString(startPoint: Point2, parts: PathCommand[]): string;
|
56
|
+
static toString(startPoint: Point2, parts: PathCommand[], onlyAbsCommands?: boolean): string;
|
56
57
|
static fromString(pathString: string): Path;
|
57
58
|
static empty: Path;
|
58
59
|
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Bezier } from 'bezier-js';
|
2
|
+
import { toRoundedString, toStringOfSamePrecision } from './rounding';
|
2
3
|
import LineSegment2 from './LineSegment2';
|
3
4
|
import Rect2 from './Rect2';
|
4
5
|
import { Vec2 } from './Vec2';
|
@@ -109,8 +110,8 @@ export default class Path {
|
|
109
110
|
}
|
110
111
|
return result;
|
111
112
|
}
|
112
|
-
|
113
|
-
const startPoint =
|
113
|
+
mapPoints(mapping) {
|
114
|
+
const startPoint = mapping(this.startPoint);
|
114
115
|
const newParts = [];
|
115
116
|
let exhaustivenessCheck;
|
116
117
|
for (const part of this.parts) {
|
@@ -119,22 +120,22 @@ export default class Path {
|
|
119
120
|
case PathCommandType.LineTo:
|
120
121
|
newParts.push({
|
121
122
|
kind: part.kind,
|
122
|
-
point:
|
123
|
+
point: mapping(part.point),
|
123
124
|
});
|
124
125
|
break;
|
125
126
|
case PathCommandType.CubicBezierTo:
|
126
127
|
newParts.push({
|
127
128
|
kind: part.kind,
|
128
|
-
controlPoint1:
|
129
|
-
controlPoint2:
|
130
|
-
endPoint:
|
129
|
+
controlPoint1: mapping(part.controlPoint1),
|
130
|
+
controlPoint2: mapping(part.controlPoint2),
|
131
|
+
endPoint: mapping(part.endPoint),
|
131
132
|
});
|
132
133
|
break;
|
133
134
|
case PathCommandType.QuadraticBezierTo:
|
134
135
|
newParts.push({
|
135
136
|
kind: part.kind,
|
136
|
-
controlPoint:
|
137
|
-
endPoint:
|
137
|
+
controlPoint: mapping(part.controlPoint),
|
138
|
+
endPoint: mapping(part.endPoint),
|
138
139
|
});
|
139
140
|
break;
|
140
141
|
default:
|
@@ -144,6 +145,9 @@ export default class Path {
|
|
144
145
|
}
|
145
146
|
return new Path(startPoint, newParts);
|
146
147
|
}
|
148
|
+
transformedBy(affineTransfm) {
|
149
|
+
return this.mapPoints(point => affineTransfm.transformVec2(point));
|
150
|
+
}
|
147
151
|
// Creates a new path by joining [other] to the end of this path
|
148
152
|
union(other) {
|
149
153
|
if (!other) {
|
@@ -201,58 +205,61 @@ export default class Path {
|
|
201
205
|
};
|
202
206
|
}
|
203
207
|
toString() {
|
204
|
-
|
208
|
+
// Hueristic: Try to determine whether converting absolute to relative commands is worth it.
|
209
|
+
// If we're near (0, 0), it probably isn't worth it and if bounding boxes are large,
|
210
|
+
// it also probably isn't worth it.
|
211
|
+
const makeRelativeCommands = Math.abs(this.bbox.topLeft.x) > 10 && Math.abs(this.bbox.size.x) < 2
|
212
|
+
&& Math.abs(this.bbox.topLeft.y) > 10 && Math.abs(this.bbox.size.y) < 2;
|
213
|
+
return Path.toString(this.startPoint, this.parts, !makeRelativeCommands);
|
205
214
|
}
|
206
215
|
serialize() {
|
207
216
|
return this.toString();
|
208
217
|
}
|
209
|
-
|
218
|
+
// [onlyAbsCommands]: True if we should avoid converting absolute coordinates to relative offsets -- such
|
219
|
+
// conversions can lead to smaller output strings, but also take time.
|
220
|
+
static toString(startPoint, parts, onlyAbsCommands = true) {
|
210
221
|
const result = [];
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
const
|
215
|
-
const
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
// Left-shift
|
231
|
-
newPostDecimal = newPostDecimal.substring(1);
|
232
|
-
carry = 1;
|
222
|
+
let prevPoint;
|
223
|
+
const addCommand = (command, ...points) => {
|
224
|
+
const absoluteCommandParts = [];
|
225
|
+
const relativeCommandParts = [];
|
226
|
+
const makeAbsCommand = !prevPoint || onlyAbsCommands;
|
227
|
+
const roundedPrevX = prevPoint ? toRoundedString(prevPoint.x) : '';
|
228
|
+
const roundedPrevY = prevPoint ? toRoundedString(prevPoint.y) : '';
|
229
|
+
for (const point of points) {
|
230
|
+
// Relative commands are often shorter as strings than absolute commands.
|
231
|
+
if (!makeAbsCommand) {
|
232
|
+
const xComponentRelative = toStringOfSamePrecision(point.x - prevPoint.x, roundedPrevX, roundedPrevY);
|
233
|
+
const yComponentRelative = toStringOfSamePrecision(point.y - prevPoint.y, roundedPrevX, roundedPrevY);
|
234
|
+
// No need for an additional separator if it starts with a '-'
|
235
|
+
if (yComponentRelative.charAt(0) === '-') {
|
236
|
+
relativeCommandParts.push(`${xComponentRelative}${yComponentRelative}`);
|
237
|
+
}
|
238
|
+
else {
|
239
|
+
relativeCommandParts.push(`${xComponentRelative},${yComponentRelative}`);
|
240
|
+
}
|
233
241
|
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
242
|
+
else {
|
243
|
+
const xComponent = toRoundedString(point.x);
|
244
|
+
const yComponent = toRoundedString(point.y);
|
245
|
+
absoluteCommandParts.push(`${xComponent},${yComponent}`);
|
238
246
|
}
|
239
|
-
text = `${negativeSign + (preDecimal + carry).toString()}.${newPostDecimal}`;
|
240
247
|
}
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
248
|
+
let commandString;
|
249
|
+
if (makeAbsCommand) {
|
250
|
+
commandString = `${command}${absoluteCommandParts.join(' ')}`;
|
251
|
+
}
|
252
|
+
else {
|
253
|
+
commandString = `${command.toLowerCase()}${relativeCommandParts.join(' ')}`;
|
254
|
+
}
|
255
|
+
// Don't add no-ops.
|
256
|
+
if (commandString === 'l0,0') {
|
257
|
+
return;
|
258
|
+
}
|
259
|
+
result.push(commandString);
|
260
|
+
if (points.length > 0) {
|
261
|
+
prevPoint = points[points.length - 1];
|
254
262
|
}
|
255
|
-
result.push(`${command}${parts.join(' ')}`);
|
256
263
|
};
|
257
264
|
addCommand('M', startPoint);
|
258
265
|
let exhaustivenessCheck;
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -23,7 +23,7 @@ export default class Vec3 {
|
|
23
23
|
extend(distance: number, direction: Vec3): Vec3;
|
24
24
|
lerp(target: Vec3, fractionTo: number): Vec3;
|
25
25
|
zip(other: Vec3, zip: (componentInThis: number, componentInOther: number) => number): Vec3;
|
26
|
-
map(fn: (component: number) => number): Vec3;
|
26
|
+
map(fn: (component: number, index: number) => number): Vec3;
|
27
27
|
asArray(): number[];
|
28
28
|
eq(other: Vec3, fuzz: number): boolean;
|
29
29
|
toString(): string;
|
@@ -86,7 +86,7 @@ export default class Vec3 {
|
|
86
86
|
}
|
87
87
|
// Returns a vector with each component acted on by [fn]
|
88
88
|
map(fn) {
|
89
|
-
return Vec3.of(fn(this.x), fn(this.y), fn(this.z));
|
89
|
+
return Vec3.of(fn(this.x, 0), fn(this.y, 1), fn(this.z, 2));
|
90
90
|
}
|
91
91
|
asArray() {
|
92
92
|
return [this.x, this.y, this.z];
|