react-native-nano-icons 1.0.1 → 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 +7 -0
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +6 -1
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +4 -2
- package/ios/NanoIconView.mm +12 -0
- 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 +22 -18
- 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 +2 -1
- package/lib/module/utils/fingerPrint.js +3 -2
- package/lib/module/utils/fontIdentity.js +2 -2
- package/lib/module/utils/fontScale.js +10 -2
- 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 +2 -1
- 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/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 +2 -1
- 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
|
@@ -1,57 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeSameColorPaths = mergeSameColorPaths;
|
|
4
|
-
|
|
5
|
-
* Concatenate multiple SVG path `d` strings into a single compound path.
|
|
6
|
-
* This preserves the exact geometry of each path (no boolean operations)
|
|
7
|
-
* while combining them into one glyph. Under nonzero winding, this renders
|
|
8
|
-
* identically to drawing each path separately with the same color.
|
|
9
|
-
*/
|
|
10
|
-
function concatPathDs(ds) {
|
|
11
|
-
if (ds.length === 0)
|
|
12
|
-
return null;
|
|
13
|
-
if (ds.length === 1)
|
|
14
|
-
return ds[0];
|
|
15
|
-
return ds.join(' ');
|
|
16
|
-
}
|
|
4
|
+
const winding_1 = require("../pathkit/winding");
|
|
17
5
|
/**
|
|
18
6
|
* Merge consecutive same-color paths into single compound paths.
|
|
19
7
|
* Preserves z-order: only merges runs of adjacent paths with identical fill color.
|
|
20
8
|
*/
|
|
21
|
-
function mergeSameColorPaths(paths, logger) {
|
|
9
|
+
function mergeSameColorPaths(paths, pathkit, logger) {
|
|
22
10
|
if (paths.length <= 1)
|
|
23
11
|
return paths;
|
|
12
|
+
const analyses = new Map();
|
|
13
|
+
const analysisOf = (index) => {
|
|
14
|
+
if (!analyses.has(index)) {
|
|
15
|
+
analyses.set(index, (0, winding_1.analyzeWinding)(pathkit, paths[index].d));
|
|
16
|
+
}
|
|
17
|
+
return analyses.get(index);
|
|
18
|
+
};
|
|
24
19
|
const result = [];
|
|
25
20
|
let i = 0;
|
|
26
21
|
while (i < paths.length) {
|
|
27
|
-
const fill = paths[i]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// be merged — their CW hole contours would cancel CCW contours from
|
|
31
|
-
// adjacent paths, producing incorrect fill.
|
|
32
|
-
const knockout = paths[i].knockout;
|
|
22
|
+
const { fill, knockout } = paths[i];
|
|
23
|
+
const ds = [];
|
|
24
|
+
let sign = 1;
|
|
33
25
|
let j = i + 1;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
while (j < paths.length &&
|
|
27
|
+
paths[j].fill === fill &&
|
|
28
|
+
paths[j].knockout === knockout &&
|
|
29
|
+
analysisOf(i) !== null &&
|
|
30
|
+
analysisOf(j) !== null) {
|
|
31
|
+
if (ds.length === 0) {
|
|
32
|
+
const first = analysisOf(i);
|
|
33
|
+
sign = first.outerSigns.find((s) => s !== 0);
|
|
34
|
+
ds.push((0, winding_1.pathDataWithWinding)(pathkit, paths[i].d, first, sign));
|
|
40
35
|
}
|
|
36
|
+
ds.push((0, winding_1.pathDataWithWinding)(pathkit, paths[j].d, analysisOf(j), sign));
|
|
37
|
+
j++;
|
|
41
38
|
}
|
|
42
|
-
if (
|
|
39
|
+
if (ds.length === 0) {
|
|
43
40
|
result.push(paths[i]);
|
|
44
41
|
}
|
|
45
42
|
else {
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
logger?.info(` ⊕ Merged ${group.length} same-color paths (fill=${fill})`);
|
|
50
|
-
result.push(knockout ? { d: merged, fill, knockout } : { d: merged, fill });
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
result.push(...group);
|
|
54
|
-
}
|
|
43
|
+
logger?.info(` ⊕ Merged ${ds.length} same-color paths (fill=${fill})`);
|
|
44
|
+
const d = ds.join(' ');
|
|
45
|
+
result.push(knockout ? { d, fill, knockout } : { d, fill });
|
|
55
46
|
}
|
|
56
47
|
i = j;
|
|
57
48
|
}
|
|
@@ -2,14 +2,13 @@ import { type Element } from '@xmldom/xmldom';
|
|
|
2
2
|
export type ParsedPath = {
|
|
3
3
|
d: string;
|
|
4
4
|
fill: string | null;
|
|
5
|
-
fillRule?: 'evenodd';
|
|
6
|
-
noMerge?: boolean;
|
|
7
5
|
knockout?: boolean;
|
|
8
6
|
};
|
|
9
7
|
export type ParsedFlatSvg = {
|
|
10
8
|
viewBox: [number, number, number, number];
|
|
11
9
|
paths: ParsedPath[];
|
|
12
10
|
};
|
|
11
|
+
export declare function attribute(el: Element, name: string): string | null;
|
|
13
12
|
export declare function calculateOpColor(fill: string | null, opacity: number, el: Element): `rgba(${number},${number},${number},${number})`;
|
|
14
13
|
/**
|
|
15
14
|
* If a flattened path lost its initial moveto (e.g. an empty `Mx y z`
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attribute = attribute;
|
|
3
4
|
exports.calculateOpColor = calculateOpColor;
|
|
4
5
|
exports.sanitizePathData = sanitizePathData;
|
|
5
6
|
exports.parseFlattenedSvg = parseFlattenedSvg;
|
|
@@ -7,17 +8,32 @@ exports.shouldSkipPath = shouldSkipPath;
|
|
|
7
8
|
const xmldom_1 = require("@xmldom/xmldom");
|
|
8
9
|
const parse_1 = require("../../utils/parse");
|
|
9
10
|
const svgPatterns_1 = require("../../utils/svgPatterns");
|
|
11
|
+
const ELEMENT_NODE = 1;
|
|
12
|
+
function attribute(el, name) {
|
|
13
|
+
return el.hasAttribute(name) ? el.getAttribute(name) : null;
|
|
14
|
+
}
|
|
10
15
|
// if the fill is implicit, walk ancestors for the first explicit fill value
|
|
11
16
|
function resolveInheritedFill(el) {
|
|
12
|
-
let current = el.
|
|
13
|
-
while (current
|
|
14
|
-
const fill = current
|
|
17
|
+
let current = el.parentNode;
|
|
18
|
+
while (current?.nodeType === ELEMENT_NODE) {
|
|
19
|
+
const fill = attribute(current, 'fill');
|
|
15
20
|
if (fill !== null && fill !== 'inherit')
|
|
16
21
|
return fill;
|
|
17
|
-
current = current.
|
|
22
|
+
current = current.parentNode;
|
|
18
23
|
}
|
|
19
24
|
return 'black';
|
|
20
25
|
}
|
|
26
|
+
function ancestorOpacity(el) {
|
|
27
|
+
let opacity = 1;
|
|
28
|
+
let current = el.parentNode;
|
|
29
|
+
while (current?.nodeType === ELEMENT_NODE) {
|
|
30
|
+
const value = attribute(current, 'opacity');
|
|
31
|
+
if (value !== null)
|
|
32
|
+
opacity *= parseFloat(value);
|
|
33
|
+
current = current.parentNode;
|
|
34
|
+
}
|
|
35
|
+
return opacity;
|
|
36
|
+
}
|
|
21
37
|
// bake opacity into the fill as an rgba(...)
|
|
22
38
|
function calculateOpColor(fill, opacity, el) {
|
|
23
39
|
const resolvedFill = fill ?? resolveInheritedFill(el);
|
|
@@ -45,30 +61,28 @@ function sanitizePathData(d) {
|
|
|
45
61
|
const y = nums[nums.length - 1];
|
|
46
62
|
return { d: `M${x},${y} ${trimmed}`, sanitized: true };
|
|
47
63
|
}
|
|
64
|
+
function isUnpainted(fill) {
|
|
65
|
+
const f = (fill ?? '').trim().toLowerCase();
|
|
66
|
+
return f === 'transparent' || f === 'none';
|
|
67
|
+
}
|
|
48
68
|
const parsePath = (p) => {
|
|
49
69
|
const d = p.getAttribute('d') ?? '';
|
|
50
|
-
const op = p
|
|
51
|
-
const fillOp = p
|
|
52
|
-
const fill = p
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
p.getAttribute('clip-rule') === 'evenodd'
|
|
56
|
-
? 'evenodd'
|
|
57
|
-
: undefined;
|
|
58
|
-
if (op !== null || fillOp !== null) {
|
|
70
|
+
const op = attribute(p, 'opacity');
|
|
71
|
+
const fillOp = attribute(p, 'fill-opacity');
|
|
72
|
+
const fill = attribute(p, 'fill');
|
|
73
|
+
const groupOp = ancestorOpacity(p);
|
|
74
|
+
if (!isUnpainted(fill) && (op !== null || fillOp !== null || groupOp !== 1)) {
|
|
59
75
|
const opVal = op !== null ? parseFloat(op) : 1;
|
|
60
76
|
const fillOpVal = fillOp !== null ? parseFloat(fillOp) : 1;
|
|
61
|
-
const combinedOpacity = opVal * fillOpVal;
|
|
77
|
+
const combinedOpacity = opVal * fillOpVal * groupOp;
|
|
62
78
|
return {
|
|
63
79
|
d,
|
|
64
80
|
fill: calculateOpColor(fill, combinedOpacity, p),
|
|
65
|
-
fillRule,
|
|
66
81
|
};
|
|
67
82
|
}
|
|
68
83
|
return {
|
|
69
84
|
d,
|
|
70
85
|
fill,
|
|
71
|
-
fillRule,
|
|
72
86
|
};
|
|
73
87
|
};
|
|
74
88
|
function parseFlattenedSvg(flattenedSvg, options) {
|
|
@@ -104,6 +118,5 @@ function parseFlattenedSvg(flattenedSvg, options) {
|
|
|
104
118
|
function shouldSkipPath(d, fill) {
|
|
105
119
|
if (!d || d.trim() === '')
|
|
106
120
|
return true;
|
|
107
|
-
|
|
108
|
-
return f === 'transparent' || f === 'none';
|
|
121
|
+
return isUnpainted(fill);
|
|
109
122
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type { PathKitModule, PathKitPath } from './types';
|
|
1
|
+
import type { Cmd, PathKitModule, PathKitPath } from './types';
|
|
2
2
|
export declare function orientedPathData(PathKit: PathKitModule, path: PathKitPath): string;
|
|
3
3
|
export declare function canonicalWinding(PathKit: PathKitModule, d: string): string;
|
|
4
4
|
export declare function reversedWinding(PathKit: PathKitModule, d: string): string;
|
|
5
|
+
export type WindingAnalysis = {
|
|
6
|
+
contours: Cmd[][];
|
|
7
|
+
outerSigns: (-1 | 0 | 1)[];
|
|
8
|
+
};
|
|
9
|
+
export declare function analyzeWinding(PathKit: PathKitModule, d: string): WindingAnalysis | null;
|
|
10
|
+
export declare function pathDataWithWinding(PathKit: PathKitModule, d: string, analysis: WindingAnalysis, sign: -1 | 1): string;
|
|
@@ -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, '');
|