react-native-nano-icons 1.0.0 → 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 (120) 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 +9 -2
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
  6. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +122 -0
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +60 -0
  8. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +0 -39
  9. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +2 -16
  10. package/ios/NanoIconView.mm +17 -5
  11. package/ios/NanoIconsFontLoader.mm +5 -0
  12. package/lib/commonjs/cli/build.d.ts +26 -0
  13. package/lib/commonjs/cli/build.js +174 -64
  14. package/lib/commonjs/cli/buildSymbols.d.ts +17 -0
  15. package/lib/commonjs/cli/buildSymbols.js +103 -42
  16. package/lib/commonjs/cli/expoConfig.d.ts +10 -0
  17. package/lib/commonjs/cli/expoConfig.js +22 -7
  18. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  19. package/lib/commonjs/cli/fingerprint.js +36 -0
  20. package/lib/commonjs/cli/index.d.ts +2 -2
  21. package/lib/commonjs/cli/index.js +3 -1
  22. package/lib/commonjs/cli/link.d.ts +4 -0
  23. package/lib/commonjs/cli/link.js +25 -0
  24. package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
  25. package/lib/commonjs/cli/sameOutputs.js +45 -0
  26. package/lib/commonjs/index.node.js +1 -1
  27. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
  28. package/lib/commonjs/plugin/src/buildFonts.js +11 -3
  29. package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
  30. package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
  31. package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
  32. package/lib/commonjs/plugin/src/frozen.js +18 -0
  33. package/lib/commonjs/plugin/src/index.js +3 -3
  34. package/lib/commonjs/plugin/src/types.d.ts +10 -0
  35. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
  36. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
  37. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
  38. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
  39. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
  40. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
  41. package/lib/commonjs/scripts/cli.js +31 -2
  42. package/lib/commonjs/src/core/flatten/dom.js +40 -5
  43. package/lib/commonjs/src/core/flatten/element.js +2 -1
  44. package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
  45. package/lib/commonjs/src/core/font/compile.d.ts +0 -1
  46. package/lib/commonjs/src/core/font/compile.js +2 -8
  47. package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
  48. package/lib/commonjs/src/core/glyph/merge.js +27 -36
  49. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
  50. package/lib/commonjs/src/core/glyph/parse.js +31 -18
  51. package/lib/commonjs/src/core/pathkit/winding.d.ts +7 -1
  52. package/lib/commonjs/src/core/pathkit/winding.js +172 -0
  53. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  54. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  55. package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
  56. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  57. package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
  58. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
  59. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  60. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  61. package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
  62. package/lib/commonjs/src/utils/fingerPrint.js +3 -1
  63. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  64. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  65. package/lib/module/createNanoIconsSet.js +0 -1
  66. package/lib/module/createNanoIconsSet.native.js +26 -21
  67. package/lib/module/createNanoIconsSet.shared.js +32 -18
  68. package/lib/module/createNanoIconsSet.web.js +103 -61
  69. package/lib/module/devServerFont.js +1 -1
  70. package/lib/module/devServerFont.web.js +3 -5
  71. package/lib/module/fontIntegrity.js +20 -38
  72. package/lib/module/fontIntegrity.web.js +48 -0
  73. package/lib/module/fontIntegrityStore.js +65 -0
  74. package/lib/module/index.js +1 -1
  75. package/lib/module/index.node.js +1 -1
  76. package/lib/module/index.web.js +4 -0
  77. package/lib/module/loadDynamicFont.js +3 -15
  78. package/lib/module/specs/NanoIconViewNativeComponent.ts +3 -2
  79. package/lib/module/utils/fingerPrint.js +3 -2
  80. package/lib/module/utils/fontIdentity.js +2 -2
  81. package/lib/module/utils/fontScale.js +23 -0
  82. package/lib/module/utils/glyphRuntime.js +13 -0
  83. package/lib/module/utils/iconAccessibility.js +26 -0
  84. package/lib/module/utils/iconPropsEqual.js +27 -0
  85. package/lib/module/utils/webCss.js +26 -0
  86. package/lib/module/utils/webStyle.js +86 -0
  87. package/lib/module/webFont.js +33 -0
  88. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  89. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  90. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  91. package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
  92. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  93. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  94. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  95. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  96. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  97. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  98. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  99. package/lib/typescript/src/index.d.ts +2 -1
  100. package/lib/typescript/src/index.web.d.ts +5 -0
  101. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  102. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +3 -2
  103. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  104. package/lib/typescript/src/types.d.ts +37 -9
  105. package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
  106. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  107. package/lib/typescript/src/utils/fontScale.d.ts +2 -0
  108. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  109. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  110. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  111. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  112. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  113. package/lib/typescript/src/webFont.d.ts +6 -0
  114. package/package.json +19 -3
  115. package/src/const/codegenPrimitives.ts +3 -3
  116. package/src/specs/NanoIconViewNativeComponent.ts +3 -2
  117. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  118. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  119. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  120. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
