react-native-nano-icons 1.0.0-beta.1 → 1.0.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.
Files changed (129) hide show
  1. package/README.md +124 -2
  2. package/android/build.gradle +8 -1
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +53 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
  5. package/android/src/main/jni/CMakeLists.txt +38 -0
  6. package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
  8. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
  9. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
  10. package/ios/NanoIconInlineBaseline.h +4 -0
  11. package/ios/NanoIconInlineBaseline.mm +190 -0
  12. package/ios/NanoIconView.h +1 -0
  13. package/ios/NanoIconView.mm +118 -107
  14. package/lib/commonjs/cli/build.d.ts +5 -0
  15. package/lib/commonjs/cli/build.js +37 -15
  16. package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
  17. package/lib/commonjs/cli/buildSymbols.js +134 -0
  18. package/lib/commonjs/cli/config.d.ts +3 -1
  19. package/lib/commonjs/cli/config.js +3 -3
  20. package/lib/commonjs/cli/expoConfig.d.ts +3 -0
  21. package/lib/commonjs/cli/expoConfig.js +17 -6
  22. package/lib/commonjs/cli/index.d.ts +4 -2
  23. package/lib/commonjs/cli/index.js +12 -1
  24. package/lib/commonjs/cli/link.d.ts +15 -0
  25. package/lib/commonjs/cli/link.js +185 -1
  26. package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
  27. package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
  28. package/lib/commonjs/metro/index.d.ts +35 -0
  29. package/lib/commonjs/metro/index.js +92 -0
  30. package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
  31. package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
  32. package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
  33. package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
  34. package/lib/commonjs/plugin/src/index.d.ts +1 -1
  35. package/lib/commonjs/plugin/src/index.js +9 -3
  36. package/lib/commonjs/plugin/src/types.d.ts +34 -2
  37. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
  38. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
  39. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
  40. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
  41. package/lib/commonjs/scripts/cli.js +27 -9
  42. package/lib/commonjs/src/core/font/compile.js +3 -5
  43. package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
  44. package/lib/commonjs/src/core/font/quadratic.js +2 -0
  45. package/lib/commonjs/src/core/glyph/merge.js +3 -1
  46. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -0
  47. package/lib/commonjs/src/core/pathkit/contours.d.ts +1 -0
  48. package/lib/commonjs/src/core/pathkit/contours.js +18 -0
  49. package/lib/commonjs/src/core/pathkit/evenodd.js +1 -15
  50. package/lib/commonjs/src/core/pathkit/winding.d.ts +4 -0
  51. package/lib/commonjs/src/core/pathkit/winding.js +59 -0
  52. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  53. package/lib/commonjs/src/core/pipeline/config.js +6 -0
  54. package/lib/commonjs/src/core/pipeline/iconPool.d.ts +13 -2
  55. package/lib/commonjs/src/core/pipeline/iconPool.js +89 -31
  56. package/lib/commonjs/src/core/pipeline/index.d.ts +2 -0
  57. package/lib/commonjs/src/core/pipeline/index.js +3 -1
  58. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -0
  59. package/lib/commonjs/src/core/pipeline/prepare.js +18 -0
  60. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +3 -0
  61. package/lib/commonjs/src/core/pipeline/prepareIcon.js +11 -8
  62. package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
  63. package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
  64. package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
  65. package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -0
  66. package/lib/commonjs/src/core/pipeline/prepareWorker.js +3 -3
  67. package/lib/commonjs/src/core/pipeline/preparedSvgCache.d.ts +6 -0
  68. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
  69. package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +5 -0
  70. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +10 -8
  71. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
  72. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
  73. package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
  74. package/lib/commonjs/src/core/symbols/contents.js +15 -0
  75. package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
  76. package/lib/commonjs/src/core/symbols/knockout.js +51 -0
  77. package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
  78. package/lib/commonjs/src/core/symbols/layers.js +182 -0
  79. package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
  80. package/lib/commonjs/src/core/symbols/template.js +140 -0
  81. package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
  82. package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
  83. package/lib/commonjs/src/utils/fingerPrint.d.ts +11 -0
  84. package/lib/commonjs/src/utils/fingerPrint.js +28 -9
  85. package/lib/commonjs/src/utils/naming.d.ts +10 -0
  86. package/lib/commonjs/src/utils/naming.js +49 -0
  87. package/lib/module/createNanoIconsSet.native.js +29 -26
  88. package/lib/module/createNanoIconsSet.shared.js +3 -2
  89. package/lib/module/createNanoIconsSet.web.js +17 -5
  90. package/lib/module/devServerFont.js +30 -0
  91. package/lib/module/devServerFont.web.js +25 -0
  92. package/lib/module/loadDynamicFont.js +6 -3
  93. package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
  94. package/lib/module/symbols/index.android.js +42 -0
  95. package/lib/module/symbols/index.ios.js +35 -0
  96. package/lib/module/symbols/index.js +35 -0
  97. package/lib/module/symbols/index.native.js +12 -0
  98. package/lib/module/symbols/types.js +1 -0
  99. package/lib/module/utils/fingerPrint.js +18 -3
  100. package/lib/module/utils/glyphRuntime.js +36 -2
  101. package/lib/module/utils/naming.js +46 -0
  102. package/lib/module/utils/validateLayerColor.js +24 -0
  103. package/lib/typescript/src/core/glyph/parse.d.ts +1 -0
  104. package/lib/typescript/src/core/pathkit/contours.d.ts +1 -0
  105. package/lib/typescript/src/core/pathkit/winding.d.ts +5 -0
  106. package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
  107. package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
  108. package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
  109. package/lib/typescript/src/core/symbols/template.d.ts +23 -0
  110. package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
  111. package/lib/typescript/src/devServerFont.d.ts +4 -0
  112. package/lib/typescript/src/devServerFont.web.d.ts +4 -0
  113. package/lib/typescript/src/loadDynamicFont.d.ts +1 -0
  114. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +6 -5
  115. package/lib/typescript/src/symbols/index.android.d.ts +33 -0
  116. package/lib/typescript/src/symbols/index.d.ts +31 -0
  117. package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
  118. package/lib/typescript/src/symbols/index.native.d.ts +8 -0
  119. package/lib/typescript/src/symbols/types.d.ts +24 -0
  120. package/lib/typescript/src/types.d.ts +2 -0
  121. package/lib/typescript/src/utils/fingerPrint.d.ts +11 -0
  122. package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
  123. package/lib/typescript/src/utils/naming.d.ts +11 -0
  124. package/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
  125. package/metro.js +1 -0
  126. package/package.json +26 -2
  127. package/react-native-nano-icons.podspec +4 -1
  128. package/react-native.config.js +10 -0
  129. package/src/specs/NanoIconViewNativeComponent.ts +9 -6
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FontRebuildWatcher = exports.CHANGE_LABEL = exports.ADDED_FILES_SETTLE_MS = exports.REBUILD_DEBOUNCE_MS = exports.FONT_ROUTE = void 0;
7
+ exports.summarize = summarize;
8
+ exports.toWatchEvents = toWatchEvents;
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const index_1 = require("../cli/index");
12
+ exports.FONT_ROUTE = '/__nanoicons/';
13
+ exports.REBUILD_DEBOUNCE_MS = 50;
14
+ exports.ADDED_FILES_SETTLE_MS = 250;
15
+ const MAX_LISTED_CHANGES = 3;
16
+ const WEB_PLATFORM = /[?&]platform=web(?:&|$)/;
17
+ exports.CHANGE_LABEL = {
18
+ add: 'added',
19
+ change: 'changed',
20
+ delete: 'removed',
21
+ };
22
+ function setName(set) {
23
+ return set.fontFamily ?? node_path_1.default.basename(set.inputDir);
24
+ }
25
+ function summarize(changes) {
26
+ const listed = changes.slice(0, MAX_LISTED_CHANGES).join(', ');
27
+ const rest = changes.length - MAX_LISTED_CHANGES;
28
+ return rest > 0 ? `${listed} and ${rest} more` : listed;
29
+ }
30
+ function toWatchEvents(change) {
31
+ if ('eventsQueue' in change && Array.isArray(change.eventsQueue)) {
32
+ return change.eventsQueue;
33
+ }
34
+ if (!('changes' in change) || !change.changes)
35
+ return [];
36
+ const { changes, rootDir } = change;
37
+ const events = [];
38
+ const collect = (files, type) => {
39
+ if (!files)
40
+ return;
41
+ for (const [relativePath] of files) {
42
+ events.push({ filePath: node_path_1.default.resolve(rootDir, relativePath), type });
43
+ }
44
+ };
45
+ collect(changes.addedFiles, 'add');
46
+ collect(changes.modifiedFiles, 'change');
47
+ collect(changes.removedFiles, 'delete');
48
+ return events;
49
+ }
50
+ class FontRebuildWatcher {
51
+ projectRoot;
52
+ logger;
53
+ svgWorkerPool;
54
+ setsByInputDir = new Map();
55
+ fontsByFamily = new Map();
56
+ dirty = new Map();
57
+ preparedSvgCache = new Map();
58
+ webDetected = false;
59
+ pending = Promise.resolve();
60
+ timer;
61
+ settleMs = exports.REBUILD_DEBOUNCE_MS;
62
+ constructor(projectRoot, iconSets, watcher, logger, svgWorkerPool = new index_1.SvgWorkerPool()) {
63
+ this.projectRoot = projectRoot;
64
+ this.logger = logger;
65
+ this.svgWorkerPool = svgWorkerPool;
66
+ for (const set of iconSets) {
67
+ this.setsByInputDir.set(node_path_1.default.resolve(projectRoot, set.inputDir), set);
68
+ }
69
+ watcher.on('change', (change) => this.onChange(toWatchEvents(change)));
70
+ this.svgWorkerPool.warm();
71
+ this.schedule(iconSets);
72
+ }
73
+ get build() {
74
+ return this.pending;
75
+ }
76
+ fontFor(family) {
77
+ return this.fontsByFamily.get(family);
78
+ }
79
+ onChange(events) {
80
+ for (const event of events) {
81
+ if (!event.filePath.toLowerCase().endsWith('.svg'))
82
+ continue;
83
+ const set = this.setsByInputDir.get(node_path_1.default.dirname(event.filePath));
84
+ if (!set)
85
+ continue;
86
+ if (event.type === 'add')
87
+ this.settleMs = exports.ADDED_FILES_SETTLE_MS;
88
+ this.schedule([set], `${node_path_1.default.basename(event.filePath)} ${exports.CHANGE_LABEL[event.type]}`);
89
+ }
90
+ }
91
+ schedule(sets, change) {
92
+ for (const set of sets) {
93
+ const changes = this.dirty.get(set) ?? [];
94
+ if (change)
95
+ changes.push(change);
96
+ this.dirty.set(set, changes);
97
+ }
98
+ if (this.timer)
99
+ clearTimeout(this.timer);
100
+ this.timer = setTimeout(() => this.flush(), this.settleMs);
101
+ }
102
+ flush() {
103
+ this.timer = undefined;
104
+ this.settleMs = exports.REBUILD_DEBOUNCE_MS;
105
+ this.pending = this.pending.then(() => this.rebuildDirty());
106
+ }
107
+ async rebuildDirty() {
108
+ const sets = [...this.dirty.keys()];
109
+ for (const [set, changes] of this.dirty) {
110
+ if (changes.length) {
111
+ this.logger.notify(`${setName(set)}: ${summarize(changes)}, rebuilding…`);
112
+ }
113
+ }
114
+ this.dirty.clear();
115
+ if (!sets.length)
116
+ return;
117
+ let built;
118
+ try {
119
+ built = await (0, index_1.buildAllFonts)(sets, this.projectRoot, {
120
+ logger: this.logger,
121
+ keepOutputsOnFailure: true,
122
+ preparedSvgCache: this.preparedSvgCache,
123
+ svgWorkerPool: this.svgWorkerPool,
124
+ withWeb: this.webDetected,
125
+ });
126
+ }
127
+ catch (err) {
128
+ if (!(err instanceof index_1.IconSetBuildError)) {
129
+ this.logger.fail(err instanceof Error ? err.message : String(err));
130
+ return;
131
+ }
132
+ built = err.built;
133
+ }
134
+ for (const font of built) {
135
+ for (const [family, previous] of this.fontsByFamily) {
136
+ if (previous.fontFamily === font.fontFamily) {
137
+ this.fontsByFamily.delete(family);
138
+ }
139
+ }
140
+ this.fontsByFamily.set(font.family, font);
141
+ }
142
+ }
143
+ middleware = (req, res, next) => {
144
+ const url = req.url ?? '';
145
+ if (!this.webDetected && WEB_PLATFORM.test(url)) {
146
+ this.webDetected = true;
147
+ this.schedule([...this.setsByInputDir.values()].filter((set) => set.web), 'web bundle requested');
148
+ }
149
+ const isFontRequest = url.startsWith(exports.FONT_ROUTE) &&
150
+ (req.method === 'GET' || req.method === 'HEAD');
151
+ if (!isFontRequest) {
152
+ next();
153
+ return;
154
+ }
155
+ const family = decodeURIComponent(url.slice(exports.FONT_ROUTE.length).replace(/\.ttf(\?.*)?$/, ''));
156
+ void this.pending.then(() => {
157
+ const font = this.fontsByFamily.get(family);
158
+ if (!font || !node_fs_1.default.existsSync(font.ttfPath)) {
159
+ res.statusCode = 404;
160
+ res.end();
161
+ return;
162
+ }
163
+ res.statusCode = 200;
164
+ res.setHeader('Content-Type', 'font/ttf');
165
+ res.setHeader('Cache-Control', 'no-store');
166
+ if (req.method === 'HEAD') {
167
+ res.end();
168
+ return;
169
+ }
170
+ node_fs_1.default.createReadStream(font.ttfPath).pipe(res);
171
+ });
172
+ };
173
+ }
174
+ exports.FontRebuildWatcher = FontRebuildWatcher;
@@ -0,0 +1,35 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type IconSetConfig, type SymbolSetConfig } from '../cli/index';
3
+ import { type FileWatcher, type Next } from './fontRebuildWatcher';
4
+ export type { IconSetConfig, SymbolSetConfig };
5
+ export type Middleware = (req: IncomingMessage, res: ServerResponse, next: Next) => void;
6
+ export type MetroServerLike = {
7
+ getBundler(): {
8
+ getBundler(): {
9
+ getWatcher(): FileWatcher;
10
+ };
11
+ };
12
+ };
13
+ export type MetroConfigLike = {
14
+ projectRoot?: string;
15
+ watchFolders?: readonly string[];
16
+ server?: {
17
+ enhanceMiddleware?: (middleware: Middleware, server: MetroServerLike) => Middleware;
18
+ };
19
+ };
20
+ export type WithNanoIconsOptions = {
21
+ iconSets?: IconSetConfig[];
22
+ symbolSets?: SymbolSetConfig[];
23
+ projectRoot?: string;
24
+ };
25
+ export type WithNanoIcons<T extends MetroConfigLike> = T & {
26
+ server: NonNullable<T['server']> & {
27
+ enhanceMiddleware: (middleware: Middleware, server: MetroServerLike) => Middleware;
28
+ };
29
+ };
30
+ export declare function resolveIconSets(projectRoot: string): IconSetConfig[];
31
+ export declare function resolveSymbolSets(projectRoot: string): SymbolSetConfig[];
32
+ export declare function unwatchedIconSets<T extends {
33
+ inputDir: string;
34
+ }>(iconSets: T[], projectRoot: string, watchFolders: readonly string[]): T[];
35
+ export declare function withNanoIcons<T extends MetroConfigLike>(config: T, options?: WithNanoIconsOptions): WithNanoIcons<T>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveIconSets = resolveIconSets;
7
+ exports.resolveSymbolSets = resolveSymbolSets;
8
+ exports.unwatchedIconSets = unwatchedIconSets;
9
+ exports.withNanoIcons = withNanoIcons;
10
+ const node_fs_1 = __importDefault(require("node:fs"));
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const index_1 = require("../cli/index");
13
+ const fontRebuildWatcher_1 = require("./fontRebuildWatcher");
14
+ const symbolRebuildWatcher_1 = require("./symbolRebuildWatcher");
15
+ function resolveIconSets(projectRoot) {
16
+ if (node_fs_1.default.existsSync(node_path_1.default.join(projectRoot, '.nanoicons.json'))) {
17
+ return (0, index_1.loadNanoIconsConfig)(projectRoot).iconSets ?? [];
18
+ }
19
+ return (0, index_1.loadIconSetsFromAppConfig)(projectRoot);
20
+ }
21
+ function resolveSymbolSets(projectRoot) {
22
+ if (node_fs_1.default.existsSync(node_path_1.default.join(projectRoot, '.nanoicons.json'))) {
23
+ return (0, index_1.loadNanoIconsConfig)(projectRoot).symbolSets ?? [];
24
+ }
25
+ return (0, index_1.loadSymbolSetsFromAppConfig)(projectRoot);
26
+ }
27
+ function bufferedLogger() {
28
+ const ready = (0, index_1.createQuietLogger)((0, index_1.detectExpoLogLevel)());
29
+ const verbose = (0, index_1.createQuietLogger)('verbose');
30
+ const call = (method) => (msg) => {
31
+ void ready.then((logger) => logger[method](msg));
32
+ };
33
+ return {
34
+ start: call('start'),
35
+ update: call('update'),
36
+ succeed: call('succeed'),
37
+ fail: call('fail'),
38
+ info: call('info'),
39
+ warn: call('warn'),
40
+ notify: (msg) => void verbose.then((logger) => logger.info(msg)),
41
+ };
42
+ }
43
+ function isInside(dir, root) {
44
+ const relative = node_path_1.default.relative(root, dir);
45
+ return !relative.startsWith('..') && !node_path_1.default.isAbsolute(relative);
46
+ }
47
+ function unwatchedIconSets(iconSets, projectRoot, watchFolders) {
48
+ const roots = [projectRoot, ...watchFolders];
49
+ return iconSets.filter((set) => {
50
+ const inputDir = node_path_1.default.resolve(projectRoot, set.inputDir);
51
+ return !roots.some((root) => isInside(inputDir, root));
52
+ });
53
+ }
54
+ function withNanoIcons(config, options) {
55
+ const projectRoot = options?.projectRoot ?? config.projectRoot ?? process.cwd();
56
+ const previous = config.server?.enhanceMiddleware;
57
+ const enhanceMiddleware = (middleware, server) => {
58
+ const enhanced = previous ? previous(middleware, server) : middleware;
59
+ if (process.env['NODE_ENV'] === 'production')
60
+ return enhanced;
61
+ const logger = bufferedLogger();
62
+ let iconSets;
63
+ let symbolSets;
64
+ try {
65
+ iconSets = options?.iconSets ?? resolveIconSets(projectRoot);
66
+ symbolSets =
67
+ options?.symbolSets ??
68
+ (options?.iconSets ? [] : resolveSymbolSets(projectRoot));
69
+ }
70
+ catch (err) {
71
+ logger.warn(`Icon hot reload is off: ${err instanceof Error ? err.message : String(err)}`);
72
+ return enhanced;
73
+ }
74
+ for (const set of unwatchedIconSets(iconSets, projectRoot, config.watchFolders ?? [])) {
75
+ logger.warn(`Icon set "${set.fontFamily ?? node_path_1.default.basename(set.inputDir)}": ${set.inputDir} is outside Metro's watch folders, so its svg changes will not trigger a rebuild. Add the folder to watchFolders in metro.config.js.`);
76
+ }
77
+ for (const set of unwatchedIconSets(symbolSets, projectRoot, config.watchFolders ?? [])) {
78
+ logger.warn(`Symbol set "${set.name ?? node_path_1.default.basename(set.inputDir)}": ${set.inputDir} is outside Metro's watch folders, so its svg changes will not trigger a rebuild. Add the folder to watchFolders in metro.config.js.`);
79
+ }
80
+ const watcher = server.getBundler().getBundler().getWatcher();
81
+ const svgWorkerPool = new index_1.SvgWorkerPool();
82
+ const fonts = new fontRebuildWatcher_1.FontRebuildWatcher(projectRoot, iconSets, watcher, logger, svgWorkerPool);
83
+ if (symbolSets.length) {
84
+ new symbolRebuildWatcher_1.SymbolRebuildWatcher(projectRoot, symbolSets, watcher, logger, svgWorkerPool);
85
+ }
86
+ return (req, res, next) => fonts.middleware(req, res, () => enhanced(req, res, next));
87
+ };
88
+ return {
89
+ ...config,
90
+ server: { ...config.server, enhanceMiddleware },
91
+ };
92
+ }
@@ -0,0 +1,19 @@
1
+ import { type SvgWorkerPool, type SymbolSetConfig } from '../cli/index';
2
+ import { type DevLogger, type FileWatcher } from './fontRebuildWatcher';
3
+ export declare class SymbolRebuildWatcher {
4
+ private readonly projectRoot;
5
+ private readonly symbolSets;
6
+ private readonly logger;
7
+ private readonly svgWorkerPool;
8
+ private readonly inputDirs;
9
+ private readonly preparedSvgCache;
10
+ private changes;
11
+ private pending;
12
+ private timer;
13
+ private settleMs;
14
+ constructor(projectRoot: string, symbolSets: SymbolSetConfig[], watcher: FileWatcher, logger: DevLogger, svgWorkerPool: SvgWorkerPool);
15
+ get build(): Promise<void>;
16
+ private onChange;
17
+ private flush;
18
+ private rebuild;
19
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SymbolRebuildWatcher = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const index_1 = require("../cli/index");
9
+ const fontRebuildWatcher_1 = require("./fontRebuildWatcher");
10
+ class SymbolRebuildWatcher {
11
+ projectRoot;
12
+ symbolSets;
13
+ logger;
14
+ svgWorkerPool;
15
+ inputDirs;
16
+ preparedSvgCache = new Map();
17
+ changes = [];
18
+ pending = Promise.resolve();
19
+ timer;
20
+ settleMs = fontRebuildWatcher_1.REBUILD_DEBOUNCE_MS;
21
+ constructor(projectRoot, symbolSets, watcher, logger, svgWorkerPool) {
22
+ this.projectRoot = projectRoot;
23
+ this.symbolSets = symbolSets;
24
+ this.logger = logger;
25
+ this.svgWorkerPool = svgWorkerPool;
26
+ this.inputDirs = new Set(symbolSets.map((set) => node_path_1.default.resolve(projectRoot, set.inputDir)));
27
+ watcher.on('change', (change) => this.onChange((0, fontRebuildWatcher_1.toWatchEvents)(change)));
28
+ }
29
+ get build() {
30
+ return this.pending;
31
+ }
32
+ onChange(events) {
33
+ for (const event of events) {
34
+ if (!event.filePath.toLowerCase().endsWith('.svg'))
35
+ continue;
36
+ if (!this.inputDirs.has(node_path_1.default.dirname(event.filePath)))
37
+ continue;
38
+ if (event.type === 'add')
39
+ this.settleMs = fontRebuildWatcher_1.ADDED_FILES_SETTLE_MS;
40
+ this.changes.push(`${node_path_1.default.basename(event.filePath)} ${fontRebuildWatcher_1.CHANGE_LABEL[event.type]}`);
41
+ if (this.timer)
42
+ clearTimeout(this.timer);
43
+ this.timer = setTimeout(() => this.flush(), this.settleMs);
44
+ }
45
+ }
46
+ flush() {
47
+ this.timer = undefined;
48
+ this.settleMs = fontRebuildWatcher_1.REBUILD_DEBOUNCE_MS;
49
+ const changes = this.changes.splice(0);
50
+ this.pending = this.pending.then(() => this.rebuild(changes));
51
+ }
52
+ async rebuild(changes) {
53
+ this.logger.notify(`Symbols: ${(0, fontRebuildWatcher_1.summarize)(changes)}, rebuilding…`);
54
+ try {
55
+ const built = await (0, index_1.buildAllSymbols)(this.symbolSets, this.projectRoot, {
56
+ logger: this.logger,
57
+ keepOutputsOnFailure: true,
58
+ preparedSvgCache: this.preparedSvgCache,
59
+ svgWorkerPool: this.svgWorkerPool,
60
+ });
61
+ await (0, index_1.linkBareSymbols)(this.projectRoot, built, this.logger);
62
+ await (0, index_1.linkBareAndroidDrawables)(this.projectRoot, built, this.logger);
63
+ this.logger.warn('Native symbols changed. Rebuild the native app to see them.');
64
+ }
65
+ catch (err) {
66
+ const message = err instanceof Error ? err.message : String(err);
67
+ if (err instanceof index_1.SymbolSetBuildError) {
68
+ this.logger.warn(`${message}. Native symbols were not relinked.`);
69
+ }
70
+ else {
71
+ this.logger.fail(message);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ exports.SymbolRebuildWatcher = SymbolRebuildWatcher;
@@ -0,0 +1,3 @@
1
+ import type { SymbolSetConfig, BuiltSymbolSet } from './types';
2
+ export declare function buildAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string): Promise<BuiltSymbolSet[]>;
3
+ export declare function getOrBuildSymbols(projectRoot: string, symbolSets: SymbolSetConfig[]): Promise<BuiltSymbolSet[]>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAllSymbols = buildAllSymbols;
4
+ exports.getOrBuildSymbols = getOrBuildSymbols;
5
+ const index_1 = require("../../cli/index");
6
+ // Build all symbol sets.
7
+ async function buildAllSymbols(symbolSets, projectRoot) {
8
+ const logger = await (0, index_1.createQuietLogger)((0, index_1.detectExpoLogLevel)());
9
+ return (0, index_1.buildAllSymbols)(symbolSets, projectRoot, { logger });
10
+ }
11
+ // Single build run per process; reused across mods.
12
+ let _buildPromise = null;
13
+ function getOrBuildSymbols(projectRoot, symbolSets) {
14
+ if (!_buildPromise) {
15
+ _buildPromise = buildAllSymbols(symbolSets, projectRoot);
16
+ }
17
+ return _buildPromise;
18
+ }
@@ -2,4 +2,4 @@ import type { ConfigPlugin } from '@expo/config-plugins';
2
2
  import type { NanoIconsPluginOptions } from './types';
3
3
  declare const withNanoIcons: ConfigPlugin<NanoIconsPluginOptions>;
4
4
  export default withNanoIcons;
5
- export type { NanoIconsPluginOptions, IconSetConfig, BuiltFont } from './types';
5
+ export type { NanoIconsPluginOptions, IconSetConfig, SymbolSetConfig, BuiltFont, BuiltSymbolSet, } from './types';
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const withNanoIconsFontLinking_1 = require("./withNanoIconsFontLinking");
4
+ const withNanoIconsSymbolLinking_1 = require("./withNanoIconsSymbolLinking");
5
+ const withNanoIconsDrawableLinking_1 = require("./withNanoIconsDrawableLinking");
4
6
  const withNanoIcons = (config, options) => {
5
- if (!options?.iconSets?.length)
6
- return config;
7
- config = (0, withNanoIconsFontLinking_1.withNanoIconsFontLinking)(config, options.iconSets);
7
+ if (options?.iconSets?.length) {
8
+ config = (0, withNanoIconsFontLinking_1.withNanoIconsFontLinking)(config, options.iconSets);
9
+ }
10
+ if (options?.symbolSets?.length) {
11
+ config = (0, withNanoIconsSymbolLinking_1.withNanoIconsSymbolLinking)(config, options.symbolSets);
12
+ config = (0, withNanoIconsDrawableLinking_1.withNanoIconsDrawableLinking)(config, options.symbolSets);
13
+ }
8
14
  return config;
9
15
  };
10
16
  exports.default = withNanoIcons;
@@ -31,10 +31,42 @@ export interface IconSetConfig {
31
31
  web?: boolean;
32
32
  }
33
33
  /**
34
- * plugins: [ [ "react-native-nano-icons", { iconSets: [...] } ] ]
34
+ * Config for one symbol set: input SVGs → `.symbolset`, linked into the iOS
35
+ * asset catalog for `UIImage(named:)`.
35
36
  */
37
+ export interface SymbolSetConfig {
38
+ /** Folder of SVG files (relative to project root). */
39
+ inputDir: string;
40
+ /** Set name; defaults to the inputDir basename. */
41
+ name?: string;
42
+ /** Symbol name prefix (default "nano"): home.svg → "nano.home". */
43
+ prefix?: string;
44
+ /** Output dir; defaults to a sibling nanoicons folder next to inputDir. */
45
+ outputDir?: string;
46
+ }
47
+ /** Result of building one symbol set. */
48
+ export interface BuiltSymbolSet {
49
+ name: string;
50
+ prefix: string;
51
+ /** Directory containing the generated asset folders. */
52
+ symbolsDir: string;
53
+ /** The generated `.symbolset` folders. */
54
+ assetDirs: string[];
55
+ /** Directory containing the generated Android VectorDrawable `.xml` files. */
56
+ drawablesDir: string;
57
+ /** The generated VectorDrawable `.xml` file paths. */
58
+ drawableFiles: string[];
59
+ /** The generated types-only `.d.ts` (icon-name + iOS-symbol-name unions). */
60
+ dtsPath: string;
61
+ symbolmapPath: string;
62
+ symbols: Record<string, string>;
63
+ /** Icon → Android drawable resource name (e.g. "home" → "nano_home"). */
64
+ drawables: Record<string, string>;
65
+ }
66
+ /** plugins: [ [ "react-native-nano-icons", { iconSets: [...], symbolSets: [...] } ] ] */
36
67
  export interface NanoIconsPluginOptions {
37
- iconSets: IconSetConfig[];
68
+ iconSets?: IconSetConfig[];
69
+ symbolSets?: SymbolSetConfig[];
38
70
  }
39
71
  /**
40
72
  * Result of building one icon set.
@@ -0,0 +1,8 @@
1
+ import { withDangerousMod } from '@expo/config-plugins';
2
+ import type { SymbolSetConfig } from './types';
3
+ /**
4
+ * Copy generated VectorDrawables into the Android app's res/drawable. AGP
5
+ * compiles them automatically and they resolve by name — the native-tab-bar
6
+ * counterpart to the iOS asset catalog, so no gradle changes are needed.
7
+ */
8
+ export declare function withNanoIconsDrawableLinking(config: Parameters<typeof withDangerousMod>[0], symbolSets: SymbolSetConfig[]): ReturnType<typeof withDangerousMod>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.withNanoIconsDrawableLinking = withNanoIconsDrawableLinking;
7
+ const config_plugins_1 = require("@expo/config-plugins");
8
+ const path_1 = __importDefault(require("path"));
9
+ const index_1 = require("../../cli/index");
10
+ const buildSymbols_1 = require("./buildSymbols");
11
+ const ANDROID_DRAWABLES_DIR = 'app/src/main/res/drawable';
12
+ /**
13
+ * Copy generated VectorDrawables into the Android app's res/drawable. AGP
14
+ * compiles them automatically and they resolve by name — the native-tab-bar
15
+ * counterpart to the iOS asset catalog, so no gradle changes are needed.
16
+ */
17
+ function withNanoIconsDrawableLinking(config, symbolSets) {
18
+ return (0, config_plugins_1.withDangerousMod)(config, [
19
+ 'android',
20
+ async (config) => {
21
+ const built = await (0, buildSymbols_1.getOrBuildSymbols)(config.modRequest.projectRoot, symbolSets);
22
+ if (!built?.length)
23
+ return config;
24
+ const drawableDir = path_1.default.join(config.modRequest.platformProjectRoot, ANDROID_DRAWABLES_DIR);
25
+ (0, index_1.copyDrawablesIntoResDir)(drawableDir, built);
26
+ return config;
27
+ },
28
+ ]);
29
+ }
@@ -0,0 +1,8 @@
1
+ import { withDangerousMod } from '@expo/config-plugins';
2
+ import type { SymbolSetConfig } from './types';
3
+ /**
4
+ * Write generated assets into the app's existing ios/<projectName>/Images.xcassets.
5
+ * The Expo prebuild template creates and links that catalog, so no pbxproj
6
+ * changes are needed — actool compiles them and they load by name.
7
+ */
8
+ export declare function withNanoIconsSymbolLinking(config: Parameters<typeof withDangerousMod>[0], symbolSets: SymbolSetConfig[]): ReturnType<typeof withDangerousMod>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.withNanoIconsSymbolLinking = withNanoIconsSymbolLinking;
7
+ const config_plugins_1 = require("@expo/config-plugins");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const index_1 = require("../../cli/index");
11
+ const buildSymbols_1 = require("./buildSymbols");
12
+ /**
13
+ * Write generated assets into the app's existing ios/<projectName>/Images.xcassets.
14
+ * The Expo prebuild template creates and links that catalog, so no pbxproj
15
+ * changes are needed — actool compiles them and they load by name.
16
+ */
17
+ function withNanoIconsSymbolLinking(config, symbolSets) {
18
+ return (0, config_plugins_1.withDangerousMod)(config, [
19
+ 'ios',
20
+ async (config) => {
21
+ const built = await (0, buildSymbols_1.getOrBuildSymbols)(config.modRequest.projectRoot, symbolSets);
22
+ if (!built?.length)
23
+ return config;
24
+ const projectName = config.modRequest.projectName;
25
+ if (!projectName)
26
+ return config;
27
+ const imagesCatalog = path_1.default.join(config.modRequest.platformProjectRoot, projectName, 'Images.xcassets');
28
+ if (!fs_1.default.existsSync(imagesCatalog)) {
29
+ console.warn(`[react-native-nano-icons] ${projectName}/Images.xcassets not found — skipping symbol linking. ` +
30
+ `Run "expo prebuild" first so the catalog exists.`);
31
+ return config;
32
+ }
33
+ (0, index_1.copySymbolsetsIntoCatalog)(imagesCatalog, built);
34
+ return config;
35
+ },
36
+ ]);
37
+ }
@@ -36,18 +36,36 @@ async function main(logger) {
36
36
  }
37
37
  else {
38
38
  const config = (0, index_1.loadNanoIconsConfig)(configRoot);
39
- let built;
40
39
  let buildError;
41
- try {
42
- built = await (0, index_1.buildAllFonts)(config.iconSets, appRoot, { logger });
40
+ if (config.iconSets?.length) {
41
+ let built;
42
+ try {
43
+ built = await (0, index_1.buildAllFonts)(config.iconSets, appRoot, { logger });
44
+ }
45
+ catch (err) {
46
+ if (!(err instanceof index_1.IconSetBuildError))
47
+ throw err;
48
+ buildError = err;
49
+ built = err.built;
50
+ }
51
+ await (0, index_1.linkBare)(appRoot, built, logger, config.iconSets.length);
43
52
  }
44
- catch (err) {
45
- if (!(err instanceof index_1.IconSetBuildError))
46
- throw err;
47
- buildError = err;
48
- built = err.built;
53
+ if (config.symbolSets?.length) {
54
+ let builtSymbols;
55
+ try {
56
+ builtSymbols = await (0, index_1.buildAllSymbols)(config.symbolSets, appRoot, {
57
+ logger,
58
+ });
59
+ }
60
+ catch (err) {
61
+ if (!(err instanceof index_1.SymbolSetBuildError))
62
+ throw err;
63
+ buildError ??= err;
64
+ builtSymbols = err.built;
65
+ }
66
+ await (0, index_1.linkBareSymbols)(appRoot, builtSymbols, logger);
67
+ await (0, index_1.linkBareAndroidDrawables)(appRoot, builtSymbols, logger);
49
68
  }
50
- await (0, index_1.linkBare)(appRoot, built, logger, config.iconSets.length);
51
69
  if (buildError)
52
70
  throw buildError;
53
71
  }
@@ -9,12 +9,11 @@ exports.compileWoff2FromTtf = compileWoff2FromTtf;
9
9
  const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const node_path_1 = __importDefault(require("node:path"));
11
11
  const metrics_1 = require("./metrics");
12
+ const config_1 = require("../pipeline/config");
12
13
  const svg2ttf_1 = __importDefault(require("svg2ttf"));
13
14
  const fonteditor_core_1 = require("fonteditor-core");
14
15
  const svgPatterns_1 = require("../../utils/svgPatterns");
15
16
  const dom_1 = require("../flatten/dom");
16
- const quadratic_1 = require("./quadratic");
17
- const QUADRATIC_ERROR_BOUND_EM = 1 / 512;
18
17
  function escapeXml(s) {
19
18
  return s.replace(svgPatterns_1.XML_AMP, '&amp;').replace(svgPatterns_1.XML_QUOT, '&quot;');
20
19
  }
@@ -26,8 +25,7 @@ function buildSvgFontXml(opts) {
26
25
  const glyphLines = glyphs.map((g) => {
27
26
  const hex = g.codepoint.toString(16);
28
27
  const name = `u${hex.padStart(4, '0')}`;
29
- const d = (0, quadratic_1.toQuadraticPath)(g.d, upm * QUADRATIC_ERROR_BOUND_EM);
30
- return `<glyph glyph-name="${name}" unicode="&#x${hex};" horiz-adv-x="${g.advanceWidth}" d="${escapeXml(d)}"/>`;
28
+ return `<glyph glyph-name="${name}" unicode="&#x${hex};" horiz-adv-x="${g.advanceWidth}" d="${escapeXml(g.d)}"/>`;
31
29
  });
32
30
  return `<?xml version="1.0" standalone="no"?>
33
31
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
@@ -74,7 +72,7 @@ async function compileTtfFromGlyphs(opts) {
74
72
  const rawBuf = Buffer.from(ttfRaw.buffer);
75
73
  const fixedBuf = (0, metrics_1.forceTtfMetrics)(rawBuf, upm, ascent, descent, lineGap);
76
74
  node_fs_1.default.mkdirSync(node_path_1.default.dirname(outTtfPath), { recursive: true });
77
- node_fs_1.default.writeFileSync(outTtfPath, fixedBuf);
75
+ (0, config_1.writeFileAtomic)(outTtfPath, fixedBuf);
78
76
  return fixedBuf;
79
77
  }
80
78
  let woff2Ready;