svg-path-simplify 0.0.9 → 0.1.2
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 +114 -46
- package/debug.cjs +11 -0
- package/dist/svg-path-simplify.esm.js +613 -98
- package/dist/svg-path-simplify.esm.min.js +1 -1
- package/dist/svg-path-simplify.js +613 -98
- package/dist/svg-path-simplify.min.js +1 -1
- package/dist/svg-path-simplify.poly.cjs +29 -0
- package/index.html +5 -1
- package/package.json +36 -16
- package/src/index-node.js +15 -0
- package/src/index-poly.js +27 -0
- package/src/index.js +1 -6
- package/src/pathSimplify-main.js +47 -14
- package/src/svgii/geometry.js +54 -4
- package/src/svgii/geometry_deduceRadius.js +50 -0
- package/src/svgii/pathData_convert.js +339 -5
- package/src/svgii/pathData_refine_round.js +222 -0
- package/src/svgii/pathData_remove_collinear.js +8 -3
- package/src/svgii/pathData_remove_short.js +66 -0
- package/src/svgii/pathData_reorder.js +27 -11
- package/src/svgii/pathData_simplify_refineCorners.js +57 -37
- package/src/svgii/svg_cleanup.js +28 -29
- package/src/svgii/visualize.js +2 -2
- package/testSVG.js +27 -20
- package/dist/svg-path-simplify.node.js +0 -5129
- package/dist/svg-path-simplify.node.min.js +0 -1
- package/src/dom-polyfill.js +0 -29
- package/src/dom-polyfill_back.js +0 -22
package/src/svgii/visualize.js
CHANGED
|
@@ -233,9 +233,9 @@ export function renderPoint(
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
|
|
236
|
-
export function renderPath(svg, d = '', stroke = 'green', strokeWidth = '1%', render = true) {
|
|
236
|
+
export function renderPath(svg, d = '', stroke = 'green', strokeWidth = '1%', opacity="1", render = true) {
|
|
237
237
|
|
|
238
|
-
let path = `<path d="${d}" fill="none" stroke="${stroke}" stroke-width="${strokeWidth}" /> `;
|
|
238
|
+
let path = `<path d="${d}" fill="none" stroke="${stroke}" stroke-width="${strokeWidth}" stroke-opacity="${opacity}" /> `;
|
|
239
239
|
|
|
240
240
|
if (render) {
|
|
241
241
|
svg.insertAdjacentHTML("beforeend", path);
|
package/testSVG.js
CHANGED
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
// add suport for DOM manipulations
|
|
2
|
-
import { DOMParser, parseHTML } from 'linkedom';
|
|
3
|
-
//import { XMLSerializerPoly, DOMParserPoly } from 'svg-path-simplify/dom_polyfills.js';
|
|
4
|
-
import { svgPathSimplify } from 'svg-path-simplify';
|
|
5
|
-
|
|
6
1
|
|
|
2
|
+
/**
|
|
3
|
+
* load node polyfills for DOM parsing
|
|
4
|
+
* loads linkedom npm module for DOM parsing and emulation
|
|
5
|
+
*/
|
|
6
|
+
import 'svg-path-simplify/node';
|
|
7
|
+
import { svgPathSimplify } from 'svg-path-simplify';
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
let svgMarkup =
|
|
10
|
-
|
|
11
|
-
<!-- Generator: Adobe Illustrator
|
|
11
|
+
`<?xml version="1.0" encoding="utf-8"?>
|
|
12
|
+
<!-- Generator: Super Adobe Illustrator 33.0.0 Turbo, SVG Export Plug-In . SVG Version: 123.00 Build 0) -->
|
|
12
13
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
13
|
-
<svg version="
|
|
14
|
-
height="
|
|
14
|
+
<svg version="5.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="47px"
|
|
15
|
+
height="120px" viewBox="0 0 47 120" enable-background="new 0 0 47 120" xml:space="preserve">
|
|
15
16
|
<g id="garamond">
|
|
16
|
-
<path id="path1" d="
|
|
17
|
+
<path id="path1" d="M23.6 39.6 Q34.7 39.6 40.9 47 Q47 54.4 47 67.1 L47 67.1 Q47 75.3 44.2 81.5 Q41.4 87.8 36.1 91.3 Q30.8 94.7 23.5 94.7 L23.5 94.7 Q12.4 94.7 6.2 87.3 Q0 79.9 0 67.2 L0 67.2 Q0 59 2.8 52.8 Q5.6 46.5 10.9 43 Q16.2 39.6 23.6 39.6 L23.6 39.6 ZM23.6 47 Q9.9 47 9.9 67.2 L9.9 67.2 Q9.9 87.3 23.5 87.3 L23.5 87.3 Q37.1 87.3 37.1 67.1 L37.1 67.1 Q37.1 47 23.6 47 L23.6 47 Z "/>
|
|
17
18
|
</g>
|
|
18
19
|
</svg>`
|
|
19
20
|
|
|
21
|
+
// try to simplify
|
|
22
|
+
let svgOpt = svgPathSimplify(svgMarkup);
|
|
23
|
+
|
|
24
|
+
// simplified pathData
|
|
25
|
+
console.log(svgOpt)
|
|
26
|
+
|
|
27
|
+
|
|
20
28
|
|
|
21
29
|
/*
|
|
22
|
-
*/
|
|
23
30
|
let document = new DOMParser().parseFromString(svgMarkup, 'image/svg+xml');
|
|
24
31
|
let svg = document.querySelector('svg');
|
|
25
32
|
let path = svg.querySelector('path');
|
|
26
|
-
let
|
|
33
|
+
let els = svg.querySelectorAll('path')
|
|
34
|
+
let d = path.getAttribute('d').substring(0, 10)
|
|
35
|
+
//console.log(els);
|
|
27
36
|
|
|
28
|
-
let markup = document.toString()
|
|
29
|
-
markup = new XMLSerializer().serializeToString(svg)
|
|
30
37
|
|
|
31
|
-
|
|
38
|
+
//let markup = document.toString()
|
|
39
|
+
let markup = new XMLSerializer().serializeToString(svg)
|
|
40
|
+
*/
|
|
41
|
+
//console.log(markup);
|
|
32
42
|
|
|
33
|
-
/*
|
|
34
|
-
// try to simplify
|
|
35
|
-
let svgOpt = svgPathSimplify(svgMarkup);
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
|
|
45
|
+
/*
|
|
39
46
|
*/
|