react-native-nano-icons 1.0.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.
Files changed (138) hide show
  1. package/README.md +139 -21
  2. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +7 -0
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
  6. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +6 -1
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +4 -2
  8. package/ios/NanoIconView.mm +34 -44
  9. package/ios/NanoIconsFontLoader.mm +5 -0
  10. package/lib/commonjs/cli/build.d.ts +26 -0
  11. package/lib/commonjs/cli/build.js +174 -64
  12. package/lib/commonjs/cli/buildSymbols.d.ts +30 -1
  13. package/lib/commonjs/cli/buildSymbols.js +120 -42
  14. package/lib/commonjs/cli/expoConfig.d.ts +11 -0
  15. package/lib/commonjs/cli/expoConfig.js +28 -9
  16. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  17. package/lib/commonjs/cli/fingerprint.js +42 -0
  18. package/lib/commonjs/cli/index.d.ts +2 -2
  19. package/lib/commonjs/cli/index.js +3 -1
  20. package/lib/commonjs/cli/link.d.ts +4 -0
  21. package/lib/commonjs/cli/link.js +38 -1
  22. package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
  23. package/lib/commonjs/cli/sameOutputs.js +45 -0
  24. package/lib/commonjs/index.node.js +1 -1
  25. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
  26. package/lib/commonjs/plugin/src/buildFonts.js +11 -3
  27. package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
  28. package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
  29. package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
  30. package/lib/commonjs/plugin/src/frozen.js +18 -0
  31. package/lib/commonjs/plugin/src/index.js +3 -3
  32. package/lib/commonjs/plugin/src/types.d.ts +22 -1
  33. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
  34. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
  35. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
  36. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
  37. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
  38. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
  39. package/lib/commonjs/scripts/cli.js +31 -2
  40. package/lib/commonjs/src/core/flatten/dom.js +40 -5
  41. package/lib/commonjs/src/core/flatten/element.js +2 -1
  42. package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
  43. package/lib/commonjs/src/core/font/compile.d.ts +0 -1
  44. package/lib/commonjs/src/core/font/compile.js +2 -8
  45. package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
  46. package/lib/commonjs/src/core/glyph/merge.js +27 -36
  47. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
  48. package/lib/commonjs/src/core/glyph/parse.js +31 -18
  49. package/lib/commonjs/src/core/glyph/placement.d.ts +1 -0
  50. package/lib/commonjs/src/core/glyph/placement.js +9 -3
  51. package/lib/commonjs/src/core/pathkit/types.d.ts +1 -0
  52. package/lib/commonjs/src/core/pathkit/winding.d.ts +14 -3
  53. package/lib/commonjs/src/core/pathkit/winding.js +434 -7
  54. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  55. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  56. package/lib/commonjs/src/core/pipeline/prepare.js +4 -16
  57. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  58. package/lib/commonjs/src/core/pipeline/prepareIcon.js +3 -1
  59. package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +2 -0
  60. package/lib/commonjs/src/core/pipeline/prepareSymbol.js +15 -3
  61. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +2 -2
  62. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  63. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +2 -0
  64. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +2 -0
  65. package/lib/commonjs/src/core/symbols/contents.d.ts +1 -1
  66. package/lib/commonjs/src/core/symbols/contents.js +6 -2
  67. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  68. package/lib/commonjs/src/core/symbols/layers.d.ts +1 -0
  69. package/lib/commonjs/src/core/symbols/layers.js +133 -92
  70. package/lib/commonjs/src/core/symbols/template.d.ts +8 -3
  71. package/lib/commonjs/src/core/symbols/template.js +23 -8
  72. package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +8 -0
  73. package/lib/commonjs/src/core/symbols/vectorDrawable.js +28 -2
  74. package/lib/commonjs/src/utils/fingerPrint.d.ts +3 -0
  75. package/lib/commonjs/src/utils/fingerPrint.js +5 -1
  76. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  77. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  78. package/lib/module/createNanoIconsSet.js +0 -1
  79. package/lib/module/createNanoIconsSet.native.js +22 -18
  80. package/lib/module/createNanoIconsSet.shared.js +32 -18
  81. package/lib/module/createNanoIconsSet.web.js +103 -61
  82. package/lib/module/devServerFont.js +1 -1
  83. package/lib/module/devServerFont.web.js +3 -5
  84. package/lib/module/fontIntegrity.js +20 -38
  85. package/lib/module/fontIntegrity.web.js +48 -0
  86. package/lib/module/fontIntegrityStore.js +65 -0
  87. package/lib/module/index.js +1 -1
  88. package/lib/module/index.node.js +1 -1
  89. package/lib/module/index.web.js +4 -0
  90. package/lib/module/loadDynamicFont.js +3 -15
  91. package/lib/module/specs/NanoIconViewNativeComponent.ts +2 -1
  92. package/lib/module/utils/fingerPrint.js +4 -3
  93. package/lib/module/utils/fontIdentity.js +2 -2
  94. package/lib/module/utils/fontScale.js +10 -2
  95. package/lib/module/utils/glyphRuntime.js +13 -0
  96. package/lib/module/utils/iconAccessibility.js +26 -0
  97. package/lib/module/utils/iconPropsEqual.js +27 -0
  98. package/lib/module/utils/webCss.js +26 -0
  99. package/lib/module/utils/webStyle.js +86 -0
  100. package/lib/module/webFont.js +33 -0
  101. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  102. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  103. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  104. package/lib/typescript/src/core/glyph/placement.d.ts +1 -0
  105. package/lib/typescript/src/core/pathkit/types.d.ts +1 -0
  106. package/lib/typescript/src/core/pathkit/winding.d.ts +14 -3
  107. package/lib/typescript/src/core/symbols/contents.d.ts +1 -1
  108. package/lib/typescript/src/core/symbols/layers.d.ts +1 -0
  109. package/lib/typescript/src/core/symbols/template.d.ts +8 -3
  110. package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +8 -0
  111. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  112. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  113. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  114. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  115. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  116. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  117. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  118. package/lib/typescript/src/index.d.ts +2 -1
  119. package/lib/typescript/src/index.web.d.ts +5 -0
  120. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  121. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +2 -1
  122. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  123. package/lib/typescript/src/types.d.ts +37 -9
  124. package/lib/typescript/src/utils/fingerPrint.d.ts +3 -0
  125. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  126. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  127. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  128. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  129. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  130. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  131. package/lib/typescript/src/webFont.d.ts +6 -0
  132. package/package.json +19 -3
  133. package/src/const/codegenPrimitives.ts +3 -3
  134. package/src/specs/NanoIconViewNativeComponent.ts +2 -1
  135. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  136. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  137. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  138. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
