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.
Files changed (227) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/bundle.js +2 -2
  3. package/dist/bundledStyles.js +1 -0
  4. package/dist/cjs/src/Color4.d.ts +8 -0
  5. package/dist/cjs/src/Color4.js +67 -0
  6. package/dist/cjs/src/Editor.d.ts +2 -2
  7. package/dist/cjs/src/Editor.js +2 -2
  8. package/dist/cjs/src/SVGLoader.js +8 -5
  9. package/dist/cjs/src/components/AbstractComponent.d.ts +2 -2
  10. package/dist/cjs/src/components/AbstractComponent.js +3 -3
  11. package/dist/cjs/src/components/ImageBackground.js +1 -1
  12. package/dist/cjs/src/components/RestylableComponent.d.ts +21 -2
  13. package/dist/cjs/src/components/Stroke.d.ts +35 -0
  14. package/dist/cjs/src/components/Stroke.js +36 -2
  15. package/dist/cjs/src/components/TextComponent.d.ts +26 -4
  16. package/dist/cjs/src/components/TextComponent.js +22 -0
  17. package/dist/cjs/src/components/lib.d.ts +3 -2
  18. package/dist/cjs/src/lib.d.ts +30 -0
  19. package/dist/cjs/src/lib.js +30 -0
  20. package/dist/cjs/src/rendering/RenderingStyle.d.ts +4 -4
  21. package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +10 -10
  22. package/dist/cjs/src/rendering/lib.d.ts +2 -0
  23. package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
  24. package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
  25. package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
  26. package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
  27. package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
  28. package/dist/cjs/src/toolbar/IconProvider.d.ts +2 -2
  29. package/dist/cjs/src/toolbar/localization.js +1 -1
  30. package/dist/cjs/src/toolbar/widgets/BaseWidget.js +1 -1
  31. package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
  32. package/dist/cjs/src/tools/SoundUITool.js +164 -0
  33. package/dist/cjs/src/tools/TextTool.d.ts +2 -2
  34. package/dist/cjs/src/tools/ToolController.js +6 -1
  35. package/dist/cjs/src/tools/lib.d.ts +1 -0
  36. package/dist/cjs/src/tools/lib.js +3 -1
  37. package/dist/cjs/src/tools/localization.d.ts +3 -0
  38. package/dist/cjs/src/tools/localization.js +3 -0
  39. package/dist/mjs/src/Color4.d.ts +8 -0
  40. package/dist/mjs/src/Color4.mjs +64 -0
  41. package/dist/mjs/src/Editor.d.ts +2 -2
  42. package/dist/mjs/src/Editor.mjs +2 -2
  43. package/dist/mjs/src/SVGLoader.mjs +8 -5
  44. package/dist/mjs/src/components/AbstractComponent.d.ts +2 -2
  45. package/dist/mjs/src/components/AbstractComponent.mjs +3 -3
  46. package/dist/mjs/src/components/ImageBackground.mjs +1 -1
  47. package/dist/mjs/src/components/RestylableComponent.d.ts +21 -2
  48. package/dist/mjs/src/components/Stroke.d.ts +35 -0
  49. package/dist/mjs/src/components/Stroke.mjs +36 -2
  50. package/dist/mjs/src/components/TextComponent.d.ts +26 -4
  51. package/dist/mjs/src/components/TextComponent.mjs +22 -0
  52. package/dist/mjs/src/components/lib.d.ts +3 -2
  53. package/dist/mjs/src/lib.d.ts +30 -0
  54. package/dist/mjs/src/lib.mjs +30 -0
  55. package/dist/mjs/src/rendering/RenderingStyle.d.ts +4 -4
  56. package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +10 -10
  57. package/dist/mjs/src/rendering/lib.d.ts +2 -0
  58. package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
  59. package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
  60. package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
  61. package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
  62. package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
  63. package/dist/mjs/src/toolbar/IconProvider.d.ts +2 -2
  64. package/dist/mjs/src/toolbar/localization.mjs +1 -1
  65. package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +1 -1
  66. package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
  67. package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
  68. package/dist/mjs/src/tools/TextTool.d.ts +2 -2
  69. package/dist/mjs/src/tools/ToolController.mjs +6 -1
  70. package/dist/mjs/src/tools/lib.d.ts +1 -0
  71. package/dist/mjs/src/tools/lib.mjs +1 -0
  72. package/dist/mjs/src/tools/localization.d.ts +3 -0
  73. package/dist/mjs/src/tools/localization.mjs +3 -0
  74. package/package.json +6 -4
  75. package/src/Editor.css +2 -2
  76. package/src/tools/SoundUITool.css +15 -0
  77. package/src/tools/tools.css +4 -0
  78. package/src/Color4.test.ts +0 -40
  79. package/src/Color4.ts +0 -236
  80. package/src/Editor.loadFrom.test.ts +0 -24
  81. package/src/Editor.toSVG.test.ts +0 -111
  82. package/src/Editor.ts +0 -1122
  83. package/src/EditorImage.test.ts +0 -120
  84. package/src/EditorImage.ts +0 -603
  85. package/src/EventDispatcher.test.ts +0 -123
  86. package/src/EventDispatcher.ts +0 -71
  87. package/src/Pointer.ts +0 -127
  88. package/src/SVGLoader.test.ts +0 -114
  89. package/src/SVGLoader.ts +0 -511
  90. package/src/UndoRedoHistory.test.ts +0 -33
  91. package/src/UndoRedoHistory.ts +0 -102
  92. package/src/Viewport.ts +0 -319
  93. package/src/bundle/bundled.ts +0 -7
  94. package/src/commands/Command.ts +0 -45
  95. package/src/commands/Duplicate.ts +0 -48
  96. package/src/commands/Erase.ts +0 -74
  97. package/src/commands/SerializableCommand.ts +0 -49
  98. package/src/commands/UnresolvedCommand.ts +0 -37
  99. package/src/commands/invertCommand.ts +0 -51
  100. package/src/commands/lib.ts +0 -16
  101. package/src/commands/localization.ts +0 -47
  102. package/src/commands/uniteCommands.test.ts +0 -23
  103. package/src/commands/uniteCommands.ts +0 -135
  104. package/src/components/AbstractComponent.transformBy.test.ts +0 -22
  105. package/src/components/AbstractComponent.ts +0 -364
  106. package/src/components/ImageBackground.test.ts +0 -35
  107. package/src/components/ImageBackground.ts +0 -176
  108. package/src/components/ImageComponent.ts +0 -171
  109. package/src/components/RestylableComponent.ts +0 -142
  110. package/src/components/SVGGlobalAttributesObject.ts +0 -81
  111. package/src/components/Stroke.test.ts +0 -139
  112. package/src/components/Stroke.ts +0 -245
  113. package/src/components/TextComponent.test.ts +0 -99
  114. package/src/components/TextComponent.ts +0 -315
  115. package/src/components/UnknownSVGObject.test.ts +0 -10
  116. package/src/components/UnknownSVGObject.ts +0 -60
  117. package/src/components/builders/ArrowBuilder.ts +0 -107
  118. package/src/components/builders/FreehandLineBuilder.ts +0 -212
  119. package/src/components/builders/LineBuilder.ts +0 -77
  120. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
  121. package/src/components/builders/RectangleBuilder.ts +0 -74
  122. package/src/components/builders/types.ts +0 -15
  123. package/src/components/lib.ts +0 -25
  124. package/src/components/localization.ts +0 -22
  125. package/src/components/util/StrokeSmoother.ts +0 -293
  126. package/src/components/util/describeComponentList.ts +0 -18
  127. package/src/lib.ts +0 -37
  128. package/src/localization.ts +0 -34
  129. package/src/localizations/de.ts +0 -98
  130. package/src/localizations/en.ts +0 -8
  131. package/src/localizations/es.ts +0 -74
  132. package/src/localizations/getLocalizationTable.test.ts +0 -27
  133. package/src/localizations/getLocalizationTable.ts +0 -55
  134. package/src/math/LineSegment2.test.ts +0 -99
  135. package/src/math/LineSegment2.ts +0 -160
  136. package/src/math/Mat33.test.ts +0 -244
  137. package/src/math/Mat33.ts +0 -437
  138. package/src/math/Path.fromString.test.ts +0 -223
  139. package/src/math/Path.test.ts +0 -198
  140. package/src/math/Path.toString.test.ts +0 -77
  141. package/src/math/Path.ts +0 -790
  142. package/src/math/Rect2.test.ts +0 -204
  143. package/src/math/Rect2.ts +0 -315
  144. package/src/math/Triangle.ts +0 -29
  145. package/src/math/Vec2.test.ts +0 -30
  146. package/src/math/Vec2.ts +0 -18
  147. package/src/math/Vec3.test.ts +0 -44
  148. package/src/math/Vec3.ts +0 -218
  149. package/src/math/lib.ts +0 -15
  150. package/src/math/rounding.test.ts +0 -65
  151. package/src/math/rounding.ts +0 -156
  152. package/src/rendering/Display.ts +0 -249
  153. package/src/rendering/RenderingStyle.test.ts +0 -68
  154. package/src/rendering/RenderingStyle.ts +0 -55
  155. package/src/rendering/TextRenderingStyle.ts +0 -45
  156. package/src/rendering/caching/CacheRecord.test.ts +0 -49
  157. package/src/rendering/caching/CacheRecord.ts +0 -77
  158. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  159. package/src/rendering/caching/RenderingCache.test.ts +0 -44
  160. package/src/rendering/caching/RenderingCache.ts +0 -66
  161. package/src/rendering/caching/RenderingCacheNode.ts +0 -405
  162. package/src/rendering/caching/testUtils.ts +0 -35
  163. package/src/rendering/caching/types.ts +0 -34
  164. package/src/rendering/lib.ts +0 -6
  165. package/src/rendering/localization.ts +0 -20
  166. package/src/rendering/renderers/AbstractRenderer.ts +0 -222
  167. package/src/rendering/renderers/CanvasRenderer.ts +0 -296
  168. package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
  169. package/src/rendering/renderers/DummyRenderer.ts +0 -136
  170. package/src/rendering/renderers/SVGRenderer.ts +0 -354
  171. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
  172. package/src/testing/beforeEachFile.ts +0 -8
  173. package/src/testing/createEditor.ts +0 -11
  174. package/src/testing/global.d.ts +0 -17
  175. package/src/testing/lib.ts +0 -3
  176. package/src/testing/loadExpectExtensions.ts +0 -25
  177. package/src/testing/sendPenEvent.ts +0 -31
  178. package/src/testing/sendTouchEvent.ts +0 -78
  179. package/src/toolbar/HTMLToolbar.ts +0 -492
  180. package/src/toolbar/IconProvider.ts +0 -736
  181. package/src/toolbar/lib.ts +0 -4
  182. package/src/toolbar/localization.ts +0 -106
  183. package/src/toolbar/makeColorInput.ts +0 -145
  184. package/src/toolbar/types.ts +0 -5
  185. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  186. package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
  187. package/src/toolbar/widgets/BaseWidget.ts +0 -377
  188. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
  189. package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
  190. package/src/toolbar/widgets/HandToolWidget.ts +0 -250
  191. package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
  192. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  193. package/src/toolbar/widgets/PenToolWidget.ts +0 -288
  194. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
  195. package/src/toolbar/widgets/TextToolWidget.ts +0 -145
  196. package/src/toolbar/widgets/lib.ts +0 -13
  197. package/src/tools/BaseTool.ts +0 -76
  198. package/src/tools/Eraser.test.ts +0 -103
  199. package/src/tools/Eraser.ts +0 -139
  200. package/src/tools/FindTool.ts +0 -152
  201. package/src/tools/PanZoom.test.ts +0 -310
  202. package/src/tools/PanZoom.ts +0 -520
  203. package/src/tools/PasteHandler.ts +0 -95
  204. package/src/tools/Pen.test.ts +0 -194
  205. package/src/tools/Pen.ts +0 -226
  206. package/src/tools/PipetteTool.ts +0 -55
  207. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
  208. package/src/tools/SelectionTool/Selection.ts +0 -607
  209. package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
  210. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
  211. package/src/tools/SelectionTool/SelectionTool.ts +0 -480
  212. package/src/tools/SelectionTool/TransformMode.ts +0 -114
  213. package/src/tools/SelectionTool/types.ts +0 -11
  214. package/src/tools/TextTool.ts +0 -326
  215. package/src/tools/ToolController.ts +0 -178
  216. package/src/tools/ToolEnabledGroup.ts +0 -14
  217. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  218. package/src/tools/ToolbarShortcutHandler.ts +0 -34
  219. package/src/tools/UndoRedoShortcut.test.ts +0 -56
  220. package/src/tools/UndoRedoShortcut.ts +0 -25
  221. package/src/tools/lib.ts +0 -21
  222. package/src/tools/localization.ts +0 -66
  223. package/src/types.ts +0 -234
  224. package/src/util/assertions.ts +0 -55
  225. package/src/util/fileToBase64.ts +0 -18
  226. package/src/util/untilNextAnimationFrame.ts +0 -9
  227. package/src/util/waitForTimeout.ts +0 -9
@@ -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
- });