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
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runFontPipeline = runFontPipeline;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
7
8
  const promises_1 = __importDefault(require("node:fs/promises"));
8
9
  const node_path_1 = __importDefault(require("node:path"));
9
10
  const compile_1 = require("../font/compile");
11
+ const quadratic_1 = require("../font/quadratic");
10
12
  const fontIdentity_1 = require("../../utils/fontIdentity");
11
13
  const config_1 = require("./config");
12
14
  const iconPool_1 = require("./iconPool");
@@ -22,12 +24,9 @@ async function runFontPipeline(config, paths, options) {
22
24
  (0, config_1.ensureDir)(paths.outputDir);
23
25
  const files = (await promises_1.default.readdir(paths.inputDir)).filter((f) => f.toLowerCase().endsWith('.svg'));
24
26
  const inputHash = options?.inputHash;
25
- const family = inputHash
26
- ? (0, fontIdentity_1.buildFontFamily)(config.fontFamily, inputHash)
27
- : config.fontFamily;
28
27
  const glyphMap = {
29
28
  m: {
30
- f: family,
29
+ f: config.fontFamily,
31
30
  u: config.upm,
32
31
  z: config.safeZone,
33
32
  s: config.startUnicode,
@@ -47,6 +46,7 @@ async function runFontPipeline(config, paths, options) {
47
46
  fontFamily: config.fontFamily,
48
47
  upm: config.upm,
49
48
  safeZone: config.safeZone,
49
+ curveTolerance: config.curveTolerance ?? quadratic_1.QUADRATIC_ERROR_BOUND_EM,
50
50
  })), options?.concurrency ?? (0, iconPool_1.defaultConcurrency)(), options?.preparedSvgCache, options?.svgWorkerPool, options?.svgHashByFile);
51
51
  for (const result of results) {
52
52
  for (const [level, msg] of result.logs)
@@ -76,20 +76,28 @@ async function runFontPipeline(config, paths, options) {
76
76
  }
77
77
  logger?.info(`Compiling TTF…`);
78
78
  const ttfPath = node_path_1.default.join(paths.outputDir, `${config.fontFamily}.ttf`);
79
+ const compile = (fontName) => (0, compile_1.compileTtfFromGlyphs)({
80
+ glyphs: allGlyphs,
81
+ fontName,
82
+ upm: config.upm,
83
+ ascent: config.upm,
84
+ descent: 0,
85
+ });
86
+ let family = config.fontFamily;
79
87
  let ttfBuffer;
80
88
  try {
81
- ttfBuffer = await (0, compile_1.compileTtfFromGlyphs)({
82
- glyphs: allGlyphs,
83
- outTtfPath: ttfPath,
84
- fontName: family,
85
- upm: config.upm,
86
- ascent: config.upm,
87
- descent: 0,
88
- });
89
+ ttfBuffer = await compile(family);
90
+ if (inputHash) {
91
+ family = (0, fontIdentity_1.buildFontFamily)(config.fontFamily, node_crypto_1.default.createHash('sha256').update(ttfBuffer).digest('hex'));
92
+ ttfBuffer = await compile(family);
93
+ }
89
94
  }
90
95
  catch (err) {
91
96
  (0, compile_1.parseCompileTtfFromGlyphsError)(err, codepointToIcon);
92
97
  }
98
+ glyphMap.m.f = family;
99
+ if (ttfBuffer)
100
+ (0, config_1.writeFileAtomic)(ttfPath, ttfBuffer);
93
101
  let woff2Path;
94
102
  if (config.web && ttfBuffer) {
95
103
  logger?.info(`Compiling WOFF2…`);
@@ -7,6 +7,8 @@ export type SymbolsPipelineConfig = {
7
7
  name: string;
8
8
  /** Symbol name prefix, e.g. "nano" → "nano.home". */
9
9
  prefix: string;
10
+ fit?: 'content' | 'viewBox';
11
+ scale?: number;
10
12
  };
11
13
  export type SymbolsPipelinePaths = {
12
14
  inputDir: string;
@@ -70,6 +70,8 @@ async function runSymbolPipeline(config, paths, options) {
70
70
  filePath: node_path_1.default.join(paths.inputDir, file),
71
71
  setName: config.name,
72
72
  prefix: config.prefix,
73
+ fit: config.fit ?? 'content',
74
+ scale: config.scale ?? 1,
73
75
  })), options?.concurrency ?? (0, iconPool_1.defaultConcurrency)(), options?.preparedSvgCache, options?.svgWorkerPool, options?.svgHashByFile);