@@ -77,6 +77,11 @@ RCT_EXPORT_METHOD(isFontRegistered:(NSString *)family
77
77
  resolve(@(NanoIconIsFontResolvable(family)));
78
78
  }
79
79
 
80
+ RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, isFontAvailable:(NSString *)family)
81
+ {
82
+ return @(NanoIconIsFontResolvable(family));
83
+ }
84
+
80
85
  #ifdef RCT_NEW_ARCH_ENABLED
81
86
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
82
87
  (const facebook::react::ObjCTurboModule::InitParams &)params
@@ -11,6 +11,8 @@ export type IconSetConfig = {
11
11
  upm?: number;
12
12
  /** Safe zone inside UPM for glyphs (default upm * 1020 / 1024, i.e. 1020 at the default upm). Must not exceed upm. */
13
13
  safeZone?: number;
14
+ /** Max distance between the font's quadratic curves and the SVG curves, as a fraction of the em (default 1/512). Must be positive. */
15
+ curveTolerance?: number;
14
16
  /** First Unicode codepoint for glyphs (default 0xe900). Hex string or number. */
15
17
  startUnicode?: number | string;
16
18
  /** Linking type for the font (default 'static'). Static bundles the TTF, dynamic delivers it via OTA*/
@@ -30,6 +32,30 @@ export declare class IconSetBuildError extends Error {
30
32
  built: BuiltFont[];
31
33
  constructor(message: string, built: BuiltFont[]);
32
34
  }
35
+ export type StaleSet = {
36
+ name: string;
37
+ reason: string;
38
+ };
39
+ /**
40
+ * The input fingerprint of each icon set: the value a build stores in its glyphmap as `m.h`.
41
+ */
42
+ export declare function fingerprintIconSets(iconSets: IconSetConfig[], projectRoot: string): {
43
+ fontFamily: string;
44
+ hash: string;
45
+ }[];
46
+ /**
47
+ * Report the icon sets whose generated files are out of date, without writing anything to the project.
48
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
49
+ * the set is built into a temp dir and compared with them. With `appRoot`, a static set is also out of date
50
+ * when its font linked into that app's android/ or ios/ project differs from the generated TTF.
51
+ * With `existingOnly`, sets without a glyphmap are skipped.
52
+ */
53
+ export declare function checkAllFonts(iconSets: IconSetConfig[], projectRoot: string, options?: {
54
+ logger?: NanoLogger;
55
+ withWeb?: boolean;
56
+ appRoot?: string;
57
+ existingOnly?: boolean;
58
+ }): Promise<StaleSet[]>;
33
59
  /**
34
60
  * Build TTF + glyphmap for all icon sets using a single PathKit instance.
35
61
  * Output is placed in a "nanoicons" folder next to each input dir (sibling to inputDir).
@@ -4,10 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.IconSetBuildError = void 0;
7
+ exports.fingerprintIconSets = fingerprintIconSets;
8
+ exports.checkAllFonts = checkAllFonts;
7
9
  exports.buildAllFonts = buildAllFonts;
8
10
  const path_1 = __importDefault(require("path"));
9
11
  const fs_1 = __importDefault(require("fs"));
12
+ const util_1 = require("util");
10
13
  const index_1 = require("../src/core/pipeline/index");
14
+ const quadratic_1 = require("../src/core/font/quadratic");
15
+ const link_1 = require("./link");
16
+ const sameOutputs_1 = require("./sameOutputs");
11
17
  const fingerPrint_1 = require("../src/utils/fingerPrint");
12
18
  const packageVersion_1 = require("../src/utils/packageVersion");
13
19
  class IconSetBuildError extends Error {
@@ -28,32 +34,171 @@ function webOutputFor(configured, withWeb) {
28
34
  return 'required';
29
35
  return 'ignored';
30
36
  }
31
- function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger) {
32
- const ttfPath = path_1.default.join(outputDir, `${fontFamily}.ttf`);
33
- const glyphmapPath = path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`);
34
- const woff2Path = path_1.default.join(outputDir, `${fontFamily}.woff2`);
35
- if (!fs_1.default.existsSync(outputDir) ||
36
- !fs_1.default.existsSync(ttfPath) ||
37
- !fs_1.default.existsSync(glyphmapPath) ||
38
- (webOutput === 'required' && !fs_1.default.existsSync(woff2Path))) {
39
- return undefined;
37
+ const STALE_REASON = {
38
+ missing: (file) => `${file} is missing`,
39
+ invalidJson: (file) => `${file} is not valid JSON`,
40
+ incomplete: (file) => `${file} is incomplete`,
41
+ inputsChanged: 'its SVGs, options or installed versions changed',
42
+ linkingChanged: (linking) => `its linking changed to "${linking}"`,
43
+ webOutputChanged: (enabled) => `web output was turned ${enabled ? 'on' : 'off'}`,
44
+ };
45
+ function currentOutput(set, logger) {
46
+ const { fontFamily, ttfPath, glyphmapPath, woff2Path, webOutput } = set;
47
+ const missing = [
48
+ ttfPath,
49
+ glyphmapPath,
50
+ ...(webOutput === 'required' ? [woff2Path] : []),
51
+ ].find((file) => !fs_1.default.existsSync(file));
52
+ if (missing) {
53
+ return { staleBecause: STALE_REASON.missing(path_1.default.basename(missing)) };
54
+ }
55
+ let glyphmap;
56
+ try {
57
+ glyphmap = JSON.parse(fs_1.default.readFileSync(glyphmapPath, 'utf8'));
58
+ }
59
+ catch {
60
+ return {
61
+ staleBecause: STALE_REASON.invalidJson(path_1.default.basename(glyphmapPath)),
62
+ };
40
63
  }
41
- const glyphmap = JSON.parse(fs_1.default.readFileSync(glyphmapPath, 'utf8'));
42
64
  const storedHash = glyphmap?.m?.h;
43
65
  const storedFamily = glyphmap?.m?.f;
44
66
  const storedLinking = glyphmap?.m?.l === 'd' ? 'dynamic' : 'static';
45
67
  const storedWeb = glyphmap?.m?.w === true;
46
- const webCurrent = webOutput === 'ignored' || storedWeb === (webOutput === 'required');
47
- if (storedHash &&
48
- storedFamily &&
49
- storedHash === inputHash &&
50
- storedLinking === linking &&
51
- webCurrent) {
52
- const iconCount = Object.keys(glyphmap?.i ?? {}).length;
53
- logger?.succeed(`${fontFamily}.ttf is up to date [${iconCount} icon${iconCount === 1 ? '' : 's'}]`);
54
- return storedFamily;
68
+ if (!storedHash || !storedFamily) {
69
+ return {
70
+ staleBecause: STALE_REASON.incomplete(path_1.default.basename(glyphmapPath)),
71
+ };
72
+ }
73
+ if (storedHash !== set.inputHash) {
74
+ return { staleBecause: STALE_REASON.inputsChanged };
75
+ }
76
+ if (storedLinking !== set.linking) {
77
+ return { staleBecause: STALE_REASON.linkingChanged(set.linking) };
78
+ }
79
+ if (webOutput !== 'ignored' && storedWeb !== (webOutput === 'required')) {
80
+ return { staleBecause: STALE_REASON.webOutputChanged(!storedWeb) };
81
+ }
82
+ const iconCount = Object.keys(glyphmap?.i ?? {}).length;
83
+ logger?.succeed(`${fontFamily}.ttf is up to date [${iconCount} icon${iconCount === 1 ? '' : 's'}]`);
84
+ return { family: storedFamily };
85
+ }
86
+ function resolveIconSet(set, projectRoot, withWeb, versions) {
87
+ const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
88
+ const fontFamily = set.fontFamily ?? path_1.default.basename(inputDir);
89
+ const linking = set.linking ?? 'static';
90
+ const web = (set.web ?? false) && withWeb;
91
+ const webOutput = webOutputFor(set.web ?? false, withWeb);
92
+ if (!fs_1.default.existsSync(inputDir)) {
93
+ throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
94
+ }
95
+ const upm = set.upm ?? DEFAULT_UPM;
96
+ const safeZone = set.safeZone ?? Math.round(upm * DEFAULT_SAFE_ZONE_RATIO);
97
+ if (safeZone > upm) {
98
+ throw new Error(`[react-native-nano-icons] safeZone (${safeZone}) of "${fontFamily}" must not exceed upm (${upm}).`);
99
+ }
100
+ const curveTolerance = set.curveTolerance ?? quadratic_1.QUADRATIC_ERROR_BOUND_EM;
101
+ if (!Number.isFinite(curveTolerance) || curveTolerance <= 0) {
102
+ throw new Error(`[react-native-nano-icons] curveTolerance (${(0, util_1.inspect)(curveTolerance)}) of "${fontFamily}" must be a positive number.`);
103
+ }
104
+ const outputDir = set.outputDir
105
+ ? path_1.default.resolve(projectRoot, set.outputDir)
106
+ : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
107
+ const config = {
108
+ fontFamily,
109
+ upm,
110
+ safeZone,
111
+ curveTolerance,
112
+ startUnicode: set.startUnicode !== undefined
113
+ ? typeof set.startUnicode === 'string'
114
+ ? parseInt(set.startUnicode, 16)
115
+ : set.startUnicode
116
+ : DEFAULT_START_UNICODE,
117
+ linking,
118
+ web,
119
+ };
120
+ const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSvgDirSync)(inputDir, {
121
+ upm: config.upm,
122
+ safeZone: config.safeZone,
123
+ curveTolerance: config.curveTolerance,
124
+ startUnicode: config.startUnicode,
125
+ ...versions,
126
+ });
127
+ return {
128
+ fontFamily,
129
+ inputDir,
130
+ outputDir,
131
+ ttfPath: path_1.default.join(outputDir, `${fontFamily}.ttf`),
132
+ glyphmapPath: path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`),
133
+ woff2Path: path_1.default.join(outputDir, `${fontFamily}.woff2`),
134
+ linking,
135
+ web,
136
+ webOutput,
137
+ config,
138
+ inputHash,
139
+ svgHashByFile,
140
+ };
141
+ }
142
+ async function familyIfBuiltTheSame(set) {
143
+ const same = await (0, sameOutputs_1.buildsSameOutputs)(set.outputDir, path_1.default.basename(set.glyphmapPath), (outputDir) => (0, index_1.runFontPipeline)(set.config, { inputDir: set.inputDir, outputDir, tempDir: outputDir }, { inputHash: set.inputHash, svgHashByFile: set.svgHashByFile }));
144
+ return same
145
+ ? JSON.parse(fs_1.default.readFileSync(set.glyphmapPath, 'utf8')).m.f
146
+ : undefined;
147
+ }
148
+ /**
149
+ * The input fingerprint of each icon set: the value a build stores in its glyphmap as `m.h`.
150
+ */
151
+ function fingerprintIconSets(iconSets, projectRoot) {
152
+ const versions = {
153
+ version: (0, packageVersion_1.packageVersion)(),
154
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
155
+ };
156
+ return iconSets.map((set) => {
157
+ const { fontFamily, inputHash } = resolveIconSet(set, projectRoot, true, versions);
158
+ return { fontFamily, hash: inputHash };
159
+ });
160
+ }
161
+ /**
162
+ * Report the icon sets whose generated files are out of date, without writing anything to the project.
163
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
164
+ * the set is built into a temp dir and compared with them. With `appRoot`, a static set is also out of date
165
+ * when its font linked into that app's android/ or ios/ project differs from the generated TTF.
166
+ * With `existingOnly`, sets without a glyphmap are skipped.
167
+ */
168
+ async function checkAllFonts(iconSets, projectRoot, options) {
169
+ const versions = {
170
+ version: (0, packageVersion_1.packageVersion)(),
171
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
172
+ };
173
+ const stale = [];
174
+ for (const set of iconSets) {
175
+ const resolved = resolveIconSet(set, projectRoot, options?.withWeb ?? true, versions);
176
+ if (options?.existingOnly && !fs_1.default.existsSync(resolved.glyphmapPath)) {
177
+ continue;
178
+ }
179
+ let state = currentOutput(resolved, options?.logger);
180
+ if ('staleBecause' in state &&
181
+ state.staleBecause === STALE_REASON.inputsChanged) {
182
+ const family = await familyIfBuiltTheSame(resolved);
183
+ if (family) {
184
+ options?.logger?.succeed(`${resolved.fontFamily}.ttf is up to date: its inputs changed, but it builds the same`);
185
+ state = { family };
186
+ }
187
+ }
188
+ if ('staleBecause' in state) {
189
+ options?.logger?.fail(`${resolved.fontFamily}.ttf is out of date: ${state.staleBecause}`);
190
+ stale.push({ name: resolved.fontFamily, reason: state.staleBecause });
191
+ continue;
192
+ }
193
+ if (options?.appRoot && resolved.linking === 'static') {
194
+ const reason = (0, link_1.staleLinkedFont)(options.appRoot, state.family, resolved.ttfPath);
195
+ if (reason) {
196
+ options.logger?.fail(reason);
197
+ stale.push({ name: resolved.fontFamily, reason });
198
+ }
199
+ }
55
200
  }
56
- return undefined;
201
+ return stale;
57
202
  }
58
203
  /**
59
204
  * Build TTF + glyphmap for all icon sets using a single PathKit instance.
@@ -63,56 +208,21 @@ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOut
63
208
  async function buildAllFonts(iconSets, projectRoot, options) {
64
209
  const withWeb = options?.withWeb ?? true;
65
210
  const logger = options?.logger;
66
- const version = (0, packageVersion_1.packageVersion)();
67
- const toolchain = (0, packageVersion_1.fontToolchainVersions)();
211
+ const versions = {
212
+ version: (0, packageVersion_1.packageVersion)(),
213
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
214
+ };
68
215
  const results = [];
69
216
  const failures = [];
70
217
  let allSkipped = true;
71
218
  for (let i = 0; i < iconSets.length; i++) {
72
- const set = iconSets[i];
73
- const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
74
- const fontFamily = set.fontFamily ?? path_1.default.basename(inputDir);
75
- const linking = set.linking ?? 'static';
76
- const web = (set.web ?? false) && withWeb;
77
- const webOutput = webOutputFor(set.web ?? false, withWeb);
78
- if (!fs_1.default.existsSync(inputDir)) {
79
- throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
80
- }
81
- const upm = set.upm ?? DEFAULT_UPM;
82
- const safeZone = set.safeZone ?? Math.round(upm * DEFAULT_SAFE_ZONE_RATIO);
83
- if (safeZone > upm) {
84
- throw new Error(`[react-native-nano-icons] safeZone (${safeZone}) of "${fontFamily}" must not exceed upm (${upm}).`);
85
- }
86
- const outputDir = set.outputDir
87
- ? path_1.default.resolve(projectRoot, set.outputDir)
88
- : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
89
- const ttfPath = path_1.default.join(outputDir, `${fontFamily}.ttf`);
90
- const glyphmapPath = path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`);
91
- const woff2Path = path_1.default.join(outputDir, `${fontFamily}.woff2`);
92
- const config = {
93
- fontFamily,
94
- upm,
95
- safeZone,
96
- startUnicode: set.startUnicode !== undefined
97
- ? typeof set.startUnicode === 'string'
98
- ? parseInt(set.startUnicode, 16)
99
- : set.startUnicode
100
- : DEFAULT_START_UNICODE,
101
- linking,
102
- web,
103
- };
104
- const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSvgDirSync)(inputDir, {
105
- upm: config.upm,
106
- safeZone: config.safeZone,
107
- startUnicode: config.startUnicode,
108
- version,
109
- toolchain,
110
- });
111
- const currentFamily = familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger);
112
- if (currentFamily) {
219
+ const resolved = resolveIconSet(iconSets[i], projectRoot, withWeb, versions);
220
+ const { fontFamily, inputDir, outputDir, ttfPath, glyphmapPath, woff2Path, linking, web, webOutput, config, inputHash, svgHashByFile, } = resolved;
221
+ const current = currentOutput(resolved, logger);
222
+ if ('family' in current) {
113
223
  results.push({
114
224
  fontFamily,
115
- family: currentFamily,
225
+ family: current.family,
116
226
  ttfPath,
117
227
  glyphmapPath,
118
228
  linking,
@@ -3,13 +3,26 @@ import type { SvgWorkerPool } from '../src/core/pipeline/iconPool';
3
3
  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
+ import type { StaleSet } from './build';
7
+ export type SymbolFit = 'content' | 'viewBox';
6
8
  export type SymbolSetConfig = {
7
9
  /** Folder of SVG files (relative to project root). */
8
10
  inputDir: string;
9
- /** Set name; defaults to the inputDir basename. */
11
+ /** Set's name; defaults to the inputDir basename. */
10
12
  name?: string;
11
13
  /** Symbol name prefix (default "nano"): home.svg → "nano.home". */
12
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;
13
26
  /** Output dir; defaults to a sibling nanoicons folder next to inputDir. */
14
27
  outputDir?: string;
15
28
  };
