svg-path-commander 2.1.2 → 2.1.5
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/README.md +4 -4
- package/dist/svg-path-commander.cjs +1 -1
- package/dist/svg-path-commander.cjs.map +1 -1
- package/dist/svg-path-commander.d.ts +755 -849
- package/dist/svg-path-commander.js +1 -1
- package/dist/svg-path-commander.js.map +1 -1
- package/dist/svg-path-commander.mjs +947 -611
- package/dist/svg-path-commander.mjs.map +1 -1
- package/package.json +14 -22
- package/.eslintrc.cjs +0 -225
- package/.prettierrc.json +0 -15
- package/dts.config.ts +0 -15
- package/src/convert/pathToAbsolute.ts +0 -18
- package/src/convert/pathToCurve.ts +0 -43
- package/src/convert/pathToRelative.ts +0 -18
- package/src/convert/pathToString.ts +0 -50
- package/src/index.ts +0 -454
- package/src/interface.ts +0 -130
- package/src/math/arcTools.ts +0 -396
- package/src/math/bezier.ts +0 -261
- package/src/math/cubicTools.ts +0 -124
- package/src/math/distanceSquareRoot.ts +0 -15
- package/src/math/lineTools.ts +0 -69
- package/src/math/midPoint.ts +0 -18
- package/src/math/polygonTools.ts +0 -48
- package/src/math/quadTools.ts +0 -100
- package/src/math/rotateVector.ts +0 -17
- package/src/math/roundTo.ts +0 -7
- package/src/options/options.ts +0 -9
- package/src/parser/error.ts +0 -2
- package/src/parser/finalizeSegment.ts +0 -35
- package/src/parser/invalidPathValue.ts +0 -2
- package/src/parser/isArcCommand.ts +0 -11
- package/src/parser/isDigit.ts +0 -12
- package/src/parser/isDigitStart.ts +0 -14
- package/src/parser/isMoveCommand.ts +0 -17
- package/src/parser/isPathCommand.ts +0 -28
- package/src/parser/isSpace.ts +0 -23
- package/src/parser/paramsCount.ts +0 -16
- package/src/parser/paramsParser.ts +0 -14
- package/src/parser/parsePathString.ts +0 -33
- package/src/parser/pathParser.ts +0 -29
- package/src/parser/scanFlag.ts +0 -29
- package/src/parser/scanParam.ts +0 -102
- package/src/parser/scanSegment.ts +0 -84
- package/src/parser/skipSpaces.ts +0 -17
- package/src/process/absolutizeSegment.ts +0 -63
- package/src/process/arcToCubic.ts +0 -128
- package/src/process/getSVGMatrix.ts +0 -70
- package/src/process/iterate.ts +0 -58
- package/src/process/lineToCubic.ts +0 -17
- package/src/process/normalizePath.ts +0 -33
- package/src/process/normalizeSegment.ts +0 -84
- package/src/process/optimizePath.ts +0 -63
- package/src/process/projection2d.ts +0 -52
- package/src/process/quadToCubic.ts +0 -31
- package/src/process/relativizeSegment.ts +0 -59
- package/src/process/reverseCurve.ts +0 -24
- package/src/process/reversePath.ts +0 -114
- package/src/process/roundPath.ts +0 -33
- package/src/process/roundSegment.ts +0 -9
- package/src/process/segmentToCubic.ts +0 -48
- package/src/process/shortenSegment.ts +0 -71
- package/src/process/splitCubic.ts +0 -29
- package/src/process/splitPath.ts +0 -63
- package/src/process/transformPath.ts +0 -110
- package/src/types.ts +0 -228
- package/src/util/distanceEpsilon.ts +0 -3
- package/src/util/getClosestPoint.ts +0 -15
- package/src/util/getDrawDirection.ts +0 -16
- package/src/util/getPathArea.ts +0 -70
- package/src/util/getPathBBox.ts +0 -98
- package/src/util/getPointAtLength.ts +0 -110
- package/src/util/getPropertiesAtLength.ts +0 -67
- package/src/util/getPropertiesAtPoint.ts +0 -84
- package/src/util/getSegmentAtLength.ts +0 -15
- package/src/util/getSegmentOfPoint.ts +0 -18
- package/src/util/getTotalLength.ts +0 -68
- package/src/util/isAbsoluteArray.ts +0 -18
- package/src/util/isCurveArray.ts +0 -15
- package/src/util/isNormalizedArray.ts +0 -16
- package/src/util/isPathArray.ts +0 -24
- package/src/util/isPointInStroke.ts +0 -16
- package/src/util/isRelativeArray.ts +0 -18
- package/src/util/isValidPath.ts +0 -27
- package/src/util/shapeParams.ts +0 -16
- package/src/util/shapeToPath.ts +0 -86
- package/src/util/shapeToPathArray.ts +0 -183
- package/test/class.test.ts +0 -504
- package/test/fixtures/getMarkup.ts +0 -17
- package/test/fixtures/shapeObjects.ts +0 -11
- package/test/fixtures/shapes.js +0 -104
- package/test/fixtures/simpleShapes.js +0 -75
- package/test/static.test.ts +0 -330
- package/vite.config.mts +0 -41
- package/vitest.config-ui.mts +0 -26
- package/vitest.config.mts +0 -26
package/test/class.test.ts
DELETED
|
@@ -1,504 +0,0 @@
|
|
|
1
|
-
import { expect, it, describe, beforeEach, vi } from 'vitest';
|
|
2
|
-
import SVGPathCommander from '~/index';
|
|
3
|
-
import invalidPathValue from '../src/parser/invalidPathValue';
|
|
4
|
-
import error from '../src/parser/error';
|
|
5
|
-
|
|
6
|
-
import getMarkup from './fixtures/getMarkup';
|
|
7
|
-
import shapes from './fixtures/shapes';
|
|
8
|
-
import simpleShapes from './fixtures/simpleShapes';
|
|
9
|
-
|
|
10
|
-
import "../docs/assets/style.css";
|
|
11
|
-
|
|
12
|
-
describe('SVGPathCommander Class Test', () => {
|
|
13
|
-
const wrapper = document.createElement('div');
|
|
14
|
-
document.body.append(wrapper);
|
|
15
|
-
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
wrapper.innerHTML = '';
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('Test init with no parameter / empty throws error', () => {
|
|
21
|
-
try {
|
|
22
|
-
// @ts-expect-error
|
|
23
|
-
new SVGPathCommander();
|
|
24
|
-
} catch (er) {
|
|
25
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
26
|
-
expect(er).to.have.property('message', `${error}: "pathValue" is undefined`);
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
new SVGPathCommander('');
|
|
30
|
-
} catch (er) {
|
|
31
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
32
|
-
expect(er).to.have.property('message', `${error}: "pathValue" is empty`);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('Test init with invalid path value throws error', () => {
|
|
37
|
-
try {
|
|
38
|
-
new SVGPathCommander('M04 36.9a23.5 23');
|
|
39
|
-
} catch (er) {
|
|
40
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
41
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} at index 1, "0" illegal number`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
new SVGPathCommander('M4 36.9efa23.5 23');
|
|
46
|
-
} catch (er) {
|
|
47
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
48
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} at index 8, "f" invalid integer exponent`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
new SVGPathCommander('M4 .ea23.5 23');
|
|
53
|
-
} catch (er) {
|
|
54
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
55
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} at index 4, "e" invalid float exponent`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
new SVGPathCommander('M4 36.9a23.5 23');
|
|
60
|
-
} catch (er) {
|
|
61
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
62
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} at index 15, "pathValue" is missing param`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
new SVGPathCommander('M2 0a2 2 0 00-2 2 12');
|
|
67
|
-
} catch (er) {
|
|
68
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
69
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} at index 20, "pathValue" is missing param`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
new SVGPathCommander('M2 0aa 2 0 00-2 2 12');
|
|
74
|
-
} catch (er) {
|
|
75
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
76
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} at index 5, "a" is not a number`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
new SVGPathCommander('M2 0a2 2 0 21-2 2 12');
|
|
81
|
-
} catch (er) {
|
|
82
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
83
|
-
expect(er).to.have.property('message', `${error}: invalid Arc flag "2", expecting 0 or 1 at index 11`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
new SVGPathCommander('M2 0a2 2 0 03-2 2 12');
|
|
88
|
-
} catch (er) {
|
|
89
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
90
|
-
expect(er).to.have.property('message', `${error}: invalid Arc flag "3", expecting 0 or 1 at index 12`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
new SVGPathCommander('2 0a2 2 0 00-2 2');
|
|
95
|
-
} catch (er) {
|
|
96
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
97
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} "2" is not a path command at index 0`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
new SVGPathCommander(`M13.158 9.208a1.63 1.63 0 0 0 -0.906 0.274a1.63 1.63 0 0 0 -0.601 0.73a1.63 1.63 0 0 0 -0.094 0.942a1.63 1.63 0 0 0 3.229 -0.314a1.6 1.6 0 0 0 -0.12 -0.627a1.6 1.6 0 0 0 -0.353 -0.533a1.6 1.6 0 0 0 -0.53 -0.356a1.6 1.6 0 0 0 -0.625 -0.125z
|
|
102
|
-
a1.63 1.63 0 0 0 -0.906 0.274a1.63 1.63 0 0 0 -0.601 0.73a1.63 1.63 0 0 0 -0.094 0.942a1.63 1.63 0 0 0 3.229 -0.314a1.6 1.6 0 0 0 -0.12 -0.627a1.6 1.6 0 0 0 -0.353 -0.533a1.6 1.6 0 0 0 -0.53 -0.356a1.6 1.6 0 0 0 -0.625 -0.125za1.63 1.63 0 0 0 -0.906 0.274a1.63 1.63 0 0 0 -0.601 0.73a1.63 1.63 0 0 0 -0.094 0.942a1.63 1.63 0 0 0 3.229 -0.314a1.6 1.6 0 0 0 -0.12 -0.627a1.6 1.6 0 0 0 -0.353 -0.533a1.6 1.6 0 0 0 -0.53 -0.356a1.6 1.6 0 0 0 -0.625 -0.125z`);
|
|
103
|
-
} catch (er) {
|
|
104
|
-
expect(er).to.be.instanceOf(TypeError);
|
|
105
|
-
expect(er).to.have.property('message', `${error}: ${invalidPathValue} "a" is not a MoveTo path command at index 240`);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('Test init with valid path value works', async () => {
|
|
110
|
-
const container = getMarkup();
|
|
111
|
-
wrapper.append(container);
|
|
112
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
113
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
114
|
-
const rect = new SVGPathCommander(
|
|
115
|
-
`M 2 0,
|
|
116
|
-
a2,2 0 00-2 2
|
|
117
|
-
v12
|
|
118
|
-
a2 2 0 002 2
|
|
119
|
-
h12
|
|
120
|
-
a2 2 0 0 0 2-2
|
|
121
|
-
V2
|
|
122
|
-
a2 2 0 0 0-2-2
|
|
123
|
-
H2
|
|
124
|
-
z`,
|
|
125
|
-
{ origin: [8,8,24] }
|
|
126
|
-
);
|
|
127
|
-
expect(rect.segments).to.have.length(10);
|
|
128
|
-
expect(rect.origin).to.deep.equal([8,8,24]);
|
|
129
|
-
expect(rect.round).to.equal(4);
|
|
130
|
-
path.setAttribute('d', rect.toString());
|
|
131
|
-
expect(path.getAttribute('d')).to.equal(rect.toString())
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('Test overloaded moveTo', async () => {
|
|
135
|
-
const container = getMarkup();
|
|
136
|
-
wrapper.append(container);
|
|
137
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
138
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
139
|
-
|
|
140
|
-
const star = new SVGPathCommander(
|
|
141
|
-
`M12.774 14.5111 8.0167 12.292 3.4918 14.9529 4.1321 9.7428 0.2031 6.2615 5.3562 5.2604 7.4528 0.4479 9.9972 5.0393 15.222 5.5463 11.6414 9.3851Z`,
|
|
142
|
-
{round: 2}
|
|
143
|
-
);
|
|
144
|
-
const star1 = new SVGPathCommander(
|
|
145
|
-
`m12.774 14.5111 -4.7573 -2.2191 -4.5249 2.6609 0.6403 -5.2101 -3.929 -3.4813 5.1531 -1.0011 2.0966 -4.8125 2.5444 4.5914 5.2248 0.507 -3.5806 3.8388z`,
|
|
146
|
-
{round: 2}
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
expect(star.segments).to.have.length(11);
|
|
150
|
-
expect(star1.segments).to.have.length(11);
|
|
151
|
-
|
|
152
|
-
path.setAttribute('d', star.toString());
|
|
153
|
-
expect(path.getAttribute('d')).to.equal(star.toString());
|
|
154
|
-
|
|
155
|
-
path.setAttribute('d', star1.toString());
|
|
156
|
-
expect(path.getAttribute('d')).to.equal(star1.toString());
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('Test rounding `off`, and [0-5]', async () => {
|
|
160
|
-
const container = getMarkup();
|
|
161
|
-
wrapper.append(container);
|
|
162
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
163
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
164
|
-
|
|
165
|
-
const rect = new SVGPathCommander(
|
|
166
|
-
'M2 0C0.8954304997175604 -8.780183295920349e-10 -1.3527075029566811e-16 0.8954304997175604 0 2C0 2 0 9.875 0 14C1.3527075029566811e-16 15.10456950028244 0.8954304997175604 16.000000000878018 2 16C8 16 10.25 16 14 16C15.104569499040734 15.999999999121982 16 15.104569499040734 16 14C16 8 16 5.75 16 2C16 0.8954305009592662 15.104569499040734 8.780185991465076e-10 14 0C8 0 5.75 0 2 0',
|
|
167
|
-
{ round: 2 }
|
|
168
|
-
);
|
|
169
|
-
expect(rect.round).to.equal(2);
|
|
170
|
-
path.setAttribute('d', rect.toString());
|
|
171
|
-
expect(path.getAttribute('d')).to.equal('M2 0C0.9 0 0 0.9 0 2C0 2 0 9.88 0 14C0 15.1 0.9 16 2 16C8 16 10.25 16 14 16C15.1 16 16 15.1 16 14C16 8 16 5.75 16 2C16 0.9 15.1 0 14 0C8 0 5.75 0 2 0')
|
|
172
|
-
|
|
173
|
-
const rect1 = new SVGPathCommander(
|
|
174
|
-
'M7.94 7.92C7.928954 7.92 7.92 7.928954 7.92 7.94C7.92 7.94 7.92 8.01875 7.92 8.06C7.92 8.071046 7.928954 8.08 7.94 8.08C8 8.08 8.0225 8.08 8.06 8.08C8.071046 8.08 8.08 8.071046 8.08 8.06C8.08 8 8.08 7.9775 8.08 7.94C8.08 7.928954 8.071046 7.92 8.06 7.92C8 7.92 7.9775 7.92 7.94 7.92',
|
|
175
|
-
{ round: 'off' }
|
|
176
|
-
);
|
|
177
|
-
expect(rect1.round).to.equal('off');
|
|
178
|
-
path.setAttribute('d', rect1.toString());
|
|
179
|
-
expect(path.getAttribute('d')).to.equal('M7.94 7.92C7.928954 7.92 7.92 7.928954 7.92 7.94C7.92 7.94 7.92 8.01875 7.92 8.06C7.92 8.071046 7.928954 8.08 7.94 8.08C8 8.08 8.0225 8.08 8.06 8.08C8.071046 8.08 8.08 8.071046 8.08 8.06C8.08 8 8.08 7.9775 8.08 7.94C8.08 7.928954 8.071046 7.92 8.06 7.92C8 7.92 7.9775 7.92 7.94 7.92')
|
|
180
|
-
|
|
181
|
-
const rect2 = new SVGPathCommander(
|
|
182
|
-
'M895.02 5.12C963.38 5.12 1018.88 60.62 1018.88 128.98V895.03C1018.88 963.39 963.38 1018.89 895.02 1018.89H128.98C60.62 1018.88 5.12 963.38 5.12 895.02V128.98C5.12 60.62 60.62 5.12 128.98 5.12H895.03Z',
|
|
183
|
-
{ round: 0 }
|
|
184
|
-
);
|
|
185
|
-
expect(rect2.round).to.equal(0);
|
|
186
|
-
path.setAttribute('d', rect2.toString());
|
|
187
|
-
expect(path.getAttribute('d')).to.equal('M895 5C963 5 1019 61 1019 129V895C1019 963 963 1019 895 1019H129C61 1019 5 963 5 895V129C5 61 61 5 129 5H895Z')
|
|
188
|
-
|
|
189
|
-
const roundSample = 'M2 0C0.8954304997175604 -8.780183295920349e-10 -1.3527075029566811e-16 0.8954304997175604 0 2C0 2 0 9.875 0 14C1.3527075029566811e-16 15.10456950028244 0.8954304997175604 16.000000000878018 2 16C8 16 10.25 16 14 16C15.104569499040734 15.999999999121982 16 15.104569499040734 16 14C16 8 16 5.75 16 2C16 0.8954305009592662 15.104569499040734 8.780185991465076e-10 14 0C8 0 5.75 0 2 0';
|
|
190
|
-
const rect3 = new SVGPathCommander(roundSample, {round: 'off'});
|
|
191
|
-
expect(rect3.round).to.equal('off');
|
|
192
|
-
path.setAttribute('d', rect3.toString());
|
|
193
|
-
expect(path.getAttribute('d')).to.equal(roundSample);
|
|
194
|
-
|
|
195
|
-
const rect4 = new SVGPathCommander(roundSample, {round: 0});
|
|
196
|
-
expect(rect4.round).to.equal(0);
|
|
197
|
-
path.setAttribute('d', rect4.toString());
|
|
198
|
-
expect(path.getAttribute('d')).to.equal('M2 0C1 0 0 1 0 2C0 2 0 10 0 14C0 15 1 16 2 16C8 16 10 16 14 16C15 16 16 15 16 14C16 8 16 6 16 2C16 1 15 0 14 0C8 0 6 0 2 0');
|
|
199
|
-
|
|
200
|
-
const rect5 = new SVGPathCommander(roundSample, {round: 5});
|
|
201
|
-
expect(rect5.round).to.equal(5);
|
|
202
|
-
path.setAttribute('d', rect5.toString());
|
|
203
|
-
expect(path.getAttribute('d')).to.equal('M2 0C0.89543 0 0 0.89543 0 2C0 2 0 9.875 0 14C0 15.10457 0.89543 16 2 16C8 16 10.25 16 14 16C15.10457 16 16 15.10457 16 14C16 8 16 5.75 16 2C16 0.89543 15.10457 0 14 0C8 0 5.75 0 2 0')
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('Test getBBox', async () => {
|
|
207
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').getBBox();
|
|
208
|
-
expect(rect, 'Using the SVGPathCommander').to.deep.equal({cx: 8, cy: 8, cz: 24, height: 16, width: 16, x: 0, x2: 16, y: 0, y2: 16});
|
|
209
|
-
expect(SVGPathCommander.getPathBBox(''), 'Using the static method').to.deep.equal({cx: 0, cy: 0, cz: 0, height: 0, width: 0, x: 0, x2: 0, y: 0, y2: 0});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('Test getTotalLength', () => {
|
|
213
|
-
const len = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').getTotalLength();
|
|
214
|
-
expect(Math.round(len)).to.equal(61);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('Test getPointAtLength', () => {
|
|
218
|
-
const pt = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').getPointAtLength(25);
|
|
219
|
-
expect(pt).to.deep.equal({ x: 8.716814692820414, y: 16 });
|
|
220
|
-
|
|
221
|
-
const pt1 = new SVGPathCommander('M2 0A2 2 0 00 2 0').getPointAtLength(0);
|
|
222
|
-
expect(pt1).to.deep.equal({ x: 2, y: 0 });
|
|
223
|
-
|
|
224
|
-
const pt2 = new SVGPathCommander('M2 0A0 2 0 00 0 2').getPointAtLength(0.5);
|
|
225
|
-
expect(pt2).to.deep.equal({x: 0, y: 2 });
|
|
226
|
-
|
|
227
|
-
const pt3 = new SVGPathCommander('M2 0A3 2 0 00 0 2').getPointAtLength(5);
|
|
228
|
-
expect(pt3).to.deep.equal({x: 0, y: 2});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('Test toAbsolute', async () => {
|
|
232
|
-
const container = getMarkup();
|
|
233
|
-
wrapper.append(container);
|
|
234
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
235
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
236
|
-
|
|
237
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').toAbsolute();
|
|
238
|
-
path.setAttribute('d', rect.toString());
|
|
239
|
-
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2V14A2 2 0 0 0 2 16H14A2 2 0 0 0 16 14V2A2 2 0 0 0 14 0H2Z')
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('Test toRelative', async () => {
|
|
243
|
-
const container = getMarkup();
|
|
244
|
-
wrapper.append(container);
|
|
245
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
246
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
247
|
-
|
|
248
|
-
const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2V14A2 2 0 0 0 2 16H14A2 2 0 0 0 16 14V2A2 2 0 0 0 14 0H2Z').toRelative();
|
|
249
|
-
path.setAttribute('d', rect.toString());
|
|
250
|
-
expect(path.getAttribute('d')).to.equal('M2 0a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-12z')
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('Test toCurve', async () => {
|
|
254
|
-
const container = getMarkup();
|
|
255
|
-
wrapper.append(container);
|
|
256
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
257
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
258
|
-
|
|
259
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z', { round: 'off' }).toCurve();
|
|
260
|
-
path.setAttribute('d', rect.toString());
|
|
261
|
-
expect(rect.round).to.equal('off')
|
|
262
|
-
expect(path.getAttribute('d')).to.equal('M2 0C0.8954305003384135 2.0290612532945332e-16 -1.3527075021963556e-16 0.8954305003384133 0 2C0 6 0 10 0 14C1.3527075021963556e-16 15.104569499661586 0.8954305003384133 16 2 16C6 16 10 16 14 16C15.104569499661586 16 16 15.104569499661586 16 14C16 10 16 6 16 2C16 0.8954305003384135 15.104569499661586 6.763537510981778e-17 14 0C10 0 6 0 2 0C2 0 2 0 2 0')
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('Test normalize', async () => {
|
|
266
|
-
const container = getMarkup();
|
|
267
|
-
wrapper.append(container);
|
|
268
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
269
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
270
|
-
|
|
271
|
-
const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2z').normalize();
|
|
272
|
-
path.setAttribute('d', rect.toString());
|
|
273
|
-
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2L0 14A2 2 0 0 0 2 16L14 16A2 2 0 0 0 16 14L16 2A2 2 0 0 0 14 0L2 0Z')
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it('Test optimize', async () => {
|
|
277
|
-
const container = getMarkup();
|
|
278
|
-
wrapper.append(container);
|
|
279
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
280
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
281
|
-
|
|
282
|
-
const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2L0 14A2 2 0 0 0 2 16L14 16A2 2 0 0 0 16 14L16 2A2 2 0 0 0 14 0L2 0Z').optimize();
|
|
283
|
-
|
|
284
|
-
path.setAttribute('d', rect.toString());
|
|
285
|
-
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2z');
|
|
286
|
-
// add at least one round: 'off' test
|
|
287
|
-
expect(new SVGPathCommander(simpleShapes.normalized[2], { round: 'off' }).optimize().toString()).to.equal(simpleShapes.initial[2]);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('Test reverse single path', async () => {
|
|
291
|
-
const container = getMarkup();
|
|
292
|
-
wrapper.append(container);
|
|
293
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
294
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
295
|
-
|
|
296
|
-
const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2z').reverse();
|
|
297
|
-
path.setAttribute('d', rect.toString());
|
|
298
|
-
expect(path.getAttribute('d')).to.equal('M2 0H14A2 2 0 0 1 16 2V14A2 2 0 0 1 14 16H2A2 2 0 0 1 0 14V2A2 2 0 0 1 2 0Z')
|
|
299
|
-
|
|
300
|
-
const rect1 = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2z').reverse(true);
|
|
301
|
-
|
|
302
|
-
path.setAttribute('d', rect1.toString());
|
|
303
|
-
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2V14A2 2 0 0 0 2 16H14A2 2 0 0 0 16 14V2A2 2 0 0 0 14 0H2Z')
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('Test reverse composite', async () => {
|
|
307
|
-
const container = getMarkup();
|
|
308
|
-
wrapper.append(container);
|
|
309
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
310
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
311
|
-
|
|
312
|
-
const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2zM4 4h8l-4 8z').reverse();
|
|
313
|
-
path.setAttribute('d', rect.toString());
|
|
314
|
-
expect(path.getAttribute('d')).to.equal('M2 0H14A2 2 0 0 1 16 2V14A2 2 0 0 1 14 16H2A2 2 0 0 1 0 14V2A2 2 0 0 1 2 0ZM8 12L12 4H4Z')
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('Test reverse composite path with `onlySubpath`', async () => {
|
|
318
|
-
const container = getMarkup();
|
|
319
|
-
wrapper.append(container);
|
|
320
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
321
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
322
|
-
|
|
323
|
-
const rect = new SVGPathCommander('M2 0A2 2 0 0 0 0 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2V2A2 2 0 0 0 14 0H2zM4 4h8l-4 8z').reverse(true);
|
|
324
|
-
path.setAttribute('d', rect.toString());
|
|
325
|
-
expect(path.getAttribute('d')).to.equal('M2 0A2 2 0 0 0 0 2V14A2 2 0 0 0 2 16H14A2 2 0 0 0 16 14V2A2 2 0 0 0 14 0H2ZM8 12L12 4H4Z')
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('Test flipX', () => {
|
|
329
|
-
const triangle = new SVGPathCommander('M0 0L16 0 L8 16');
|
|
330
|
-
expect(triangle.flipX().toString()).to.equal('M16 0H0L8 16');
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('Test flipY', () => {
|
|
334
|
-
const triangle = new SVGPathCommander('M0 0L16 0 L8 16');
|
|
335
|
-
expect(triangle.flipY().toString()).to.equal('M0 16H16L8 0');
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it('Test empty transform', () => {
|
|
339
|
-
const transform = {}
|
|
340
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z');
|
|
341
|
-
const transformed = rect.transform(transform);
|
|
342
|
-
const transformed1 = rect.transform();
|
|
343
|
-
// @ts-expect-error
|
|
344
|
-
const transformed2 = rect.transform('');
|
|
345
|
-
|
|
346
|
-
expect(rect.segments).to.deep.equal(transformed.segments);
|
|
347
|
-
expect(rect.segments).to.deep.equal(transformed1.segments);
|
|
348
|
-
expect(rect.segments).to.deep.equal(transformed2.segments);
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
it('Test transform', async () => {
|
|
352
|
-
const container = getMarkup();
|
|
353
|
-
wrapper.append(container);
|
|
354
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
355
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
356
|
-
|
|
357
|
-
const transform = {
|
|
358
|
-
rotate: [15,15],
|
|
359
|
-
skew: [-15,15],
|
|
360
|
-
}
|
|
361
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').transform(transform);
|
|
362
|
-
path.setAttribute('d', rect.toString());
|
|
363
|
-
expect(path.getAttribute('d')).to.equal('M1.829 0.5176C0.8189 0.2318 -0.1718 0.8649 -0.3837 1.9319L-2.6856 13.523C-2.8975 14.5899 -2.2504 15.6866 -1.2403 15.9725L9.734 19.0783C10.7442 19.3642 11.7349 18.731 11.9468 17.6641L14.2487 6.073C14.4606 5.006 13.8135 3.9094 12.8033 3.6235L1.829 0.5176Z')
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it('Test transform with custom [x,y] origin', async () => {
|
|
367
|
-
const container = getMarkup();
|
|
368
|
-
wrapper.append(container);
|
|
369
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
370
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
371
|
-
|
|
372
|
-
const transform = {
|
|
373
|
-
rotate: [15,15],
|
|
374
|
-
skew: [-15,15],
|
|
375
|
-
origin: [0,0]
|
|
376
|
-
}
|
|
377
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').transform(transform);
|
|
378
|
-
path.setAttribute('d', rect.toString());
|
|
379
|
-
expect(path.getAttribute('d')).to.equal('M1.829 0.5176C0.8189 0.2318 -0.1718 0.8649 -0.3837 1.9319L-2.6856 13.523C-2.8975 14.5899 -2.2504 15.6866 -1.2403 15.9725L9.734 19.0783C10.7442 19.3642 11.7349 18.731 11.9468 17.6641L14.2487 6.073C14.4606 5.006 13.8135 3.9094 12.8033 3.6235L1.829 0.5176Z')
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it('Test transform with custom [x,y,z] origin option', async () => {
|
|
383
|
-
const container = getMarkup();
|
|
384
|
-
wrapper.append(container);
|
|
385
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
386
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
387
|
-
|
|
388
|
-
const transform = {
|
|
389
|
-
rotate: [15,15],
|
|
390
|
-
skew: [-15,15]
|
|
391
|
-
}
|
|
392
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z', {origin: [8,0,24]}).transform(transform);
|
|
393
|
-
path.setAttribute('d', rect.toString());
|
|
394
|
-
expect(path.getAttribute('d')).to.equal('M2.2644 -1.6232C1.1515 -1.9382 -0.0487 -1.2959 -0.4093 -0.1515L-5.2306 15.1494C-5.7788 16.8892 -5.0014 18.5047 -3.5039 18.6907L10.9116 20.4811C12.0888 20.6273 13.1574 19.4458 13.3135 17.8935L14.7232 3.8815C14.8313 2.8068 14.1803 1.7491 13.2594 1.4884L2.2644 -1.6232Z');
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('Test transform with invalid origin value/option, should use [0,0,0]', async () => {
|
|
398
|
-
const container = getMarkup();
|
|
399
|
-
wrapper.append(container);
|
|
400
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
401
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
402
|
-
|
|
403
|
-
const transform = {
|
|
404
|
-
rotate: [15,15],
|
|
405
|
-
skew: [-15,15],
|
|
406
|
-
scale: 1.2,
|
|
407
|
-
}
|
|
408
|
-
// @ts-expect-error
|
|
409
|
-
const rect = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z', { origin: ['a','f','-8f'] }).transform(transform);
|
|
410
|
-
path.setAttribute('d', rect.toString());
|
|
411
|
-
expect(path.getAttribute('d')).to.equal('M2.1949 0.6212C0.9827 0.2781 -0.2061 1.0379 -0.4604 2.3182L-3.2228 16.2276C-3.477 17.5079 -2.7005 18.8239 -1.4883 19.1669L11.6808 22.8939C12.893 23.237 14.0818 22.4772 14.3361 21.1969L17.0985 7.2875C17.3527 6.0072 16.5762 4.6912 15.364 4.3482L2.1949 0.6212Z');
|
|
412
|
-
|
|
413
|
-
const transform1 = {
|
|
414
|
-
rotate: [15,15],
|
|
415
|
-
skew: [-15,15],
|
|
416
|
-
scale: 1.2,
|
|
417
|
-
origin: ['aa5','3f','-8f']
|
|
418
|
-
}
|
|
419
|
-
// @ts-expect-error
|
|
420
|
-
const rect1 = new SVGPathCommander('M2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z').transform(transform1);
|
|
421
|
-
path.setAttribute('d', rect1.toString());
|
|
422
|
-
expect(path.getAttribute('d')).to.equal('M2.1949 0.6212C0.9827 0.2781 -0.2061 1.0379 -0.4604 2.3182L-3.2228 16.2276C-3.477 17.5079 -2.7005 18.8239 -1.4883 19.1669L11.6808 22.8939C12.893 23.237 14.0818 22.4772 14.3361 21.1969L17.0985 7.2875C17.3527 6.0072 16.5762 4.6912 15.364 4.3482L2.1949 0.6212Z');
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
simpleShapes.initial.forEach((shape, i) => {
|
|
426
|
-
it(`Test simple shapes #${i}`, async () => {
|
|
427
|
-
const container = getMarkup();
|
|
428
|
-
wrapper.append(container);
|
|
429
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
430
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
431
|
-
|
|
432
|
-
// 'Shape samples from [MDN docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path_commands)'
|
|
433
|
-
path.ownerSVGElement?.setAttribute('viewBox', '0 0 200 100');
|
|
434
|
-
|
|
435
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).normalize().toString());
|
|
436
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.normalized[i]);
|
|
437
|
-
|
|
438
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({translate: 15, rotate: 15, scale: 0.5}).toString());
|
|
439
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.transformed[i]);
|
|
440
|
-
|
|
441
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({scale: [0.55,0.6,0.65]}).toString());
|
|
442
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.scaled3d[i]);
|
|
443
|
-
|
|
444
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({skew: 45}).toString());
|
|
445
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.skewedX[i]);
|
|
446
|
-
|
|
447
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({skew: [45,0]}).toString());
|
|
448
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.skewedX[i]);
|
|
449
|
-
|
|
450
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({skew: [0,45]}).toString());
|
|
451
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.skewedY[i]);
|
|
452
|
-
|
|
453
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).reverse().toString());
|
|
454
|
-
expect(path.getAttribute('d')).to.equal(simpleShapes.reversed[i]);
|
|
455
|
-
|
|
456
|
-
expect(new SVGPathCommander(shape).getTotalLength()).to.equal(simpleShapes.length[i]);
|
|
457
|
-
expect(new SVGPathCommander(shape).getPointAtLength(0)).to.deep.equal(simpleShapes.pointAt0[i]);
|
|
458
|
-
expect(new SVGPathCommander(shape).getPointAtLength(50)).to.deep.equal(simpleShapes.pointAt50[i]);
|
|
459
|
-
expect(new SVGPathCommander(shape).getPointAtLength(400)).to.deep.equal(simpleShapes.pointAt400[i]);
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
shapes.initial.forEach((shape, i) => {
|
|
464
|
-
it(`Test composite shapes #${i}`, async () => {
|
|
465
|
-
const container = getMarkup();
|
|
466
|
-
wrapper.append(container);
|
|
467
|
-
await vi.waitFor(() => container.querySelector('svg'), { timeout: 200 });
|
|
468
|
-
const path = await vi.waitFor(() => container.querySelector('path') as SVGPathElement, { timeout: 200 });
|
|
469
|
-
|
|
470
|
-
const normalized = new SVGPathCommander(shape, { round: 2 }).normalize().toString();
|
|
471
|
-
path.setAttribute('d', normalized);
|
|
472
|
-
expect(path.getAttribute('d')).to.equal(shapes.normalized[i]);
|
|
473
|
-
expect(new SVGPathCommander(normalized, { round: 2}).normalize().toString()).to.equal(shapes.normalized[i]); // test path already normalized
|
|
474
|
-
|
|
475
|
-
const optimized = new SVGPathCommander(shape, { round: 2 }).optimize().toString();
|
|
476
|
-
path.setAttribute('d', optimized);
|
|
477
|
-
expect(path.getAttribute('d')).to.equal(shapes.optimized[i]);
|
|
478
|
-
// skip checking for already optimized
|
|
479
|
-
|
|
480
|
-
const relative = new SVGPathCommander(shape, { round: 2 }).toRelative().toString();
|
|
481
|
-
path.setAttribute('d', relative);
|
|
482
|
-
expect(path.getAttribute('d')).to.equal(shapes.relative[i]);
|
|
483
|
-
expect(new SVGPathCommander(relative, { round: 2}).toRelative().toString()).to.equal(shapes.relative[i]);
|
|
484
|
-
|
|
485
|
-
const absolute = new SVGPathCommander(shape, { round: 2 }).toAbsolute().toString();
|
|
486
|
-
path.setAttribute('d', absolute);
|
|
487
|
-
expect(path.getAttribute('d')).to.equal(shapes.absolute[i]);
|
|
488
|
-
expect(new SVGPathCommander(absolute, { round: 2}).toAbsolute().toString()).to.equal(shapes.absolute[i]);
|
|
489
|
-
|
|
490
|
-
const curve = new SVGPathCommander(shape, { round: 2 }).toCurve().toString();
|
|
491
|
-
path.setAttribute('d', curve);
|
|
492
|
-
expect(path.getAttribute('d')).to.equal(shapes.curve[i]);
|
|
493
|
-
expect(new SVGPathCommander(curve, { round: 2}).toCurve().toString()).to.equal(shapes.curve[i]);
|
|
494
|
-
|
|
495
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({scale: 0.9}).toString());
|
|
496
|
-
expect(path.getAttribute('d')).to.equal(shapes.scaled[i]);
|
|
497
|
-
|
|
498
|
-
path.setAttribute('d', new SVGPathCommander(shape, { round: 2 }).transform({translate: [1,1,0]}).toString());
|
|
499
|
-
expect(path.getAttribute('d')).to.equal(shapes.translated[i]);
|
|
500
|
-
expect(new SVGPathCommander(shape).getTotalLength()).to.equal(shapes.length[i]);
|
|
501
|
-
expect(new SVGPathCommander(shape).getPointAtLength(50)).to.deep.equal(shapes.pointAt50[i]);
|
|
502
|
-
});
|
|
503
|
-
})
|
|
504
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export default function getMarkup() {
|
|
2
|
-
const markup = `<div class="row row-lg">
|
|
3
|
-
<div class="col col-md-4 mx-auto">
|
|
4
|
-
<div class="text-center">
|
|
5
|
-
<svg id="test-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
|
|
6
|
-
<path d="M0 0L0 0" fill="rgba(255,0,255,0.75)"></path>
|
|
7
|
-
</svg>
|
|
8
|
-
</div>
|
|
9
|
-
</div>
|
|
10
|
-
</div>`;
|
|
11
|
-
|
|
12
|
-
const domParser = new DOMParser();
|
|
13
|
-
let tempDocument = domParser.parseFromString(markup, 'text/html');
|
|
14
|
-
const container = tempDocument.querySelector('div')!;
|
|
15
|
-
|
|
16
|
-
return container;
|
|
17
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const shapeObjects = [
|
|
2
|
-
{ type: 'line', id:'line', x1: 0, y1: 0, x2: 182, y2: 72, stroke: 'turquoise', strokeWidth: 2 },
|
|
3
|
-
{ type: 'ellipse', id: 'ellipse', cx: '68.3', cy:'37', rx: '15.1', ry: '23.4', fill: 'darkorange' },
|
|
4
|
-
{ type: 'circle', id:'circle', cx:27.5, cy:36.9, r:23.5, fill: 'orangered' },
|
|
5
|
-
{ type: 'polygon', id:'polygon', points: '107.4,13 113.7,28.8 127.9,31.3 117.6,43.5 120.1,60.8 107.4,52.6 94.6,60.8 97.1,43.5 86.8,31.3 101,28.8', fill:'yellow' },
|
|
6
|
-
{ type: 'polyline', id:'polyline', points: '107.39,17.78 112.43,30.42 123.79,32.42 115.55,42.18 117.55,56.02 107.39,49.46 97.15,56.02 99.15,42.18 90.91,32.42 102.27,30.42', fill:'black' },
|
|
7
|
-
{ type: 'rect', id: 'rect', x: '131', y: '13.2', width: '47.5', height: '47.6', ry: '25', fill: 'yellowgreen' },
|
|
8
|
-
{ type: 'glyph', id: 'glyph', d: 'M143.5 22.72H166s3 0 3 3v22.56s0 3 -3 3h-22.5s-3 0 -3 -3V25.72s0 -3 3 -3', fill: 'rgba(255,255,255,0.3)' },
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
export default shapeObjects;
|