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,26 @@
1
+ import { type SymbolsPipelineResult } from '../src/core/pipeline/runSymbolPipeline';
2
+ import type { SvgWorkerPool } from '../src/core/pipeline/iconPool';
3
+ import type { SymbolTask } from '../src/core/pipeline/prepareSymbol';
4
+ import type { PreparedSvgCache } from '../src/core/pipeline/preparedSvgCache';
5
+ import type { NanoLogger } from './logger';
6
+ export type SymbolSetConfig = {
7
+ /** Folder of SVG files (relative to project root). */
8
+ inputDir: string;
9
+ /** Set name; defaults to the inputDir basename. */
10
+ name?: string;
11
+ /** Symbol name prefix (default "nano"): home.svg → "nano.home". */
12
+ prefix?: string;
13
+ /** Output dir; defaults to a sibling nanoicons folder next to inputDir. */
14
+ outputDir?: string;
15
+ };
16
+ export type BuiltSymbolSet = SymbolsPipelineResult;
17
+ export declare class SymbolSetBuildError extends Error {
18
+ built: BuiltSymbolSet[];
19
+ constructor(message: string, built: BuiltSymbolSet[]);
20
+ }
21
+ export declare function buildAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
22
+ logger?: NanoLogger;
23
+ keepOutputsOnFailure?: boolean;
24
+ preparedSvgCache?: PreparedSvgCache<SymbolTask>;
25
+ svgWorkerPool?: SvgWorkerPool;
26
+ }): Promise<BuiltSymbolSet[]>;
@@ -0,0 +1,134 @@
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.SymbolSetBuildError = void 0;
7
+ exports.buildAllSymbols = buildAllSymbols;
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const runSymbolPipeline_1 = require("../src/core/pipeline/runSymbolPipeline");
11
+ const fingerPrint_1 = require("../src/utils/fingerPrint");
12
+ const naming_1 = require("../src/utils/naming");
13
+ const packageVersion_1 = require("../src/utils/packageVersion");
14
+ class SymbolSetBuildError extends Error {
15
+ built;
16
+ constructor(message, built) {
17
+ super(message);
18
+ this.built = built;
19
+ }
20
+ }
21
+ exports.SymbolSetBuildError = SymbolSetBuildError;
22
+ const DEFAULT_PREFIX = 'nano';
23
+ function shouldSkipGeneration(inputHash, outputDir, name, logger) {
24
+ const symbolmapPath = path_1.default.join(outputDir, `${name}.symbolmap.json`);
25
+ const dtsPath = path_1.default.join(outputDir, `${name}.symbols.d.ts`);
26
+ const symbolsDir = path_1.default.join(outputDir, `${name}.symbols`);
27
+ const drawablesDir = path_1.default.join(outputDir, `${name}.drawables`);
28
+ if (!fs_1.default.existsSync(symbolmapPath) ||
29
+ !fs_1.default.existsSync(dtsPath) ||
30
+ !fs_1.default.existsSync(symbolsDir) ||
31
+ !fs_1.default.existsSync(drawablesDir)) {
32
+ return null;
33
+ }
34
+ let symbolmap;
35
+ try {
36
+ symbolmap = JSON.parse(fs_1.default.readFileSync(symbolmapPath, 'utf8'));
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ if (!symbolmap?.m?.h || symbolmap.m.h !== inputHash)
42
+ return null;
43
+ const symbols = symbolmap.s ?? {};
44
+ const drawables = symbolmap.d ?? {};
45
+ const assetDirs = Object.values(symbols).map((assetName) => path_1.default.join(symbolsDir, `${assetName}.symbolset`));
46
+ const drawableFiles = Object.values(drawables).flatMap((resourceName) => [
47
+ path_1.default.join(drawablesDir, `${resourceName}.xml`),
48
+ path_1.default.join(drawablesDir, `${(0, naming_1.toOriginalDrawableResourceName)(resourceName)}.xml`),
49
+ ]);
50
+ if (!assetDirs.every((d) => fs_1.default.existsSync(d)))
51
+ return null;
52
+ if (!drawableFiles.every((f) => fs_1.default.existsSync(f)))
53
+ return null;
54
+ logger?.info(`${name}: SVG fingerprint unchanged, skipping build.`);
55
+ return {
56
+ name,
57
+ prefix: symbolmap.m.p,
58
+ symbolsDir,
59
+ assetDirs,
60
+ drawablesDir,
61
+ drawableFiles,
62
+ dtsPath,
63
+ symbolmapPath,
64
+ symbols,
65
+ drawables,
66
+ };
67
+ }
68
+ // Build all symbol sets. Output goes in a "nanoicons" folder next to each
69
+ // inputDir, matching the font pipeline's convention.
70
+ async function buildAllSymbols(symbolSets, projectRoot, options) {
71
+ const logger = options?.logger;
72
+ const version = (0, packageVersion_1.packageVersion)();
73
+ const toolchain = (0, packageVersion_1.fontToolchainVersions)();
74
+ const results = [];
75
+ const failures = [];
76
+ for (let i = 0; i < symbolSets.length; i++) {
77
+ const set = symbolSets[i];
78
+ const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
79
+ const name = set.name ?? path_1.default.basename(inputDir);
80
+ const prefix = set.prefix ?? DEFAULT_PREFIX;
81
+ if (!fs_1.default.existsSync(inputDir)) {
82
+ throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
83
+ }
84
+ const outputDir = set.outputDir
85
+ ? path_1.default.resolve(projectRoot, set.outputDir)
86
+ : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
87
+ if ('multicolor' in set) {
88
+ logger?.warn(`${name}: "multicolor" is no longer needed — every symbol now carries both rendering modes; remove it from the config.`);
89
+ }
90
+ const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSymbolDirSync)(inputDir, {
91
+ prefix,
92
+ version,
93
+ toolchain,
94
+ });
95
+ const skipped = shouldSkipGeneration(inputHash, outputDir, name, logger);
96
+ if (skipped) {
97
+ results.push(skipped);
98
+ continue;
99
+ }
100
+ logger?.start(`Building ${name} (${i + 1}/${symbolSets.length})…`);
101
+ let out;
102
+ try {
103
+ out = await (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix }, { inputDir, outputDir }, {
104
+ logger,
105
+ inputHash,
106
+ preparedSvgCache: options?.preparedSvgCache,
107
+ svgWorkerPool: options?.svgWorkerPool,
108
+ svgHashByFile,
109
+ });
110
+ }
111
+ catch (err) {
112
+ if (!options?.keepOutputsOnFailure)
113
+ removeOutputs(outputDir, name);
114
+ logger?.fail(err instanceof Error ? err.message : String(err));
115
+ failures.push(name);
116
+ continue;
117
+ }
118
+ results.push(out);
119
+ }
120
+ if (failures.length) {
121
+ throw new SymbolSetBuildError(`${failures.length} symbol set${failures.length === 1 ? '' : 's'} failed to build: ${failures.join(', ')}`, results);
122
+ }
123
+ return results;
124
+ }
125
+ function removeOutputs(outputDir, name) {
126
+ for (const output of [
127
+ `${name}.symbolmap.json`,
128
+ `${name}.symbols.d.ts`,
129
+ `${name}.symbols`,
130
+ `${name}.drawables`,
131
+ ]) {
132
+ fs_1.default.rmSync(path_1.default.join(outputDir, output), { recursive: true, force: true });
133
+ }
134
+ }
@@ -1,6 +1,8 @@
1
1
  import type { IconSetConfig } from './build';
