js-draw 0.1.9 → 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 +18 -0
- package/README.md +15 -3
- package/dist/bundle.js +1 -1
- package/dist/src/Editor.d.ts +7 -2
- package/dist/src/Editor.js +74 -25
- 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/UndoRedoHistory.js +3 -0
- package/dist/src/Viewport.d.ts +8 -25
- package/dist/src/Viewport.js +17 -10
- package/dist/src/bundle/bundled.d.ts +2 -1
- package/dist/src/bundle/bundled.js +2 -1
- 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/en.d.ts +3 -0
- package/dist/src/localizations/en.js +4 -0
- package/dist/src/localizations/es.d.ts +3 -0
- package/dist/src/localizations/es.js +18 -0
- package/dist/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/src/localizations/getLocalizationTable.js +43 -0
- package/dist/src/{geometry → math}/LineSegment2.d.ts +1 -0
- package/dist/src/{geometry → math}/LineSegment2.js +16 -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 +1 -0
- package/dist/src/{geometry → math}/Rect2.js +16 -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/HTMLToolbar.js +5 -7
- package/dist/src/toolbar/icons.d.ts +3 -0
- package/dist/src/toolbar/icons.js +152 -142
- package/dist/src/toolbar/localization.d.ts +4 -1
- package/dist/src/toolbar/localization.js +4 -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 +31 -0
- package/dist/src/toolbar/widgets/HandToolWidget.js +10 -3
- package/dist/src/toolbar/widgets/SelectionWidget.d.ts +0 -1
- package/dist/src/toolbar/widgets/SelectionWidget.js +23 -30
- package/dist/src/tools/BaseTool.d.ts +2 -1
- package/dist/src/tools/BaseTool.js +3 -0
- package/dist/src/tools/Eraser.js +1 -1
- package/dist/src/tools/PanZoom.d.ts +3 -2
- package/dist/src/tools/PanZoom.js +32 -16
- package/dist/src/tools/SelectionTool.d.ts +11 -4
- package/dist/src/tools/SelectionTool.js +135 -23
- package/dist/src/tools/TextTool.js +1 -1
- package/dist/src/tools/ToolController.js +6 -2
- package/dist/src/tools/localization.d.ts +1 -0
- package/dist/src/tools/localization.js +1 -0
- package/dist/src/types.d.ts +13 -6
- package/dist/src/types.js +1 -0
- package/package.json +9 -1
- package/src/Editor.ts +86 -24
- 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/UndoRedoHistory.ts +4 -0
- package/src/Viewport.ts +21 -17
- package/src/bundle/bundled.ts +2 -1
- 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/en.ts +8 -0
- package/src/localizations/es.ts +63 -0
- package/src/localizations/getLocalizationTable.test.ts +27 -0
- package/src/localizations/getLocalizationTable.ts +53 -0
- package/src/{geometry → math}/LineSegment2.test.ts +15 -0
- package/src/{geometry → math}/LineSegment2.ts +20 -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 +20 -7
- package/src/{geometry → math}/Rect2.ts +19 -1
- 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/HTMLToolbar.ts +5 -8
- package/src/toolbar/icons.ts +167 -147
- package/src/toolbar/localization.ts +8 -2
- package/src/toolbar/makeColorInput.ts +2 -1
- package/src/toolbar/toolbar.css +7 -3
- package/src/toolbar/widgets/ActionButtonWidget.ts +31 -0
- package/src/toolbar/widgets/BaseWidget.ts +36 -0
- package/src/toolbar/widgets/HandToolWidget.ts +14 -3
- package/src/toolbar/widgets/SelectionWidget.ts +46 -41
- package/src/tools/BaseTool.ts +5 -1
- package/src/tools/Eraser.ts +2 -2
- package/src/tools/PanZoom.ts +39 -18
- package/src/tools/SelectionTool.test.ts +26 -5
- package/src/tools/SelectionTool.ts +162 -27
- package/src/tools/TextTool.ts +2 -2
- package/src/tools/ToolController.ts +6 -2
- package/src/tools/UndoRedoShortcut.test.ts +1 -1
- package/src/tools/localization.ts +2 -0
- package/src/types.ts +14 -5
- package/dist-test/test-dist-bundle.html +0 -42
@@ -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;
|
@@ -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}` });
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { defaultEditorLocalization } from '../localization';
|
2
|
+
// A partial Spanish localization.
|
3
|
+
const localization = Object.assign(Object.assign({}, defaultEditorLocalization), {
|
4
|
+
// Strings for the main editor interface
|
5
|
+
// (see src/localization.ts)
|
6
|
+
loading: (percentage) => `Cargando: ${percentage}%...`, imageEditor: 'Editor de dibujos', undoAnnouncement: (commandDescription) => `${commandDescription} fue deshecho`, redoAnnouncement: (commandDescription) => `${commandDescription} fue rehecho`, undo: 'Deshace', redo: 'Rehace',
|
7
|
+
// Strings for the toolbar
|
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', pickColorFromScreen: 'Selecciona un color de la pantalla', clickToPickColorAnnouncement: 'Haga un clic en la pantalla para seleccionar un color', dropdownShown(toolName) {
|
10
|
+
return `Menú por ${toolName} es visible`;
|
11
|
+
}, dropdownHidden: function (toolName) {
|
12
|
+
return `Menú por ${toolName} fue ocultado`;
|
13
|
+
}, colorChangedAnnouncement: function (color) {
|
14
|
+
return `Color fue cambiado a ${color}`;
|
15
|
+
}, keyboardPanZoom: 'Mover la pantalla con el teclado', penTool: function (penId) {
|
16
|
+
return `Lapiz ${penId}`;
|
17
|
+
}, selectionTool: 'Selecciona', eraserTool: 'Borrador', textTool: 'Texto', enterTextToInsert: 'Entra texto', rerenderAsText: 'Redibuja la pantalla al texto' });
|
18
|
+
export default localization;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { defaultEditorLocalization } from '../localization';
|
2
|
+
import en from './en';
|
3
|
+
import es from './es';
|
4
|
+
const allLocales = {
|
5
|
+
en,
|
6
|
+
es,
|
7
|
+
};
|
8
|
+
// [locale]: A string in the format languageCode_Region or just languageCode. For example, en_US.
|
9
|
+
const languageFromLocale = (locale) => {
|
10
|
+
const matches = /^(\w+)[_-](\w+)$/.exec(locale);
|
11
|
+
if (!matches) {
|
12
|
+
// If not in languageCode_region format, the locale should be the
|
13
|
+
// languageCode. Return that.
|
14
|
+
return locale;
|
15
|
+
}
|
16
|
+
return matches[1];
|
17
|
+
};
|
18
|
+
const getLocalizationTable = (userLocales) => {
|
19
|
+
userLocales !== null && userLocales !== void 0 ? userLocales : (userLocales = navigator.languages);
|
20
|
+
let prevLanguage;
|
21
|
+
for (const locale of userLocales) {
|
22
|
+
const language = languageFromLocale(locale);
|
23
|
+
// If the specific localization of the language is not available, but
|
24
|
+
// a localization for the language is,
|
25
|
+
if (prevLanguage && language !== prevLanguage) {
|
26
|
+
if (prevLanguage in allLocales) {
|
27
|
+
return allLocales[prevLanguage];
|
28
|
+
}
|
29
|
+
}
|
30
|
+
// If the full locale (e.g. en_US) is available,
|
31
|
+
if (locale in allLocales) {
|
32
|
+
return allLocales[locale];
|
33
|
+
}
|
34
|
+
prevLanguage = language;
|
35
|
+
}
|
36
|
+
if (prevLanguage && prevLanguage in allLocales) {
|
37
|
+
return allLocales[prevLanguage];
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
return defaultEditorLocalization;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
export default getLocalizationTable;
|
@@ -97,4 +97,20 @@ export default class LineSegment2 {
|
|
97
97
|
t: resultT,
|
98
98
|
};
|
99
99
|
}
|
100
|
+
// Returns the closest point on this to [target]
|
101
|
+
closestPointTo(target) {
|
102
|
+
// Distance from P1 along this' direction.
|
103
|
+
const projectedDistFromP1 = target.minus(this.p1).dot(this.direction);
|
104
|
+
const projectedDistFromP2 = this.length - projectedDistFromP1;
|
105
|
+
const projection = this.p1.plus(this.direction.times(projectedDistFromP1));
|
106
|
+
if (projectedDistFromP1 > 0 && projectedDistFromP1 < this.length) {
|
107
|
+
return projection;
|
108
|
+
}
|
109
|
+
if (Math.abs(projectedDistFromP2) < Math.abs(projectedDistFromP1)) {
|
110
|
+
return this.p2;
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
return this.p1;
|
114
|
+
}
|
115
|
+
}
|
100
116
|
}
|
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
|
}
|