js-draw 0.18.2 → 0.19.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/CHANGELOG.md +7 -0
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -0
- package/dist/cjs/src/Color4.d.ts +8 -0
- package/dist/cjs/src/Color4.js +67 -0
- package/dist/cjs/src/Editor.d.ts +2 -2
- package/dist/cjs/src/Editor.js +2 -2
- package/dist/cjs/src/SVGLoader.js +8 -5
- package/dist/cjs/src/components/AbstractComponent.d.ts +2 -2
- package/dist/cjs/src/components/AbstractComponent.js +3 -3
- package/dist/cjs/src/components/ImageBackground.js +1 -1
- package/dist/cjs/src/components/RestylableComponent.d.ts +21 -2
- package/dist/cjs/src/components/Stroke.d.ts +35 -0
- package/dist/cjs/src/components/Stroke.js +36 -2
- package/dist/cjs/src/components/TextComponent.d.ts +26 -4
- package/dist/cjs/src/components/TextComponent.js +22 -0
- package/dist/cjs/src/components/lib.d.ts +3 -2
- package/dist/cjs/src/lib.d.ts +30 -0
- package/dist/cjs/src/lib.js +30 -0
- package/dist/cjs/src/rendering/RenderingStyle.d.ts +4 -4
- package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/cjs/src/rendering/lib.d.ts +2 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
- package/dist/cjs/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/cjs/src/toolbar/localization.js +1 -1
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +1 -1
- package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/cjs/src/tools/SoundUITool.js +164 -0
- package/dist/cjs/src/tools/TextTool.d.ts +2 -2
- package/dist/cjs/src/tools/ToolController.js +6 -1
- package/dist/cjs/src/tools/lib.d.ts +1 -0
- package/dist/cjs/src/tools/lib.js +3 -1
- package/dist/cjs/src/tools/localization.d.ts +3 -0
- package/dist/cjs/src/tools/localization.js +3 -0
- package/dist/mjs/src/Color4.d.ts +8 -0
- package/dist/mjs/src/Color4.mjs +64 -0
- package/dist/mjs/src/Editor.d.ts +2 -2
- package/dist/mjs/src/Editor.mjs +2 -2
- package/dist/mjs/src/SVGLoader.mjs +8 -5
- package/dist/mjs/src/components/AbstractComponent.d.ts +2 -2
- package/dist/mjs/src/components/AbstractComponent.mjs +3 -3
- package/dist/mjs/src/components/ImageBackground.mjs +1 -1
- package/dist/mjs/src/components/RestylableComponent.d.ts +21 -2
- package/dist/mjs/src/components/Stroke.d.ts +35 -0
- package/dist/mjs/src/components/Stroke.mjs +36 -2
- package/dist/mjs/src/components/TextComponent.d.ts +26 -4
- package/dist/mjs/src/components/TextComponent.mjs +22 -0
- package/dist/mjs/src/components/lib.d.ts +3 -2
- package/dist/mjs/src/lib.d.ts +30 -0
- package/dist/mjs/src/lib.mjs +30 -0
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +4 -4
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/mjs/src/rendering/lib.d.ts +2 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
- package/dist/mjs/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/mjs/src/toolbar/localization.mjs +1 -1
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +1 -1
- package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
- package/dist/mjs/src/tools/TextTool.d.ts +2 -2
- package/dist/mjs/src/tools/ToolController.mjs +6 -1
- package/dist/mjs/src/tools/lib.d.ts +1 -0
- package/dist/mjs/src/tools/lib.mjs +1 -0
- package/dist/mjs/src/tools/localization.d.ts +3 -0
- package/dist/mjs/src/tools/localization.mjs +3 -0
- package/package.json +6 -4
- package/src/Editor.css +2 -2
- package/src/tools/SoundUITool.css +15 -0
- package/src/tools/tools.css +4 -0
- package/src/Color4.test.ts +0 -40
- package/src/Color4.ts +0 -236
- package/src/Editor.loadFrom.test.ts +0 -24
- package/src/Editor.toSVG.test.ts +0 -111
- package/src/Editor.ts +0 -1122
- package/src/EditorImage.test.ts +0 -120
- package/src/EditorImage.ts +0 -603
- package/src/EventDispatcher.test.ts +0 -123
- package/src/EventDispatcher.ts +0 -71
- package/src/Pointer.ts +0 -127
- package/src/SVGLoader.test.ts +0 -114
- package/src/SVGLoader.ts +0 -511
- package/src/UndoRedoHistory.test.ts +0 -33
- package/src/UndoRedoHistory.ts +0 -102
- package/src/Viewport.ts +0 -319
- package/src/bundle/bundled.ts +0 -7
- package/src/commands/Command.ts +0 -45
- package/src/commands/Duplicate.ts +0 -48
- package/src/commands/Erase.ts +0 -74
- package/src/commands/SerializableCommand.ts +0 -49
- package/src/commands/UnresolvedCommand.ts +0 -37
- package/src/commands/invertCommand.ts +0 -51
- package/src/commands/lib.ts +0 -16
- package/src/commands/localization.ts +0 -47
- package/src/commands/uniteCommands.test.ts +0 -23
- package/src/commands/uniteCommands.ts +0 -135
- package/src/components/AbstractComponent.transformBy.test.ts +0 -22
- package/src/components/AbstractComponent.ts +0 -364
- package/src/components/ImageBackground.test.ts +0 -35
- package/src/components/ImageBackground.ts +0 -176
- package/src/components/ImageComponent.ts +0 -171
- package/src/components/RestylableComponent.ts +0 -142
- package/src/components/SVGGlobalAttributesObject.ts +0 -81
- package/src/components/Stroke.test.ts +0 -139
- package/src/components/Stroke.ts +0 -245
- package/src/components/TextComponent.test.ts +0 -99
- package/src/components/TextComponent.ts +0 -315
- package/src/components/UnknownSVGObject.test.ts +0 -10
- package/src/components/UnknownSVGObject.ts +0 -60
- package/src/components/builders/ArrowBuilder.ts +0 -107
- package/src/components/builders/FreehandLineBuilder.ts +0 -212
- package/src/components/builders/LineBuilder.ts +0 -77
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
- package/src/components/builders/RectangleBuilder.ts +0 -74
- package/src/components/builders/types.ts +0 -15
- package/src/components/lib.ts +0 -25
- package/src/components/localization.ts +0 -22
- package/src/components/util/StrokeSmoother.ts +0 -293
- package/src/components/util/describeComponentList.ts +0 -18
- package/src/lib.ts +0 -37
- package/src/localization.ts +0 -34
- package/src/localizations/de.ts +0 -98
- package/src/localizations/en.ts +0 -8
- package/src/localizations/es.ts +0 -74
- package/src/localizations/getLocalizationTable.test.ts +0 -27
- package/src/localizations/getLocalizationTable.ts +0 -55
- package/src/math/LineSegment2.test.ts +0 -99
- package/src/math/LineSegment2.ts +0 -160
- package/src/math/Mat33.test.ts +0 -244
- package/src/math/Mat33.ts +0 -437
- package/src/math/Path.fromString.test.ts +0 -223
- package/src/math/Path.test.ts +0 -198
- package/src/math/Path.toString.test.ts +0 -77
- package/src/math/Path.ts +0 -790
- package/src/math/Rect2.test.ts +0 -204
- package/src/math/Rect2.ts +0 -315
- package/src/math/Triangle.ts +0 -29
- package/src/math/Vec2.test.ts +0 -30
- package/src/math/Vec2.ts +0 -18
- package/src/math/Vec3.test.ts +0 -44
- package/src/math/Vec3.ts +0 -218
- package/src/math/lib.ts +0 -15
- package/src/math/rounding.test.ts +0 -65
- package/src/math/rounding.ts +0 -156
- package/src/rendering/Display.ts +0 -249
- package/src/rendering/RenderingStyle.test.ts +0 -68
- package/src/rendering/RenderingStyle.ts +0 -55
- package/src/rendering/TextRenderingStyle.ts +0 -45
- package/src/rendering/caching/CacheRecord.test.ts +0 -49
- package/src/rendering/caching/CacheRecord.ts +0 -77
- package/src/rendering/caching/CacheRecordManager.ts +0 -71
- package/src/rendering/caching/RenderingCache.test.ts +0 -44
- package/src/rendering/caching/RenderingCache.ts +0 -66
- package/src/rendering/caching/RenderingCacheNode.ts +0 -405
- package/src/rendering/caching/testUtils.ts +0 -35
- package/src/rendering/caching/types.ts +0 -34
- package/src/rendering/lib.ts +0 -6
- package/src/rendering/localization.ts +0 -20
- package/src/rendering/renderers/AbstractRenderer.ts +0 -222
- package/src/rendering/renderers/CanvasRenderer.ts +0 -296
- package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
- package/src/rendering/renderers/DummyRenderer.ts +0 -136
- package/src/rendering/renderers/SVGRenderer.ts +0 -354
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
- package/src/testing/beforeEachFile.ts +0 -8
- package/src/testing/createEditor.ts +0 -11
- package/src/testing/global.d.ts +0 -17
- package/src/testing/lib.ts +0 -3
- package/src/testing/loadExpectExtensions.ts +0 -25
- package/src/testing/sendPenEvent.ts +0 -31
- package/src/testing/sendTouchEvent.ts +0 -78
- package/src/toolbar/HTMLToolbar.ts +0 -492
- package/src/toolbar/IconProvider.ts +0 -736
- package/src/toolbar/lib.ts +0 -4
- package/src/toolbar/localization.ts +0 -106
- package/src/toolbar/makeColorInput.ts +0 -145
- package/src/toolbar/types.ts +0 -5
- package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
- package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
- package/src/toolbar/widgets/BaseWidget.ts +0 -377
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
- package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
- package/src/toolbar/widgets/HandToolWidget.ts +0 -250
- package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
- package/src/toolbar/widgets/OverflowWidget.ts +0 -92
- package/src/toolbar/widgets/PenToolWidget.ts +0 -288
- package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
- package/src/toolbar/widgets/TextToolWidget.ts +0 -145
- package/src/toolbar/widgets/lib.ts +0 -13
- package/src/tools/BaseTool.ts +0 -76
- package/src/tools/Eraser.test.ts +0 -103
- package/src/tools/Eraser.ts +0 -139
- package/src/tools/FindTool.ts +0 -152
- package/src/tools/PanZoom.test.ts +0 -310
- package/src/tools/PanZoom.ts +0 -520
- package/src/tools/PasteHandler.ts +0 -95
- package/src/tools/Pen.test.ts +0 -194
- package/src/tools/Pen.ts +0 -226
- package/src/tools/PipetteTool.ts +0 -55
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
- package/src/tools/SelectionTool/Selection.ts +0 -607
- package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
- package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
- package/src/tools/SelectionTool/SelectionTool.ts +0 -480
- package/src/tools/SelectionTool/TransformMode.ts +0 -114
- package/src/tools/SelectionTool/types.ts +0 -11
- package/src/tools/TextTool.ts +0 -326
- package/src/tools/ToolController.ts +0 -178
- package/src/tools/ToolEnabledGroup.ts +0 -14
- package/src/tools/ToolSwitcherShortcut.ts +0 -39
- package/src/tools/ToolbarShortcutHandler.ts +0 -34
- package/src/tools/UndoRedoShortcut.test.ts +0 -56
- package/src/tools/UndoRedoShortcut.ts +0 -25
- package/src/tools/lib.ts +0 -21
- package/src/tools/localization.ts +0 -66
- package/src/types.ts +0 -234
- package/src/util/assertions.ts +0 -55
- package/src/util/fileToBase64.ts +0 -18
- package/src/util/untilNextAnimationFrame.ts +0 -9
- package/src/util/waitForTimeout.ts +0 -9
package/src/math/Path.test.ts
DELETED
@@ -1,198 +0,0 @@
|
|
1
|
-
import { Bezier } from 'bezier-js';
|
2
|
-
import LineSegment2 from './LineSegment2';
|
3
|
-
import Path, { PathCommandType } from './Path';
|
4
|
-
import Rect2 from './Rect2';
|
5
|
-
import { Vec2 } from './Vec2';
|
6
|
-
|
7
|
-
describe('Path', () => {
|
8
|
-
it('should instantiate Beziers from cubic and quatratic commands', () => {
|
9
|
-
const path = new Path(Vec2.zero, [
|
10
|
-
{
|
11
|
-
kind: PathCommandType.CubicBezierTo,
|
12
|
-
controlPoint1: Vec2.of(1, 1),
|
13
|
-
controlPoint2: Vec2.of(-1, -1),
|
14
|
-
endPoint: Vec2.of(3, 3),
|
15
|
-
},
|
16
|
-
{
|
17
|
-
kind: PathCommandType.QuadraticBezierTo,
|
18
|
-
controlPoint: Vec2.of(1, 1),
|
19
|
-
endPoint: Vec2.of(0, 0),
|
20
|
-
},
|
21
|
-
]);
|
22
|
-
|
23
|
-
expect(path.geometry.length).toBe(2);
|
24
|
-
|
25
|
-
const firstItem = path.geometry[0];
|
26
|
-
const secondItem = path.geometry[1];
|
27
|
-
expect(firstItem).toBeInstanceOf(Bezier);
|
28
|
-
expect(secondItem).toBeInstanceOf(Bezier);
|
29
|
-
|
30
|
-
// Force TypeScript to do type narrowing.
|
31
|
-
if (!(firstItem instanceof Bezier) || !(secondItem instanceof Bezier)) {
|
32
|
-
throw new Error('Invalid state! .toBeInstanceOf should have caused test to fail!');
|
33
|
-
}
|
34
|
-
|
35
|
-
// Make sure the control points (and start/end points) match what was set
|
36
|
-
expect(firstItem.points).toMatchObject([
|
37
|
-
{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: -1, y: -1 }, { x: 3, y: 3 }
|
38
|
-
]);
|
39
|
-
expect(secondItem.points).toMatchObject([
|
40
|
-
{ x: 3, y: 3 }, { x: 1, y: 1 }, { x: 0, y: 0 },
|
41
|
-
]);
|
42
|
-
});
|
43
|
-
|
44
|
-
it('should create LineSegments from line commands', () => {
|
45
|
-
const lineStart = Vec2.zero;
|
46
|
-
const lineEnd = Vec2.of(100, 100);
|
47
|
-
|
48
|
-
const path = new Path(lineStart, [
|
49
|
-
{
|
50
|
-
kind: PathCommandType.LineTo,
|
51
|
-
point: lineEnd,
|
52
|
-
},
|
53
|
-
]);
|
54
|
-
|
55
|
-
expect(path.geometry.length).toBe(1);
|
56
|
-
expect(path.geometry[0]).toBeInstanceOf(LineSegment2);
|
57
|
-
expect(path.geometry[0]).toMatchObject(
|
58
|
-
new LineSegment2(lineStart, lineEnd)
|
59
|
-
);
|
60
|
-
});
|
61
|
-
|
62
|
-
it('should give all intersections for a path made up of lines', () => {
|
63
|
-
const lineStart = Vec2.of(100, 100);
|
64
|
-
const path = new Path(lineStart, [
|
65
|
-
{
|
66
|
-
kind: PathCommandType.LineTo,
|
67
|
-
point: Vec2.of(-100, 100),
|
68
|
-
},
|
69
|
-
{
|
70
|
-
kind: PathCommandType.LineTo,
|
71
|
-
point: Vec2.of(0, 0),
|
72
|
-
},
|
73
|
-
{
|
74
|
-
kind: PathCommandType.LineTo,
|
75
|
-
point: Vec2.of(100, -100),
|
76
|
-
},
|
77
|
-
]);
|
78
|
-
|
79
|
-
const intersections = path.intersection(
|
80
|
-
new LineSegment2(Vec2.of(-50, 200), Vec2.of(-50, -200))
|
81
|
-
);
|
82
|
-
|
83
|
-
// Should only have intersections in quadrants II and III.
|
84
|
-
expect(intersections.length).toBe(2);
|
85
|
-
|
86
|
-
// First intersection should be with the first curve
|
87
|
-
const firstIntersection = intersections[0];
|
88
|
-
expect(firstIntersection.point.xy).toMatchObject({
|
89
|
-
x: -50,
|
90
|
-
y: 100,
|
91
|
-
});
|
92
|
-
expect(firstIntersection.curve.get(firstIntersection.parameterValue)).toMatchObject({
|
93
|
-
x: -50,
|
94
|
-
y: 100,
|
95
|
-
});
|
96
|
-
});
|
97
|
-
|
98
|
-
describe('polylineApproximation', () => {
|
99
|
-
it('should approximate Bézier curves with polylines', () => {
|
100
|
-
const path = Path.fromString('m0,0 l4,4 Q 1,4 4,1z');
|
101
|
-
|
102
|
-
expect(path.polylineApproximation()).toMatchObject([
|
103
|
-
new LineSegment2(Vec2.of(0, 0), Vec2.of(4, 4)),
|
104
|
-
new LineSegment2(Vec2.of(4, 4), Vec2.of(1, 4)),
|
105
|
-
new LineSegment2(Vec2.of(1, 4), Vec2.of(4, 1)),
|
106
|
-
new LineSegment2(Vec2.of(4, 1), Vec2.of(0, 0)),
|
107
|
-
]);
|
108
|
-
});
|
109
|
-
});
|
110
|
-
|
111
|
-
describe('roughlyIntersectsClosed', () => {
|
112
|
-
it('small, line-only path', () => {
|
113
|
-
const path = Path.fromString('m0,0 l10,10 L0,10 z');
|
114
|
-
expect(
|
115
|
-
path.closedRoughlyIntersects(Rect2.fromCorners(Vec2.zero, Vec2.of(20, 20)))
|
116
|
-
).toBe(true);
|
117
|
-
expect(
|
118
|
-
path.closedRoughlyIntersects(Rect2.fromCorners(Vec2.zero, Vec2.of(2, 2)))
|
119
|
-
).toBe(true);
|
120
|
-
expect(
|
121
|
-
path.closedRoughlyIntersects(new Rect2(10, 1, 1, 1))
|
122
|
-
).toBe(false);
|
123
|
-
expect(
|
124
|
-
path.closedRoughlyIntersects(new Rect2(1, 5, 1, 1))
|
125
|
-
).toBe(true);
|
126
|
-
});
|
127
|
-
|
128
|
-
it('path with Bézier curves', () => {
|
129
|
-
const path = Path.fromString(`
|
130
|
-
M1090,2560
|
131
|
-
L1570,2620
|
132
|
-
Q1710,1300 1380,720
|
133
|
-
Q980,100 -460,-640
|
134
|
-
L-680,-200
|
135
|
-
Q670,470 960,980
|
136
|
-
Q1230,1370 1090,2560
|
137
|
-
`);
|
138
|
-
expect(
|
139
|
-
path.closedRoughlyIntersects(new Rect2(0, 0, 500, 500))
|
140
|
-
).toBe(true);
|
141
|
-
expect(
|
142
|
-
path.closedRoughlyIntersects(new Rect2(0, 0, 5, 5))
|
143
|
-
).toBe(true);
|
144
|
-
expect(
|
145
|
-
path.closedRoughlyIntersects(new Rect2(-10000, 0, 500, 500))
|
146
|
-
).toBe(false);
|
147
|
-
});
|
148
|
-
});
|
149
|
-
|
150
|
-
describe('roughlyIntersects', () => {
|
151
|
-
it('should consider parts outside bbox of individual parts of a line as not intersecting', () => {
|
152
|
-
const path = Path.fromString(`
|
153
|
-
M10,10
|
154
|
-
L20,20
|
155
|
-
L100,21
|
156
|
-
`);
|
157
|
-
expect(
|
158
|
-
path.roughlyIntersects(new Rect2(0, 0, 50, 50))
|
159
|
-
).toBe(true);
|
160
|
-
expect(
|
161
|
-
path.roughlyIntersects(new Rect2(0, 0, 5, 5))
|
162
|
-
).toBe(false);
|
163
|
-
expect(
|
164
|
-
path.roughlyIntersects(new Rect2(8, 22, 1, 1))
|
165
|
-
).toBe(false);
|
166
|
-
expect(
|
167
|
-
path.roughlyIntersects(new Rect2(21, 11, 1, 1))
|
168
|
-
).toBe(false);
|
169
|
-
expect(
|
170
|
-
path.roughlyIntersects(new Rect2(50, 19, 1, 2))
|
171
|
-
).toBe(true);
|
172
|
-
});
|
173
|
-
});
|
174
|
-
|
175
|
-
describe('fromRect', () => {
|
176
|
-
const filledRect = Path.fromRect(Rect2.unitSquare);
|
177
|
-
const strokedRect = Path.fromRect(Rect2.unitSquare, 0.1);
|
178
|
-
|
179
|
-
it('filled should be closed shape', () => {
|
180
|
-
const lastSegment = filledRect.parts[filledRect.parts.length - 1];
|
181
|
-
|
182
|
-
if (lastSegment.kind !== PathCommandType.LineTo) {
|
183
|
-
throw new Error('Rectangles should only be made up of lines');
|
184
|
-
}
|
185
|
-
|
186
|
-
expect(filledRect.startPoint).objEq(lastSegment.point);
|
187
|
-
});
|
188
|
-
|
189
|
-
it('stroked should be closed shape', () => {
|
190
|
-
const lastSegment = strokedRect.parts[strokedRect.parts.length - 1];
|
191
|
-
if (lastSegment.kind !== PathCommandType.LineTo) {
|
192
|
-
throw new Error('Rectangles should only be made up of lines');
|
193
|
-
}
|
194
|
-
|
195
|
-
expect(strokedRect.startPoint).objEq(lastSegment.point);
|
196
|
-
});
|
197
|
-
});
|
198
|
-
});
|
@@ -1,77 +0,0 @@
|
|
1
|
-
import Path, { PathCommandType } from './Path';
|
2
|
-
import { Vec2 } from './Vec2';
|
3
|
-
|
4
|
-
|
5
|
-
describe('Path.toString', () => {
|
6
|
-
it('a single-point path should produce a move-to command', () => {
|
7
|
-
const path = new Path(Vec2.of(0, 0), []);
|
8
|
-
expect(path.toString()).toBe('M0,0');
|
9
|
-
});
|
10
|
-
|
11
|
-
it('should convert lineTo commands to L SVG commands', () => {
|
12
|
-
const path = new Path(Vec2.of(0.1, 0.2), [
|
13
|
-
{
|
14
|
-
kind: PathCommandType.LineTo,
|
15
|
-
point: Vec2.of(0.3, 0.4),
|
16
|
-
},
|
17
|
-
]);
|
18
|
-
expect(path.toString()).toBe('M.1,.2L.3,.4');
|
19
|
-
});
|
20
|
-
|
21
|
-
it('should fix rounding errors', () => {
|
22
|
-
const path = new Path(Vec2.of(0.100000001, 0.199999999), [
|
23
|
-
{
|
24
|
-
kind: PathCommandType.QuadraticBezierTo,
|
25
|
-
controlPoint: Vec2.of(9999, -10.999999995),
|
26
|
-
endPoint: Vec2.of(0.000300001, 1.400000002),
|
27
|
-
},
|
28
|
-
{
|
29
|
-
kind: PathCommandType.LineTo,
|
30
|
-
point: Vec2.of(184.00482359999998, 1)
|
31
|
-
}
|
32
|
-
]);
|
33
|
-
|
34
|
-
expect(path.toString()).toBe('M.1,.2Q9999,-11 .0003,1.4L184.0048236,1');
|
35
|
-
});
|
36
|
-
|
37
|
-
it('should not remove trailing zeroes before decimal points', () => {
|
38
|
-
const path = new Path(Vec2.of(1000, 2_000_000), [
|
39
|
-
{
|
40
|
-
kind: PathCommandType.LineTo,
|
41
|
-
point: Vec2.of(30.00000001, 40.000000001),
|
42
|
-
},
|
43
|
-
]);
|
44
|
-
|
45
|
-
expect(path.toString()).toBe('M1000,2000000l-970-1999960');
|
46
|
-
});
|
47
|
-
|
48
|
-
it('deserialized path should serialize to the same/similar path, but with rounded components', () => {
|
49
|
-
const path1 = Path.fromString('M100,100 L101,101 Q102,102 90.000000001,89.99999999 Z');
|
50
|
-
path1['cachedStringVersion'] = null; // Clear the cache.
|
51
|
-
|
52
|
-
expect(path1.toString()).toBe([
|
53
|
-
'M100,100', 'l1,1', 'q1,1 -11-11', 'l10,10'
|
54
|
-
].join(''));
|
55
|
-
});
|
56
|
-
|
57
|
-
it('should not lose precision when saving', () => {
|
58
|
-
const pathStr = 'M184.2,52.3l-.2-.2q-2.7,2.4 -3.2,3.5q-2.8,7 -.9,6.1q4.3-2.6 4.8-6.1q1.2-8.8 .4-8.3q-4.2,5.2 -3.9,3.9q.2-1.6 .3-2.1q.2-1.3 -.2-1q-3.8,6.5 -3.2,3.3q.6-4.1 1.1-5.3q4.1-10 3.3-8.3q-5.3,13.1 -6.6,14.1q-3.3,2.8 -1.8-1.5q2.8-9.7 2.7-8.4q0,.3 0,.4q-1.4,7.1 -2.7,8.5q-2.6,3.2 -2.5,2.9q-.3-1.9 -.7-1.9q-4.1,4.4 -2.9,1.9q1.1-3 .3-2.6q-1.8,2 -2.5,2.4q-4.5,2.8 -4.2,1.9q.3-1.6 .2-1.4q1.5,2.2 1.3,2.9q-.8,3.9 -.5,3.3q.8-7.6 2.5-13.3q2.6-9.2 2.9-6.9q.3,1.4 .3,1.2q-.7-.4 -.9,0q-2.2,11.6 -7.6,13.6q-3.9,1.6 -2.1-1.3q3-5.5 2.6-3.4q-.2,1.8 -.5,1.8q-3.2,.5 -4.1,1.2q-2.6,2.6 -1.9,2.5q4.7-4.4 3.7-5.5q-1.1-.9 -1.6-.6q-7.2,7.5 -3.9,6.5q.3-.1 .4-.4q.6-5.3 -.2-4.9q-2.8,2.3 -3.1,2.4q-3.7,1.5 -3.5,.5q.3-3.6 1.4-3.3q3.5,.7 1.9,2.4q-1.7,2.3 -1.6,.8q0-3.5 -.9-3.1q-5.1,3.3 -4.9,2.8q.1-4 -.8-3.5q-4.3,3.4 -4.6,2.5q-1-2.1 .5-8.7l-.2,0q-1.6,6.6 -.7,8.9q.7,1.2 5.2-2.3q.4-.5 .2,3.1q.1,1 5.5-2.4q.4-.4 .3,2.7q.1,2 2.4-.4q1.7-2.3 -2.1-3.2q-1.7-.3 -2,3.7q0,1.4 4.1-.1q.3-.1 3.1-2.4q.3-.5 -.4,4.5q0-.1 -.2,0q-2.6,1.2 4.5-5.7q0-.2 .8,.6q.9,.6 -3.7,4.7q-.5,1 2.7-1.7q.6-.7 3.7-1.2q.7-.2 .9-2.2q.1-2.7 -3.4,3.2q-1.8,3.4 2.7,1.9q5.6-2.1 7.8-14q-.1,.1 .3,.4q.6,.1 .3-1.6q-.7-2.8 -3.7,6.7q-1.8,5.8 -2.5,13.5q.1,1.1 1.3-3.1q.2-1 -1.3-3.3q-.5-.5 -1,1.6q-.1,1.3 4.8-1.5q1-1 3-2q.1-.4 -1.1,2q-1.1,3.1 3.7-1.3q-.4,0 -.1,1.5q.3,.8 3.3-2.5q1.3-1.6 2.7-8.9q0-.1 0-.4q-.3-1.9 -3.5,8.2q-1.3,4.9 2.4,2.1q1.4-1.2 6.6-14.3q.8-2.4 -3.9,7.9q-.6,1.3 -1.1,5.5q-.3,3.7 4-3.1q-.2,0 -.6,.6q-.2,.6 -.3,2.3q0,1.8 4.7-3.5q.1-.5 -1.2,7.9q-.5,3.2 -4.6,5.7q-1.3,1 1.5-5.5q.4-1.1 3.01-3.5';
|
59
|
-
|
60
|
-
const path1 = Path.fromString(pathStr);
|
61
|
-
path1['cachedStringVersion'] = null; // Clear the cache.
|
62
|
-
const path = Path.fromString(path1.toString(true));
|
63
|
-
path1['cachedStringVersion'] = null; // Clear the cache.
|
64
|
-
|
65
|
-
expect(path.toString(true)).toBe(path1.toString(true));
|
66
|
-
});
|
67
|
-
|
68
|
-
it('should remove no-op move-tos', () => {
|
69
|
-
const path1 = Path.fromString('M50,75m0,0q0,12.5 0,50q0,6.3 25,0');
|
70
|
-
path1['cachedStringVersion'] = null;
|
71
|
-
const path2 = Path.fromString('M150,175M150,175q0,12.5 0,50q0,6.3 25,0');
|
72
|
-
path2['cachedStringVersion'] = null;
|
73
|
-
|
74
|
-
expect(path1.toString()).toBe('M50,75q0,12.5 0,50q0,6.3 25,0');
|
75
|
-
expect(path2.toString()).toBe('M150,175q0,12.5 0,50q0,6.3 25,0');
|
76
|
-
});
|
77
|
-
});
|