@@ -18,6 +31,22 @@ export declare class SymbolSetBuildError extends Error {
18
31
  built: BuiltSymbolSet[];
19
32
  constructor(message: string, built: BuiltSymbolSet[]);
20
33
  }
34
+ /**
35
+ * The input fingerprint of each symbol set: the value a build stores in its symbolmap as `m.h`.
36
+ */
37
+ export declare function fingerprintSymbolSets(symbolSets: SymbolSetConfig[], projectRoot: string): {
38
+ name: string;
39
+ hash: string;
40
+ }[];
41
+ /**
42
+ * Report the symbol sets whose generated files are out of date, without writing anything to the project.
43
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
44
+ * the set is built into a temp dir and compared with them. With `existingOnly`, sets without a symbolmap are skipped.
45
+ */
46
+ export declare function checkAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
47
+ logger?: NanoLogger;
48
+ existingOnly?: boolean;
49
+ }): Promise<StaleSet[]>;
21
50
  export declare function buildAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
22
51
  logger?: NanoLogger;
23
52
  keepOutputsOnFailure?: boolean;
@@ -4,10 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SymbolSetBuildError = void 0;
7
+ exports.fingerprintSymbolSets = fingerprintSymbolSets;
8
+ exports.checkAllSymbols = checkAllSymbols;
7
9
  exports.buildAllSymbols = buildAllSymbols;
