react-native-nano-icons 1.0.0 → 1.1.0-beta.1

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 (120) hide show
  1. package/README.md +137 -21
  2. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +9 -2
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
  6. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +122 -0
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +60 -0
  8. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +0 -39
  9. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +2 -16
  10. package/ios/NanoIconView.mm +17 -5
  11. package/ios/NanoIconsFontLoader.mm +5 -0
  12. package/lib/commonjs/cli/build.d.ts +26 -0
  13. package/lib/commonjs/cli/build.js +174 -64
  14. package/lib/commonjs/cli/buildSymbols.d.ts +17 -0
  15. package/lib/commonjs/cli/buildSymbols.js +103 -42
  16. package/lib/commonjs/cli/expoConfig.d.ts +10 -0
  17. package/lib/commonjs/cli/expoConfig.js +22 -7
  18. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  19. package/lib/commonjs/cli/fingerprint.js +36 -0
  20. package/lib/commonjs/cli/index.d.ts +2 -2
  21. package/lib/commonjs/cli/index.js +3 -1
  22. package/lib/commonjs/cli/link.d.ts +4 -0
  23. package/lib/commonjs/cli/link.js +25 -0
  24. package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
  25. package/lib/commonjs/cli/sameOutputs.js +45 -0
  26. package/lib/commonjs/index.node.js +1 -1
  27. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
  28. package/lib/commonjs/plugin/src/buildFonts.js +11 -3
  29. package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
  30. package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
  31. package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
  32. package/lib/commonjs/plugin/src/frozen.js +18 -0
  33. package/lib/commonjs/plugin/src/index.js +3 -3
  34. package/lib/commonjs/plugin/src/types.d.ts +10 -0
  35. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
  36. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
  37. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
  38. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
  39. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
  40. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
  41. package/lib/commonjs/scripts/cli.js +31 -2
  42. package/lib/commonjs/src/core/flatten/dom.js +40 -5
  43. package/lib/commonjs/src/core/flatten/element.js +2 -1
  44. package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
  45. package/lib/commonjs/src/core/font/compile.d.ts +0 -1
  46. package/lib/commonjs/src/core/font/compile.js +2 -8
  47. package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
  48. package/lib/commonjs/src/core/glyph/merge.js +27 -36
  49. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
  50. package/lib/commonjs/src/core/glyph/parse.js +31 -18
  51. package/lib/commonjs/src/core/pathkit/winding.d.ts +7 -1
  52. package/lib/commonjs/src/core/pathkit/winding.js +172 -0
  53. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  54. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  55. package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
  56. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  57. package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
  58. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
  59. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  60. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  61. package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
  62. package/lib/commonjs/src/utils/fingerPrint.js +3 -1
  63. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  64. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  65. package/lib/module/createNanoIconsSet.js +0 -1
  66. package/lib/module/createNanoIconsSet.native.js +26 -21
  67. package/lib/module/createNanoIconsSet.shared.js +32 -18
  68. package/lib/module/createNanoIconsSet.web.js +103 -61
  69. package/lib/module/devServerFont.js +1 -1
  70. package/lib/module/devServerFont.web.js +3 -5
  71. package/lib/module/fontIntegrity.js +20 -38
  72. package/lib/module/fontIntegrity.web.js +48 -0
  73. package/lib/module/fontIntegrityStore.js +65 -0
  74. package/lib/module/index.js +1 -1
  75. package/lib/module/index.node.js +1 -1
  76. package/lib/module/index.web.js +4 -0
  77. package/lib/module/loadDynamicFont.js +3 -15
  78. package/lib/module/specs/NanoIconViewNativeComponent.ts +3 -2
  79. package/lib/module/utils/fingerPrint.js +3 -2
  80. package/lib/module/utils/fontIdentity.js +2 -2
  81. package/lib/module/utils/fontScale.js +23 -0
  82. package/lib/module/utils/glyphRuntime.js +13 -0
  83. package/lib/module/utils/iconAccessibility.js +26 -0
  84. package/lib/module/utils/iconPropsEqual.js +27 -0
  85. package/lib/module/utils/webCss.js +26 -0
  86. package/lib/module/utils/webStyle.js +86 -0
  87. package/lib/module/webFont.js +33 -0
  88. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  89. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  90. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  91. package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
  92. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  93. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  94. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  95. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  96. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  97. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  98. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  99. package/lib/typescript/src/index.d.ts +2 -1
  100. package/lib/typescript/src/index.web.d.ts +5 -0
  101. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  102. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +3 -2
  103. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  104. package/lib/typescript/src/types.d.ts +37 -9
  105. package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
  106. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  107. package/lib/typescript/src/utils/fontScale.d.ts +2 -0
  108. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  109. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  110. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  111. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  112. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  113. package/lib/typescript/src/webFont.d.ts +6 -0
  114. package/package.json +19 -3
  115. package/src/const/codegenPrimitives.ts +3 -3
  116. package/src/specs/NanoIconViewNativeComponent.ts +3 -2
  117. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  118. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  119. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  120. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.orientedPathData = orientedPathData;
