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.
- package/README.md +137 -21
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
- package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +9 -2
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +122 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +60 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +0 -39
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +2 -16
- package/ios/NanoIconView.mm +17 -5
- package/ios/NanoIconsFontLoader.mm +5 -0
- package/lib/commonjs/cli/build.d.ts +26 -0
- package/lib/commonjs/cli/build.js +174 -64
- package/lib/commonjs/cli/buildSymbols.d.ts +17 -0
- package/lib/commonjs/cli/buildSymbols.js +103 -42
- package/lib/commonjs/cli/expoConfig.d.ts +10 -0
- package/lib/commonjs/cli/expoConfig.js +22 -7
- package/lib/commonjs/cli/fingerprint.d.ts +15 -0
- package/lib/commonjs/cli/fingerprint.js +36 -0
- package/lib/commonjs/cli/index.d.ts +2 -2
- package/lib/commonjs/cli/index.js +3 -1
- package/lib/commonjs/cli/link.d.ts +4 -0
- package/lib/commonjs/cli/link.js +25 -0
- package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
- package/lib/commonjs/cli/sameOutputs.js +45 -0
- package/lib/commonjs/index.node.js +1 -1
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
- package/lib/commonjs/plugin/src/buildFonts.js +11 -3
- package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
- package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
- package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
- package/lib/commonjs/plugin/src/frozen.js +18 -0
- package/lib/commonjs/plugin/src/index.js +3 -3
- package/lib/commonjs/plugin/src/types.d.ts +10 -0
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
- package/lib/commonjs/scripts/cli.js +31 -2
- package/lib/commonjs/src/core/flatten/dom.js +40 -5
- package/lib/commonjs/src/core/flatten/element.js +2 -1
- package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
- package/lib/commonjs/src/core/font/compile.d.ts +0 -1
- package/lib/commonjs/src/core/font/compile.js +2 -8
- package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
- package/lib/commonjs/src/core/glyph/merge.js +27 -36
- package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
- package/lib/commonjs/src/core/glyph/parse.js +31 -18
- package/lib/commonjs/src/core/pathkit/winding.d.ts +7 -1
- package/lib/commonjs/src/core/pathkit/winding.js +172 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
- package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
- package/lib/commonjs/src/core/symbols/knockout.js +4 -3
- package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
- package/lib/commonjs/src/utils/fingerPrint.js +3 -1
- package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
- package/lib/commonjs/src/utils/fontIdentity.js +2 -2
- package/lib/module/createNanoIconsSet.js +0 -1
- package/lib/module/createNanoIconsSet.native.js +26 -21
- package/lib/module/createNanoIconsSet.shared.js +32 -18
- package/lib/module/createNanoIconsSet.web.js +103 -61
- package/lib/module/devServerFont.js +1 -1
- package/lib/module/devServerFont.web.js +3 -5
- package/lib/module/fontIntegrity.js +20 -38
- package/lib/module/fontIntegrity.web.js +48 -0
- package/lib/module/fontIntegrityStore.js +65 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.node.js +1 -1
- package/lib/module/index.web.js +4 -0
- package/lib/module/loadDynamicFont.js +3 -15
- package/lib/module/specs/NanoIconViewNativeComponent.ts +3 -2
- package/lib/module/utils/fingerPrint.js +3 -2
- package/lib/module/utils/fontIdentity.js +2 -2
- package/lib/module/utils/fontScale.js +23 -0
- package/lib/module/utils/glyphRuntime.js +13 -0
- package/lib/module/utils/iconAccessibility.js +26 -0
- package/lib/module/utils/iconPropsEqual.js +27 -0
- package/lib/module/utils/webCss.js +26 -0
- package/lib/module/utils/webStyle.js +86 -0
- package/lib/module/webFont.js +33 -0
- package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
- package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
- package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
- package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
- package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
- package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
- package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
- package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
- package/lib/typescript/src/fontIntegrity.d.ts +2 -14
- package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
- package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.web.d.ts +5 -0
- package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +3 -2
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/types.d.ts +37 -9
- package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
- package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
- package/lib/typescript/src/utils/fontScale.d.ts +2 -0
- package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
- package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
- package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
- package/lib/typescript/src/utils/webCss.d.ts +9 -0
- package/lib/typescript/src/utils/webStyle.d.ts +3 -0
- package/lib/typescript/src/webFont.d.ts +6 -0
- package/package.json +19 -3
- package/src/const/codegenPrimitives.ts +3 -3
- package/src/specs/NanoIconViewNativeComponent.ts +3 -2
- package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
- package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
- 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
|
+
}
|
|
@@ -8,7 +8,7 @@ export type PreparedSvg = {
|
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Shared per-file SVG prep: validate → preprocess → flatten → parse →
|
|
11
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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 *
|
|
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:
|
|
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 (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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 =
|
|
15
|
+
const fromStyle = (0, parse_1.attribute)(el, 'style')?.match(styleDeclaration(property));
|
|
15
16
|
if (fromStyle)
|
|
16
17
|
return fromStyle[2].trim();
|
|
17
|
-
return
|
|
18
|
+
return (0, parse_1.attribute)(el, property);
|
|
18
19
|
}
|
|
19
20
|
function setPaint(el, property, value) {
|
|
20
|
-
const 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
|
}
|
|
@@ -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,
|
|
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,
|
|
13
|
-
return `${fontFamily}-${
|
|
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,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
|
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
|
|
83
|
+
accessibilityRole,
|
|
81
84
|
accessibilityElementsHidden,
|
|
82
85
|
importantForAccessibility,
|
|
83
86
|
testID,
|
|
84
87
|
ref
|
|
85
88
|
}) => {
|
|
86
|
-
const fontScale = allowFontScaling
|
|
89
|
+
const fontScale = useFontScale(allowFontScaling);
|
|
87
90
|
const [adv, layers] = resolveGlyphEntry(glyphMap, name);
|
|
88
91
|
const scaledSize = size * fontScale;
|
|
89
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
135
|
+
fontScale: fontScale,
|
|
128
136
|
advanceWidth: adv,
|
|
129
137
|
unitsPerEm: unitsPerEm,
|
|
138
|
+
squareGlyphScale: squareGlyphScale,
|
|
130
139
|
style: style,
|
|
131
|
-
|
|
132
|
-
accessibilityRole: accessibilityRole,
|
|
133
|
-
accessibilityLabel: accessibilityLabel ?? name,
|
|
134
|
-
accessibilityElementsHidden: accessibilityElementsHidden,
|
|
135
|
-
importantForAccessibility: importantForAccessibility,
|
|
140
|
+
...accessibility,
|
|
136
141
|
testID: testID
|
|
137
142
|
});
|
|
138
|
-
},
|
|
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 {
|
|
6
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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,
|
|
126
|
+
style: [styleOverrides, glyphStyle, {
|
|
113
127
|
color: layerColor
|
|
114
128
|
}],
|
|
115
129
|
children: getChar(codepoint)
|
|
116
130
|
}, i);
|
|
117
131
|
})
|
|
118
132
|
});
|
|
119
|
-
},
|
|
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, {
|