8
10
  const path_1 = __importDefault(require("path"));
9
11
  const fs_1 = __importDefault(require("fs"));
10
12
  const runSymbolPipeline_1 = require("../src/core/pipeline/runSymbolPipeline");
13
+ const sameOutputs_1 = require("./sameOutputs");
11
14
  const fingerPrint_1 = require("../src/utils/fingerPrint");
12
15
  const naming_1 = require("../src/utils/naming");
13
16
  const packageVersion_1 = require("../src/utils/packageVersion");
@@ -20,26 +23,32 @@ class SymbolSetBuildError extends Error {
20
23
  }
21
24
  exports.SymbolSetBuildError = SymbolSetBuildError;
22
25
  const DEFAULT_PREFIX = 'nano';
23
- function shouldSkipGeneration(inputHash, outputDir, name, logger) {
26
+ const STALE_REASON = {
27
+ missing: (file) => `${file} is missing`,
28
+ invalidJson: (file) => `${file} is not valid JSON`,
29
+ inputsChanged: 'its SVGs, options or installed versions changed',
30
+ };
31
+ function currentSymbolOutput(inputHash, outputDir, name, logger) {
24
32
  const symbolmapPath = path_1.default.join(outputDir, `${name}.symbolmap.json`);
25
33
  const dtsPath = path_1.default.join(outputDir, `${name}.symbols.d.ts`);
26
34
  const symbolsDir = path_1.default.join(outputDir, `${name}.symbols`);
27
35
  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;
36
+ const missing = [symbolmapPath, dtsPath, symbolsDir, drawablesDir].find((file) => !fs_1.default.existsSync(file));
37
+ if (missing) {
38
+ return { staleBecause: STALE_REASON.missing(path_1.default.basename(missing)) };
33
39
  }
34
40
  let symbolmap;
35
41
  try {
36
42
  symbolmap = JSON.parse(fs_1.default.readFileSync(symbolmapPath, 'utf8'));
37
43
  }
38
44
  catch {
39
- return null;
45
+ return {
46
+ staleBecause: STALE_REASON.invalidJson(path_1.default.basename(symbolmapPath)),
47
+ };
48
+ }
49
+ if (!symbolmap?.m?.h || symbolmap.m.h !== inputHash) {
50
+ return { staleBecause: STALE_REASON.inputsChanged };
40
51
  }
41
- if (!symbolmap?.m?.h || symbolmap.m.h !== inputHash)
42
- return null;
43
52
  const symbols = symbolmap.s ?? {};
44
53
  const drawables = symbolmap.d ?? {};
45
54
  const assetDirs = Object.values(symbols).map((assetName) => path_1.default.join(symbolsDir, `${assetName}.symbolset`));
@@ -47,60 +56,129 @@ function shouldSkipGeneration(inputHash, outputDir, name, logger) {
47
56
  path_1.default.join(drawablesDir, `${resourceName}.xml`),
48
57
  path_1.default.join(drawablesDir, `${(0, naming_1.toOriginalDrawableResourceName)(resourceName)}.xml`),
49
58
  ]);
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;
59
+ const missingAsset = [...assetDirs, ...drawableFiles].find((file) => !fs_1.default.existsSync(file));
60
+ if (missingAsset) {
61
+ return {
62
+ staleBecause: STALE_REASON.missing(path_1.default.basename(missingAsset)),
63
+ };
64
+ }
54
65
  logger?.info(`${name}: SVG fingerprint unchanged, skipping build.`);
55
66
  return {
67
+ built: {
68
+ name,
69
+ prefix: symbolmap.m.p,
70
+ symbolsDir,
71
+ assetDirs,
72
+ drawablesDir,
73
+ drawableFiles,
74
+ dtsPath,
75
+ symbolmapPath,
76
+ symbols,
77
+ drawables,
78
+ },
79
+ };
80
+ }
81
+ function resolveSymbolSet(set, projectRoot, versions) {
82
+ const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
83
+ const name = set.name ?? path_1.default.basename(inputDir);
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
+ }
93
+ if (!fs_1.default.existsSync(inputDir)) {
94
+ throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
95
+ }
96
+ const outputDir = set.outputDir
97
+ ? path_1.default.resolve(projectRoot, set.outputDir)
98
+ : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
99
+ const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSymbolDirSync)(inputDir, { prefix, fit, scale, ...versions });
100
+ return {
101
+ inputDir,
56
102
  name,
57
- prefix: symbolmap.m.p,
58
- symbolsDir,
59
- assetDirs,
60
- drawablesDir,
61
- drawableFiles,
62
- dtsPath,
63
- symbolmapPath,
64
- symbols,
65
- drawables,
103
+ prefix,
104
+ fit,
105
+ scale,
106
+ outputDir,
107
+ inputHash,
108
+ svgHashByFile,
109
+ };
110
+ }
111
+ /**
112
+ * The input fingerprint of each symbol set: the value a build stores in its symbolmap as `m.h`.
113
+ */
114
+ function fingerprintSymbolSets(symbolSets, projectRoot) {
115
+ const versions = {
116
+ version: (0, packageVersion_1.packageVersion)(),
117
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
66
118
  };
119
+ return symbolSets.map((set) => {
120
+ const { name, inputHash } = resolveSymbolSet(set, projectRoot, versions);
121
+ return { name, hash: inputHash };
122
+ });
123
+ }
124
+ /**
125
+ * Report the symbol sets whose generated files are out of date, without writing anything to the project.
126
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
127
+ * the set is built into a temp dir and compared with them. With `existingOnly`, sets without a symbolmap are skipped.
128
+ */
129
+ async function checkAllSymbols(symbolSets, projectRoot, options) {
130
+ const versions = {
131
+ version: (0, packageVersion_1.packageVersion)(),
132
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
133
+ };
134
+ const stale = [];
135
+ for (const set of symbolSets) {
136
+ const { inputDir, name, prefix, fit, scale, outputDir, inputHash, svgHashByFile, } = resolveSymbolSet(set, projectRoot, versions);
137
+ if (options?.existingOnly &&
138
+ !fs_1.default.existsSync(path_1.default.join(outputDir, `${name}.symbolmap.json`))) {
139
+ continue;
140
+ }
141
+ const state = currentSymbolOutput(inputHash, outputDir, name);
142
+ if ('staleBecause' in state &&
143
+ state.staleBecause === STALE_REASON.inputsChanged &&
144
+ (await (0, sameOutputs_1.buildsSameOutputs)(outputDir, `${name}.symbolmap.json`, (dir) => (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix, fit, scale }, { inputDir, outputDir: dir }, { inputHash, svgHashByFile })))) {
145
+ options?.logger?.succeed(`${name} symbols are up to date: their inputs changed, but they build the same`);
146
+ }
147
+ else if ('staleBecause' in state) {
148
+ options?.logger?.fail(`${name} symbols are out of date: ${state.staleBecause}`);
149
+ stale.push({ name, reason: state.staleBecause });
150
+ }
151
+ else {
152
+ options?.logger?.succeed(`${name} symbols are up to date`);
153
+ }
154
+ }
155
+ return stale;
67
156
  }