4
4
  exports.canonicalWinding = canonicalWinding;
5
5
  exports.reversedWinding = reversedWinding;
6
+ exports.analyzeWinding = analyzeWinding;
7
+ exports.pathDataWithWinding = pathDataWithWinding;
6
8
  const contours_1 = require("./contours");
7
9
  function conicsToCubics(cmds, V) {
8
10
  let x = 0;
@@ -57,3 +59,173 @@ function reversedWinding(PathKit, d) {
57
59
  path.delete?.();
58
60
  return (0, contours_1.cmdsToPathData)(contours.flatMap((c) => (0, contours_1.reverseClosedContourKeepStart)(c.cmds, c.explicitCloseWanted, V)), V);
59
61
  }
62
+ const BOUNDARY_TOLERANCE = 2e-3;
63
+ function boxOf(points) {
64
+ let box = [Infinity, Infinity, -Infinity, -Infinity];
65
+ for (const [x, y] of points) {
66
+ box = [
67
+ Math.min(box[0], x),
68
+ Math.min(box[1], y),
69
+ Math.max(box[2], x),
70
+ Math.max(box[3], y),
71
+ ];
72
+ }
73
+ return box;
74
+ }
75
+ function boxesOverlap(a, b, margin = 0) {
76
+ return (a[0] <= b[2] + margin &&
77
+ b[0] <= a[2] + margin &&
78
+ a[1] <= b[3] + margin &&
79
+ b[1] <= a[3] + margin);
80
+ }
81
+ function distanceToSegment(p, a, b) {
82
+ const dx = b[0] - a[0];
83
+ const dy = b[1] - a[1];
84
+ const lengthSq = dx * dx + dy * dy;
85
+ const t = lengthSq === 0
86
+ ? 0
87
+ : Math.max(0, Math.min(1, ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / lengthSq));
88
+ return Math.hypot(p[0] - (a[0] + t * dx), p[1] - (a[1] + t * dy));
89
+ }
90
+ function cross(o, a, b) {
91
+ return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
92
+ }
93
+ function segmentsTouch(a, b, c, d) {
94
+ if (Math.sign(cross(a, b, c)) * Math.sign(cross(a, b, d)) < 0 &&
95
+ Math.sign(cross(c, d, a)) * Math.sign(cross(c, d, b)) < 0) {
96
+ return true;
97
+ }
98
+ return (distanceToSegment(a, c, d) <= BOUNDARY_TOLERANCE ||
99
+ distanceToSegment(b, c, d) <= BOUNDARY_TOLERANCE ||
100
+ distanceToSegment(c, a, b) <= BOUNDARY_TOLERANCE ||
101
+ distanceToSegment(d, a, b) <= BOUNDARY_TOLERANCE);
102
+ }
103
+ function distance(a, b) {
104
+ return Math.hypot(a[0] - b[0], a[1] - b[1]);
105
+ }
106
+ function ringOf(polyline) {
107
+ const ring = [];
108
+ for (const p of polyline) {
109
+ const last = ring[ring.length - 1];
110
+ if (!last || distance(p, last) > BOUNDARY_TOLERANCE)
111
+ ring.push(p);
112
+ }
113
+ if (ring.length > 1 &&
114
+ distance(ring[0], ring[ring.length - 1]) <= BOUNDARY_TOLERANCE) {
115
+ ring.pop();
116
+ }
117
+ return ring;
118
+ }
119
+ function contoursTouch(rings) {
120
+ const edges = [];
121
+ for (const [ring, points] of rings.entries()) {
122
+ if (points.length < 3)
123
+ continue;
124
+ for (const [index, a] of points.entries()) {
125
+ const b = points[(index + 1) % points.length];
126
+ edges.push({ ring, index, a, b, box: boxOf([a, b]) });
127
+ }
128
+ }
129
+ edges.sort((e, f) => e.box[0] - f.box[0]);
130
+ const adjacent = (e, f) => {
131
+ if (e.ring !== f.ring)
132
+ return false;
133
+ const gap = Math.abs(e.index - f.index);
134
+ return gap === 1 || gap === rings[e.ring].length - 1;
135
+ };
136
+ for (const [i, edge] of edges.entries()) {
137
+ for (let j = i + 1; j < edges.length; j++) {
138
+ const other = edges[j];
139
+ if (other.box[0] > edge.box[2] + BOUNDARY_TOLERANCE)
140
+ break;
141
+ if (boxesOverlap(edge.box, other.box, BOUNDARY_TOLERANCE) &&
142
+ !adjacent(edge, other) &&
143
+ segmentsTouch(edge.a, edge.b, other.a, other.b)) {
144
+ return true;
145
+ }
146
+ }
147
+ }
148
+ return false;
149
+ }
150
+ function isInside(inner, outer) {
151
+ if (!boxesOverlap(inner.box, outer.box))
152
+ return false;
153
+ const [x, y] = inner.polygon[0];
154
+ return (0, contours_1.pointInPolygon)(x, y, outer.polygon);
155
+ }
156
+ function analyzeWinding(PathKit, d) {
157
+ const path = PathKit.FromSVGString(d);
158
+ if (!path)
159
+ return null;
160
+ const V = (0, contours_1.verbMap)(PathKit);
161
+ const contours = (0, contours_1.splitContours)(conicsToCubics(path.toCmds(), V), V);
162
+ path.delete?.();
163
+ const closed = contours.map((contour) => (0, contours_1.ensureClosed)(contour, V));
164
+ const rings = closed.map((contour) => ringOf((0, contours_1.contourToPolyline)(contour, V)));
165
+ if (contoursTouch(rings))
166
+ return null;
167
+ const outlines = closed.map((contour, i) => {
168
+ const area = (0, contours_1.approxSignedAreaFromContourCmds)(contour, V);
169
+ if (area === 0)
170
+ return null;
171
+ const polygon = rings[i];
172
+ return { area, polygon, box: boxOf(polygon) };
173
+ });
174
+ const outerSigns = [];
175
+ const parents = [];
176
+ for (const [i, outline] of outlines.entries()) {
177
+ if (!outline) {
178
+ outerSigns.push(0);
179
+ parents.push(null);
180
+ continue;
181
+ }
182
+ let depth = 0;
183
+ let parent = null;
184
+ for (const [j, other] of outlines.entries()) {
185
+ if (!other || j === i)
186
+ continue;
187
+ if (isInside(outline, other)) {
188
+ depth++;
189
+ if (parent === null ||
190
+ Math.abs(other.area) < Math.abs(outlines[parent].area)) {
191
+ parent = j;
192
+ }
193
+ }
194
+ }
195
+ outerSigns.push((Math.sign(outline.area) * (depth % 2 === 0 ? 1 : -1)));
196
+ parents.push(parent);
197
+ }
198
+ for (const [i, parent] of parents.entries()) {
199
+ if (parent !== null && outerSigns[i] !== outerSigns[parent])
200
+ return null;
201
+ }
202
+ if (outerSigns.every((sign) => sign === 0))
203
+ return null;
204
+ return { contours, outerSigns };
205
+ }
206
+ function reversedContour(contour, V) {
207
+ const drawn = contour.filter((cmd) => cmd[0] !== V.CLOSE);
208
+ const ends = drawn.map((cmd) => cmd.slice(-2));
209
+ const out = [[V.MOVE, ...ends[ends.length - 1]]];
210
+ for (let i = drawn.length - 1; i >= 1; i--) {
211
+ const cmd = drawn[i];
212
+ const start = ends[i - 1];
213
+ if (cmd[0] === V.LINE)
214
+ out.push([V.LINE, ...start]);
215
+ else if (cmd[0] === V.QUAD)
216
+ out.push([V.QUAD, cmd[1], cmd[2], ...start]);
217
+ else if (cmd[0] === V.CUBIC) {
218
+ out.push([V.CUBIC, cmd[3], cmd[4], cmd[1], cmd[2], ...start]);
219
+ }
220
+ }
221
+ if (drawn.length < contour.length)
222
+ out.push([V.CLOSE]);
223
+ return out;
224
+ }
225
+ function pathDataWithWinding(PathKit, d, analysis, sign) {
226
+ const { contours, outerSigns } = analysis;
227
+ if (outerSigns.every((s) => s === 0 || s === sign))
228
+ return d;
229
+ const V = (0, contours_1.verbMap)(PathKit);
230
+ return (0, contours_1.cmdsToPathData)(contours.flatMap((contour, i) => outerSigns[i] === -sign ? reversedContour(contour, V) : contour), V);
231
+ }
@@ -2,6 +2,7 @@ export type PipelineConfig = {
2
2
  fontFamily: string;
3
3
  upm: number;
4
4
  safeZone: number;
5
+ curveTolerance?: number;
5
6
  startUnicode: number;
6
7
  linking: 'static' | 'dynamic';
7
8
  web?: boolean;
@@ -8,7 +8,7 @@ export type PreparedSvg = {
8
8
  };
9
9
  /**
10
10
  * Shared per-file SVG prep: validate → preprocess → flatten → parse →
11
- * evenodd convert → same-color merge. Returns null for unsupported SVGs.
11
+ * same-color merge. Returns null for unsupported SVGs.
12
12
  */
13
13
  export declare function prepareSvgLayers(opts: {
14
14
  filePath: string;
@@ -9,7 +9,6 @@ const index_1 = require("../flatten/index");
9
9
  const merge_1 = require("../glyph/merge");
10
10
  const parse_1 = require("../glyph/parse");
11
11
  const validate_1 = require("../glyph/validate");
12
- const evenodd_1 = require("../pathkit/evenodd");
13
12
  const knockout_1 = require("../symbols/knockout");
14
13
  function tagKnockoutPaths(paths, svg, pathkit, fileLabel, logger) {
15
14
  const marked = (0, knockout_1.markKnockoutFills)(svg);
@@ -27,11 +26,11 @@ function tagKnockoutPaths(paths, svg, pathkit, fileLabel, logger) {
27
26
  }
28
27
  /**
29
28
  * Shared per-file SVG prep: validate → preprocess → flatten → parse →
30
- * evenodd convert → same-color merge. Returns null for unsupported SVGs.
29
+ * same-color merge. Returns null for unsupported SVGs.
31
30
  */
32
31
  async function prepareSvgLayers(opts) {
33
32
  const { filePath, fileLabel, pathkit, logger } = opts;
34
- const rawContent = await promises_1.default.readFile(filePath, 'utf-8');
33
+ const rawContent = (await promises_1.default.readFile(filePath, 'utf-8')).replace(/^\uFEFF/, '');
35
34
  const validation = (0, validate_1.validateSvg)(rawContent);
36
35
  if (validation.valid === false) {
37
36
  logger?.warn(`${fileLabel} skipped: ${validation.reason}`);
@@ -57,18 +56,6 @@ async function prepareSvgLayers(opts) {
57
56
  if (opts.tagKnockouts) {
58
57
  tagKnockoutPaths(parsed.paths, preprocessed, pathkit, fileLabel, logger);
59
58
  }
60
- // Convert evenodd to nonzero winding with our containment-based
61
- // algorithm. Mark as noMerge — compound paths with holes must stay
62
- // separate so their CW hole contours don't cancel adjacent paths' CCW
63
- // contours.
64
- for (const p of parsed.paths) {
65
- if (p.fillRule === 'evenodd') {
66
- logger?.info(` ↻ ${fileLabel} converting evenodd path to nonzero winding`);
67
- p.d = (0, evenodd_1.convertEvenoddToWinding)(pathkit, p.d);
68
- delete p.fillRule;
69
- p.noMerge = true;
70
- }
71
- }
72
- const mergedPaths = (0, merge_1.mergeSameColorPaths)(parsed.paths, logger);
59
+ const mergedPaths = (0, merge_1.mergeSameColorPaths)(parsed.paths, pathkit, logger);
73
60
  return { viewBox: parsed.viewBox, paths: mergedPaths };
74
61
  }
@@ -7,6 +7,7 @@ export type IconTask = {
7
7
  fontFamily: string;
8
8
  upm: number;
9
9
  safeZone: number;
10
+ curveTolerance: number;
10
11
  };
11
12
  export type IconLog = [level: 'info' | 'warn' | 'fail', message: string];
12
13
  export type IconLayer = {
@@ -71,7 +71,7 @@ async function prepareIcon(task, pathkit) {
71
71
  });
72
72
  result.layers.push({
73
73
  fill: p.fill,
74
- d: (0, quadratic_1.toQuadraticPath)(placed, task.upm * quadratic_1.QUADRATIC_ERROR_BOUND_EM),
74
+ d: (0, quadratic_1.toQuadraticPath)(placed, task.upm * task.curveTolerance),
75
75
  });
76
76
  }
77
77
  if (result.layers.length === 0) {
@@ -17,7 +17,7 @@ function preparedSvgCacheKey(task, hash) {
17
17
  if (task.kind === 'symbol') {
18
18
  return `symbol:${task.setName}:${task.file}:${task.prefix}:${contentHash}`;
19
19
  }
20
- return `${task.file}:${task.upm}:${task.safeZone}:${contentHash}`;
20
+ return `${task.file}:${task.upm}:${task.safeZone}:${task.curveTolerance}:${contentHash}`;
21
21
  }
22
22
  async function prepareIconsWithCache(tasks, concurrency, cache, pool, svgHashByFile) {
23
23
  const prepare = (batch) => pool ? pool.prepare(batch) : (0, iconPool_1.prepareIcons)(batch, concurrency);
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runFontPipeline = runFontPipeline;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
7
8
  const promises_1 = __importDefault(require("node:fs/promises"));
8
9
  const node_path_1 = __importDefault(require("node:path"));
9
10
  const compile_1 = require("../font/compile");
11
+ const quadratic_1 = require("../font/quadratic");
10
12
  const fontIdentity_1 = require("../../utils/fontIdentity");
11
13
  const config_1 = require("./config");
12
14
  const iconPool_1 = require("./iconPool");
@@ -22,12 +24,9 @@ async function runFontPipeline(config, paths, options) {
22
24
  (0, config_1.ensureDir)(paths.outputDir);
23
25
  const files = (await promises_1.default.readdir(paths.inputDir)).filter((f) => f.toLowerCase().endsWith('.svg'));
24
26
  const inputHash = options?.inputHash;
25
- const family = inputHash
26
- ? (0, fontIdentity_1.buildFontFamily)(config.fontFamily, inputHash)
27
- : config.fontFamily;
28
27
  const glyphMap = {
29
28
  m: {
30
- f: family,
29
+ f: config.fontFamily,
31
30
  u: config.upm,
32
31
  z: config.safeZone,
33
32
  s: config.startUnicode,
@@ -47,6 +46,7 @@ async function runFontPipeline(config, paths, options) {
47
46
  fontFamily: config.fontFamily,
48
47
  upm: config.upm,
49
48
  safeZone: config.safeZone,
49
+ curveTolerance: config.curveTolerance ?? quadratic_1.QUADRATIC_ERROR_BOUND_EM,
50
50
  })), options?.concurrency ?? (0, iconPool_1.defaultConcurrency)(), options?.preparedSvgCache, options?.svgWorkerPool, options?.svgHashByFile);
51
51
  for (const result of results) {
52
52
  for (const [level, msg] of result.logs)
@@ -76,20 +76,28 @@ async function runFontPipeline(config, paths, options) {
76
76
  }
77
77
  logger?.info(`Compiling TTF…`);
78
78
  const ttfPath = node_path_1.default.join(paths.outputDir, `${config.fontFamily}.ttf`);
79
+ const compile = (fontName) => (0, compile_1.compileTtfFromGlyphs)({
80
+ glyphs: allGlyphs,
81
+ fontName,
82
+ upm: config.upm,
83
+ ascent: config.upm,
84
+ descent: 0,
85
+ });
86
+ let family = config.fontFamily;
79
87
  let ttfBuffer;
80
88
  try {
81
- ttfBuffer = await (0, compile_1.compileTtfFromGlyphs)({
82
- glyphs: allGlyphs,
83
- outTtfPath: ttfPath,
84
- fontName: family,
85
- upm: config.upm,
86
- ascent: config.upm,
87
- descent: 0,
88
- });
89
+ ttfBuffer = await compile(family);
90
+ if (inputHash) {
91
+ family = (0, fontIdentity_1.buildFontFamily)(config.fontFamily, node_crypto_1.default.createHash('sha256').update(ttfBuffer).digest('hex'));
92
+ ttfBuffer = await compile(family);
93
+ }
89
94
  }
90
95
  catch (err) {
91
96
  (0, compile_1.parseCompileTtfFromGlyphsError)(err, codepointToIcon);
92
97
  }
98
+ glyphMap.m.f = family;
99
+ if (ttfBuffer)
100
+ (0, config_1.writeFileAtomic)(ttfPath, ttfBuffer);
93
101
  let woff2Path;
94
102
  if (config.web && ttfBuffer) {
95
103
  logger?.info(`Compiling WOFF2…`);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KNOCKOUT_MARKER_FILL = exports.KNOCKOUT_ATTRIBUTE = void 0;
4
4
  exports.markKnockoutFills = markKnockoutFills;
5
5
  const xmldom_1 = require("@xmldom/xmldom");
6
+ const parse_1 = require("../glyph/parse");
6
7
  exports.KNOCKOUT_ATTRIBUTE = 'data-nano-knockout';
7
8
  exports.KNOCKOUT_MARKER_FILL = '#fe01fe';
8
9
  const ELEMENT_NODE = 1;
@@ -11,13 +12,13 @@ function styleDeclaration(property) {
11
12
  return new RegExp(`(^|;)\\s*${property}\\s*:([^;]*)`);
12
13
  }
13
14
  function explicitPaint(el, property) {
14
- const fromStyle = el.getAttribute('style')?.match(styleDeclaration(property));
15
+ const fromStyle = (0, parse_1.attribute)(el, 'style')?.match(styleDeclaration(property));
15
16
  if (fromStyle)
16
17
  return fromStyle[2].trim();
17
- return el.getAttribute(property);
18
+ return (0, parse_1.attribute)(el, property);
18
19
  }
19
20
  function setPaint(el, property, value) {
20
- const style = el.getAttribute('style');
21
+ const style = (0, parse_1.attribute)(el, 'style');
21
22
  if (style !== null) {
22
23
  el.setAttribute('style', style.replace(styleDeclaration(property), '$1'));
23
24
  }
@@ -1,6 +1,7 @@
1
1
  export type FingerprintInputs = {
2
2
  upm: number;
3
3
  safeZone: number;
4
+ curveTolerance: number;
4
5
  startUnicode: number;
5
6
  version: string;
6
7
  toolchain: readonly string[];
@@ -6,6 +6,7 @@ exports.fingerprintSymbolDirSync = fingerprintSymbolDirSync;
6
6
  const crypto = require('crypto');
7
7
  const fs = require('fs');
8
8
  const path = require('path');
9
+ const CRLF = /\r\n/g;
9
10
  function getFingerprintSync(dir, inputs) {
10
11
  return fingerprintSvgDirSync(dir, inputs).hash;
11
12
  }
@@ -13,6 +14,7 @@ function fingerprintSvgDirSync(dir, inputs) {
13
14
  return hashSvgDir(dir, [
14
15
  inputs.upm,
15
16
  inputs.safeZone,
17
+ inputs.curveTolerance,
16
18
  inputs.startUnicode,
17
19
  inputs.version,
18
20
  inputs.toolchain,
@@ -35,7 +37,7 @@ function hashSvgDir(dir, settings) {
35
37
  const svgHashByFile = new Map();
36
38
  for (const file of files) {
37
39
  const filePath = path.join(dir, file);
38
- const content = fs.readFileSync(filePath);
40
+ const content = fs.readFileSync(filePath, 'utf8').replace(CRLF, '\n');
39
41
  // Hash both path and content
40
42
  hash.update(file);
41
43
  hash.update(content);
@@ -1,4 +1,4 @@
1
- export declare function buildFontFamily(fontFamily: string, inputHash: string): string;
1
+ export declare function buildFontFamily(fontFamily: string, contentHash: string): string;
2
2
  export declare function configuredFontFamily(family: string): string;
3
3
  export declare function isFontFileOf(fontFamily: string, fileName: string): boolean;
4
4
  export declare function isBuildFontFile(fileName: string): boolean;
@@ -9,8 +9,8 @@ const BUILD_HASH = `[0-9a-f]{${BUILD_HASH_LENGTH}}`;
9
9
  const BUILD_SUFFIX = new RegExp(`-${BUILD_HASH}$`);
10
10
  const BUILD_FONT_FILE = new RegExp(`-${BUILD_HASH}\\.ttf$`);
11
11
  const REGEX_SPECIALS = /[.*+?^${}()|[\]\\]/g;
12
- function buildFontFamily(fontFamily, inputHash) {
13
- return `${fontFamily}-${inputHash.slice(0, BUILD_HASH_LENGTH)}`;
12
+ function buildFontFamily(fontFamily, contentHash) {
13
+ return `${fontFamily}-${contentHash.slice(0, BUILD_HASH_LENGTH)}`;
14
14
  }
15
15
  function configuredFontFamily(family) {
16
16
  return family.replace(BUILD_SUFFIX, '');
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  import { createJSIconSet } from "./createNanoIconsSet.shared.js";
4
- export { shallowEqualColor } from "./utils/shallowEqualColor.js";
5
4
  export function createIconSet(glyphMap, font) {
6
5
  return createJSIconSet(glyphMap, font);
7
6
  }
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  import { memo, useMemo } from 'react';
4
- import { PixelRatio, UIManager, View } from 'react-native';
5
- import { shallowEqualColor } from "./utils/shallowEqualColor.js";
4
+ import { UIManager, View } from 'react-native';
5
+ import { areIconPropsEqual } from "./utils/iconPropsEqual.js";
6
+ import { iconAccessibilityProps } from "./utils/iconAccessibility.js";
7
+ import { useFontScale } from "./utils/fontScale.js";
6
8
  import { validateLayerColor } from "./utils/validateLayerColor.js";
7
- import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createLayerColorResolver, tintableLayers } from "./utils/glyphRuntime.js";
9
+ import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createLayerColorResolver, squareGlyphBox, tintableLayers } from "./utils/glyphRuntime.js";
8
10
  import NanoIconViewNative from './specs/NanoIconViewNativeComponent';
9
11
  import { createJSIconSet, warnIfLinkingMismatch } from "./createNanoIconsSet.shared.js";
10
12
  import { loadDynamicFont, useDynamicFontPending } from "./loadDynamicFont.js";
11
- import { checkFontIntegrity, isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch } from "./fontIntegrity.js";
13
+ import { checkFontIntegrity, checkStaticFontNow, isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch } from './fontIntegrity';
12
14
  import { jsx as _jsx } from "react/jsx-runtime";
13
- export { shallowEqualColor };
14
15
  const HAS_NATIVE_IMPL = UIManager.hasViewManagerConfig('NanoIconView');
15
16
  async function loadFontFromDevServer(family) {
16
17
  if (__DEV__) {
@@ -29,6 +30,7 @@ export function createIconSet(glyphMap, font) {
29
30
  }
30
31
  const fontFamilyBasename = glyphMap.m.f;
31
32
  const unitsPerEm = glyphMap.m.u;
33
+ const safeZone = glyphMap.m.z;
32
34
  warnIfLinkingMismatch(fontFamilyBasename, glyphMap.m.l, font);
33
35
 
34
36
  // dynamically linked font - register and hide icons until ready
@@ -43,7 +45,7 @@ export function createIconSet(glyphMap, font) {
43
45
  void reportDynamicFontLoadFailure(fontFamilyBasename, err);
44
46
  }
45
47
  });
46
- } else if (linking === 'static') {
48
+ } else if (linking === 'static' && !checkStaticFontNow(fontFamilyBasename)) {
47
49
  void ensureStaticFont(fontFamilyBasename);
48
50
  }
49
51
 
@@ -75,18 +77,21 @@ export function createIconSet(glyphMap, font) {
75
77
  tintMode,
76
78
  style,
77
79
  allowFontScaling = true,
80
+ frame,
78
81
  accessible,
79
82
  accessibilityLabel,
80
- accessibilityRole = 'image',
83
+ accessibilityRole,
81
84
  accessibilityElementsHidden,
82
85
  importantForAccessibility,
83
86
  testID,
84
87
  ref
85
88
  }) => {
86
- const fontScale = allowFontScaling ? PixelRatio.getFontScale() : 1;
89
+ const fontScale = useFontScale(allowFontScaling);
87
90
  const [adv, layers] = resolveGlyphEntry(glyphMap, name);
88
91
  const scaledSize = size * fontScale;
89
- const width = adv / unitsPerEm * scaledSize;
92
+ const square = frame === 'square';
93
+ const width = square ? scaledSize : adv / unitsPerEm * scaledSize;
94
+ const squareGlyphScale = square ? squareGlyphBox(adv, unitsPerEm, safeZone).scale : undefined;
90
95
  const pending = useDynamicFontPending(managed, fontFamilyBasename);
91
96
  const nameStr = name;
92
97
  const codepoints = getCodepoints(nameStr, layers);
@@ -98,6 +103,13 @@ export function createIconSet(glyphMap, font) {
98
103
  const resolveColor = createLayerColorResolver(color, tintMode, layers);
99
104
  return layers.map(([, srcColor], i) => validateLayerColor(resolveColor(i, srcColor), nameStr, i));
100
105
  }, [nameStr, color, tintMode]);
106
+ const accessibility = iconAccessibilityProps({
107
+ accessible,
108
+ accessibilityLabel,
109
+ accessibilityRole,
110
+ accessibilityElementsHidden,
111
+ importantForAccessibility
112
+ });
101
113
  const nativeStyle = useMemo(() => [{
102
114
  width,
103
115
  height: scaledSize
@@ -109,11 +121,7 @@ export function createIconSet(glyphMap, font) {
109
121
  return /*#__PURE__*/_jsx(View, {
110
122
  ref: ref,
111
123
  style: nativeStyle,
112
- accessible: accessible,
113
- accessibilityRole: accessibilityRole,
114
- accessibilityLabel: accessibilityLabel ?? name,
115
- accessibilityElementsHidden: accessibilityElementsHidden,
116
- importantForAccessibility: importantForAccessibility,
124
+ ...accessibility,
117
125
  testID: testID
118
126
  });
119
127
  }
@@ -124,18 +132,15 @@ export function createIconSet(glyphMap, font) {
124
132
  colors: layerColors,
125
133
  tintLayers: tintableLayers(layers, tintMode),
126
134
  size: size,
127
- allowFontScaling: allowFontScaling,
135
+ fontScale: fontScale,
128
136
  advanceWidth: adv,
129
137
  unitsPerEm: unitsPerEm,
138
+ squareGlyphScale: squareGlyphScale,
130
139
  style: style,
131
- accessible: accessible,
132
- accessibilityRole: accessibilityRole,
133
- accessibilityLabel: accessibilityLabel ?? name,
134
- accessibilityElementsHidden: accessibilityElementsHidden,
135
- importantForAccessibility: importantForAccessibility,
140
+ ...accessibility,
136
141
  testID: testID
137
142
  });
138
- }, (prev, next) => prev.name === next.name && prev.size === next.size && prev.allowFontScaling === next.allowFontScaling && prev.style === next.style && prev.tintMode === next.tintMode && shallowEqualColor(prev.color, next.color));
143
+ }, areIconPropsEqual);
139
144
  Icon.displayName = `NanoIcon(${fontFamilyBasename})`;
140
145
  const IconComp = Icon;
141
146
  IconComp.loadFont = override => glyphMap.m.l === 'd' ? loadDynamicFont(fontFamilyBasename, override ?? font, {
@@ -2,15 +2,14 @@
2
2
 
3
3
  import { memo, useMemo } from 'react';
4
4
  import { PixelRatio, Platform, Text, View } from 'react-native';
5
- import { shallowEqualColor } from "./utils/shallowEqualColor.js";
6
- import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createCharCache, createLayerColorResolver } from "./utils/glyphRuntime.js";
5
+ import { areIconPropsEqual } from "./utils/iconPropsEqual.js";
6
+ import { iconAccessibilityProps } from "./utils/iconAccessibility.js";
7
+ import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createCharCache, createLayerColorResolver, squareGlyphBox } from "./utils/glyphRuntime.js";
7
8
  import { loadDynamicFont, useDynamicFontPending } from "./loadDynamicFont.js";
8
9
  import { warnRuntime } from "./utils/runtimeLog.js";
9
- import { isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch, reportMissingDynamicFont } from "./fontIntegrity.js";
10
+ import { isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch, reportMissingDynamicFont } from './fontIntegrity';
10
11
  import { configuredFontFamily } from "./utils/fontIdentity.js";
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
- export { shallowEqualColor };
13
-
14
13
  /**
15
14
  * Warn when the `font` argument and the glyphmap's linking mode are inconsistent.
16
15
  *
@@ -33,7 +32,7 @@ export function warnIfLinkingMismatch(fontFamily, linking, font) {
33
32
 
34
33
  /**
35
34
  * JS implementation using <View> + <Text> layers.
36
- * Used on web and as a fallback when native component is unavailable (e.g. Expo Go).
35
+ * Used as a fallback when native component is unavailable (e.g. Expo Go).
37
36
  */
38
37
 
39
38
  export function createJSIconSet(glyphMap, font) {
@@ -64,6 +63,7 @@ export function createJSIconSet(glyphMap, font) {
64
63
  bottom: 0
65
64
  };
66
65
  const unitsPerEm = glyphMap.m.u;
66
+ const safeZone = glyphMap.m.z;
67
67
  const getChar = createCharCache();
68
68
  const Icon = /*#__PURE__*/memo(({
69
69
  name,
@@ -72,9 +72,10 @@ export function createJSIconSet(glyphMap, font) {
72
72
  tintMode,
73
73
  style,
74
74
  allowFontScaling = true,
75
+ frame,
75
76
  accessible,
76
77
  accessibilityLabel,
77
- accessibilityRole = 'image',
78
+ accessibilityRole,
78
79
  accessibilityElementsHidden,
79
80
  importantForAccessibility,
80
81
  testID,
@@ -83,7 +84,8 @@ export function createJSIconSet(glyphMap, font) {
83
84
  const fontScale = allowFontScaling ? PixelRatio.getFontScale() : 1;
84
85
  const [adv, layers] = resolveGlyphEntry(glyphMap, name);
85
86
  const scaledSize = size * fontScale;
86
- const width = adv / unitsPerEm * scaledSize;
87
+ const square = frame === 'square';
88
+ const width = square ? scaledSize : adv / unitsPerEm * scaledSize;
87
89
  const pending = useDynamicFontPending(managed, fontBasename);
88
90
  const resolveColor = createLayerColorResolver(color, tintMode, layers);
89
91
  const containerStyle = useMemo(() => [{
@@ -91,17 +93,29 @@ export function createJSIconSet(glyphMap, font) {
91
93
  width,
92
94
  bottom: 0
93
95
  }, style], [scaledSize, width, style]);
94
- const sizeStyle = useMemo(() => ({
95
- fontSize: size
96
- }), [size]);
96
+ const glyphStyle = useMemo(() => {
97
+ if (!square) return {
98
+ fontSize: size
99
+ };
100
+ const box = squareGlyphBox(adv, unitsPerEm, safeZone);
101
+ return {
102
+ fontSize: size * box.scale,
103
+ left: '50%',
104
+ bottom: '50%',
105
+ marginLeft: -box.width * scaledSize / 2,
106
+ marginBottom: -box.scale * scaledSize / 2
107
+ };
108
+ }, [size, scaledSize, square, adv]);
97
109
  return /*#__PURE__*/_jsx(View, {
98
110
  ref: ref,
99
111
  style: containerStyle,
100
- accessible: accessible,
101
- accessibilityRole: accessibilityRole,
102
- accessibilityLabel: accessibilityLabel ?? name,
103
- accessibilityElementsHidden: accessibilityElementsHidden,
104
- importantForAccessibility: importantForAccessibility,
112
+ ...iconAccessibilityProps({
113
+ accessible,
114
+ accessibilityLabel,
115
+ accessibilityRole,
116
+ accessibilityElementsHidden,
117
+ importantForAccessibility
118
+ }),
105
119
  testID: testID,
106
120
  children: pending ? null : layers.map(([codepoint, srcColor], i) => {
107
121
  const layerColor = resolveColor(i, srcColor);
@@ -109,14 +123,14 @@ export function createJSIconSet(glyphMap, font) {
109
123
  selectable: false,
110
124
  accessible: false,
111
125
  allowFontScaling: allowFontScaling,
112
- style: [styleOverrides, sizeStyle, {
126
+ style: [styleOverrides, glyphStyle, {
113
127
  color: layerColor
114
128
  }],
115
129
  children: getChar(codepoint)
116
130
  }, i);
117
131
  })
118
132
  });
119
- }, (prev, next) => prev.name === next.name && prev.size === next.size && prev.allowFontScaling === next.allowFontScaling && prev.style === next.style && prev.tintMode === next.tintMode && shallowEqualColor(prev.color, next.color));
133
+ }, areIconPropsEqual);
120
134
  Icon.displayName = `NanoIcon(${fontBasename})`;
121
135
  const IconComp = Icon;
122
136
  IconComp.loadFont = override => glyphMap.m.l === 'd' ? loadDynamicFont(fontBasename, override ?? font, {