react-native-nano-icons 1.1.0-beta.1 → 1.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/ios/NanoIconView.mm +22 -44
- package/lib/commonjs/cli/buildSymbols.d.ts +13 -1
- package/lib/commonjs/cli/buildSymbols.js +24 -7
- package/lib/commonjs/cli/expoConfig.d.ts +1 -0
- package/lib/commonjs/cli/expoConfig.js +6 -2
- package/lib/commonjs/cli/fingerprint.js +7 -1
- package/lib/commonjs/cli/link.js +13 -1
- package/lib/commonjs/plugin/src/types.d.ts +12 -1
- package/lib/commonjs/src/core/glyph/merge.d.ts +1 -1
- package/lib/commonjs/src/core/glyph/merge.js +2 -2
- package/lib/commonjs/src/core/glyph/placement.d.ts +1 -0
- package/lib/commonjs/src/core/glyph/placement.js +9 -3
- package/lib/commonjs/src/core/pathkit/types.d.ts +1 -0
- package/lib/commonjs/src/core/pathkit/winding.d.ts +9 -4
- package/lib/commonjs/src/core/pathkit/winding.js +303 -48
- package/lib/commonjs/src/core/pipeline/prepare.js +2 -1
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +2 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.js +15 -3
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +2 -0
- package/lib/commonjs/src/core/symbols/contents.d.ts +1 -1
- package/lib/commonjs/src/core/symbols/contents.js +6 -2
- package/lib/commonjs/src/core/symbols/layers.d.ts +1 -0
- package/lib/commonjs/src/core/symbols/layers.js +133 -92
- package/lib/commonjs/src/core/symbols/template.d.ts +8 -3
- package/lib/commonjs/src/core/symbols/template.js +23 -8
- package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +8 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.js +28 -2
- package/lib/commonjs/src/utils/fingerPrint.d.ts +2 -0
- package/lib/commonjs/src/utils/fingerPrint.js +2 -0
- package/lib/module/utils/fingerPrint.js +1 -1
- package/lib/typescript/src/core/glyph/merge.d.ts +1 -1
- package/lib/typescript/src/core/glyph/placement.d.ts +1 -0
- package/lib/typescript/src/core/pathkit/types.d.ts +1 -0
- package/lib/typescript/src/core/pathkit/winding.d.ts +9 -4
- package/lib/typescript/src/core/symbols/contents.d.ts +1 -1
- package/lib/typescript/src/core/symbols/layers.d.ts +1 -0
- package/lib/typescript/src/core/symbols/template.d.ts +8 -3
- package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +8 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -650,6 +650,8 @@ Each entry of `symbolSets` generates one set of [native symbols](#-native-symbol
|
|
|
650
650
|
| `inputDir` | `string` | **Yes** | — | Path to the directory containing your `.svg` files, relative to the folder of `.nanoicons.json` or the app config. Subfolders are not read. |
|
|
651
651
|
| `name` | `string` | No | Folder name | Set name, used for output filenames and the generated typed manifest. |
|
|
652
652
|
| `prefix` | `string` | No | `nano` | Symbol-name prefix: `home.svg` → `nano.home` (iOS) / `nano_home` (Android). On Android, names are lowercased and other characters become `_`. Sets that share a prefix and a file name overwrite each other. |
|
|
653
|
+
| `fit` | `'content' \| 'viewBox'` | No | `'content'` | How each icon fills its symbol and drawable. `'content'` scales the drawn shapes to the full height. `'viewBox'` keeps the padding of the SVG's `viewBox`, so a set drawn on one grid (for example 24×24) keeps its relative sizes, and sizes the `viewBox` like an SF Symbol's em square (iOS) or a 24 dp Material icon (Android). |
|
|
654
|
+
| `scale` | `number` | No | `1` | Size of every icon in the set. With `fit: 'viewBox'`, `1` matches the size of SF Symbols and `0.9` draws icons 10% smaller. On Android an icon can't grow past its 24 dp box, so values above `1` only use the padding around the drawing. |
|
|
653
655
|
| `outputDir` | `string` | No | Sibling `nanoicons` folder | Path where the generated artifacts are written, relative to the folder of `.nanoicons.json` or the app config. Defaults to a `nanoicons` folder next to `inputDir`. |
|
|
654
656
|
|
|
655
657
|
### `nativeNanoSymbol()`
|
package/ios/NanoIconView.mm
CHANGED
|
@@ -6,9 +6,20 @@
|
|
|
6
6
|
#import <react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h>
|
|
7
7
|
#import <react/renderer/components/RNNanoIconsSpec/NanoIconProps.h>
|
|
8
8
|
#import "NanoIconInlineBaseline.h"
|
|
9
|
+
#include <unordered_map>
|
|
9
10
|
|
|
10
11
|
using namespace facebook::react;
|
|
11
12
|
|
|
13
|
+
static CGPathRef NanoIconOutlineForGlyph(CTFontRef font, CGGlyph glyph) {
|
|
14
|
+
static std::unordered_map<CTFontRef, std::unordered_map<CGGlyph, CGPathRef>> outlines;
|
|
15
|
+
auto &fontOutlines = outlines[font];
|
|
16
|
+
auto cached = fontOutlines.find(glyph);
|
|
17
|
+
if (cached != fontOutlines.end()) return cached->second;
|
|
18
|
+
CGPathRef outline = CTFontCreatePathForGlyph(font, glyph, NULL);
|
|
19
|
+
fontOutlines.emplace(glyph, outline);
|
|
20
|
+
return outline;
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
// Forward-declare so the layer subclass can call the drawing method.
|
|
13
24
|
@interface NanoIconView ()
|
|
14
25
|
- (void)_resolveFontIfMissing;
|
|
@@ -48,6 +59,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
48
59
|
|
|
49
60
|
@implementation NanoIconView {
|
|
50
61
|
CTFontRef _font; // borrowed from the shared resolver cache — do NOT CFRelease
|
|
62
|
+
CTFontRef _outlineFont;
|
|
51
63
|
NSString *_fontFamily;
|
|
52
64
|
CGFloat _fontSize;
|
|
53
65
|
std::vector<CGGlyph> _glyphs;
|
|
@@ -214,7 +226,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
214
226
|
// Render multi-color icons by drawing each color layer glyph at the same
|
|
215
227
|
// position. Layers stack via painter's order to compose the final icon.
|
|
216
228
|
- (void)_drawIconInContext:(CGContextRef)context bounds:(CGRect)bounds {
|
|
217
|
-
if (!_font || _glyphs.empty()) return;
|
|
229
|
+
if (!_font || !_outlineFont || _glyphs.empty()) return;
|
|
218
230
|
if (!_metricsValid) [self _updateMetrics];
|
|
219
231
|
|
|
220
232
|
CGContextSaveGState(context);
|
|
@@ -230,56 +242,20 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
230
242
|
CGContextScaleCTM(context, glyphScale, glyphScale);
|
|
231
243
|
}
|
|
232
244
|
CGContextScaleCTM(context, _fitScale, _fitScale);
|
|
245
|
+
CGContextTranslateCTM(context, _baselinePosition.x, _baselinePosition.y);
|
|
246
|
+
CGContextScaleCTM(context, CTFontGetSize(_font), CTFontGetSize(_font));
|
|
233
247
|
|
|
234
|
-
size_t i = 0;
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
248
|
+
for (size_t i = 0; i < _glyphs.size(); i++) {
|
|
249
|
+
CGPathRef outline = _glyphs[i] ? NanoIconOutlineForGlyph(_outlineFont, _glyphs[i]) : NULL;
|
|
250
|
+
if (!outline) continue;
|
|
238
251
|
CGColorRef color = [self _colorForLayer:i];
|
|
239
252
|
if (!color) {
|
|
240
253
|
static CGColorRef sBlack = CGColorCreateSRGB(0, 0, 0, 1);
|
|
241
254
|
color = sBlack;
|
|
242
255
|
}
|
|
243
256
|
CGContextSetFillColorWithColor(context, color);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
size_t batchStart = i;
|
|
247
|
-
size_t batchCount = 0;
|
|
248
|
-
CGPoint posBuf[16];
|
|
249
|
-
CGGlyph glyphBuf[16];
|
|
250
|
-
|
|
251
|
-
while (i < _glyphs.size()) {
|
|
252
|
-
if (_glyphs[i] == 0) { i++; continue; }
|
|
253
|
-
CGColorRef next = [self _colorForLayer:i];
|
|
254
|
-
if (i > batchStart && next != color) break;
|
|
255
|
-
if (batchCount < 16) {
|
|
256
|
-
posBuf[batchCount] = _baselinePosition;
|
|
257
|
-
glyphBuf[batchCount] = _glyphs[i];
|
|
258
|
-
}
|
|
259
|
-
batchCount++;
|
|
260
|
-
i++;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
CGPoint *positions = posBuf;
|
|
264
|
-
CGGlyph *glyphs = glyphBuf;
|
|
265
|
-
if (batchCount > 16) {
|
|
266
|
-
positions = (CGPoint *)malloc(batchCount * sizeof(CGPoint));
|
|
267
|
-
glyphs = (CGGlyph *)malloc(batchCount * sizeof(CGGlyph));
|
|
268
|
-
size_t idx = 0;
|
|
269
|
-
for (size_t j = batchStart; j < i; j++) {
|
|
270
|
-
if (_glyphs[j] == 0) continue;
|
|
271
|
-
positions[idx] = _baselinePosition;
|
|
272
|
-
glyphs[idx] = _glyphs[j];
|
|
273
|
-
idx++;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
CTFontDrawGlyphs(_font, glyphs, positions, batchCount, context);
|
|
278
|
-
|
|
279
|
-
if (batchCount > 16) {
|
|
280
|
-
free(positions);
|
|
281
|
-
free(glyphs);
|
|
282
|
-
}
|
|
257
|
+
CGContextAddPath(context, outline);
|
|
258
|
+
CGContextFillPath(context);
|
|
283
259
|
}
|
|
284
260
|
|
|
285
261
|
CGContextRestoreGState(context);
|
|
@@ -333,6 +309,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
333
309
|
_fontFamily = [NSString stringWithUTF8String:newViewProps.fontFamily.c_str()];
|
|
334
310
|
_fontSize = newViewProps.size;
|
|
335
311
|
_font = NanoIconResolveFont(_fontFamily, _fontSize);
|
|
312
|
+
_outlineFont = NanoIconResolveFont(_fontFamily, 1);
|
|
336
313
|
_metricsValid = NO;
|
|
337
314
|
fontChanged = YES;
|
|
338
315
|
needsRedraw = YES;
|
|
@@ -417,6 +394,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
|
|
|
417
394
|
- (void)_resolveFontIfMissing {
|
|
418
395
|
if (_font || _fontFamily.length == 0) return;
|
|
419
396
|
_font = NanoIconResolveFont(_fontFamily, _fontSize);
|
|
397
|
+
_outlineFont = NanoIconResolveFont(_fontFamily, 1);
|
|
420
398
|
if (!_font) return;
|
|
421
399
|
const auto &viewProps = static_cast<const NanoIconProps &>(*_props);
|
|
422
400
|
[self _mapGlyphs:viewProps.codepoints];
|
|
@@ -4,13 +4,25 @@ import type { SymbolTask } from '../src/core/pipeline/prepareSymbol';
|
|
|
4
4
|
import type { PreparedSvgCache } from '../src/core/pipeline/preparedSvgCache';
|
|
5
5
|
import type { NanoLogger } from './logger';
|
|
6
6
|
import type { StaleSet } from './build';
|
|
7
|
+
export type SymbolFit = 'content' | 'viewBox';
|
|
7
8
|
export type SymbolSetConfig = {
|
|
8
9
|
/** Folder of SVG files (relative to project root). */
|
|
9
10
|
inputDir: string;
|
|
10
|
-
/** Set name; defaults to the inputDir basename. */
|
|
11
|
+
/** Set's name; defaults to the inputDir basename. */
|
|
11
12
|
name?: string;
|
|
12
13
|
/** Symbol name prefix (default "nano"): home.svg → "nano.home". */
|
|
13
14
|
prefix?: string;
|
|
15
|
+
/**
|
|
16
|
+
* How each icon fills the symbol: `'content'` (default) scales its drawn shapes to
|
|
17
|
+
* the full height; `'viewBox'` keeps the padding of its SVG viewBox.
|
|
18
|
+
*/
|
|
19
|
+
fit?: SymbolFit;
|
|
20
|
+
/**
|
|
21
|
+
* Size of every icon in the set (default 1). With `fit: 'viewBox'`, 1 matches the size
|
|
22
|
+
* of SF Symbols. On Android an icon can't grow past its 24 dp box, so values above 1
|
|
23
|
+
* only use the padding around the drawing.
|
|
24
|
+
*/
|
|
25
|
+
scale?: number;
|
|
14
26
|
/** Output dir; defaults to a sibling nanoicons folder next to inputDir. */
|
|
15
27
|
outputDir?: string;
|
|
16
28
|
};
|
|
@@ -26,7 +26,7 @@ const DEFAULT_PREFIX = 'nano';
|
|
|
26
26
|
const STALE_REASON = {
|
|
27
27
|
missing: (file) => `${file} is missing`,
|
|
28
28
|
invalidJson: (file) => `${file} is not valid JSON`,
|
|
29
|
-
inputsChanged: 'its SVGs,
|
|
29
|
+
inputsChanged: 'its SVGs, options or installed versions changed',
|
|
30
30
|
};
|
|
31
31
|
function currentSymbolOutput(inputHash, outputDir, name, logger) {
|
|
32
32
|
const symbolmapPath = path_1.default.join(outputDir, `${name}.symbolmap.json`);
|
|
@@ -82,14 +82,31 @@ function resolveSymbolSet(set, projectRoot, versions) {
|
|
|
82
82
|
const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
|
|
83
83
|
const name = set.name ?? path_1.default.basename(inputDir);
|
|
84
84
|
const prefix = set.prefix ?? DEFAULT_PREFIX;
|
|
85
|
+
const fit = set.fit ?? 'content';
|
|
86
|
+
if (fit !== 'content' && fit !== 'viewBox') {
|
|
87
|
+
throw new Error(`[react-native-nano-icons] "${name}": "fit" must be "content" or "viewBox", got ${JSON.stringify(set.fit)}`);
|
|
88
|
+
}
|
|
89
|
+
const scale = set.scale ?? 1;
|
|
90
|
+
if (typeof scale !== 'number' || !Number.isFinite(scale) || scale <= 0) {
|
|
91
|
+
throw new Error(`[react-native-nano-icons] "${name}": "scale" must be a positive number, got ${JSON.stringify(set.scale)}`);
|
|
92
|
+
}
|
|
85
93
|
if (!fs_1.default.existsSync(inputDir)) {
|
|
86
94
|
throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
|
|
87
95
|
}
|
|
88
96
|
const outputDir = set.outputDir
|
|
89
97
|
? path_1.default.resolve(projectRoot, set.outputDir)
|
|
90
98
|
: path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
|
|
91
|
-
const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSymbolDirSync)(inputDir, { prefix, ...versions });
|
|
92
|
-
return {
|
|
99
|
+
const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSymbolDirSync)(inputDir, { prefix, fit, scale, ...versions });
|
|
100
|
+
return {
|
|
101
|
+
inputDir,
|
|
102
|
+
name,
|
|
103
|
+
prefix,
|
|
104
|
+
fit,
|
|
105
|
+
scale,
|
|
106
|
+
outputDir,
|
|
107
|
+
inputHash,
|
|
108
|
+
svgHashByFile,
|
|
109
|
+
};
|
|
93
110
|
}
|
|
94
111
|
/**
|
|
95
112
|
* The input fingerprint of each symbol set: the value a build stores in its symbolmap as `m.h`.
|
|
@@ -116,7 +133,7 @@ async function checkAllSymbols(symbolSets, projectRoot, options) {
|
|
|
116
133
|
};
|
|
117
134
|
const stale = [];
|
|
118
135
|
for (const set of symbolSets) {
|
|
119
|
-
const { inputDir, name, prefix, outputDir, inputHash, svgHashByFile } = resolveSymbolSet(set, projectRoot, versions);
|
|
136
|
+
const { inputDir, name, prefix, fit, scale, outputDir, inputHash, svgHashByFile, } = resolveSymbolSet(set, projectRoot, versions);
|
|
120
137
|
if (options?.existingOnly &&
|
|
121
138
|
!fs_1.default.existsSync(path_1.default.join(outputDir, `${name}.symbolmap.json`))) {
|
|
122
139
|
continue;
|
|
@@ -124,7 +141,7 @@ async function checkAllSymbols(symbolSets, projectRoot, options) {
|
|
|
124
141
|
const state = currentSymbolOutput(inputHash, outputDir, name);
|
|
125
142
|
if ('staleBecause' in state &&
|
|
126
143
|
state.staleBecause === STALE_REASON.inputsChanged &&
|
|
127
|
-
(await (0, sameOutputs_1.buildsSameOutputs)(outputDir, `${name}.symbolmap.json`, (dir) => (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix }, { inputDir, outputDir: dir }, { inputHash, svgHashByFile })))) {
|
|
144
|
+
(await (0, sameOutputs_1.buildsSameOutputs)(outputDir, `${name}.symbolmap.json`, (dir) => (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix, fit, scale }, { inputDir, outputDir: dir }, { inputHash, svgHashByFile })))) {
|
|
128
145
|
options?.logger?.succeed(`${name} symbols are up to date: their inputs changed, but they build the same`);
|
|
129
146
|
}
|
|
130
147
|
else if ('staleBecause' in state) {
|
|
@@ -149,7 +166,7 @@ async function buildAllSymbols(symbolSets, projectRoot, options) {
|
|
|
149
166
|
const failures = [];
|
|
150
167
|
for (let i = 0; i < symbolSets.length; i++) {
|
|
151
168
|
const set = symbolSets[i];
|
|
152
|
-
const { inputDir, name, prefix, outputDir, inputHash, svgHashByFile } = resolveSymbolSet(set, projectRoot, versions);
|
|
169
|
+
const { inputDir, name, prefix, fit, scale, outputDir, inputHash, svgHashByFile, } = resolveSymbolSet(set, projectRoot, versions);
|
|
153
170
|
if ('multicolor' in set) {
|
|
154
171
|
logger?.warn(`${name}: "multicolor" is no longer needed — every symbol now carries both rendering modes; remove it from the config.`);
|
|
155
172
|
}
|
|
@@ -161,7 +178,7 @@ async function buildAllSymbols(symbolSets, projectRoot, options) {
|
|
|
161
178
|
logger?.start(`Building ${name} (${i + 1}/${symbolSets.length})…`);
|
|
162
179
|
let out;
|
|
163
180
|
try {
|
|
164
|
-
out = await (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix }, { inputDir, outputDir }, {
|
|
181
|
+
out = await (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix, fit, scale }, { inputDir, outputDir }, {
|
|
165
182
|
logger,
|
|
166
183
|
inputHash,
|
|
167
184
|
preparedSvgCache: options?.preparedSvgCache,
|
|
@@ -19,4 +19,5 @@ export declare function loadSymbolSetsFromAppConfig(projectRoot: string): Symbol
|
|
|
19
19
|
* or `undefined` when it is not listed.
|
|
20
20
|
*/
|
|
21
21
|
export declare function findPluginOptions(projectRoot: string): NanoIconsPluginOptions | undefined;
|
|
22
|
+
export declare function resolveExpoConfigModule(projectRoot: string): string | undefined;
|
|
22
23
|
export {};
|
|
@@ -4,6 +4,7 @@ exports.loadDynamicSetsFromAppConfig = loadDynamicSetsFromAppConfig;
|
|
|
4
4
|
exports.loadIconSetsFromAppConfig = loadIconSetsFromAppConfig;
|
|
5
5
|
exports.loadSymbolSetsFromAppConfig = loadSymbolSetsFromAppConfig;
|
|
6
6
|
exports.findPluginOptions = findPluginOptions;
|
|
7
|
+
exports.resolveExpoConfigModule = resolveExpoConfigModule;
|
|
7
8
|
/**
|
|
8
9
|
* Load icon sets configured with linking: 'dynamic' from the Expo app config
|
|
9
10
|
* (app.json, app.config.js, or app.config.ts).
|
|
@@ -12,6 +13,10 @@ exports.findPluginOptions = findPluginOptions;
|
|
|
12
13
|
* falling back to @expo/config.
|
|
13
14
|
*/
|
|
14
15
|
function loadDynamicSetsFromAppConfig(projectRoot) {
|
|
16
|
+
if (!resolveExpoConfigModule(projectRoot)) {
|
|
17
|
+
throw new Error(`[react-native-nano-icons] Could not find expo/config or @expo/config from ${projectRoot} — required for --dynamic-app-config.\n` +
|
|
18
|
+
`Run the command from your Expo app root, or pass --path <app root>.`);
|
|
19
|
+
}
|
|
15
20
|
const dynamicSets = loadIconSetsFromAppConfig(projectRoot).filter((s) => s.linking === 'dynamic');
|
|
16
21
|
if (dynamicSets.length === 0) {
|
|
17
22
|
throw new Error(`[react-native-nano-icons] No icon sets with linking: "dynamic" found.\n` +
|
|
@@ -45,8 +50,7 @@ function loadPluginOptions(projectRoot) {
|
|
|
45
50
|
function findPluginOptions(projectRoot) {
|
|
46
51
|
const configModule = resolveExpoConfigModule(projectRoot);
|
|
47
52
|
if (!configModule) {
|
|
48
|
-
throw new Error(`[react-native-nano-icons] Could not find expo/config or @expo/config from ${projectRoot}
|
|
49
|
-
`Run the command from your Expo app root, or pass --path <app root>.`);
|
|
53
|
+
throw new Error(`[react-native-nano-icons] Could not find expo/config or @expo/config from ${projectRoot}.`);
|
|
50
54
|
}
|
|
51
55
|
const { getConfig } = require(configModule);
|
|
52
56
|
const { exp } = getConfig(projectRoot, { skipSDKVersionRequirement: true });
|
|
@@ -13,6 +13,11 @@ const REASONS = ['react-native-nano-icons'];
|
|
|
13
13
|
* Returns no sources when the plugin is not configured, and warns and returns none when the sets can't be read.
|
|
14
14
|
*/
|
|
15
15
|
function nanoIconsFingerprintSources(projectRoot) {
|
|
16
|
+
if (!(0, expoConfig_1.resolveExpoConfigModule)(projectRoot)) {
|
|
17
|
+
console.warn(`[react-native-nano-icons] No fingerprint sources added: Could not find expo/config or @expo/config from ${projectRoot}.\n` +
|
|
18
|
+
`Pass the folder of your app config, e.g. nanoIconsFingerprintSources(__dirname) in a fingerprint.config.js next to it.`);
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
16
21
|
try {
|
|
17
22
|
const options = (0, expoConfig_1.findPluginOptions)(projectRoot);
|
|
18
23
|
const iconSets = (0, build_1.fingerprintIconSets)((options?.iconSets ?? []).filter((set) => set.linking !== 'dynamic'), projectRoot).map(({ fontFamily, hash }) => ({
|
|
@@ -30,7 +35,8 @@ function nanoIconsFingerprintSources(projectRoot) {
|
|
|
30
35
|
return [...iconSets, ...symbolSets];
|
|
31
36
|
}
|
|
32
37
|
catch (err) {
|
|
33
|
-
|
|
38
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
39
|
+
console.warn(`[react-native-nano-icons] No fingerprint sources added: ${message.replace(/^\[react-native-nano-icons\] /, '')}`);
|
|
34
40
|
return [];
|
|
35
41
|
}
|
|
36
42
|
}
|
package/lib/commonjs/cli/link.js
CHANGED
|
@@ -47,6 +47,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
47
47
|
const node_path_1 = __importDefault(require("node:path"));
|
|
48
48
|
const plist = __importStar(require("plist"));
|
|
49
49
|
const contents_1 = require("../src/core/symbols/contents");
|
|
50
|
+
const vectorDrawable_1 = require("../src/core/symbols/vectorDrawable");
|
|
50
51
|
const naming_1 = require("../src/utils/naming");
|
|
51
52
|
const fontIdentity_1 = require("../src/utils/fontIdentity");
|
|
52
53
|
const ANDROID_FONTS_DIR = 'android/app/src/main/assets/fonts';
|
|
@@ -235,6 +236,7 @@ const XML_FILE_RE = /\.xml$/;
|
|
|
235
236
|
// scan below only sees names still in the config.
|
|
236
237
|
const SYMBOL_LEDGER = '.nanoicons-catalog.json';
|
|
237
238
|
const DRAWABLE_LEDGER = '.nanoicons-drawables.json';
|
|
239
|
+
const DRAWABLE_KEEP_FILE = 'nanoicons_keep.xml';
|
|
238
240
|
function readLedger(ledgerPath) {
|
|
239
241
|
try {
|
|
240
242
|
const names = JSON.parse(node_fs_1.default.readFileSync(ledgerPath, 'utf8'));
|
|
@@ -334,7 +336,9 @@ async function linkBareSymbols(projectRoot, builtSymbolSets, logger) {
|
|
|
334
336
|
// ---------------------------------------------------------------------------
|
|
335
337
|
// Copy generated VectorDrawable XML into a res/drawable dir, first removing what
|
|
336
338
|
// we linked last time (ledger) plus any current-prefix match. Handles removed
|
|
337
|
-
// icons, prefix renames and dropped sets.
|
|
339
|
+
// icons, prefix renames and dropped sets. A keep file in res/raw lists them so
|
|
340
|
+
// release builds with resource shrinking don't strip them from react-native-screens'
|
|
341
|
+
// tab bar, which looks them up by name.
|
|
338
342
|
function copyDrawablesIntoResDir(drawableDir, builtSymbolSets) {
|
|
339
343
|
node_fs_1.default.mkdirSync(drawableDir, { recursive: true });
|
|
340
344
|
const outputDir = builtSymbolSets[0]
|
|
@@ -367,6 +371,14 @@ function copyDrawablesIntoResDir(drawableDir, builtSymbolSets) {
|
|
|
367
371
|
}
|
|
368
372
|
if (ledgerPath)
|
|
369
373
|
node_fs_1.default.writeFileSync(ledgerPath, JSON.stringify(linked));
|
|
374
|
+
const keepPath = node_path_1.default.join(node_path_1.default.dirname(drawableDir), 'raw', DRAWABLE_KEEP_FILE);
|
|
375
|
+
if (linked.length) {
|
|
376
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(keepPath), { recursive: true });
|
|
377
|
+
node_fs_1.default.writeFileSync(keepPath, (0, vectorDrawable_1.buildDrawableKeepXml)(linked.map((name) => name.replace(XML_FILE_RE, ''))), 'utf8');
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
node_fs_1.default.rmSync(keepPath, { force: true });
|
|
381
|
+
}
|
|
370
382
|
}
|
|
371
383
|
/**
|
|
372
384
|
* Link generated VectorDrawables into the Android app's res/drawable. They are
|
|
@@ -39,10 +39,21 @@ export interface IconSetConfig {
|
|
|
39
39
|
export interface SymbolSetConfig {
|
|
40
40
|
/** Folder of SVG files (relative to project root). */
|
|
41
41
|
inputDir: string;
|
|
42
|
-
/** Set name; defaults to the inputDir basename. */
|
|
42
|
+
/** Set's name; defaults to the inputDir basename. */
|
|
43
43
|
name?: string;
|
|
44
44
|
/** Symbol name prefix (default "nano"): home.svg → "nano.home". */
|
|
45
45
|
prefix?: string;
|
|
46
|
+
/**
|
|
47
|
+
* How each icon fills the symbol: `'content'` (default) scales its drawn shapes to
|
|
48
|
+
* the full height; `'viewBox'` keeps the padding of its SVG viewBox.
|
|
49
|
+
*/
|
|
50
|
+
fit?: 'content' | 'viewBox';
|
|
51
|
+
/**
|
|
52
|
+
* Size of every icon in the set (default 1). With `fit: 'viewBox'`, 1 matches the size
|
|
53
|
+
* of SF Symbols. On Android an icon can't grow past its 24 dp box, so values above 1
|
|
54
|
+
* only use the padding around the drawing.
|
|
55
|
+
*/
|
|
56
|
+
scale?: number;
|
|
46
57
|
/** Output dir; defaults to a sibling nanoicons folder next to inputDir. */
|
|
47
58
|
outputDir?: string;
|
|
48
59
|
}
|
|
@@ -5,4 +5,4 @@ import type { ParsedPath } from './parse';
|
|
|
5
5
|
* Merge consecutive same-color paths into single compound paths.
|
|
6
6
|
* Preserves z-order: only merges runs of adjacent paths with identical fill color.
|
|
7
7
|
*/
|
|
8
|
-
export declare function mergeSameColorPaths(paths: ParsedPath[], pathkit: PathKitModule, logger?: NanoLogger): ParsedPath[];
|
|
8
|
+
export declare function mergeSameColorPaths(paths: ParsedPath[], pathkit: PathKitModule, logger?: NanoLogger, tolerance?: number): ParsedPath[];
|
|
@@ -6,13 +6,13 @@ const winding_1 = require("../pathkit/winding");
|
|
|
6
6
|
* Merge consecutive same-color paths into single compound paths.
|
|
7
7
|
* Preserves z-order: only merges runs of adjacent paths with identical fill color.
|
|
8
8
|
*/
|
|
9
|
-
function mergeSameColorPaths(paths, pathkit, logger) {
|
|
9
|
+
function mergeSameColorPaths(paths, pathkit, logger, tolerance) {
|
|
10
10
|
if (paths.length <= 1)
|
|
11
11
|
return paths;
|
|
12
12
|
const analyses = new Map();
|
|
13
13
|
const analysisOf = (index) => {
|
|
14
14
|
if (!analyses.has(index)) {
|
|
15
|
-
analyses.set(index, (0, winding_1.analyzeWinding)(pathkit, paths[index].d));
|
|
15
|
+
analyses.set(index, (0, winding_1.analyzeWinding)(pathkit, paths[index].d, tolerance));
|
|
16
16
|
}
|
|
17
17
|
return analyses.get(index);
|
|
18
18
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.computePlacement = computePlacement;
|
|
4
4
|
exports.transformPathForFont = transformPathForFont;
|
|
5
|
+
const winding_1 = require("../pathkit/winding");
|
|
5
6
|
function roundInt(n) {
|
|
6
7
|
return Math.round(n);
|
|
7
8
|
}
|
|
@@ -32,10 +33,15 @@ function computePlacement(opts) {
|
|
|
32
33
|
* SVG→font Y-axis flip into a single affine transform applied via PathKit.
|
|
33
34
|
*/
|
|
34
35
|
function transformPathForFont(PathKit, d, opts) {
|
|
35
|
-
const { vx, vy, scale, xOff, yOff, upm } = opts;
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
36
|
+
const { vx, vy, scale, xOff, yOff, upm, touchTolerance } = opts;
|
|
37
|
+
const parsed = PathKit.FromSVGString(d);
|
|
38
|
+
if (!parsed)
|
|
38
39
|
return d;
|
|
40
|
+
// Repairs the outline before placement.
|
|
41
|
+
const safe = (0, winding_1.rasterSafePathData)(PathKit, parsed, touchTolerance);
|
|
42
|
+
const p = safe === null ? parsed : (PathKit.FromSVGString(safe) ?? parsed);
|
|
43
|
+
if (p !== parsed)
|
|
44
|
+
parsed.delete?.();
|
|
39
45
|
// Combined affine: placement + Y-flip for font coordinates.
|
|
40
46
|
// x' = scale * (x - vx) + xOff
|
|
41
47
|
// y' = upm - (scale * (y - vy) + yOff)
|
|
@@ -10,6 +10,7 @@ export type VerbMap = {
|
|
|
10
10
|
};
|
|
11
11
|
export interface PathKitPath {
|
|
12
12
|
delete?: () => void;
|
|
13
|
+
copy: () => PathKitPath;
|
|
13
14
|
moveTo: (x: number, y: number) => void;
|
|
14
15
|
lineTo: (x: number, y: number) => void;
|
|
15
16
|
quadTo: (x1: number, y1: number, x2: number, y2: number) => void;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { Cmd, PathKitModule, PathKitPath } from './types';
|
|
1
|
+
import type { Cmd, PathKitModule, PathKitPath, VerbMap } from './types';
|
|
2
2
|
export declare function orientedPathData(PathKit: PathKitModule, path: PathKitPath): string;
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function reversedWinding(PathKit: PathKitModule, d: string): string;
|
|
3
|
+
export declare function touchTolerance(viewBox: readonly [number, number, number, number]): number;
|
|
5
4
|
export type WindingAnalysis = {
|
|
6
5
|
contours: Cmd[][];
|
|
7
6
|
outerSigns: (-1 | 0 | 1)[];
|
|
8
7
|
};
|
|
9
|
-
export declare function analyzeWinding(PathKit: PathKitModule, d: string): WindingAnalysis | null;
|
|
8
|
+
export declare function analyzeWinding(PathKit: PathKitModule, d: string, tolerance?: number): WindingAnalysis | null;
|
|
9
|
+
export declare function reversedContour(contour: readonly Cmd[], V: VerbMap): Cmd[];
|
|
10
10
|
export declare function pathDataWithWinding(PathKit: PathKitModule, d: string, analysis: WindingAnalysis, sign: -1 | 1): string;
|
|
11
|
+
export declare function rasterSafePathData(PathKit: PathKitModule, path: PathKitPath, tolerance: number): string | null;
|
|
12
|
+
export declare function canonicalWinding(PathKit: PathKitModule, d: string, tolerance?: number): string;
|
|
13
|
+
export declare function reversedWinding(PathKit: PathKitModule, d: string, tolerance?: number): string;
|
|
14
|
+
export type PathOpKind = 'union' | 'intersect' | 'difference';
|
|
15
|
+
export declare function pathOpData(PathKit: PathKitModule, a: string, b: string, kind: PathOpKind): string | null;
|