@@ -1,46 +1,7 @@
1
1
  #include "NanoIconViewShadowNode.h"
2
2
 
3
- #include <react/renderer/core/LayoutConstraints.h>
4
- #include <react/renderer/core/LayoutContext.h>
5
-
6
3
  namespace facebook::react {
7
4
 
8
5
  extern const char NanoIconViewComponentName[] = "NanoIconView";
9
6
 
10
- Size NanoIconViewShadowNode::measureContent(
11
- const LayoutContext &layoutContext,
12
- const LayoutConstraints &layoutConstraints) const {
13
- const auto &props = getConcreteProps();
14
- const Float height =
15
- props.size * (props.allowFontScaling ? layoutContext.fontSizeMultiplier : 1);
16
- const Float width = props.unitsPerEm > 0
17
- ? height * static_cast<Float>(props.advanceWidth) / static_cast<Float>(props.unitsPerEm)
18
- : height;
19
- return layoutConstraints.clamp({width, height});
20
- }
21
-
22
- bool NanoIconViewShadowNode::shouldNewRevisionDirtyMeasurement(
23
- const ShadowNode & /*sourceShadowNode*/,
24
- const ShadowNodeFragment & /*fragment*/) const {
25
- return false;
26
- }
27
-
28
- void NanoIconViewShadowNode::completeClone(
29
- const ShadowNode &sourceShadowNode,
30
- const ShadowNodeFragment &fragment) {
31
- ConcreteViewShadowNode::completeClone(sourceShadowNode, fragment);
32
- if (fragment.props == nullptr) {
33
- return;
34
- }
35
- const auto &oldProps =
36
- static_cast<const NanoIconViewProps &>(*sourceShadowNode.getProps());
37
- const auto &newProps = getConcreteProps();
38
- if (oldProps.size != newProps.size ||
39
- oldProps.allowFontScaling != newProps.allowFontScaling ||
40
- oldProps.advanceWidth != newProps.advanceWidth ||
41
- oldProps.unitsPerEm != newProps.unitsPerEm) {
42
- dirtyLayout();
43
- }
44
- }
45
-
46
7
  } // namespace facebook::react
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <react/renderer/components/RNNanoIconsSpec/EventEmitters.h>
4
- #include <react/renderer/components/RNNanoIconsSpec/Props.h>
4
+ #include <react/renderer/components/RNNanoIconsSpec/NanoIconProps.h>
5
5
  #include <react/renderer/components/view/ConcreteViewShadowNode.h>
6
6
  #include <jsi/jsi.h>
7
7
 
@@ -12,7 +12,7 @@ JSI_EXPORT extern const char NanoIconViewComponentName[];
12
12
  class JSI_EXPORT NanoIconViewShadowNode final
13
13
  : public ConcreteViewShadowNode<
14
14
  NanoIconViewComponentName,
15
- NanoIconViewProps,
15
+ NanoIconProps,
16
16
  NanoIconViewEventEmitter> {
17
17
  public:
18
18
  using ConcreteViewShadowNode::ConcreteViewShadowNode;
@@ -20,22 +20,8 @@ class JSI_EXPORT NanoIconViewShadowNode final
20
20
  static ShadowNodeTraits BaseTraits() {
21
21
  auto traits = ConcreteViewShadowNode::BaseTraits();
22
22
  traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
23
- traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
24
23
  return traits;
25
24
  }
26
-
27
- Size measureContent(
28
- const LayoutContext &layoutContext,
29
- const LayoutConstraints &layoutConstraints) const override;
30
-
31
- void completeClone(
32
- const ShadowNode &sourceShadowNode,
33
- const ShadowNodeFragment &fragment) override;
34
-
35
- protected:
36
- bool shouldNewRevisionDirtyMeasurement(
37
- const ShadowNode &sourceShadowNode,
38
- const ShadowNodeFragment &fragment) const override;
39
25
  };
40
26
 
41
27
  } // namespace facebook::react
@@ -4,7 +4,7 @@
4
4
  #import <React/RCTConversions.h>
5
5
  #import <React/RCTFabricComponentsPlugins.h>
6
6
  #import <react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h>
7
- #import <react/renderer/components/RNNanoIconsSpec/Props.h>
7
+ #import <react/renderer/components/RNNanoIconsSpec/NanoIconProps.h>
8
8
  #import "NanoIconInlineBaseline.h"