68
157
  // Build all symbol sets. Output goes in a "nanoicons" folder next to each
69
158
  // inputDir, matching the font pipeline's convention.
70
159
  async function buildAllSymbols(symbolSets, projectRoot, options) {
71
160
  const logger = options?.logger;
72
- const version = (0, packageVersion_1.packageVersion)();
73
- const toolchain = (0, packageVersion_1.fontToolchainVersions)();
161
+ const versions = {
162
+ version: (0, packageVersion_1.packageVersion)(),
163
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
164
+ };
74
165
  const results = [];
75
166
  const failures = [];
76
167
  for (let i = 0; i < symbolSets.length; i++) {
77
168
  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');
169
+ const { inputDir, name, prefix, fit, scale, outputDir, inputHash, svgHashByFile, } = resolveSymbolSet(set, projectRoot, versions);
87
170
  if ('multicolor' in set) {
88
171
  logger?.warn(`${name}: "multicolor" is no longer needed — every symbol now carries both rendering modes; remove it from the config.`);
89
172
  }
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);
173
+ const current = currentSymbolOutput(inputHash, outputDir, name, logger);
174
+ if ('built' in current) {
175
+ results.push(current.built);
98
176
  continue;
99
177
  }
100
178
  logger?.start(`Building ${name} (${i + 1}/${symbolSets.length})…`);
101
179
  let out;
102
180
  try {
103
- out = await (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix }, { inputDir, outputDir }, {
181
+ out = await (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix, fit, scale }, { inputDir, outputDir }, {
104
182
  logger,
105
183
  inputHash,
106
184
  preparedSvgCache: options?.preparedSvgCache,
@@ -8,5 +8,16 @@ import type { SymbolSetConfig } from './buildSymbols';
8
8
  * falling back to @expo/config.
9
9
  */
10
10
  export declare function loadDynamicSetsFromAppConfig(projectRoot: string): IconSetConfig[];
11
+ type NanoIconsPluginOptions = {
12
+ iconSets?: IconSetConfig[];
13
+ symbolSets?: SymbolSetConfig[];
14
+ };
11
15
  export declare function loadIconSetsFromAppConfig(projectRoot: string): IconSetConfig[];
12
16
  export declare function loadSymbolSetsFromAppConfig(projectRoot: string): SymbolSetConfig[];
17
+ /**
18
+ * The plugin options in the Expo app config, `{}` when the plugin is listed without options,
19
+ * or `undefined` when it is not listed.
20
+ */
21
+ export declare function findPluginOptions(projectRoot: string): NanoIconsPluginOptions | undefined;
22
+ export declare function resolveExpoConfigModule(projectRoot: string): string | undefined;
23
+ export {};