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.
@@ -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
- `<?xml version="1.0" encoding="utf-8"?>
11
- <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
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="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px"
14
- height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
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="M16.2 125.7 L16.2 125.7 Q12.1 125.7 8.4 123.8 Q4.6 122 2.3 119.1 Q0 116.2 0.2 113.1 L0.2 113.1 L0.4 112.6 Q2.2 111.2 5 109.3 Q7.8 107.4 11.4 105.1 Q15 102.8 19.1 100.4 L19.1 100.4 L19.2 99.5 Q16.8 98.1 15.5 94.7 Q14.1 91.3 14.1 86.7 L14.1 86.7 Q14.1 81.1 16 75.5 Q17.9 70 21.1 65.5 Q24.2 61 28.1 58.3 Q32 55.6 35.9 55.6 L35.9 55.6 L46.1 57.2 L47.2 54.7 L47.7 54.6 L50.8 56.1 L51.6 57 Q49.2 61.4 47.6 65.1 Q45.9 68.9 45 72 Q44 75.1 43.7 77.8 L43.7 77.8 Q43.4 80.3 43.2 83.7 Q43 87.1 42.8 90.6 Q42.6 94.2 42.5 97.1 Q42.3 100.1 42.1 101.6 L42.1 101.6 Q41.7 105.1 40 108.5 Q38.2 112 35.6 115.1 Q32.9 118.2 29.7 120.6 Q26.5 123 23 124.3 Q19.5 125.7 16.2 125.7 ZM19.5 119.9 L19.5 119.9 Q25.9 119.9 30.4 115.3 Q34.9 110.7 35.9 102.7 L35.9 102.7 L38.4 82 L37.6 81.8 Q34.5 87.5 32.3 91 Q30 94.6 28 96.8 Q25.9 99 23.5 100.8 L23.5 100.8 Q20.4 103.1 16.8 105.3 Q13.2 107.6 10.7 109.4 Q8.1 111.3 8.1 112.3 L8.1 112.3 Q8.1 114 9.9 115.8 Q11.6 117.5 14.3 118.7 Q16.9 119.9 19.5 119.9 ZM24.8 92.9 L24.8 92.9 Q26.3 92.9 29 89.4 Q31.6 86 35.2 79.5 Q38.7 73.1 42.9 64.1 L42.9 64.1 Q40.9 63.1 39.1 62.4 Q37.2 61.7 35.7 61.3 Q34.1 61 32.8 61 L32.8 61 Q29.8 61 27.1 64 Q24.4 67.1 22.7 71.9 Q21 76.7 21 82 L21 82 Q21 86.3 22.2 89.6 Q23.3 92.9 24.8 92.9 Z "/>
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 d = path.getAttribute('d')
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
- console.log(markup);
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
- // simplified pathData
38
- console.log(svgOpt)
44
+
45
+ /*
39
46
  */