2
+ import type { SymbolSetConfig } from './buildSymbols';
2
3
  export type NanoIconsConfig = {
3
- iconSets: IconSetConfig[];
4
+ iconSets?: IconSetConfig[];
5
+ symbolSets?: SymbolSetConfig[];
4
6
  };
5
7
  /**
6
8
  * Load .nanoicons.json from the given directory.
@@ -20,14 +20,14 @@ function loadNanoIconsConfig(configRoot) {
20
20
  }
21
21
  const raw = node_fs_1.default.readFileSync(configPath, 'utf8');
22
22
  const config = JSON.parse(raw);
23
- if (!config?.iconSets?.length) {
24
- throw new Error(`🔬❌ [react-native-nano-icons] .nanoicons.json must contain an "iconSets" array with at least one entry.`);
23
+ if (!config?.iconSets?.length && !config?.symbolSets?.length) {
24
+ throw new Error(`🔬❌ [react-native-nano-icons] .nanoicons.json must contain an "iconSets" or "symbolSets" array with at least one entry.`);
25
25
  }
26
26
  return config;
27
27
  }
28
28
  function loadDynamicIconSets(configRoot) {
29
29
  const config = loadNanoIconsConfig(configRoot);
30
- const dynamicSets = config.iconSets.filter((s) => s.linking === 'dynamic');
30
+ const dynamicSets = (config.iconSets ?? []).filter((s) => s.linking === 'dynamic');
31
31
  if (dynamicSets.length === 0) {
32
32
  throw new Error(`[react-native-nano-icons] No icon sets with linking: "dynamic" found in .nanoicons.json.\n` +
33
33
  `--dynamic only processes icon sets where linking is set to "dynamic".`);
@@ -1,4 +1,5 @@
1
1
  import type { IconSetConfig } from './build';
2
+ import type { SymbolSetConfig } from './buildSymbols';
2
3
  /**
3
4
  * Load icon sets configured with linking: 'dynamic' from the Expo app config
4
5
  * (app.json, app.config.js, or app.config.ts).
@@ -7,3 +8,5 @@ import type { IconSetConfig } from './build';
7
8
  * falling back to @expo/config.
8
9
  */