9
9
 
10
10
  using namespace facebook::react;
@@ -77,7 +77,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
77
77
 
78
78
  - (instancetype)initWithFrame:(CGRect)frame {
79
79
  if (self = [super initWithFrame:frame]) {
80
- static const auto defaultProps = std::make_shared<const NanoIconViewProps>();
80
+ static const auto defaultProps = std::make_shared<const NanoIconProps>();
81
81
  _props = defaultProps;
82
82
  self.opaque = NO;
83
83
  self.backgroundColor = [UIColor clearColor];
@@ -221,6 +221,14 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
221
221
  // Flip to CoreText coordinates (Y-up) and apply fit scale.
222
222
  CGContextTranslateCTM(context, 0, bounds.size.height);
223
223
  CGContextScaleCTM(context, 1.0, -1.0);
224
+ const auto &viewProps = static_cast<const NanoIconProps &>(*_props);
225
+ if (viewProps.squareGlyphScale > 0) {
226
+ CGFloat glyphHeight = MIN(bounds.size.width, bounds.size.height) * viewProps.squareGlyphScale;
227
+ CGFloat glyphScale = glyphHeight / bounds.size.height;
228
+ CGFloat glyphWidth = glyphHeight * viewProps.advanceWidth / viewProps.unitsPerEm;
229
+ CGContextTranslateCTM(context, (bounds.size.width - glyphWidth) / 2, (bounds.size.height - glyphHeight) / 2);
230
+ CGContextScaleCTM(context, glyphScale, glyphScale);
231
+ }
224
232
  CGContextScaleCTM(context, _fitScale, _fitScale);
225
233
 
226
234
  size_t i = 0;
@@ -314,8 +322,8 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
314
322
  }
315
323
 
316
324
  - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps {
317
- const auto &oldViewProps = static_cast<const NanoIconViewProps &>(*_props);
318
- const auto &newViewProps = static_cast<const NanoIconViewProps &>(*props);
325
+ const auto &oldViewProps = static_cast<const NanoIconProps &>(*_props);
326
+ const auto &newViewProps = static_cast<const NanoIconProps &>(*props);
319
327
 
320
328
  BOOL fontChanged = NO;
321
329
  BOOL needsRedraw = NO;
@@ -354,6 +362,10 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
354
362
  needsRedraw = YES;
355
363
  }
356
364
 
365
+ if (oldViewProps.squareGlyphScale != newViewProps.squareGlyphScale) {
366
+ needsRedraw = YES;
367
+ }
368
+
357
369
  if (oldViewProps.tintLayers != newViewProps.tintLayers ||
358
370
  oldViewProps.codepoints != newViewProps.codepoints) {
359
371
  _tintable.assign(newViewProps.codepoints.size(), false);
@@ -406,7 +418,7 @@ static void NanoIconTrackLiveView(NanoIconView *view) {
406
418
  if (_font || _fontFamily.length == 0) return;
407
419
  _font = NanoIconResolveFont(_fontFamily, _fontSize);
408
420
  if (!_font) return;
409
- const auto &viewProps = static_cast<const NanoIconViewProps &>(*_props);
421
+ const auto &viewProps = static_cast<const NanoIconProps &>(*_props);
410
422
  [self _mapGlyphs:viewProps.codepoints];
411
423
  _metricsValid = NO;
412
424
  [self _setNeedsRedraw];
@@ -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,6 +3,7 @@ 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';
6
7
  export type SymbolSetConfig = {
7
8
  /** Folder of SVG files (relative to project root). */
8
9
  inputDir: string;
@@ -18,6 +19,22 @@ export declare class SymbolSetBuildError extends Error {
18
19
  built: BuiltSymbolSet[];
19
20
  constructor(message: string, built: BuiltSymbolSet[]);
20
21
  }
22
+ /**
23
+ * The input fingerprint of each symbol set: the value a build stores in its symbolmap as `m.h`.
24
+ */
25
+ export declare function fingerprintSymbolSets(symbolSets: SymbolSetConfig[], projectRoot: string): {
26
+ name: string;
27
+ hash: string;
28
+ }[];
29
+ /**
30
+ * Report the symbol sets whose generated files are out of date, without writing anything to the project.
31
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
32
+ * the set is built into a temp dir and compared with them. With `existingOnly`, sets without a symbolmap are skipped.
33
+ */
34
+ export declare function checkAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
35
+ logger?: NanoLogger;
36
+ existingOnly?: boolean;
37
+ }): Promise<StaleSet[]>;
21
38
  export declare function buildAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
22
39
  logger?: NanoLogger;
23
40
  keepOutputsOnFailure?: boolean;