74
76
  const resourceNameToFile = new Map();
75
77
  const assets = [];
@@ -1,2 +1,2 @@
1
- export declare function symbolsetContentsJson(svgFilename: string): string;
1
+ export declare function symbolsetContentsJson(svgFilename: string, multicolor?: boolean): string;
2
2
  export declare function catalogRootContentsJson(): string;
@@ -3,10 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.symbolsetContentsJson = symbolsetContentsJson;
5
5
  exports.catalogRootContentsJson = catalogRootContentsJson;
6
- function symbolsetContentsJson(svgFilename) {
6
+ // A symbol drawn in more than one colour prefers multicolor, so it keeps its
7
+ // colours wherever it is shown in its original rendering.
8
+ function symbolsetContentsJson(svgFilename, multicolor = false) {
7
9
  return JSON.stringify({
8
10
  info: { author: 'xcode', version: 1 },
9
- properties: { 'symbol-rendering-intent': 'template' },
11
+ properties: {
12
+ 'symbol-rendering-intent': multicolor ? 'multicolor' : 'template',
13
+ },
10
14
  symbols: [{ filename: svgFilename, idiom: 'universal' }],
11
15
  }, null, 2);
12
16
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KNOCKOUT_MARKER_FILL = exports.KNOCKOUT_ATTRIBUTE = void 0;
4
4
  exports.markKnockoutFills = markKnockoutFills;
5
5
  const xmldom_1 = require("@xmldom/xmldom");
6
+ const parse_1 = require("../glyph/parse");
6
7
  exports.KNOCKOUT_ATTRIBUTE = 'data-nano-knockout';
7
8
  exports.KNOCKOUT_MARKER_FILL = '#fe01fe';
8
9
  const ELEMENT_NODE = 1;
@@ -11,13 +12,13 @@ function styleDeclaration(property) {
11
12
  return new RegExp(`(^|;)\\s*${property}\\s*:([^;]*)`);
12
13
  }
13
14
  function explicitPaint(el, property) {
14
- const fromStyle = el.getAttribute('style')?.match(styleDeclaration(property));
15
+ const fromStyle = (0, parse_1.attribute)(el, 'style')?.match(styleDeclaration(property));
15
16
  if (fromStyle)
16
17
  return fromStyle[2].trim();
17
- return el.getAttribute(property);
18
+ return (0, parse_1.attribute)(el, property);
18
19
  }
19
20
  function setPaint(el, property, value) {
20
- const style = el.getAttribute('style');
21
+ const style = (0, parse_1.attribute)(el, 'style');
21
22
  if (style !== null) {
22
23
  el.setAttribute('style', style.replace(styleDeclaration(property), '$1'));
23
24
  }
@@ -28,6 +28,7 @@ export type ResolvedSymbolLayers = {
28
28
  export declare function isKnockoutFill(fill: string | null): boolean;
29
29
  export declare function resolveSymbolLayers(PathKit: PathKitModule, layers: SymbolLayerInput[], options?: {
30
30
  onKnockoutLayer?: (index: number) => void;
31
+ touchTolerance?: number;
31
32
  }): ResolvedSymbolLayers;
32
33
  /**
33
34
  * Tight bounding box [x, y, w, h] of path `d` strings in source coords, or null.
@@ -4,139 +4,180 @@ exports.isKnockoutFill = isKnockoutFill;
4
4
  exports.resolveSymbolLayers = resolveSymbolLayers;
5
5
  exports.contentBounds = contentBounds;
6
6
  const parse_1 = require("../../utils/parse");
7
+ const contours_1 = require("../pathkit/contours");
7
8
  const winding_1 = require("../pathkit/winding");
9
+ const OPAQUE_ALPHA = 0.999;
10
+ // Widest misalignment gap, as a share of the icon size.
11
+ const MAX_GAP_WIDTH_PER_SIZE = 0.001;
8
12
  function isKnockoutFill(fill) {
9
13
  if (fill === null)
10
14
  return false;
11
15
  const [r, g, b, a] = (0, parse_1.parseColor)(fill);
12
16
  return a >= 0.9 && r >= 240 && g >= 240 && b >= 240;
13
17
  }
18
+ function isOpaque(fill) {
19
+ return fill === null || (0, parse_1.parseColor)(fill)[3] >= OPAQUE_ALPHA;
20
+ }
14
21
  function knockoutFlags(layers) {
15
22
  if (layers.some((l) => l.knockout))
16
23
  return layers.map((l) => !!l.knockout);
17
24
  const whiteFlags = layers.map((l) => isKnockoutFill(l.fill));
18
25
  return whiteFlags.some((w) => !w) ? whiteFlags : layers.map(() => false);
19
26
  }
27
+ // Boolean ops on path data; a failed op returns its first operand.
20
28
  function pathOps(PathKit) {
21
- const Ops = PathKit.PathOp ?? {};
22
- const run = (a, b, op) => {
23
- if (a.trim() === '')
24
- return op === (Ops.UNION ?? 1) ? b : '';
25
- if (b.trim() === '')
26
- return op === (Ops.INTERSECT ?? 2) ? '' : a;
27
- const pa = PathKit.FromSVGString(a);
28
- const pb = PathKit.FromSVGString(b);
29
- const out = pa && pb ? PathKit.MakeFromOp(pa, pb, op) : null;
30
- pa?.delete?.();
31
- pb?.delete?.();
32
- if (!out)
33
- return a;
34
- const d = (0, winding_1.orientedPathData)(PathKit, out);
35
- out.delete?.();
36
- return d;
37
- };
38
29
  return {
39
- difference: (a, b) => run(a, b, Ops.DIFFERENCE ?? 0),
40
- union: (a, b) => run(a, b, Ops.UNION ?? 1),
41
- intersect: (a, b) => run(a, b, Ops.INTERSECT ?? 2),
30
+ difference: (a, b) => a.trim() === '' || b.trim() === ''
31
+ ? a
32
+ : ((0, winding_1.pathOpData)(PathKit, a, b, 'difference') ?? a),
33
+ intersect: (a, b) => a.trim() === '' || b.trim() === ''
34
+ ? ''
35
+ : ((0, winding_1.pathOpData)(PathKit, a, b, 'intersect') ?? a),
42
36
  };
43
37
  }
44
- function resolveWithKnockouts(PathKit, layers, flags, onKnockoutLayer) {
38
+ // Joins canonically wound paths into one path filling their union.
39
+ function joined(...ds) {
40
+ return ds.filter((d) => d.trim() !== '').join(' ');
41
+ }
42
+ // Resolves icons that have knockout layers.
43
+ function resolveWithKnockouts(PathKit, layers, flags, touchTolerance, onKnockoutLayer) {
45
44
  const ops = pathOps(PathKit);
45
+ const drawn = layers.map((layer) => (0, winding_1.canonicalWinding)(PathKit, layer.d, touchTolerance));
46
46
  const visible = new Array(layers.length).fill('');
47
+ const knockoutFootprint = joined(...drawn.filter((_, i) => flags[i]));
47
48
  let aboveAll = '';
48
- let aboveInk = '';
49
+ let knockoutsAbove = '';
50
+ let opaqueInkAbove = '';
51
+ let translucentInkAbove = '';
49
52
  for (let i = layers.length - 1; i >= 0; i--) {
50
- const d = layers[i].d;
51
- visible[i] = ops.difference(d, flags[i] ? aboveAll : aboveInk);
52
- aboveAll = ops.union(aboveAll, d);
53
- if (!flags[i])
54
- aboveInk = ops.union(aboveInk, d);
53
+ const d = drawn[i];
54
+ if (flags[i]) {
55
+ visible[i] = ops.difference(d, translucentInkAbove === ''
56
+ ? aboveAll
57
+ : joined(opaqueInkAbove, knockoutsAbove));
58
+ knockoutsAbove = joined(knockoutsAbove, d);
59
+ aboveAll = joined(aboveAll, d);
60
+ continue;
61
+ }
62
+ aboveAll = joined(aboveAll, d);
63
+ const covered = translucentInkAbove === ''
64
+ ? opaqueInkAbove
65
+ : joined(opaqueInkAbove, ops.intersect(translucentInkAbove, knockoutFootprint));
66
+ visible[i] = ops.difference(d, covered);
67
+ if (isOpaque(layers[i].fill)) {
68
+ opaqueInkAbove = joined(opaqueInkAbove, d);
69
+ }
70
+ else {
71
+ translucentInkAbove = joined(translucentInkAbove, d);
72
+ }
55
73
  }
56
74
  const emitted = [];
57
- let monochrome = '';
58
75
  layers.forEach((layer, i) => {
59
76
  const region = visible[i];
60
77
  if (region.trim() === '')
61
78
  return;
62
79
  if (!flags[i]) {
63
- emitted.push({ d: (0, winding_1.canonicalWinding)(PathKit, region), fill: layer.fill });
64
- monochrome = ops.union(monochrome, region);
80
+ emitted.push({
81
+ d: (0, winding_1.canonicalWinding)(PathKit, region, touchTolerance),
82
+ fill: layer.fill,
83
+ });
65
84
  return;
66
85
  }
67
- const inside = ops.intersect(region, monochrome);
68
- const outside = ops.difference(region, monochrome);
69
- const parts = [
70
- inside.trim() === '' ? '' : (0, winding_1.reversedWinding)(PathKit, inside),
71
- outside.trim() === '' ? '' : (0, winding_1.canonicalWinding)(PathKit, outside),
72
- ].filter((part) => part !== '');
73
- if (inside.trim() !== '')
86
+ const emit = (d) => emitted.push({ d, fill: layer.fill });
87
+ const ink = joined(...emitted.map((below) => below.d));
88
+ if (ink === '') {
89
+ emit((0, winding_1.canonicalWinding)(PathKit, region, touchTolerance));
90
+ return;
91
+ }
92
+ const inside = (0, winding_1.pathOpData)(PathKit, region, ink, 'intersect');
93
+ const outside = (0, winding_1.pathOpData)(PathKit, region, ink, 'difference');
94
+ if (inside === null || outside === null) {
95
+ onKnockoutLayer?.(i);
96
+ emit((0, winding_1.reversedWinding)(PathKit, region, touchTolerance));
97
+ return;
98
+ }
99
+ if (inside !== '')
74
100
  onKnockoutLayer?.(i);
75
- emitted.push({ d: parts.join(' '), fill: layer.fill });
76
- monochrome = ops.union(ops.difference(monochrome, inside), outside);
101
+ emit(joined((0, winding_1.reversedWinding)(PathKit, inside, touchTolerance), (0, winding_1.canonicalWinding)(PathKit, outside, touchTolerance)));
77
102
  });
78
- return { layers: emitted, monochrome: (0, winding_1.canonicalWinding)(PathKit, monochrome) };
103
+ return { layers: emitted, monochrome: joined(...emitted.map((l) => l.d)) };
79
104
  }
80
- function resolveOccluded(PathKit, layers) {
81
- const Ops = PathKit.PathOp ?? {};
82
- const DIFFERENCE = Ops.DIFFERENCE ?? 0;
83
- const UNION = Ops.UNION ?? 1;
84
- const isEmptyD = (d) => d.trim() === '';
85
- const emitted = [];
86
- // Walk top → bottom, tracking the union of everything above.
87
- let above = null;
88
- for (let i = layers.length - 1; i >= 0; i--) {
89
- const p = PathKit.FromSVGString(layers[i].d);
90
- if (!p) {
91
- emitted.push({ index: i, d: layers[i].d, fill: layers[i].fill });
92
- continue;
93
- }
94
- p.simplify();
95
- // visible region = path minus everything above
96
- let visibleD;
97
- if (above === null) {
98
- visibleD = p.toSVGString();
99
- }
100
- else {
101
- const visible = PathKit.MakeFromOp(p, above, DIFFERENCE);
102
- if (visible) {
103
- visible.simplify();
104
- visibleD = visible.toSVGString();
105
- visible.delete?.();
106
- }
107
- else {
108
- visibleD = p.toSVGString();
109
- }
110
- }
111
- if (!isEmptyD(visibleD)) {
112
- emitted.push({ index: i, d: visibleD, fill: layers[i].fill });
113
- }
114
- if (above === null) {
115
- above = p;
116
- }
117
- else {
118
- const newAbove = PathKit.MakeFromOp(above, p, UNION);
119
- p.delete?.();
120
- if (newAbove) {
121
- newAbove.simplify();
122
- above.delete?.();
123
- above = newAbove;
105
+ // Contours of a path: outlines positive area, holes negative.
106
+ function contoursOf(PathKit, d) {
107
+ const path = PathKit.FromSVGString(d);
108
+ if (!path)
109
+ return [];
110
+ const contours = (0, contours_1.orientedContours)(path.toCmds(), (0, contours_1.verbMap)(PathKit));
111
+ path.delete?.();
112
+ return contours;
113
+ }
114
+ // Length of a contour.
115
+ function perimeter(cmds, V) {
116
+ const points = (0, contours_1.contourToPolyline)(cmds, V);
117
+ return points.reduce((sum, [x, y], i) => {
118
+ const [nextX, nextY] = points[(i + 1) % points.length];
119
+ return sum + Math.hypot(nextX - x, nextY - y);
120
+ }, 0);
121
+ }
122
+ // Extends the back layer over misalignment gaps between layers.
123
+ function backLayerFillingGaps(PathKit, layers, touchTolerance) {
124
+ const [back, ...front] = layers;
125
+ const bounds = contentBounds(PathKit, layers.map((layer) => layer.d));
126
+ if (!back || !bounds || !front.every((layer) => isOpaque(layer.fill))) {
127
+ return layers;
128
+ }
129
+ const V = (0, contours_1.verbMap)(PathKit);
130
+ const area = ({ cmds }) => (0, contours_1.approxSignedAreaFromContourCmds)(cmds, V);
131
+ const maxGapWidth = MAX_GAP_WIDTH_PER_SIZE * Math.max(bounds[2], bounds[3]);
132
+ const pathData = ({ cmds }) => (0, contours_1.cmdsToPathData)(cmds, V);
133
+ const reversed = ({ cmds }) => (0, contours_1.cmdsToPathData)((0, winding_1.reversedContour)(cmds, V), V);
134
+ const ops = pathOps(PathKit);
135
+ const ink = (0, winding_1.canonicalWinding)(PathKit, layers.map((layer) => layer.d).join(' '), touchTolerance);
136
+ const patches = [];
137
+ for (const layer of layers) {
138
+ for (const hole of contoursOf(PathKit, layer.d)) {
139
+ if (area(hole) >= 0)
140
+ continue;
141
+ const uncovered = ops.difference(pathData(hole), ink);
142
+ const realHoles = [];
143
+ let hasGap = false;
144
+ for (const piece of contoursOf(PathKit, uncovered)) {
145
+ const pieceArea = area(piece);
146
+ if (pieceArea <= 0)
147
+ continue;
148
+ if ((2 * pieceArea) / perimeter(piece.cmds, V) < maxGapWidth) {
149
+ hasGap = true;
150
+ }
151
+ else {
152
+ realHoles.push(reversed(piece));
153
+ }
124
154
  }
155
+ if (hasGap)
156
+ patches.push(reversed(hole), ...realHoles);
125
157
  }
126
158
  }
127
- const monochrome = above?.toSVGString() ?? '';
128
- above?.delete?.();
159
+ return patches.length === 0
160
+ ? layers
161
+ : [{ ...back, d: [back.d, ...patches].join(' ') }, ...front];
162
+ }
163
+ // Resolves icons without knockouts.
164
+ function resolveStacked(PathKit, layers, touchTolerance) {
165
+ const emitted = [];
166
+ for (const { d, fill } of layers) {
167
+ const oriented = (0, winding_1.canonicalWinding)(PathKit, d, touchTolerance);
168
+ if (oriented.trim() !== '')
169
+ emitted.push({ d: oriented, fill });
170
+ }
171
+ const closed = backLayerFillingGaps(PathKit, emitted, touchTolerance);
129
172
  return {
130
- layers: emitted
131
- .sort((a, b) => a.index - b.index)
132
- .map((r) => ({ d: r.d, fill: r.fill })),
133
- monochrome,
173
+ layers: closed,
174
+ monochrome: closed.map((layer) => layer.d).join(' '),
134
175
  };
135
176
  }
136
177
  function resolveSymbolLayers(PathKit, layers, options) {
137
178
  const flags = knockoutFlags(layers);
138
179
  if (flags.some(Boolean)) {
139
- return resolveWithKnockouts(PathKit, layers, flags, options?.onKnockoutLayer);
180
+ return resolveWithKnockouts(PathKit, layers, flags, options?.touchTolerance, options?.onKnockoutLayer);
140
181
  }
141
182
  if (layers.length <= 1) {
142
183
  return {
@@ -144,7 +185,7 @@ function resolveSymbolLayers(PathKit, layers, options) {
144
185
  monochrome: layers[0]?.d ?? '',
145
186
  };
146
187
  }
147
- return resolveOccluded(PathKit, layers);
188
+ return resolveStacked(PathKit, layers, options?.touchTolerance);
148
189
  }
149
190
  /**
150
191
  * Tight bounding box [x, y, w, h] of path `d` strings in source coords, or null.
@@ -5,17 +5,22 @@ export type SymbolTemplateLayer = {
5
5
  fill: string | null;
6
6
  };
7
7
  export declare function layerHexColor(fill: string | null): string;
8
- export declare function layerClass(layerIndex: number): string;
8
+ /** A `currentColor` layer follows the tint in multicolor too, like the monochrome rendering. */
9
+ export declare function isTintFill(fill: string | null): boolean;
10
+ /** More than one distinct fill: the symbol is meant to be seen in colour. */
11
+ export declare function isMulticolor(layers: SymbolTemplateLayer[]): boolean;
12
+ export declare function layerClass(layerIndex: number, fill?: string | null): string;
9
13
  /**
10
14
  * Build the template SVG for one symbol. Layers are back→front; every layer
11
- * gets `monochrome-N multicolor-N:custom` classes, with the layer fills
12
- * declared in a `<style>` block.
15
+ * gets `monochrome-N multicolor-N:custom` classes (`multicolor-N:tintColor` for a
16
+ * `currentColor` layer), with the layer fills declared in a `<style>` block.
13
17
  */
14
18
  export declare function buildSymbolTemplate(opts: {
15
19
  layers: SymbolTemplateLayer[];
16
20
  viewBox: [number, number, number, number];
17
21
  /** Tight content box `[x, y, w, h]`; used instead of the viewBox when given. */
18
22
  contentBounds?: [number, number, number, number];
23
+ scale?: number;
19
24
  /** Shown in the template's Notes group. */
20
25
  descriptiveName?: string;
21
26
  logger?: NanoLogger;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.layerHexColor = layerHexColor;
4
+ exports.isTintFill = isTintFill;
5
+ exports.isMulticolor = isMulticolor;
4
6
  exports.layerClass = layerClass;
5
7
  exports.buildSymbolTemplate = buildSymbolTemplate;
6
8
  const parse_1 = require("../../utils/parse");
@@ -20,6 +22,8 @@ const CAP_CENTER = (CAPLINE_Y + BASELINE_Y) / 2; // 111
20
22
  // Content box is scaled to this height (= cap band) and centered, so symbols
21
23
  // fill their optical box instead of rendering small inside a padded viewBox.
22
24
  const GLYPH_HEIGHT = CAP_BAND;
25
+ const SF_PRO_CAP_HEIGHT_PER_EM = 1443 / 2048;
26
+ const EM_HEIGHT = CAP_BAND / SF_PRO_CAP_HEIGHT_PER_EM;
23
27
  const VARIANT_CENTERS = [
24
28
  ['Ultralight', 265],
25
29
  ['Regular', 465],
@@ -48,8 +52,19 @@ function layerHexColor(fill) {
48
52
  .toUpperCase();
49
53
  return `#${h(r)}${h(g)}${h(b)}`;
50
54
  }
51
- function layerClass(layerIndex) {
52
- return `monochrome-${layerIndex} multicolor-${layerIndex}:custom`;
55
+ /** A `currentColor` layer follows the tint in multicolor too, like the monochrome rendering. */
56
+ function isTintFill(fill) {
57
+ return fill !== null && fill.trim().toLowerCase() === 'currentcolor';
58
+ }
59
+ /** More than one distinct fill: the symbol is meant to be seen in colour. */
60
+ function isMulticolor(layers) {
61
+ return (new Set(layers.map((l) => (isTintFill(l.fill) ? 'tint' : multicolorStyle(l.fill)))).size > 1);
62
+ }
63
+ function multicolorClass(layerIndex, fill) {
64
+ return `multicolor-${layerIndex}:${isTintFill(fill) ? 'tintColor' : 'custom'}`;
65
+ }
66
+ function layerClass(layerIndex, fill = null) {
67
+ return `monochrome-${layerIndex} ${multicolorClass(layerIndex, fill)}`;
53
68
  }
54
69
  function multicolorStyle(fill) {
55
70
  const alpha = fill === null ? 1 : (0, parse_1.parseColor)(fill)[3];
@@ -59,22 +74,22 @@ function multicolorStyle(fill) {
59
74
  function renderingModeStyles(layers) {
60
75
  return layers
61
76
  .map((layer, i) => ` .monochrome-${i} {fill:#000000}\n` +
62
- ` .multicolor-${i}:custom {${multicolorStyle(layer.fill)}}`)
77
+ ` .${multicolorClass(i, layer.fill)} {${multicolorStyle(layer.fill)}}`)
63
78
  .join('\n');
64
79
  }
65
80
  /**
66
81
  * Build the template SVG for one symbol. Layers are back→front; every layer
67
- * gets `monochrome-N multicolor-N:custom` classes, with the layer fills
68
- * declared in a `<style>` block.
82
+ * gets `monochrome-N multicolor-N:custom` classes (`multicolor-N:tintColor` for a
83
+ * `currentColor` layer), with the layer fills declared in a `<style>` block.
69
84
  */
70
85
  function buildSymbolTemplate(opts) {
71
- const { layers, viewBox, contentBounds, descriptiveName, logger } = opts;
86
+ const { layers, viewBox, contentBounds, scale: glyphScale = 1, descriptiveName, logger, } = opts;
72
87
  // Fit the content box, not the padded viewBox; fall back to viewBox.
73
88
  const [bx, by, bw, bh] = contentBounds ?? viewBox;
74
89
  const safeBw = bw === 0 ? 1 : bw;
75
90
  const safeBh = bh === 0 ? 1 : bh;
76
91
  // Fit to cap-band height, clamped so wide glyphs don't overlap the next column.
77
- let scale = GLYPH_HEIGHT / safeBh;
92
+ let scale = ((contentBounds ? GLYPH_HEIGHT : EM_HEIGHT) * glyphScale) / safeBh;
78
93
  if (safeBw * scale > MAX_GLYPH_WIDTH) {
79
94
  scale = MAX_GLYPH_WIDTH / safeBw;
80
95
  logger?.info(` ↔ Wide glyph clamped to ${MAX_GLYPH_WIDTH} template units (aspect ${fmt(safeBw / safeBh)}:1)`);
@@ -84,7 +99,7 @@ function buildSymbolTemplate(opts) {
84
99
  // Center on the cap-band midline.
85
100
  const yOff = CAP_CENTER - scaledH / 2;
86
101
  const pathsMarkup = (indent) => layers
87
- .map((layer, i) => `${indent}<path class="${layerClass(i)}" d="${layer.d}"/>`)
102
+ .map((layer, i) => `${indent}<path class="${layerClass(i, layer.fill)}" d="${layer.d}"/>`)
88
103
  .join('\n');
89
104
  const groups = [];
90
105
  const margins = [];
@@ -8,4 +8,12 @@ export declare function buildVectorDrawableXml(opts: {
8
8
  viewBox: [number, number, number, number];
9
9
  /** Tight content box `[x, y, w, h]`; used instead of the viewBox when given. */
10
10
  contentBounds?: [number, number, number, number];
11
+ scale?: number;
12
+ inkBounds?: [number, number, number, number];
11
13
  }): string;
14
+ /**
15
+ * A resources file that keeps the given drawables through resource shrinking
16
+ * (`shrinkResources` in release builds): react-native-screens' native tab bar
17
+ * resolves them by name at runtime (`getIdentifier`), which the shrinker cannot see.
18
+ */
19
+ export declare function buildDrawableKeepXml(resourceNames: string[]): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildVectorDrawableXml = buildVectorDrawableXml;
4
+ exports.buildDrawableKeepXml = buildDrawableKeepXml;
4
5
  const parse_1 = require("../../utils/parse");
5
6
  /**
6
7
  * Android VectorDrawable emitter — the tab-bar counterpart to the iOS
@@ -33,13 +34,29 @@ function fillAttrs(fill) {
33
34
  const color = `android:fillColor="${hexColor(r, g, b)}"`;
34
35
  return a < 1 ? `${color} android:fillAlpha="${Number(a.toFixed(4))}"` : color;
35
36
  }
37
+ function scaledBox(box, scale, ink) {
38
+ if (scale === 1)
39
+ return box;
40
+ const [x, y, w, h] = box;
41
+ const cx = x + w / 2;
42
+ const cy = y + h / 2;
43
+ let s = scale;
44
+ if (s > 1 && ink) {
45
+ const [ix, iy, iw, ih] = ink;
46
+ const inkHalfWidth = Math.max(cx - ix, ix + iw - cx);
47
+ const inkHalfHeight = Math.max(cy - iy, iy + ih - cy);
48
+ const largestScaleKeepingInk = Math.min(w / (2 * inkHalfWidth), h / (2 * inkHalfHeight));
49
+ s = Math.max(1, Math.min(s, largestScaleKeepingInk));
50
+ }
51
+ return [cx - w / s / 2, cy - h / s / 2, w / s, h / s];
52
+ }
36
53
  /**
37
54
  * VectorDrawable XML from z-ordered layers. `contentBounds` (tight `[x,y,w,h]`,
38
55
  * defaults to viewBox) sets the viewport so padding doesn't shrink the icon.
39
56
  */
40
57
  function buildVectorDrawableXml(opts) {
41
- const { layers, viewBox, contentBounds } = opts;
42
- const [bx, by, bw0, bh0] = contentBounds ?? viewBox;
58
+ const { layers, viewBox, contentBounds, scale = 1, inkBounds } = opts;
59
+ const [bx, by, bw0, bh0] = scaledBox(contentBounds ?? viewBox, scale, inkBounds);
43
60
  const bw = bw0 === 0 ? 1 : bw0;
44
61
  const bh = bh0 === 0 ? 1 : bh0;
45
62
  // Size by height; width follows aspect ratio, capped at MAX_WIDTH.
@@ -64,3 +81,12 @@ ${paths}
64
81
  </vector>
65
82
  `;
66
83
  }
84
+ /**
85
+ * A resources file that keeps the given drawables through resource shrinking
86
+ * (`shrinkResources` in release builds): react-native-screens' native tab bar
87
+ * resolves them by name at runtime (`getIdentifier`), which the shrinker cannot see.
88
+ */
89
+ function buildDrawableKeepXml(resourceNames) {
90
+ const refs = resourceNames.map((name) => `@drawable/${name}`).join(',');
91
+ return `<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="${refs}" />\n`;
92
+ }
@@ -1,12 +1,15 @@
1
1
  export type FingerprintInputs = {
2
2
  upm: number;
3
3
  safeZone: number;
4
+ curveTolerance: number;
4
5
  startUnicode: number;
5
6
  version: string;
6
7
  toolchain: readonly string[];
7
8
  };
8
9
  export type SymbolFingerprintInputs = {
9
10
  prefix: string;
11
+ fit?: 'content' | 'viewBox';
12
+ scale?: number;
10
13
  version: string;
11
14
  toolchain: readonly string[];
12
15
  };
@@ -6,6 +6,7 @@ exports.fingerprintSymbolDirSync = fingerprintSymbolDirSync;
6
6
  const crypto = require('crypto');
7
7
  const fs = require('fs');
8
8
  const path = require('path');
9
+ const CRLF = /\r\n/g;
9
10
  function getFingerprintSync(dir, inputs) {
10
11
  return fingerprintSvgDirSync(dir, inputs).hash;
11
12
  }
@@ -13,6 +14,7 @@ function fingerprintSvgDirSync(dir, inputs) {
13
14
  return hashSvgDir(dir, [
14
15
  inputs.upm,
15
16
  inputs.safeZone,
17
+ inputs.curveTolerance,
16
18
  inputs.startUnicode,
17
19
  inputs.version,
18
20
  inputs.toolchain,
@@ -22,6 +24,8 @@ function fingerprintSymbolDirSync(dir, inputs) {
22
24
  return hashSvgDir(dir, [
23
25
  'symbol',
24
26
  inputs.prefix,
27
+ inputs.fit ?? 'content',
28
+ inputs.scale ?? 1,
25
29
  inputs.version,
26
30
  inputs.toolchain,
27
31
  ]);
@@ -35,7 +39,7 @@ function hashSvgDir(dir, settings) {
35
39
  const svgHashByFile = new Map();
36
40
  for (const file of files) {
37
41
  const filePath = path.join(dir, file);
38
- const content = fs.readFileSync(filePath);
42
+ const content = fs.readFileSync(filePath, 'utf8').replace(CRLF, '\n');
39
43
  // Hash both path and content
40
44
  hash.update(file);
41
45
  hash.update(content);