9
10
  export declare function loadDynamicSetsFromAppConfig(projectRoot: string): IconSetConfig[];
11
+ export declare function loadIconSetsFromAppConfig(projectRoot: string): IconSetConfig[];
12
+ export declare function loadSymbolSetsFromAppConfig(projectRoot: string): SymbolSetConfig[];
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadDynamicSetsFromAppConfig = loadDynamicSetsFromAppConfig;
4
+ exports.loadIconSetsFromAppConfig = loadIconSetsFromAppConfig;
5
+ exports.loadSymbolSetsFromAppConfig = loadSymbolSetsFromAppConfig;
4
6
  /**
5
7
  * Load icon sets configured with linking: 'dynamic' from the Expo app config
6
8
  * (app.json, app.config.js, or app.config.ts).
@@ -9,6 +11,20 @@ exports.loadDynamicSetsFromAppConfig = loadDynamicSetsFromAppConfig;
9
11
  * falling back to @expo/config.
10
12
  */
11
13
  function loadDynamicSetsFromAppConfig(projectRoot) {
14
+ const dynamicSets = loadIconSetsFromAppConfig(projectRoot).filter((s) => s.linking === 'dynamic');
15
+ if (dynamicSets.length === 0) {
16
+ throw new Error(`[react-native-nano-icons] No icon sets with linking: "dynamic" found.\n` +
17
+ `--dynamic --app-config only processes icon sets where linking is set to "dynamic".`);
18
+ }
19
+ return dynamicSets;
20
+ }
21
+ function loadIconSetsFromAppConfig(projectRoot) {
22
+ return loadPluginOptions(projectRoot).iconSets ?? [];
23
+ }
24
+ function loadSymbolSetsFromAppConfig(projectRoot) {
25
+ return loadPluginOptions(projectRoot).symbolSets ?? [];
26
+ }
27
+ function loadPluginOptions(projectRoot) {
12
28
  const configModule = resolveExpoConfigModule(projectRoot);
13
29
  if (!configModule) {
14
30
  throw new Error(`[react-native-nano-icons] Could not find expo/config or @expo/config from ${projectRoot} — required for --dynamic --app-config.\n` +
@@ -23,12 +39,7 @@ function loadDynamicSetsFromAppConfig(projectRoot) {
23
39
  `Add it to your app.json or app.config.js/ts under the "plugins" key.`);
24
40
  }
25
41
  const [, options] = entry;
26
- const dynamicSets = (options.iconSets ?? []).filter((s) => s.linking === 'dynamic');
27
- if (dynamicSets.length === 0) {
28
- throw new Error(`[react-native-nano-icons] No icon sets with linking: "dynamic" found.\n` +
29
- `--dynamic --app-config only processes icon sets where linking is set to "dynamic".`);
30
- }
31
- return dynamicSets;
42
+ return options;
32
43
  }
33
44
  function resolveExpoConfigModule(projectRoot) {
34
45
  const candidates = [
@@ -1,5 +1,7 @@
1
1
  export { buildAllFonts, IconSetBuildError, type IconSetConfig, type BuiltFont, } from './build';
2
+ export { buildAllSymbols, SymbolSetBuildError, type SymbolSetConfig, type BuiltSymbolSet, } from './buildSymbols';
3
+ export { SvgWorkerPool, type PreparedSvgCache, } from '../src/core/pipeline/index';
2
4
  export { createOraLogger, createQuietLogger, detectExpoLogLevel, type NanoLogger, type LogLevel, } from './logger';
3
5
  export { loadNanoIconsConfig, loadDynamicIconSets, type NanoIconsConfig, } from './config';
4
- export { loadDynamicSetsFromAppConfig } from './expoConfig';
5
- export { linkBare, syncAndroidFontAssets } from './link';
6
+ export { loadDynamicSetsFromAppConfig, loadIconSetsFromAppConfig, loadSymbolSetsFromAppConfig, } from './expoConfig';
7
+ export { linkBare, syncAndroidFontAssets, linkBareSymbols, copySymbolsetsIntoCatalog, linkBareAndroidDrawables, copyDrawablesIntoResDir, } from './link';
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syncAndroidFontAssets = exports.linkBare = exports.loadDynamicSetsFromAppConfig = exports.loadDynamicIconSets = exports.loadNanoIconsConfig = exports.detectExpoLogLevel = exports.createQuietLogger = exports.createOraLogger = exports.IconSetBuildError = exports.buildAllFonts = void 0;
3
+ exports.copyDrawablesIntoResDir = exports.linkBareAndroidDrawables = exports.copySymbolsetsIntoCatalog = exports.linkBareSymbols = exports.syncAndroidFontAssets = exports.linkBare = exports.loadSymbolSetsFromAppConfig = exports.loadIconSetsFromAppConfig = exports.loadDynamicSetsFromAppConfig = exports.loadDynamicIconSets = exports.loadNanoIconsConfig = exports.detectExpoLogLevel = exports.createQuietLogger = exports.createOraLogger = exports.SvgWorkerPool = exports.SymbolSetBuildError = exports.buildAllSymbols = exports.IconSetBuildError = exports.buildAllFonts = void 0;
4
4
  var build_1 = require("./build");
5
5
  Object.defineProperty(exports, "buildAllFonts", { enumerable: true, get: function () { return build_1.buildAllFonts; } });
6
6
  Object.defineProperty(exports, "IconSetBuildError", { enumerable: true, get: function () { return build_1.IconSetBuildError; } });
7
+ var buildSymbols_1 = require("./buildSymbols");
8
+ Object.defineProperty(exports, "buildAllSymbols", { enumerable: true, get: function () { return buildSymbols_1.buildAllSymbols; } });
9
+ Object.defineProperty(exports, "SymbolSetBuildError", { enumerable: true, get: function () { return buildSymbols_1.SymbolSetBuildError; } });
10
+ var index_1 = require("../src/core/pipeline/index");
11
+ Object.defineProperty(exports, "SvgWorkerPool", { enumerable: true, get: function () { return index_1.SvgWorkerPool; } });
7
12
  var logger_1 = require("./logger");
8
13
  Object.defineProperty(exports, "createOraLogger", { enumerable: true, get: function () { return logger_1.createOraLogger; } });
9
14
  Object.defineProperty(exports, "createQuietLogger", { enumerable: true, get: function () { return logger_1.createQuietLogger; } });
@@ -13,6 +18,12 @@ Object.defineProperty(exports, "loadNanoIconsConfig", { enumerable: true, get: f
13
18
  Object.defineProperty(exports, "loadDynamicIconSets", { enumerable: true, get: function () { return config_1.loadDynamicIconSets; } });
14
19
  var expoConfig_1 = require("./expoConfig");
15
20
  Object.defineProperty(exports, "loadDynamicSetsFromAppConfig", { enumerable: true, get: function () { return expoConfig_1.loadDynamicSetsFromAppConfig; } });
21
+ Object.defineProperty(exports, "loadIconSetsFromAppConfig", { enumerable: true, get: function () { return expoConfig_1.loadIconSetsFromAppConfig; } });
22
+ Object.defineProperty(exports, "loadSymbolSetsFromAppConfig", { enumerable: true, get: function () { return expoConfig_1.loadSymbolSetsFromAppConfig; } });
16
23
  var link_1 = require("./link");
17
24
  Object.defineProperty(exports, "linkBare", { enumerable: true, get: function () { return link_1.linkBare; } });
18
25
  Object.defineProperty(exports, "syncAndroidFontAssets", { enumerable: true, get: function () { return link_1.syncAndroidFontAssets; } });
26
+ Object.defineProperty(exports, "linkBareSymbols", { enumerable: true, get: function () { return link_1.linkBareSymbols; } });
27
+ Object.defineProperty(exports, "copySymbolsetsIntoCatalog", { enumerable: true, get: function () { return link_1.copySymbolsetsIntoCatalog; } });
28
+ Object.defineProperty(exports, "linkBareAndroidDrawables", { enumerable: true, get: function () { return link_1.linkBareAndroidDrawables; } });
29
+ Object.defineProperty(exports, "copyDrawablesIntoResDir", { enumerable: true, get: function () { return link_1.copyDrawablesIntoResDir; } });
@@ -1,6 +1,21 @@
1
1
  import type { NanoLogger } from './logger';
2
2
  import type { BuiltFont } from './build';
3
+ import type { BuiltSymbolSet } from './buildSymbols';
3
4
  export declare function syncAndroidFontAssets(fontsDir: string, staticFonts: BuiltFont[], configuredFamilies: string[]): void;
5
+ export declare function copySymbolsetsIntoCatalog(catalogDir: string, builtSymbolSets: BuiltSymbolSet[]): void;
6
+ /**
7
+ * Link custom SF Symbols into the iOS app. Primary path writes into the app's
8
+ * existing Images.xcassets (no pbxproj changes). Fallback (no Images.xcassets)
9
+ * creates NanoIconsSymbols.xcassets and registers it on the first target.
10
+ */
11
+ export declare function linkBareSymbols(projectRoot: string, builtSymbolSets: BuiltSymbolSet[], logger: NanoLogger): Promise<void>;
12
+ export declare function copyDrawablesIntoResDir(drawableDir: string, builtSymbolSets: BuiltSymbolSet[]): void;
13
+ /**
14
+ * Link generated VectorDrawables into the Android app's res/drawable. They are
15
+ * compiled automatically by AGP and resolve by name via getIdentifier — the
16
+ * native-tab-bar counterpart to the iOS asset catalog. No gradle changes needed.
17
+ */
18
+ export declare function linkBareAndroidDrawables(projectRoot: string, builtSymbolSets: BuiltSymbolSet[], logger: NanoLogger): Promise<void>;
4
19
  /**
5
20
  * Link built TTFs into native project directories.
6
21
  *
@@ -37,12 +37,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.syncAndroidFontAssets = syncAndroidFontAssets;
40
+ exports.copySymbolsetsIntoCatalog = copySymbolsetsIntoCatalog;
41
+ exports.linkBareSymbols = linkBareSymbols;
42
+ exports.copyDrawablesIntoResDir = copyDrawablesIntoResDir;
43
+ exports.linkBareAndroidDrawables = linkBareAndroidDrawables;
40
44
  exports.linkBare = linkBare;
41
45
  const node_fs_1 = __importDefault(require("node:fs"));
42
46
  const node_path_1 = __importDefault(require("node:path"));
43
47
  const plist = __importStar(require("plist"));
48
+ const contents_1 = require("../src/core/symbols/contents");
49
+ const naming_1 = require("../src/utils/naming");
44
50
  const fontIdentity_1 = require("../src/utils/fontIdentity");
45
51
  const ANDROID_FONTS_DIR = 'android/app/src/main/assets/fonts';
52
+ const ANDROID_DRAWABLES_DIR = 'android/app/src/main/res/drawable';
46
53
  const IOS_NANOICONS_FONTS_DIR = 'nanoicons-fonts';
47
54
  const IOS_RUN_SCRIPT_PHASE_NAME = 'Copy nanoicons fonts';
48
55
  const IOS_APPLICATION_PRODUCT_TYPE = 'com.apple.product-type.application';
@@ -130,7 +137,7 @@ async function linkIos(projectRoot, staticFonts, dynamicFonts, logger) {
130
137
  }
131
138
  const xcode = require('xcode');
132
139
  const project = xcode.project(pbxprojPath).parseSync();
133
- const appName = xcodeprojDir.name.replace(/\.xcodeproj$/, '');
140
+ const appName = xcodeprojDir.name.replace(XCODEPROJ_RE, '');
134
141
  const { uuid: targetUuid, target } = getAppTarget(project);
135
142
  const infoPlistPaths = resolveInfoPlistPaths(project, target, iosDir, node_path_1.default.join(iosDir, appName, 'Info.plist'));
136
143
  if (!infoPlistPaths.length) {
@@ -175,6 +182,183 @@ async function linkIos(projectRoot, staticFonts, dynamicFonts, logger) {
175
182
  }
176
183
  return true;
177
184
  }
185
+ // ---------------------------------------------------------------------------
186
+ // Custom SF Symbol linking (iOS)
187
+ // ---------------------------------------------------------------------------
188
+ const IOS_SYMBOLS_CATALOG = 'NanoIconsSymbols.xcassets';
189
+ function findIosApp(projectRoot) {
190
+ const iosDir = node_path_1.default.join(projectRoot, 'ios');
191
+ if (!node_fs_1.default.existsSync(iosDir))
192
+ return null;
193
+ const xcodeprojDir = node_fs_1.default
194
+ .readdirSync(iosDir, { withFileTypes: true })
195
+ .find((d) => d.name.endsWith('.xcodeproj'));
196
+ if (!xcodeprojDir)
197
+ return null;
198
+ return {
199
+ iosDir,
200
+ xcodeprojName: xcodeprojDir.name,
201
+ appName: xcodeprojDir.name.replace(XCODEPROJ_RE, ''),
202
+ };
203
+ }
204
+ // File/folder name matchers (filesystem, CLI-specific).
205
+ const XCODEPROJ_RE = /\.xcodeproj$/;
206
+ const NANO_ASSET_RE = /\.(symbolset|imageset)$/;
207
+ const XML_FILE_RE = /\.xml$/;
208
+ // Ledgers of what we last linked, kept in the build output dir. Read before a
209
+ // re-link so a renamed prefix or a dropped set is cleaned too — the current-prefix
210
+ // scan below only sees names still in the config.
211
+ const SYMBOL_LEDGER = '.nanoicons-catalog.json';
212
+ const DRAWABLE_LEDGER = '.nanoicons-drawables.json';
213
+ function readLedger(ledgerPath) {
214
+ try {
215
+ const names = JSON.parse(node_fs_1.default.readFileSync(ledgerPath, 'utf8'));
216
+ return Array.isArray(names) ? names : [];
217
+ }
218
+ catch {
219
+ return [];
220
+ }
221
+ }
222
+ // Copy generated asset folders into a catalog, first removing everything we
223
+ // linked last time (ledger) plus any current-prefix match (ledger-less fallback).
224
+ // Handles removed icons, mode switches, prefix renames and dropped sets.
225
+ function copySymbolsetsIntoCatalog(catalogDir, builtSymbolSets) {
226
+ const outputDir = builtSymbolSets[0]
227
+ ? node_path_1.default.dirname(builtSymbolSets[0].symbolsDir)
228
+ : null;
229
+ const ledgerPath = outputDir ? node_path_1.default.join(outputDir, SYMBOL_LEDGER) : null;
230
+ const stale = new Set(ledgerPath ? readLedger(ledgerPath) : []);
231
+ const prefixes = new Set(builtSymbolSets.map((s) => s.prefix));
232
+ for (const entry of node_fs_1.default.readdirSync(catalogDir, { withFileTypes: true })) {
233
+ if (!entry.isDirectory() || !NANO_ASSET_RE.test(entry.name))
234
+ continue;
235
+ const assetName = entry.name.replace(NANO_ASSET_RE, '');
236
+ for (const prefix of prefixes) {
237
+ if (assetName.startsWith(`${prefix}.`)) {
238
+ stale.add(entry.name);
239
+ break;
240
+ }
241
+ }
242
+ }
243
+ for (const name of stale) {
244
+ node_fs_1.default.rmSync(node_path_1.default.join(catalogDir, name), { recursive: true, force: true });
245
+ }
246
+ const linked = [];
247
+ for (const set of builtSymbolSets) {
248
+ for (const assetDir of set.assetDirs) {
249
+ const base = node_path_1.default.basename(assetDir);
250
+ node_fs_1.default.cpSync(assetDir, node_path_1.default.join(catalogDir, base), { recursive: true });
251
+ linked.push(base);
252
+ }
253
+ }
254
+ if (ledgerPath)
255
+ node_fs_1.default.writeFileSync(ledgerPath, JSON.stringify(linked));
256
+ }
257
+ /**
258
+ * Link custom SF Symbols into the iOS app. Primary path writes into the app's
259
+ * existing Images.xcassets (no pbxproj changes). Fallback (no Images.xcassets)
260
+ * creates NanoIconsSymbols.xcassets and registers it on the first target.
261
+ */
262
+ async function linkBareSymbols(projectRoot, builtSymbolSets, logger) {
263
+ if (!builtSymbolSets.length)
264
+ return;
265
+ const app = findIosApp(projectRoot);
266
+ if (!app) {
267
+ const outputDirs = [
268
+ ...new Set(builtSymbolSets.map((s) => node_path_1.default.dirname(s.symbolsDir))),
269
+ ];
270
+ const rel = node_path_1.default.relative(projectRoot, outputDirs[0] ?? '');
271
+ logger.info(`No ios/ project found — symbols saved to ${rel}/ (skipping link)`);
272
+ return;
273
+ }
274
+ const imagesCatalog = node_path_1.default.join(app.iosDir, app.appName, 'Images.xcassets');
275
+ if (node_fs_1.default.existsSync(imagesCatalog)) {
276
+ copySymbolsetsIntoCatalog(imagesCatalog, builtSymbolSets);
277
+ logger.succeed(`Linked symbols → ios/${app.appName}/Images.xcassets`);
278
+ return;
279
+ }
280
+ // Fallback: dedicated catalog + pbxproj resource entry
281
+ const catalogDir = node_path_1.default.join(app.iosDir, IOS_SYMBOLS_CATALOG);
282
+ node_fs_1.default.mkdirSync(catalogDir, { recursive: true });
283
+ node_fs_1.default.writeFileSync(node_path_1.default.join(catalogDir, 'Contents.json'), (0, contents_1.catalogRootContentsJson)(), 'utf8');
284
+ copySymbolsetsIntoCatalog(catalogDir, builtSymbolSets);
285
+ const pbxprojPath = node_path_1.default.join(app.iosDir, app.xcodeprojName, 'project.pbxproj');
286
+ const xcode = require('xcode');
287
+ const project = xcode.project(pbxprojPath);
288
+ project.parseSync();
289
+ if (!project.hasFile(IOS_SYMBOLS_CATALOG)) {
290
+ try {
291
+ project.addResourceFile(IOS_SYMBOLS_CATALOG, {
292
+ target: project.getFirstTarget().uuid,
293
+ lastKnownFileType: 'folder.assetcatalog',
294
+ sourceTree: '"<group>"',
295
+ }, undefined);
296
+ node_fs_1.default.writeFileSync(pbxprojPath, project.writeSync(), 'utf8');
297
+ }
298
+ catch (err) {
299
+ const message = err instanceof Error ? err.message : String(err);
300
+ logger.warn(`Could not register ${IOS_SYMBOLS_CATALOG} in the Xcode project (${message}). ` +
301
+ `Add ios/${IOS_SYMBOLS_CATALOG} to your app target's resources in Xcode once.`);
302
+ return;
303
+ }
304
+ }
305
+ logger.succeed(`Linked symbols → ios/${IOS_SYMBOLS_CATALOG}`);
306
+ }
307
+ // ---------------------------------------------------------------------------
308
+ // Android VectorDrawable linking
309
+ // ---------------------------------------------------------------------------
310
+ // Copy generated VectorDrawable XML into a res/drawable dir, first removing what
311
+ // we linked last time (ledger) plus any current-prefix match. Handles removed
312
+ // icons, prefix renames and dropped sets.
313
+ function copyDrawablesIntoResDir(drawableDir, builtSymbolSets) {
314
+ node_fs_1.default.mkdirSync(drawableDir, { recursive: true });
315
+ const outputDir = builtSymbolSets[0]
316
+ ? node_path_1.default.dirname(builtSymbolSets[0].drawablesDir)
317
+ : null;
318
+ const ledgerPath = outputDir ? node_path_1.default.join(outputDir, DRAWABLE_LEDGER) : null;
319
+ const stale = new Set(ledgerPath ? readLedger(ledgerPath) : []);
320
+ const prefixes = new Set(builtSymbolSets.map((s) => (0, naming_1.toDrawableResourceName)(s.prefix)));
321
+ for (const entry of node_fs_1.default.readdirSync(drawableDir, { withFileTypes: true })) {
322
+ if (!entry.isFile() || !entry.name.endsWith('.xml'))
323
+ continue;
324
+ const base = entry.name.replace(XML_FILE_RE, '');
325
+ for (const prefix of prefixes) {
326
+ if (base.startsWith(`${prefix}_`)) {
327
+ stale.add(entry.name);
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ for (const name of stale) {
333
+ node_fs_1.default.rmSync(node_path_1.default.join(drawableDir, name), { force: true });
334
+ }
335
+ const linked = [];
336
+ for (const set of builtSymbolSets) {
337
+ for (const file of set.drawableFiles) {
338
+ const base = node_path_1.default.basename(file);
339
+ node_fs_1.default.copyFileSync(file, node_path_1.default.join(drawableDir, base));
340
+ linked.push(base);
341
+ }
342
+ }
343
+ if (ledgerPath)
344
+ node_fs_1.default.writeFileSync(ledgerPath, JSON.stringify(linked));
345
+ }
346
+ /**
347
+ * Link generated VectorDrawables into the Android app's res/drawable. They are
348
+ * compiled automatically by AGP and resolve by name via getIdentifier — the
349
+ * native-tab-bar counterpart to the iOS asset catalog. No gradle changes needed.
350
+ */
351
+ async function linkBareAndroidDrawables(projectRoot, builtSymbolSets, logger) {
352
+ if (!builtSymbolSets.length)
353
+ return;
354
+ if (!node_fs_1.default.existsSync(node_path_1.default.join(projectRoot, 'android'))) {
355
+ logger.info('No android/ project found — skipping drawable link');
356
+ return;
357
+ }
358
+ const drawableDir = node_path_1.default.join(projectRoot, ANDROID_DRAWABLES_DIR);
359
+ copyDrawablesIntoResDir(drawableDir, builtSymbolSets);
360
+ logger.succeed(`Linked drawables → ${ANDROID_DRAWABLES_DIR}`);
361
+ }
178
362
  /**
179
363
  * Link built TTFs into native project directories.
180
364
  *
@@ -0,0 +1,62 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type BuiltFont, type IconSetConfig, type NanoLogger, SvgWorkerPool } from '../cli/index';
3
+ export declare const FONT_ROUTE = "/__nanoicons/";
4
+ export declare const REBUILD_DEBOUNCE_MS = 50;
5
+ export declare const ADDED_FILES_SETTLE_MS = 250;
6
+ export declare const CHANGE_LABEL: {
7
+ add: string;
8
+ change: string;
9
+ delete: string;
10
+ };
11
+ export declare function summarize(changes: string[]): string;
12
+ export type WatchEvent = {
13
+ filePath: string;
14
+ type: 'add' | 'change' | 'delete';
15
+ };
16
+ /** metro-file-map < 0.84.3: one entry per raw watcher event, absolute paths. */
17
+ type LegacyChangeEvent = {
18
+ eventsQueue: WatchEvent[];
19
+ };
20
+ /**
21
+ * metro-file-map >= 0.84.3 (Expo SDK 57 ships 0.84.5): events are
22
+ * aggregated per file into `changes`, keyed by paths relative to `rootDir`.
23
+ */
24
+ type AggregatedChangeEvent = {
25
+ rootDir: string;
26
+ changes: {
27
+ addedFiles: Iterable<[string, unknown]>;
28
+ modifiedFiles: Iterable<[string, unknown]>;
29
+ removedFiles: Iterable<[string, unknown]>;
30
+ };
31
+ };
32
+ export type ChangeEvent = LegacyChangeEvent | AggregatedChangeEvent;
33
+ export type FileWatcher = {
34
+ on(event: 'change', listener: (change: ChangeEvent) => void): unknown;
35
+ };
36
+ export declare function toWatchEvents(change: ChangeEvent): WatchEvent[];
37
+ export type Next = (err?: unknown) => void;
38
+ export type DevLogger = NanoLogger & {
39
+ notify(msg: string): void;
40
+ };
41
+ export declare class FontRebuildWatcher {
42
+ private readonly projectRoot;
43
+ private readonly logger;
44
+ private readonly svgWorkerPool;
45
+ private readonly setsByInputDir;
46
+ private readonly fontsByFamily;
47
+ private readonly dirty;
48
+ private readonly preparedSvgCache;
49
+ private webDetected;
50
+ private pending;
51
+ private timer;
52
+ private settleMs;
53
+ constructor(projectRoot: string, iconSets: IconSetConfig[], watcher: FileWatcher, logger: DevLogger, svgWorkerPool?: SvgWorkerPool);
54
+ get build(): Promise<void>;
55
+ fontFor(family: string): BuiltFont | undefined;
56
+ private onChange;
57
+ private schedule;
58
+ private flush;
59
+ private rebuildDirty;
60
+ middleware: (req: IncomingMessage, res: ServerResponse, next: Next) => void;
61
+ }
62
+ export {};