@pantoken/icon-font 0.1.8 → 0.1.10

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 (2) hide show
  1. package/dist/index.mjs +19 -15
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -79,6 +79,24 @@ function splitSubpaths(d) {
79
79
  closed: /[Zz]/.test(chunk)
80
80
  }));
81
81
  }
82
+ /** Offset centerline subpaths into a filled outline using ClipperLib. */
83
+ function strokeSubpathsToFilled(subpaths, strokeWidth) {
84
+ const offset = new ClipperLib.ClipperOffset(2, .25);
85
+ for (const sub of subpaths) {
86
+ const flattened = svgpath(sub.d).unarc().abs().round(3).toString();
87
+ for (const poly of pointsOnPath(flattened, .2, .2)) {
88
+ if (poly.length < 2) continue;
89
+ const path = poly.map(([x, y]) => ({
90
+ X: Math.round(x * SCALE),
91
+ Y: Math.round(y * SCALE)
92
+ }));
93
+ offset.AddPath(path, ClipperLib.JoinType.jtRound, sub.closed ? ClipperLib.EndType.etClosedLine : ClipperLib.EndType.etOpenRound);
94
+ }
95
+ }
96
+ const solution = new ClipperLib.Paths();
97
+ offset.Execute(solution, strokeWidth / 2 * SCALE);
98
+ return solution.map((poly) => `M${poly.map((pt) => `${pt.X / SCALE},${pt.Y / SCALE}`).join(" L")} Z`).join(" ");
99
+ }
82
100
  /**
83
101
  * Produce a filled glyph path for an icon SVG.
84
102
  *
@@ -113,22 +131,8 @@ function svgToGlyphPath(svg) {
113
131
  width,
114
132
  height
115
133
  };
116
- const offset = new ClipperLib.ClipperOffset(2, .25);
117
- for (const sub of subpaths) {
118
- const flattened = svgpath(sub.d).unarc().abs().round(3).toString();
119
- for (const poly of pointsOnPath(flattened, .2, .2)) {
120
- if (poly.length < 2) continue;
121
- const path = poly.map(([x, y]) => ({
122
- X: Math.round(x * SCALE),
123
- Y: Math.round(y * SCALE)
124
- }));
125
- offset.AddPath(path, ClipperLib.JoinType.jtRound, sub.closed ? ClipperLib.EndType.etClosedLine : ClipperLib.EndType.etOpenRound);
126
- }
127
- }
128
- const solution = new ClipperLib.Paths();
129
- offset.Execute(solution, strokeWidth / 2 * SCALE);
130
134
  return {
131
- d: solution.map((poly) => `M${poly.map((pt) => `${pt.X / SCALE},${pt.Y / SCALE}`).join(" L")} Z`).join(" "),
135
+ d: strokeSubpathsToFilled(subpaths, strokeWidth),
132
136
  width,
133
137
  height
134
138
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantoken/icon-font",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Build an installable Instructure icon font (WOFF2 + TTF) with CSS and codepoints — stroke glyphs outlined to fills.",
5
5
  "homepage": "https://pantoken.iywahl.com",
6
6
  "bugs": "https://github.com/thedannywahl/pantoken/issues",