react-native-nano-icons 1.0.1 → 1.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +137 -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 +12 -0
  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 +17 -0
  13. package/lib/commonjs/cli/buildSymbols.js +103 -42
  14. package/lib/commonjs/cli/expoConfig.d.ts +10 -0
  15. package/lib/commonjs/cli/expoConfig.js +22 -7
  16. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  17. package/lib/commonjs/cli/fingerprint.js +36 -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 +25 -0
  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 +10 -0
  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/pathkit/winding.d.ts +7 -1
  50. package/lib/commonjs/src/core/pathkit/winding.js +172 -0
  51. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  52. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  53. package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
  54. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  55. package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
  56. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
  57. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  58. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  59. package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
  60. package/lib/commonjs/src/utils/fingerPrint.js +3 -1
  61. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  62. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  63. package/lib/module/createNanoIconsSet.js +0 -1
  64. package/lib/module/createNanoIconsSet.native.js +22 -18
  65. package/lib/module/createNanoIconsSet.shared.js +32 -18
  66. package/lib/module/createNanoIconsSet.web.js +103 -61
  67. package/lib/module/devServerFont.js +1 -1
  68. package/lib/module/devServerFont.web.js +3 -5
  69. package/lib/module/fontIntegrity.js +20 -38
  70. package/lib/module/fontIntegrity.web.js +48 -0
  71. package/lib/module/fontIntegrityStore.js +65 -0
  72. package/lib/module/index.js +1 -1
  73. package/lib/module/index.node.js +1 -1
  74. package/lib/module/index.web.js +4 -0
  75. package/lib/module/loadDynamicFont.js +3 -15
  76. package/lib/module/specs/NanoIconViewNativeComponent.ts +2 -1
  77. package/lib/module/utils/fingerPrint.js +3 -2
  78. package/lib/module/utils/fontIdentity.js +2 -2
  79. package/lib/module/utils/fontScale.js +10 -2
  80. package/lib/module/utils/glyphRuntime.js +13 -0
  81. package/lib/module/utils/iconAccessibility.js +26 -0
  82. package/lib/module/utils/iconPropsEqual.js +27 -0
  83. package/lib/module/utils/webCss.js +26 -0
  84. package/lib/module/utils/webStyle.js +86 -0
  85. package/lib/module/webFont.js +33 -0
  86. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  87. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  88. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  89. package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
  90. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  91. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  92. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  93. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  94. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  95. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  96. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  97. package/lib/typescript/src/index.d.ts +2 -1
  98. package/lib/typescript/src/index.web.d.ts +5 -0
  99. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  100. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +2 -1
  101. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  102. package/lib/typescript/src/types.d.ts +37 -9
  103. package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
  104. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  105. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  106. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  107. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  108. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  109. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  110. package/lib/typescript/src/webFont.d.ts +6 -0
  111. package/package.json +19 -3
  112. package/src/const/codegenPrimitives.ts +3 -3
  113. package/src/specs/NanoIconViewNativeComponent.ts +2 -1
  114. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  115. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  116. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  117. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
@@ -2,6 +2,10 @@ import type { NanoLogger } from './logger';
2
2
  import type { BuiltFont } from './build';
3
3
  import type { BuiltSymbolSet } from './buildSymbols';
4
4
  export declare function syncAndroidFontAssets(fontsDir: string, staticFonts: BuiltFont[], configuredFamilies: string[]): void;
5
+ /**
6
+ * Why the copy of a static font linked into the app's android/ or ios/ project differs from the generated TTF, if it does.
7
+ */
8
+ export declare function staleLinkedFont(projectRoot: string, family: string, ttfPath: string): string | undefined;
5
9
  export declare function copySymbolsetsIntoCatalog(catalogDir: string, builtSymbolSets: BuiltSymbolSet[]): void;
6
10
  /**
7
11
  * Link custom SF Symbols into the iOS app. Primary path writes into the app's
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.syncAndroidFontAssets = syncAndroidFontAssets;
40
+ exports.staleLinkedFont = staleLinkedFont;
40
41
  exports.copySymbolsetsIntoCatalog = copySymbolsetsIntoCatalog;
41
42
  exports.linkBareSymbols = linkBareSymbols;
42
43
  exports.copyDrawablesIntoResDir = copyDrawablesIntoResDir;
@@ -118,6 +119,30 @@ function syncAndroidFontAssets(fontsDir, staticFonts, configuredFamilies) {
118
119
  node_fs_1.default.copyFileSync(b.ttfPath, node_path_1.default.join(fontsDir, `${b.family}.ttf`));
119
120
  }
120
121
  }
122
+ /**
123
+ * Why the copy of a static font linked into the app's android/ or ios/ project differs from the generated TTF, if it does.
124
+ */
125
+ function staleLinkedFont(projectRoot, family, ttfPath) {
126
+ const copies = [
127
+ ...(node_fs_1.default.existsSync(node_path_1.default.join(projectRoot, 'android'))
128
+ ? [node_path_1.default.join(projectRoot, ANDROID_FONTS_DIR, `${family}.ttf`)]
129
+ : []),
130
+ ...(findIosApp(projectRoot)
131
+ ? [
132
+ node_path_1.default.join(projectRoot, 'ios', IOS_NANOICONS_FONTS_DIR, node_path_1.default.basename(ttfPath)),
133
+ ]
134
+ : []),
135
+ ];
136
+ const ttf = node_fs_1.default.readFileSync(ttfPath);
137
+ for (const copy of copies) {
138
+ const relative = node_path_1.default.relative(projectRoot, copy);
139
+ if (!node_fs_1.default.existsSync(copy))
140
+ return `${relative} is missing`;
141
+ if (!node_fs_1.default.readFileSync(copy).equals(ttf))
142
+ return `${relative} is out of date`;
143
+ }
144
+ return undefined;
145
+ }
121
146
  async function linkAndroid(projectRoot, staticFonts, builtFonts) {
122
147
  syncAndroidFontAssets(node_path_1.default.join(projectRoot, ANDROID_FONTS_DIR), staticFonts, builtFonts.map((b) => b.fontFamily));
123
148
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Whether `build`, run into a temp dir, writes the same files as those in `outputDir`.
3
+ * In `mapFile` the stored input fingerprint `m.h` is ignored.
4
+ */
5
+ export declare function buildsSameOutputs(outputDir: string, mapFile: string, build: (tempDir: string) => Promise<unknown>): Promise<boolean>;
@@ -0,0 +1,45 @@
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.buildsSameOutputs = buildsSameOutputs;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Whether `build`, run into a temp dir, writes the same files as those in `outputDir`.
12
+ * In `mapFile` the stored input fingerprint `m.h` is ignored.
13
+ */
14
+ async function buildsSameOutputs(outputDir, mapFile, build) {
15
+ const tempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'nano-check-'));
16
+ try {
17
+ await build(tempDir);
18
+ return fs_1.default
19
+ .readdirSync(tempDir)
20
+ .every((entry) => sameEntry(path_1.default.join(tempDir, entry), path_1.default.join(outputDir, entry), mapFile));
21
+ }
22
+ finally {
23
+ fs_1.default.rmSync(tempDir, { recursive: true, force: true });
24
+ }
25
+ }
26
+ function sameEntry(built, existing, mapFile) {
27
+ if (!fs_1.default.existsSync(existing))
28
+ return false;
29
+ if (fs_1.default.statSync(built).isDirectory()) {
30
+ if (!fs_1.default.statSync(existing).isDirectory())
31
+ return false;
32
+ const entries = fs_1.default.readdirSync(built).sort();
33
+ return (entries.join('\n') === fs_1.default.readdirSync(existing).sort().join('\n') &&
34
+ entries.every((entry) => sameEntry(path_1.default.join(built, entry), path_1.default.join(existing, entry), mapFile)));
35
+ }
36
+ if (path_1.default.basename(built) === mapFile) {
37
+ return withoutInputHash(built) === withoutInputHash(existing);
38
+ }
39
+ return fs_1.default.readFileSync(built).equals(fs_1.default.readFileSync(existing));
40
+ }
41
+ function withoutInputHash(file) {
42
+ const map = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
43
+ delete map?.m?.h;
44
+ return JSON.stringify(map);
45
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const createNanoIconSet = (...args) => {
3
- const { createIconSet } = require('./createNanoIconsSet');
3
+ const { createIconSet } = require('../module/createNanoIconsSet.web.js');
4
4
  return createIconSet(...args);
5
5
  };
6
6
  const plugin = require('./plugin/src/index')
@@ -2,7 +2,8 @@ import type { IconSetConfig, BuiltFont } from './types';
2
2
  /**
3
3
  * Build TTF + glyphmap for all icon sets.
4
4
  * Reports every broken icon, then fails the prebuild so no set is silently left unlinked.
5
+ * When frozen, fails the prebuild instead when a set is out of date, and builds nothing.
5
6
  * EXPO_DEBUG adds the per-file processing details.
6
7
  */
7
- export declare function buildAllFonts(iconSets: IconSetConfig[], projectRoot: string): Promise<BuiltFont[]>;
8
- export declare function getOrBuildFonts(projectRoot: string, iconSets: IconSetConfig[]): Promise<BuiltFont[]>;
8
+ export declare function buildAllFonts(iconSets: IconSetConfig[], projectRoot: string, frozen?: boolean): Promise<BuiltFont[]>;
9
+ export declare function getOrBuildFonts(projectRoot: string, iconSets: IconSetConfig[], frozen?: boolean): Promise<BuiltFont[]>;
@@ -3,20 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildAllFonts = buildAllFonts;
4
4
  exports.getOrBuildFonts = getOrBuildFonts;
5
5
  const index_1 = require("../../cli/index");
6
+ const frozen_1 = require("./frozen");
6
7
  /**
7
8
  * Build TTF + glyphmap for all icon sets.
8
9
  * Reports every broken icon, then fails the prebuild so no set is silently left unlinked.
10
+ * When frozen, fails the prebuild instead when a set is out of date, and builds nothing.
9
11
  * EXPO_DEBUG adds the per-file processing details.
10
12
  */
11
- async function buildAllFonts(iconSets, projectRoot) {
13
+ async function buildAllFonts(iconSets, projectRoot, frozen) {
12
14
  const logger = await (0, index_1.createQuietLogger)((0, index_1.detectExpoLogLevel)());
15
+ const scope = (0, frozen_1.frozenScope)(frozen);
16
+ if (scope !== 'none') {
17
+ (0, frozen_1.failFrozenPrebuild)(await (0, index_1.checkAllFonts)(iconSets, projectRoot, {
18
+ existingOnly: scope === 'existing',
19
+ }));
20
+ }
13
21
  return (0, index_1.buildAllFonts)(iconSets, projectRoot, { logger });
14
22
  }
15
23
  // Single build run per process; reused across ios/android mods.
16
24
  let _buildPromise = null;
17
- function getOrBuildFonts(projectRoot, iconSets) {
25
+ function getOrBuildFonts(projectRoot, iconSets, frozen) {
18
26
  if (!_buildPromise) {
19
- _buildPromise = buildAllFonts(iconSets, projectRoot);
27
+ _buildPromise = buildAllFonts(iconSets, projectRoot, frozen);
20
28
  }
21
29
  return _buildPromise;
22
30
  }
@@ -1,3 +1,3 @@
1
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[]>;
2
+ export declare function buildAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, frozen?: boolean): Promise<BuiltSymbolSet[]>;
3
+ export declare function getOrBuildSymbols(projectRoot: string, symbolSets: SymbolSetConfig[], frozen?: boolean): Promise<BuiltSymbolSet[]>;
@@ -3,16 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildAllSymbols = buildAllSymbols;
4
4
  exports.getOrBuildSymbols = getOrBuildSymbols;
5
5
  const index_1 = require("../../cli/index");
6
+ const frozen_1 = require("./frozen");
6
7
  // Build all symbol sets.
7
- async function buildAllSymbols(symbolSets, projectRoot) {
8
+ async function buildAllSymbols(symbolSets, projectRoot, frozen) {
8
9
  const logger = await (0, index_1.createQuietLogger)((0, index_1.detectExpoLogLevel)());
10
+ const scope = (0, frozen_1.frozenScope)(frozen);
11
+ if (scope !== 'none') {
12
+ (0, frozen_1.failFrozenPrebuild)(await (0, index_1.checkAllSymbols)(symbolSets, projectRoot, {
13
+ existingOnly: scope === 'existing',
14
+ }));
15
+ }
9
16
  return (0, index_1.buildAllSymbols)(symbolSets, projectRoot, { logger });
10
17
  }
11
18
  // Single build run per process; reused across mods.
12
19
  let _buildPromise = null;
13
- function getOrBuildSymbols(projectRoot, symbolSets) {
20
+ function getOrBuildSymbols(projectRoot, symbolSets, frozen) {
14
21
  if (!_buildPromise) {
15
- _buildPromise = buildAllSymbols(symbolSets, projectRoot);
22
+ _buildPromise = buildAllSymbols(symbolSets, projectRoot, frozen);
16
23
  }
17
24
  return _buildPromise;
18
25
  }
@@ -0,0 +1,3 @@
1
+ import type { StaleSet } from '../../cli/index';
2
+ export declare function frozenScope(frozen: boolean | undefined): 'all' | 'existing' | 'none';
3
+ export declare function failFrozenPrebuild(stale: StaleSet[]): void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.frozenScope = frozenScope;
4
+ exports.failFrozenPrebuild = failFrozenPrebuild;
5
+ function frozenScope(frozen) {
6
+ if (frozen !== undefined)
7
+ return frozen ? 'all' : 'none';
8
+ const ci = process.env.CI?.toLowerCase();
9
+ return ci && ci !== 'false' && ci !== '0' ? 'existing' : 'none';
10
+ }
11
+ function failFrozenPrebuild(stale) {
12
+ if (!stale.length)
13
+ return;
14
+ const sets = stale
15
+ .map(({ name, reason }) => `${name} (${reason})`)
16
+ .join(', ');
17
+ throw new Error(`[react-native-nano-icons] frozen is on, but ${stale.length === 1 ? '1 set is' : `${stale.length} sets are`} out of date: ${sets}. Rebuild them without frozen, e.g. with a local prebuild, and commit the generated files.`);
18
+ }
@@ -5,11 +5,11 @@ const withNanoIconsSymbolLinking_1 = require("./withNanoIconsSymbolLinking");
5
5
  const withNanoIconsDrawableLinking_1 = require("./withNanoIconsDrawableLinking");
6
6
  const withNanoIcons = (config, options) => {
7
7
  if (options?.iconSets?.length) {
8
- config = (0, withNanoIconsFontLinking_1.withNanoIconsFontLinking)(config, options.iconSets);
8
+ config = (0, withNanoIconsFontLinking_1.withNanoIconsFontLinking)(config, options.iconSets, options.frozen);
9
9
  }
10
10
  if (options?.symbolSets?.length) {
11
- config = (0, withNanoIconsSymbolLinking_1.withNanoIconsSymbolLinking)(config, options.symbolSets);
12
- config = (0, withNanoIconsDrawableLinking_1.withNanoIconsDrawableLinking)(config, options.symbolSets);
11
+ config = (0, withNanoIconsSymbolLinking_1.withNanoIconsSymbolLinking)(config, options.symbolSets, options.frozen);
12
+ config = (0, withNanoIconsDrawableLinking_1.withNanoIconsDrawableLinking)(config, options.symbolSets, options.frozen);
13
13
  }
14
14
  return config;
15
15
  };
@@ -12,6 +12,8 @@ export interface IconSetConfig {
12
12
  upm?: number;
13
13
  /** Safe zone inside UPM for glyphs (default upm * 1020 / 1024, i.e. 1020 at the default upm). Must not exceed upm. */
14
14
  safeZone?: number;
15
+ /** Max distance between the font's quadratic curves and the SVG curves, as a fraction of the em (default 1/512). Must be positive. */
16
+ curveTolerance?: number;
15
17
  /** First Unicode codepoint for glyphs (default 0xe900). Hex string or number. */
16
18
  startUnicode?: number | string;
17
19
  /**
@@ -67,6 +69,14 @@ export interface BuiltSymbolSet {
67
69
  export interface NanoIconsPluginOptions {
68
70
  iconSets?: IconSetConfig[];
69
71
  symbolSets?: SymbolSetConfig[];
72
+ /**
73
+ * Fail prebuild when a set's generated files are out of date, instead of regenerating them.
74
+ *
75
+ * - unset: on in CI (`CI` is set and not `false` or `0`) for the sets whose generated files exist; the others are built.
76
+ * - `true`: on for every set, also outside CI.
77
+ * - `false`: off.
78
+ */
79
+ frozen?: boolean;
70
80
  }
71
81
  /**
72
82
  * Result of building one icon set.
@@ -5,4 +5,4 @@ import type { SymbolSetConfig } from './types';
5
5
  * compiles them automatically and they resolve by name — the native-tab-bar
6
6
  * counterpart to the iOS asset catalog, so no gradle changes are needed.
7
7
  */
8
- export declare function withNanoIconsDrawableLinking(config: Parameters<typeof withDangerousMod>[0], symbolSets: SymbolSetConfig[]): ReturnType<typeof withDangerousMod>;
8
+ export declare function withNanoIconsDrawableLinking(config: Parameters<typeof withDangerousMod>[0], symbolSets: SymbolSetConfig[], frozen?: boolean): ReturnType<typeof withDangerousMod>;
@@ -14,11 +14,11 @@ const ANDROID_DRAWABLES_DIR = 'app/src/main/res/drawable';
14
14
  * compiles them automatically and they resolve by name — the native-tab-bar
15
15
  * counterpart to the iOS asset catalog, so no gradle changes are needed.
16
16
  */
17
- function withNanoIconsDrawableLinking(config, symbolSets) {
17
+ function withNanoIconsDrawableLinking(config, symbolSets, frozen) {
18
18
  return (0, config_plugins_1.withDangerousMod)(config, [
19
19
  'android',
20
20
  async (config) => {
21
- const built = await (0, buildSymbols_1.getOrBuildSymbols)(config.modRequest.projectRoot, symbolSets);
21
+ const built = await (0, buildSymbols_1.getOrBuildSymbols)(config.modRequest.projectRoot, symbolSets, frozen);
22
22
  if (!built?.length)
23
23
  return config;
24
24
  const drawableDir = path_1.default.join(config.modRequest.platformProjectRoot, ANDROID_DRAWABLES_DIR);
@@ -8,12 +8,12 @@ import type { IconSetConfig } from './types';
8
8
  * the .ttf via a relative path outside ios/ leaves stale fonts in the .app
9
9
  * bundle when only the file contents change.
10
10
  */
11
- export declare function withNanoIconsIos(config: Parameters<typeof withXcodeProject>[0], iconSets: IconSetConfig[]): ReturnType<typeof withXcodeProject>;
11
+ export declare function withNanoIconsIos(config: Parameters<typeof withXcodeProject>[0], iconSets: IconSetConfig[], frozen?: boolean): ReturnType<typeof withXcodeProject>;
12
12
  /**
13
13
  * Copy TTFs to Android assets/fonts.
14
14
  */
15
- export declare function withNanoIconsAndroid(config: Parameters<typeof withDangerousMod>[0], iconSets: IconSetConfig[]): ReturnType<typeof withDangerousMod>;
15
+ export declare function withNanoIconsAndroid(config: Parameters<typeof withDangerousMod>[0], iconSets: IconSetConfig[], frozen?: boolean): ReturnType<typeof withDangerousMod>;
16
16
  /**
17
17
  * Apply iOS and Android font linking.
18
18
  */
19
- export declare function withNanoIconsFontLinking(config: Parameters<typeof withNanoIconsIos>[0], iconSets: IconSetConfig[]): ReturnType<typeof withNanoIconsAndroid>;
19
+ export declare function withNanoIconsFontLinking(config: Parameters<typeof withNanoIconsIos>[0], iconSets: IconSetConfig[], frozen?: boolean): ReturnType<typeof withNanoIconsAndroid>;
@@ -21,9 +21,9 @@ const IOS_FONTS_GROUP = 'Resources';
21
21
  * the .ttf via a relative path outside ios/ leaves stale fonts in the .app
22
22
  * bundle when only the file contents change.
23
23
  */
24
- function withNanoIconsIos(config, iconSets) {
24
+ function withNanoIconsIos(config, iconSets, frozen) {
25
25
  config = (0, config_plugins_1.withXcodeProject)(config, async (config) => {
26
- const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
26
+ const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets, frozen);
27
27
  const bundled = built?.filter((b) => b.linking !== 'dynamic') ?? [];
28
28
  if (!bundled.length)
29
29
  return config;
@@ -49,7 +49,7 @@ function withNanoIconsIos(config, iconSets) {
49
49
  return config;
50
50
  });
51
51
  config = (0, config_plugins_1.withInfoPlist)(config, async (config) => {
52
- const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
52
+ const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets, frozen);
53
53
  const bundled = built?.filter((b) => b.linking !== 'dynamic') ?? [];
54
54
  if (!bundled.length)
55
55
  return config;
@@ -74,11 +74,11 @@ function getUIAppFonts(infoPlist) {
74
74
  /**
75
75
  * Copy TTFs to Android assets/fonts.
76
76
  */
77
- function withNanoIconsAndroid(config, iconSets) {
77
+ function withNanoIconsAndroid(config, iconSets, frozen) {
78
78
  return (0, config_plugins_1.withDangerousMod)(config, [
79
79
  'android',
80
80
  async (config) => {
81
- const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
81
+ const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets, frozen);
82
82
  const bundled = built?.filter((b) => b.linking !== 'dynamic') ?? [];
83
83
  (0, index_1.syncAndroidFontAssets)(path_1.default.join(config.modRequest.platformProjectRoot, ANDROID_ASSETS_FONTS_DIR), bundled, built?.map((b) => b.fontFamily) ?? []);
84
84
  return config;
@@ -88,8 +88,8 @@ function withNanoIconsAndroid(config, iconSets) {
88
88
  /**
89
89
  * Apply iOS and Android font linking.
90
90
  */
91
- function withNanoIconsFontLinking(config, iconSets) {
92
- config = withNanoIconsIos(config, iconSets);
93
- config = withNanoIconsAndroid(config, iconSets);
91
+ function withNanoIconsFontLinking(config, iconSets, frozen) {
92
+ config = withNanoIconsIos(config, iconSets, frozen);
93
+ config = withNanoIconsAndroid(config, iconSets, frozen);
94
94
  return config;
95
95
  }
@@ -5,4 +5,4 @@ import type { SymbolSetConfig } from './types';
5
5
  * The Expo prebuild template creates and links that catalog, so no pbxproj
6
6
  * changes are needed — actool compiles them and they load by name.
7
7
  */
8
- export declare function withNanoIconsSymbolLinking(config: Parameters<typeof withDangerousMod>[0], symbolSets: SymbolSetConfig[]): ReturnType<typeof withDangerousMod>;
8
+ export declare function withNanoIconsSymbolLinking(config: Parameters<typeof withDangerousMod>[0], symbolSets: SymbolSetConfig[], frozen?: boolean): ReturnType<typeof withDangerousMod>;
@@ -14,11 +14,11 @@ const buildSymbols_1 = require("./buildSymbols");
14
14
  * The Expo prebuild template creates and links that catalog, so no pbxproj
15
15
  * changes are needed — actool compiles them and they load by name.
16
16
  */
17
- function withNanoIconsSymbolLinking(config, symbolSets) {
17
+ function withNanoIconsSymbolLinking(config, symbolSets, frozen) {
18
18
  return (0, config_plugins_1.withDangerousMod)(config, [
19
19
  'ios',
20
20
  async (config) => {
21
- const built = await (0, buildSymbols_1.getOrBuildSymbols)(config.modRequest.projectRoot, symbolSets);
21
+ const built = await (0, buildSymbols_1.getOrBuildSymbols)(config.modRequest.projectRoot, symbolSets, frozen);
22
22
  if (!built?.length)
23
23
  return config;
24
24
  const projectName = config.modRequest.projectName;
@@ -9,7 +9,7 @@ exports.parseCliArgs = parseCliArgs;
9
9
  exports.main = main;
10
10
  exports.runCli = runCli;
11
11
  /**
12
- * Run from your app root: npx react-native-nano-icons [--verbose] [--path <dir|file>] [--dynamic] [--dynamic-app-config] [--help]
12
+ * Run from your app root: npx react-native-nano-icons [--verbose] [--path <dir|file>] [--dynamic] [--dynamic-app-config] [--check] [--help]
13
13
  *
14
14
  * Flags:
15
15
  * -h, --help Print usage and exit without building
@@ -21,6 +21,8 @@ exports.runCli = runCli;
21
21
  * use this for OTA font regeneration without running expo prebuild.
22
22
  * --dynamic-app-config Like --dynamic, but reads the config from the Expo app config
23
23
  * (app.json / app.config.js / app.config.ts) instead of .nanoicons.json.
24
+ * --check Report the sets whose files those flags would change or whose linked fonts are out of date,
25
+ * and exit with 1 if there are any. Writes and links nothing in the project.
24
26
  */
25
27
  const node_fs_1 = __importDefault(require("node:fs"));
26
28
  const node_path_1 = __importDefault(require("node:path"));
@@ -34,6 +36,9 @@ Options:
34
36
  --path <dir|file> Folder with .nanoicons.json, or the file itself. Default: current directory.
35
37
  --dynamic Rebuild only icon sets with linking: "dynamic". Skips native linking.
36
38
  --dynamic-app-config Like --dynamic, but reads the sets from the Expo app config.
39
+ --check Report the sets whose files a build would change or whose linked fonts
40
+ are out of date, and exit with 1 if there are any. Writes and links
41
+ nothing in the project.
37
42
  --verbose Show per-SVG processing details.
38
43
  -h, --help Show this help.`;
39
44
  const CONFIG_FILE_NAME = '.nanoicons.json';
@@ -41,6 +46,7 @@ const OPTIONS = {
41
46
  path: { type: 'string' },
42
47
  dynamic: { type: 'boolean' },
43
48
  'dynamic-app-config': { type: 'boolean' },
49
+ check: { type: 'boolean' },
44
50
  verbose: { type: 'boolean' },
45
51
  help: { type: 'boolean', short: 'h' },
46
52
  };
@@ -61,6 +67,7 @@ function parseCliArgs(args) {
61
67
  const options = {
62
68
  dynamic: false,
63
69
  appConfig: false,
70
+ check: false,
64
71
  verbose: false,
65
72
  help: false,
66
73
  };
@@ -101,6 +108,8 @@ function parseCliArgs(args) {
101
108
  options.dynamic = true;
102
109
  options.appConfig = true;
103
110
  }
111
+ if (token.name === 'check')
112
+ options.check = true;
104
113
  if (token.name === 'verbose')
105
114
  options.verbose = true;
106
115
  }
@@ -110,7 +119,7 @@ function parseCliArgs(args) {
110
119
  return options;
111
120
  }
112
121
  async function main(logger, options) {
113
- const { dynamic, appConfig } = options;
122
+ const { dynamic, appConfig, check } = options;
114
123
  const { appRoot, configRoot } = resolveRoots(options.path);
115
124
  const buildRoot = appConfig ? appRoot : configRoot;
116
125
  if (dynamic) {
@@ -120,10 +129,21 @@ async function main(logger, options) {
120
129
  ? (0, index_1.loadDynamicSetsFromAppConfig)(appRoot)
121
130
  : (0, index_1.loadDynamicIconSets)(configRoot);
122
131
  logger.succeed(`Found ${dynamicIconSets.length} dynamic icon set(s) — skipping native linking.`);
132
+ if (check) {
133
+ failIfStale(await (0, index_1.checkAllFonts)(dynamicIconSets, buildRoot, { logger }));
134
+ return;
135
+ }
123
136
  await (0, index_1.buildAllFonts)(dynamicIconSets, buildRoot, { logger });
124
137
  }
125
138
  else {
126
139
  const config = (0, index_1.loadNanoIconsConfig)(configRoot);
140
+ if (check) {
141
+ failIfStale(await (0, index_1.checkAllFonts)(config.iconSets ?? [], buildRoot, {
142
+ logger,
143
+ appRoot,
144
+ }), await (0, index_1.checkAllSymbols)(config.symbolSets ?? [], buildRoot, { logger }));
145
+ return;
146
+ }
127
147
  let buildError;
128
148
  if (config.iconSets?.length) {
129
149
  let built;
@@ -158,6 +178,15 @@ async function main(logger, options) {
158
178
  throw buildError;
159
179
  }
160
180
  }
181
+ function failIfStale(fonts, symbols = []) {
182
+ const names = [
183
+ ...fonts.map((set) => `${set.name}.ttf`),
184
+ ...symbols.map((set) => `${set.name} symbols`),
185
+ ];
186
+ if (!names.length)
187
+ return;
188
+ throw new Error(`${names.length} set${names.length === 1 ? ' is' : 's are'} out of date: ${names.join(', ')}. Run the same command without --check to rebuild ${names.length === 1 ? 'it' : 'them'}.`);
189
+ }
161
190
  function resolveRoots(target) {
162
191
  const cwd = process.cwd();
163
192
  if (!target)
@@ -1,5 +1,38 @@
1
1
  "use strict";
2
2
  // Tags and attribute names use the "{namespace}local" convention.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  Object.defineProperty(exports, "__esModule", { value: true });
4
37
  exports.XEl = exports.XLINK_NS = exports.SVG_NS = void 0;
5
38
  exports.svgTag = svgTag;
@@ -11,6 +44,7 @@ exports.replaceEl = replaceEl;
11
44
  exports.delAttrs = delAttrs;
12
45
  exports.parseSvgDocument = parseSvgDocument;
13
46
  exports.serializeSvg = serializeSvg;
47
+ const xmldom = __importStar(require("@xmldom/xmldom"));
14
48
  const xmldom_1 = require("@xmldom/xmldom");
15
49
  const svgPatterns_1 = require("../../utils/svgPatterns");
16
50
  exports.SVG_NS = 'http://www.w3.org/2000/svg';
@@ -130,6 +164,7 @@ function convertElement(node) {
130
164
  }
131
165
  return el;
132
166
  }
167
+ const XMLDOM_08_MESSAGE_DECORATION = /^\[xmldom \w+\]\t|\n@[^\n]*$/g;
133
168
  function parseSvgDocument(content) {
134
169
  let text = content;
135
170
  // svgs are fond of not declaring xlink
@@ -137,11 +172,11 @@ function parseSvgDocument(content) {
137
172
  text = text.replace(/<svg([^>]*)>/, (_m, attrs) => `<svg${attrs} xmlns:xlink="${exports.XLINK_NS}">`);
138
173
  }
139
174
  let parseError = null;
140
- const parser = new xmldom_1.DOMParser({
141
- onError: (_level, message) => {
142
- parseError = parseError ?? message;
143
- },
144
- });
175
+ const onError = (_level, message) => {
176
+ parseError =
177
+ parseError ?? message.replace(XMLDOM_08_MESSAGE_DECORATION, '');
178
+ };
179
+ const parser = new xmldom_1.DOMParser('onErrorStopParsing' in xmldom ? { onError } : { errorHandler: onError });
145
180
  const doc = parser.parseFromString(text, 'text/xml');
146
181
  const root = doc.documentElement;
147
182
  if (!root || parseError) {
@@ -34,7 +34,8 @@ function clamp(value, minv = 0.0, maxv = 1.0) {
34
34
  return Math.max(Math.min(value, maxv), minv);
35
35
  }
36
36
  function elOpacity(el) {
37
- return clamp(numberAttrib(el, 'opacity', 1));
37
+ const opacity = numberAttrib(el, 'opacity', 1);
38
+ return Number.isFinite(opacity) ? clamp(opacity) : 1;
38
39
  }
39
40
  // Groups with 0 < opacity < 1 and >1 child must be retained.
40
41
  // This over-retains groups; no difference unless children overlap.
@@ -8,8 +8,20 @@ const shape_1 = require("../shape");
8
8
  const transform_1 = require("../transform");
9
9
  const defs_1 = require("./defs");
10
10
  const stroke_1 = require("./stroke");
11
+ function moveRootOpacityToGroup(root) {
12
+ const opacity = root.attrib.get('opacity');
13
+ if (opacity === undefined)
14
+ return;
15
+ const group = new dom_1.XEl((0, dom_1.svgTag)('g'), [['opacity', opacity]]);
16
+ for (const child of [...root.children]) {
17
+ group.append(child);
18
+ }
19
+ root.append(group);
20
+ root.attrib.delete('opacity');
21
+ }
11
22
  function collapse(doc) {
12
23
  doc.syncTree();
24
+ moveRootOpacityToGroup(doc.root);
13
25
  // Reversed: we want leaves first. Materialize BEFORE mutating.
14
26
  const toProcess = [...doc.breadthFirst()].reverse();
15
27
  const defs = new dom_1.XEl((0, dom_1.svgTag)('defs'));
@@ -11,7 +11,6 @@ export declare function parseCompileTtfFromGlyphsError(err: unknown, codepointTo
11
11
  */
12
12
  export declare function compileTtfFromGlyphs(opts: {
13
13
  glyphs: FontGlyph[];
14
- outTtfPath: string;
15
14
  fontName: string;
16
15
  upm: number;
17
16
  ascent: number;
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseCompileTtfFromGlyphsError = parseCompileTtfFromGlyphsError;
7
7
  exports.compileTtfFromGlyphs = compileTtfFromGlyphs;
8
8
  exports.compileWoff2FromTtf = compileWoff2FromTtf;
9
- const node_fs_1 = __importDefault(require("node:fs"));
10
- const node_path_1 = __importDefault(require("node:path"));
11
9
  const metrics_1 = require("./metrics");
12
- const config_1 = require("../pipeline/config");
13
10
  const svg2ttf_1 = __importDefault(require("svg2ttf"));
14
11
  const fonteditor_core_1 = require("fonteditor-core");
15
12
  const svgPatterns_1 = require("../../utils/svgPatterns");
@@ -57,7 +54,7 @@ function parseCompileTtfFromGlyphsError(err, codepointToIcon) {
57
54
  * Builds SVG font XML directly (no intermediate files), then converts via svg2ttf.
58
55
  */
59
56
  async function compileTtfFromGlyphs(opts) {
60
- const { glyphs, outTtfPath, fontName, upm, ascent, descent } = opts;
57
+ const { glyphs, fontName, upm, ascent, descent } = opts;
61
58
  const lineGap = opts.lineGap ?? 0;
62
59
  if (glyphs.length === 0)
63
60
  throw new Error('No glyphs to compile');
@@ -70,10 +67,7 @@ async function compileTtfFromGlyphs(opts) {
70
67
  });
71
68
  const ttfRaw = (0, svg2ttf_1.default)(svgFontString, { ts: 0 });
72
69
  const rawBuf = Buffer.from(ttfRaw.buffer);
73
- const fixedBuf = (0, metrics_1.forceTtfMetrics)(rawBuf, upm, ascent, descent, lineGap);
74
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(outTtfPath), { recursive: true });
75
- (0, config_1.writeFileAtomic)(outTtfPath, fixedBuf);
76
- return fixedBuf;
70
+ return (0, metrics_1.forceTtfMetrics)(rawBuf, upm, ascent, descent, lineGap);
77
71
  }
78
72
  let woff2Ready;
79
73
  async function compileWoff2FromTtf(ttfBuffer) {
@@ -1,7 +1,8 @@
1
+ import type { PathKitModule } from '../pathkit/types';
1
2
  import type { NanoLogger } from '../types';
2
3
  import type { ParsedPath } from './parse';
3
4
  /**
4
5
  * Merge consecutive same-color paths into single compound paths.
5
6
  * Preserves z-order: only merges runs of adjacent paths with identical fill color.
6
7
  */
7
- export declare function mergeSameColorPaths(paths: ParsedPath[], logger?: NanoLogger): ParsedPath[];
8
+ export declare function mergeSameColorPaths(paths: ParsedPath[], pathkit: PathKitModule, logger?: NanoLogger): ParsedPath[];