react-native-nano-icons 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +124 -2
  2. package/android/build.gradle +8 -1
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +53 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
  5. package/android/src/main/jni/CMakeLists.txt +38 -0
  6. package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
  8. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
  9. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
  10. package/ios/NanoIconInlineBaseline.h +4 -0
  11. package/ios/NanoIconInlineBaseline.mm +190 -0
  12. package/ios/NanoIconView.h +1 -0
  13. package/ios/NanoIconView.mm +118 -107
  14. package/lib/commonjs/cli/build.d.ts +5 -0
  15. package/lib/commonjs/cli/build.js +37 -15
  16. package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
  17. package/lib/commonjs/cli/buildSymbols.js +134 -0
  18. package/lib/commonjs/cli/config.d.ts +3 -1
  19. package/lib/commonjs/cli/config.js +3 -3
  20. package/lib/commonjs/cli/expoConfig.d.ts +3 -0
  21. package/lib/commonjs/cli/expoConfig.js +17 -6
  22. package/lib/commonjs/cli/index.d.ts +4 -2
  23. package/lib/commonjs/cli/index.js +12 -1
  24. package/lib/commonjs/cli/link.d.ts +15 -0
  25. package/lib/commonjs/cli/link.js +185 -1
  26. package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
  27. package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
  28. package/lib/commonjs/metro/index.d.ts +35 -0
  29. package/lib/commonjs/metro/index.js +92 -0
  30. package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
  31. package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
  32. package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
  33. package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
  34. package/lib/commonjs/plugin/src/index.d.ts +1 -1
  35. package/lib/commonjs/plugin/src/index.js +9 -3
  36. package/lib/commonjs/plugin/src/types.d.ts +34 -2
  37. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
  38. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
  39. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
  40. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
  41. package/lib/commonjs/scripts/cli.js +27 -9
  42. package/lib/commonjs/src/core/font/compile.js +3 -5
  43. package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
  44. package/lib/commonjs/src/core/font/quadratic.js +2 -0
  45. package/lib/commonjs/src/core/glyph/merge.js +3 -1
  46. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -0
  47. package/lib/commonjs/src/core/pathkit/contours.d.ts +1 -0
  48. package/lib/commonjs/src/core/pathkit/contours.js +18 -0
  49. package/lib/commonjs/src/core/pathkit/evenodd.js +1 -15
  50. package/lib/commonjs/src/core/pathkit/winding.d.ts +4 -0
  51. package/lib/commonjs/src/core/pathkit/winding.js +59 -0
  52. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  53. package/lib/commonjs/src/core/pipeline/config.js +6 -0
  54. package/lib/commonjs/src/core/pipeline/iconPool.d.ts +13 -2
  55. package/lib/commonjs/src/core/pipeline/iconPool.js +89 -31
  56. package/lib/commonjs/src/core/pipeline/index.d.ts +2 -0
  57. package/lib/commonjs/src/core/pipeline/index.js +3 -1
  58. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -0
  59. package/lib/commonjs/src/core/pipeline/prepare.js +18 -0
  60. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +3 -0
  61. package/lib/commonjs/src/core/pipeline/prepareIcon.js +11 -8
  62. package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
  63. package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
  64. package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
  65. package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -0
  66. package/lib/commonjs/src/core/pipeline/prepareWorker.js +3 -3
  67. package/lib/commonjs/src/core/pipeline/preparedSvgCache.d.ts +6 -0
  68. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
  69. package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +5 -0
  70. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +10 -8
  71. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
  72. package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
  73. package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
  74. package/lib/commonjs/src/core/symbols/contents.js +15 -0
  75. package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
  76. package/lib/commonjs/src/core/symbols/knockout.js +51 -0
  77. package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
  78. package/lib/commonjs/src/core/symbols/layers.js +182 -0
  79. package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
  80. package/lib/commonjs/src/core/symbols/template.js +140 -0
  81. package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
  82. package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
  83. package/lib/commonjs/src/utils/fingerPrint.d.ts +11 -0
  84. package/lib/commonjs/src/utils/fingerPrint.js +28 -9
  85. package/lib/commonjs/src/utils/naming.d.ts +10 -0
  86. package/lib/commonjs/src/utils/naming.js +49 -0
  87. package/lib/module/createNanoIconsSet.native.js +29 -26
  88. package/lib/module/createNanoIconsSet.shared.js +3 -2
  89. package/lib/module/createNanoIconsSet.web.js +17 -5
  90. package/lib/module/devServerFont.js +30 -0
  91. package/lib/module/devServerFont.web.js +25 -0
  92. package/lib/module/loadDynamicFont.js +6 -3
  93. package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
  94. package/lib/module/symbols/index.android.js +42 -0
  95. package/lib/module/symbols/index.ios.js +35 -0
  96. package/lib/module/symbols/index.js +35 -0
  97. package/lib/module/symbols/index.native.js +12 -0
  98. package/lib/module/symbols/types.js +1 -0
  99. package/lib/module/utils/fingerPrint.js +18 -3
  100. package/lib/module/utils/glyphRuntime.js +36 -2
  101. package/lib/module/utils/naming.js +46 -0
  102. package/lib/module/utils/validateLayerColor.js +24 -0
  103. package/lib/typescript/src/core/glyph/parse.d.ts +1 -0
  104. package/lib/typescript/src/core/pathkit/contours.d.ts +1 -0
  105. package/lib/typescript/src/core/pathkit/winding.d.ts +5 -0
  106. package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
  107. package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
  108. package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
  109. package/lib/typescript/src/core/symbols/template.d.ts +23 -0
  110. package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
  111. package/lib/typescript/src/devServerFont.d.ts +4 -0
  112. package/lib/typescript/src/devServerFont.web.d.ts +4 -0
  113. package/lib/typescript/src/loadDynamicFont.d.ts +1 -0
  114. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +6 -5
  115. package/lib/typescript/src/symbols/index.android.d.ts +33 -0
  116. package/lib/typescript/src/symbols/index.d.ts +31 -0
  117. package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
  118. package/lib/typescript/src/symbols/index.native.d.ts +8 -0
  119. package/lib/typescript/src/symbols/types.d.ts +24 -0
  120. package/lib/typescript/src/types.d.ts +2 -0
  121. package/lib/typescript/src/utils/fingerPrint.d.ts +11 -0
  122. package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
  123. package/lib/typescript/src/utils/naming.d.ts +11 -0
  124. package/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
  125. package/metro.js +1 -0
  126. package/package.json +26 -2
  127. package/react-native-nano-icons.podspec +4 -1
  128. package/react-native.config.js +10 -0
  129. package/src/specs/NanoIconViewNativeComponent.ts +9 -6
@@ -1 +1,2 @@
1
+ export declare const QUADRATIC_ERROR_BOUND_EM: number;
1
2
  export declare function toQuadraticPath(d: string, errorBound: number): string;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUADRATIC_ERROR_BOUND_EM = void 0;
3
4
  exports.toQuadraticPath = toQuadraticPath;
4
5
  const cubic2quad = require('cubic2quad');
5
6
  const COMMAND = /([MLQCZ])([^MLQCZ]*)/g;
6
7
  const NUMBER = /-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi;
8
+ exports.QUADRATIC_ERROR_BOUND_EM = 1 / 512;
7
9
  function toQuadraticPath(d, errorBound) {
8
10
  const out = [];
9
11
  let x = 0;
@@ -29,10 +29,12 @@ function mergeSameColorPaths(paths, logger) {
29
29
  // Paths converted from evenodd have compound hole structure and must not
30
30
  // be merged — their CW hole contours would cancel CCW contours from
31
31
  // adjacent paths, producing incorrect fill.
32
+ const knockout = paths[i].knockout;
32
33
  let j = i + 1;
33
34
  if (!paths[i].noMerge) {
34
35
  while (j < paths.length &&
35
36
  paths[j].fill === fill &&
37
+ paths[j].knockout === knockout &&
36
38
  !paths[j].noMerge) {
37
39
  j++;
38
40
  }
@@ -45,7 +47,7 @@ function mergeSameColorPaths(paths, logger) {
45
47
  const merged = concatPathDs(group.map((p) => p.d));
46
48
  if (merged) {
47
49
  logger?.info(` ⊕ Merged ${group.length} same-color paths (fill=${fill})`);
48
- result.push({ d: merged, fill });
50
+ result.push(knockout ? { d: merged, fill, knockout } : { d: merged, fill });
49
51
  }
50
52
  else {
51
53
  result.push(...group);
@@ -4,6 +4,7 @@ export type ParsedPath = {
4
4
  fill: string | null;
5
5
  fillRule?: 'evenodd';
6
6
  noMerge?: boolean;
7
+ knockout?: boolean;
7
8
  };
8
9
  export type ParsedFlatSvg = {
9
10
  viewBox: [number, number, number, number];
@@ -70,5 +70,6 @@ export type Contour = {
70
70
  };
71
71
  export declare function orientedContours(cmds: readonly Cmd[], V: VerbMap): Contour[];
72
72
  export declare function canonicalContourCmds(cmds: readonly Cmd[], recordedMoves: readonly Point[], preferMinYMinXStart: boolean, V: VerbMap): Cmd[];
73
+ export declare function cmdsToPathData(cmds: readonly Cmd[], V: VerbMap): string;
73
74
  export declare function contoursArea(cmds: readonly Cmd[], V: VerbMap): number;
74
75
  export {};
@@ -20,6 +20,7 @@ exports.getContourSamplePoint = getContourSamplePoint;
20
20
  exports.applyContainmentWinding = applyContainmentWinding;
21
21
  exports.orientedContours = orientedContours;
22
22
  exports.canonicalContourCmds = canonicalContourCmds;
23
+ exports.cmdsToPathData = cmdsToPathData;
23
24
  exports.contoursArea = contoursArea;
24
25
  function verbMap(PathKit) {
25
26
  return {
@@ -566,6 +567,23 @@ function canonicalContourCmds(cmds, recordedMoves, preferMinYMinXStart, V) {
566
567
  }
567
568
  return contours.flatMap((x) => x.cmds);
568
569
  }
570
+ function cmdsToPathData(cmds, V) {
571
+ const parts = [];
572
+ for (const cmd of cmds) {
573
+ const v = cmd[0];
574
+ if (v === V.MOVE)
575
+ parts.push(`M${roundN(cmd[1])} ${roundN(cmd[2])}`);
576
+ else if (v === V.LINE)
577
+ parts.push(`L${roundN(cmd[1])} ${roundN(cmd[2])}`);
578
+ else if (v === V.QUAD)
579
+ parts.push(`Q${roundN(cmd[1])} ${roundN(cmd[2])} ${roundN(cmd[3])} ${roundN(cmd[4])}`);
580
+ else if (v === V.CUBIC)
581
+ parts.push(`C${roundN(cmd[1])} ${roundN(cmd[2])} ${roundN(cmd[3])} ${roundN(cmd[4])} ${roundN(cmd[5])} ${roundN(cmd[6])}`);
582
+ else if (v === V.CLOSE)
583
+ parts.push('Z');
584
+ }
585
+ return parts.join(' ');
586
+ }
569
587
  function contoursArea(cmds, V) {
570
588
  let total = 0;
571
589
  for (const c of splitContours(cmds, V)) {
@@ -33,19 +33,5 @@ function convertEvenoddToWinding(PathKit, d) {
33
33
  // 2.+3. Split into contours and fix winding via containment analysis
34
34
  const allCmds = (0, contours_1.orientedContours)(cmds, V).flatMap((x) => x.cmds);
35
35
  // 4. Reconstruct d string from fixed commands
36
- const parts = [];
37
- for (const cmd of allCmds) {
38
- const v = cmd[0];
39
- if (v === V.MOVE)
40
- parts.push(`M${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])}`);
41
- else if (v === V.LINE)
42
- parts.push(`L${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])}`);
43
- else if (v === V.QUAD)
44
- parts.push(`Q${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])} ${(0, contours_1.roundN)(cmd[3])} ${(0, contours_1.roundN)(cmd[4])}`);
45
- else if (v === V.CUBIC)
46
- parts.push(`C${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])} ${(0, contours_1.roundN)(cmd[3])} ${(0, contours_1.roundN)(cmd[4])} ${(0, contours_1.roundN)(cmd[5])} ${(0, contours_1.roundN)(cmd[6])}`);
47
- else if (v === V.CLOSE)
48
- parts.push('Z');
49
- }
50
- return parts.join(' ');
36
+ return (0, contours_1.cmdsToPathData)(allCmds, V);
51
37
  }
@@ -0,0 +1,4 @@
1
+ import type { PathKitModule, PathKitPath } from './types';
2
+ export declare function orientedPathData(PathKit: PathKitModule, path: PathKitPath): string;
3
+ export declare function canonicalWinding(PathKit: PathKitModule, d: string): string;
4
+ export declare function reversedWinding(PathKit: PathKitModule, d: string): string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.orientedPathData = orientedPathData;
4
+ exports.canonicalWinding = canonicalWinding;
5
+ exports.reversedWinding = reversedWinding;
6
+ const contours_1 = require("./contours");
7
+ function conicsToCubics(cmds, V) {
8
+ let x = 0;
9
+ let y = 0;
10
+ return cmds.map((cmd) => {
11
+ const verb = cmd[0];
12
+ if (verb === V.CONIC) {
13
+ const [, cx, cy, ex, ey, w] = cmd;
14
+ const k = (4 * w) / (3 * (1 + w));
15
+ const out = [
16
+ V.CUBIC,
17
+ x + k * (cx - x),
18
+ y + k * (cy - y),
19
+ ex + k * (cx - ex),
20
+ ey + k * (cy - ey),
21
+ ex,
22
+ ey,
23
+ ];
24
+ x = ex;
25
+ y = ey;
26
+ return out;
27
+ }
28
+ if (verb !== V.CLOSE) {
29
+ x = cmd[cmd.length - 2];
30
+ y = cmd[cmd.length - 1];
31
+ }
32
+ return cmd;
33
+ });
34
+ }
35
+ function orientedContoursOf(PathKit, path) {
36
+ path.simplify();
37
+ const V = (0, contours_1.verbMap)(PathKit);
38
+ return (0, contours_1.orientedContours)(conicsToCubics(path.toCmds(), V), V);
39
+ }
40
+ function orientedPathData(PathKit, path) {
41
+ return (0, contours_1.cmdsToPathData)(orientedContoursOf(PathKit, path).flatMap((c) => c.cmds), (0, contours_1.verbMap)(PathKit));
42
+ }
43
+ function canonicalWinding(PathKit, d) {
44
+ const path = PathKit.FromSVGString(d);
45
+ if (!path)
46
+ return d;
47
+ const out = orientedPathData(PathKit, path);
48
+ path.delete?.();
49
+ return out;
50
+ }
51
+ function reversedWinding(PathKit, d) {
52
+ const path = PathKit.FromSVGString(d);
53
+ if (!path)
54
+ return d;
55
+ const V = (0, contours_1.verbMap)(PathKit);
56
+ const contours = orientedContoursOf(PathKit, path);
57
+ path.delete?.();
58
+ return (0, contours_1.cmdsToPathData)(contours.flatMap((c) => (0, contours_1.reverseClosedContourKeepStart)(c.cmds, c.explicitCloseWanted, V)), V);
59
+ }
@@ -14,3 +14,4 @@ export type PipelinePaths = {
14
14
  export declare function ensureEmptyDir(dir: string): void;
15
15
  /** Create directory if it does not exist; do not remove existing contents (for shared output dirs). */
16
16
  export declare function ensureDir(dir: string): void;
17
+ export declare function writeFileAtomic(filePath: string, data: string | Uint8Array): void;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ensureEmptyDir = ensureEmptyDir;
7
7
  exports.ensureDir = ensureDir;
8
+ exports.writeFileAtomic = writeFileAtomic;
8
9
  const node_fs_1 = __importDefault(require("node:fs"));
9
10
  function ensureEmptyDir(dir) {
10
11
  if (node_fs_1.default.existsSync(dir))
@@ -15,3 +16,8 @@ function ensureEmptyDir(dir) {
15
16
  function ensureDir(dir) {
16
17
  node_fs_1.default.mkdirSync(dir, { recursive: true });
17
18
  }
19
+ function writeFileAtomic(filePath, data) {
20
+ const tmpPath = `${filePath}.tmp`;
21
+ node_fs_1.default.writeFileSync(tmpPath, data);
22
+ node_fs_1.default.renameSync(tmpPath, filePath);
23
+ }
@@ -1,3 +1,14 @@
1
- import { type IconResult, type IconTask } from './prepareIcon';
1
+ import { type SvgPrepareTask, type SvgPrepareResult } from './prepareSvg';
2
2
  export declare function defaultConcurrency(): number;
3
- export declare function prepareIcons(tasks: IconTask[], concurrency: number): Promise<IconResult[]>;
3
+ export declare class SvgWorkerPool {
4
+ private readonly size;
5
+ private readonly workers;
6
+ private queue;
7
+ constructor(size?: number);
8
+ prepare<T extends SvgPrepareTask>(tasks: T[]): Promise<SvgPrepareResult<T>[]>;
9
+ warm(): void;
10
+ close(): Promise<void>;
11
+ private run;
12
+ private discard;
13
+ }
14
+ export declare function prepareIcons<T extends SvgPrepareTask>(tasks: T[], concurrency: number): Promise<SvgPrepareResult<T>[]>;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SvgWorkerPool = void 0;
6
7
  exports.defaultConcurrency = defaultConcurrency;
7
8
  exports.prepareIcons = prepareIcons;
8
9
  const node_fs_1 = __importDefault(require("node:fs"));
@@ -10,42 +11,99 @@ const node_os_1 = __importDefault(require("node:os"));
10
11
  const node_path_1 = __importDefault(require("node:path"));
11
12
  const node_worker_threads_1 = require("node:worker_threads");
12
13
  const load_1 = require("../pathkit/load");
13
- const prepareIcon_1 = require("./prepareIcon");
14
+ const prepareSvg_1 = require("./prepareSvg");
14
15
  const WORKER_PATH = node_path_1.default.join(__dirname, 'prepareWorker.js');
15
16
  function defaultConcurrency() {
16
17
  return Math.max(1, Math.min(8, node_os_1.default.availableParallelism()));
17
18
  }
18
- async function prepareIcons(tasks, concurrency) {
19
- const workers = Math.min(concurrency, tasks.length);
20
- if (workers <= 1 || !node_fs_1.default.existsSync(WORKER_PATH)) {
21
- const pathkit = await (0, load_1.loadPathKit)();
22
- const results = [];
23
- for (const task of tasks)
24
- results.push(await (0, prepareIcon_1.prepareIcon)(task, pathkit));
25
- return results;
19
+ async function prepareInProcess(tasks) {
20
+ const pathkit = await (0, load_1.loadPathKit)();
21
+ const results = [];
22
+ for (const task of tasks)
23
+ results.push(await (0, prepareSvg_1.prepareSvg)(task, pathkit));
24
+ return results;
25
+ }
26
+ class SvgWorkerPool {
27
+ size;
28
+ workers = [];
29
+ queue = Promise.resolve();
30
+ constructor(size = defaultConcurrency()) {
31
+ this.size = size;
26
32
  }
27
- const results = new Array(tasks.length);
28
- let next = 0;
29
- const runWorker = () => new Promise((resolve, reject) => {
30
- const worker = new node_worker_threads_1.Worker(WORKER_PATH);
31
- let current = -1;
32
- const dispatch = () => {
33
- if (next >= tasks.length) {
34
- worker.terminate().then(() => resolve(), reject);
35
- return;
36
- }
37
- current = next++;
38
- worker.postMessage(tasks[current]);
39
- };
40
- worker.on('message', (result) => {
41
- results[current] = result;
33
+ prepare(tasks) {
34
+ const run = this.queue.then(() => this.run(tasks));
35
+ this.queue = run.catch(() => { });
36
+ return run;
37
+ }
38
+ warm() {
39
+ if (!node_fs_1.default.existsSync(WORKER_PATH))
40
+ return;
41
+ for (let i = this.workers.length; i < this.size; i++) {
42
+ const worker = new node_worker_threads_1.Worker(WORKER_PATH);
43
+ worker.unref();
44
+ this.workers.push(worker);
45
+ }
46
+ }
47
+ async close() {
48
+ await Promise.all(this.workers.splice(0).map((w) => w.terminate()));
49
+ }
50
+ async run(tasks) {
51
+ const wanted = Math.min(this.size, tasks.length);
52
+ if (wanted <= 1 || !node_fs_1.default.existsSync(WORKER_PATH)) {
53
+ return prepareInProcess(tasks);
54
+ }
55
+ for (let i = this.workers.length; i < wanted; i++) {
56
+ this.workers.push(new node_worker_threads_1.Worker(WORKER_PATH));
57
+ }
58
+ const results = new Array(tasks.length);
59
+ let next = 0;
60
+ const drain = (worker) => new Promise((resolve, reject) => {
61
+ let current = -1;
62
+ const onMessage = (result) => {
63
+ results[current] = result;
64
+ dispatch();
65
+ };
66
+ const onError = (err) => {
67
+ detach();
68
+ this.discard(worker);
69
+ reject(err);
70
+ };
71
+ const detach = () => {
72
+ worker.off('message', onMessage);
73
+ worker.off('error', onError);
74
+ worker.unref();
75
+ };
76
+ const dispatch = () => {
77
+ if (next >= tasks.length) {
78
+ detach();
79
+ resolve();
80
+ return;
81
+ }
82
+ current = next++;
83
+ worker.postMessage(tasks[current]);
84
+ };
85
+ worker.ref();
86
+ worker.on('message', onMessage);
87
+ worker.on('error', onError);
42
88
  dispatch();
43
89
  });
44
- worker.on('error', (err) => {
45
- worker.terminate().finally(() => reject(err));
46
- });
47
- dispatch();
48
- });
49
- await Promise.all(Array.from({ length: workers }, runWorker));
50
- return results;
90
+ await Promise.all(this.workers.slice(0, wanted).map(drain));
91
+ return results;
92
+ }
93
+ discard(worker) {
94
+ const i = this.workers.indexOf(worker);
95
+ if (i !== -1)
96
+ this.workers.splice(i, 1);
97
+ void worker.terminate();
98
+ }
99
+ }
100
+ exports.SvgWorkerPool = SvgWorkerPool;
101
+ async function prepareIcons(tasks, concurrency) {
102
+ const pool = new SvgWorkerPool(concurrency);
103
+ try {
104
+ return await pool.prepare(tasks);
105
+ }
106
+ finally {
107
+ await pool.close();
108
+ }
51
109
  }
@@ -1,3 +1,5 @@
1
1
  export { runFontPipeline, runFontPipeline as runPipeline, type PipelineResult, } from './runFontPipeline';
2
2
  export type { PipelineConfig, PipelinePaths } from './config';
3
+ export type { PreparedSvgCache } from './preparedSvgCache';
4
+ export { SvgWorkerPool } from './iconPool';
3
5
  export { ensureEmptyDir } from './config';
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureEmptyDir = exports.runPipeline = exports.runFontPipeline = void 0;
3
+ exports.ensureEmptyDir = exports.SvgWorkerPool = exports.runPipeline = exports.runFontPipeline = void 0;
4
4
  var runFontPipeline_1 = require("./runFontPipeline");
5
5
  Object.defineProperty(exports, "runFontPipeline", { enumerable: true, get: function () { return runFontPipeline_1.runFontPipeline; } });
6
6
  Object.defineProperty(exports, "runPipeline", { enumerable: true, get: function () { return runFontPipeline_1.runFontPipeline; } });
7
+ var iconPool_1 = require("./iconPool");
8
+ Object.defineProperty(exports, "SvgWorkerPool", { enumerable: true, get: function () { return iconPool_1.SvgWorkerPool; } });
7
9
  var config_1 = require("./config");
8
10
  Object.defineProperty(exports, "ensureEmptyDir", { enumerable: true, get: function () { return config_1.ensureEmptyDir; } });
@@ -16,4 +16,5 @@ export declare function prepareSvgLayers(opts: {
16
16
  fileLabel: string;
17
17
  pathkit: PathKitModule;
18
18
  logger?: NanoLogger;
19
+ tagKnockouts?: boolean;
19
20
  }): Promise<PreparedSvg | null>;
@@ -10,6 +10,21 @@ const merge_1 = require("../glyph/merge");
10
10
  const parse_1 = require("../glyph/parse");
11
11
  const validate_1 = require("../glyph/validate");
12
12
  const evenodd_1 = require("../pathkit/evenodd");
13
+ const knockout_1 = require("../symbols/knockout");
14
+ function tagKnockoutPaths(paths, svg, pathkit, fileLabel, logger) {
15
+ const marked = (0, knockout_1.markKnockoutFills)(svg);
16
+ if (marked === null)
17
+ return;
18
+ const markedPaths = (0, parse_1.parseFlattenedSvg)((0, index_1.flattenSvg)(marked, pathkit)).paths;
19
+ if (markedPaths.length !== paths.length) {
20
+ logger?.warn(`${fileLabel}: ignoring ${knockout_1.KNOCKOUT_ATTRIBUTE}, the annotated elements change the flattened shape count`);
21
+ return;
22
+ }
23
+ markedPaths.forEach((markedPath, i) => {
24
+ if (markedPath.fill !== paths[i].fill)
25
+ paths[i].knockout = true;
26
+ });
27
+ }
13
28
  /**
14
29
  * Shared per-file SVG prep: validate → preprocess → flatten → parse →
15
30
  * evenodd convert → same-color merge. Returns null for unsupported SVGs.
@@ -39,6 +54,9 @@ async function prepareSvgLayers(opts) {
39
54
  logger?.warn(`${fileLabel} has no viewBox; assuming [${assumed.join(' ')}]`);
40
55
  },
41
56
  });
57
+ if (opts.tagKnockouts) {
58
+ tagKnockoutPaths(parsed.paths, preprocessed, pathkit, fileLabel, logger);
59
+ }
42
60
  // Convert evenodd to nonzero winding with our containment-based
43
61
  // algorithm. Mark as noMerge — compound paths with holes must stay
44
62
  // separate so their CW hole contours don't cancel adjacent paths' CCW
@@ -1,5 +1,7 @@
1
1
  import type { PathKitModule } from '../pathkit/types';
2
+ import type { NanoLogger } from '../types';
2
3
  export type IconTask = {
4
+ kind: 'font';
3
5
  file: string;
4
6
  filePath: string;
5
7
  fontFamily: string;
@@ -19,4 +21,5 @@ export type IconResult = {
19
21
  logs: IconLog[];
20
22
  error: string | null;
21
23
  };
24
+ export declare function collectingLogger(logs: IconLog[]): NanoLogger;
22
25
  export declare function prepareIcon(task: IconTask, pathkit: PathKitModule): Promise<IconResult>;
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.collectingLogger = collectingLogger;
6
7
  exports.prepareIcon = prepareIcon;
7
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const quadratic_1 = require("../font/quadratic");
8
10
  const parse_1 = require("../glyph/parse");
9
11
  const placement_1 = require("../glyph/placement");
10
12
  const prepare_1 = require("./prepare");
@@ -59,16 +61,17 @@ async function prepareIcon(task, pathkit) {
59
61
  for (const p of prepared.paths) {
60
62
  if ((0, parse_1.shouldSkipPath)(p.d, p.fill))
61
63
  continue;
64
+ const placed = (0, placement_1.transformPathForFont)(pathkit, p.d, {
65
+ vx,
66
+ vy,
67
+ scale,
68
+ xOff,
69
+ yOff,
70
+ upm: task.upm,
71
+ });
62
72
  result.layers.push({
63
73
  fill: p.fill,
64
- d: (0, placement_1.transformPathForFont)(pathkit, p.d, {
65
- vx,
66
- vy,
67
- scale,
68
- xOff,
69
- yOff,
70
- upm: task.upm,
71
- }),
74
+ d: (0, quadratic_1.toQuadraticPath)(placed, task.upm * quadratic_1.QUADRATIC_ERROR_BOUND_EM),
72
75
  });
73
76
  }
74
77
  if (result.layers.length === 0) {
@@ -0,0 +1,6 @@
1
+ import type { PathKitModule } from '../pathkit/types';
2
+ import { type IconResult, type IconTask } from './prepareIcon';
3
+ import { type SymbolResult, type SymbolTask } from './prepareSymbol';
4
+ export type SvgPrepareTask = IconTask | SymbolTask;
5
+ export type SvgPrepareResult<T extends SvgPrepareTask> = T extends IconTask ? IconResult : SymbolResult;
6
+ export declare function prepareSvg<T extends SvgPrepareTask>(task: T, pathkit: PathKitModule): Promise<SvgPrepareResult<T>>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareSvg = prepareSvg;
4
+ const prepareIcon_1 = require("./prepareIcon");
5
+ const prepareSymbol_1 = require("./prepareSymbol");
6
+ function prepareSvg(task, pathkit) {
7
+ const result = task.kind === 'font'
8
+ ? (0, prepareIcon_1.prepareIcon)(task, pathkit)
9
+ : (0, prepareSymbol_1.prepareSymbol)(task, pathkit);
10
+ return result;
11
+ }
@@ -0,0 +1,26 @@
1
+ import type { PathKitModule } from '../pathkit/types';
2
+ import { type IconLog } from './prepareIcon';
3
+ export type SymbolTask = {
4
+ kind: 'symbol';
5
+ file: string;
6
+ filePath: string;
7
+ setName: string;
8
+ prefix: string;
9
+ };
10
+ export type SymbolAsset = {
11
+ assetName: string;
12
+ assetDirName: string;
13
+ svgFilename: string;
14
+ svg: string;
15
+ contents: string;
16
+ vdXml: string;
17
+ vdOriginalXml: string;
18
+ };
19
+ export type SymbolResult = {
20
+ file: string;
21
+ iconName: string;
22
+ asset: SymbolAsset | null;
23
+ logs: IconLog[];
24
+ error: string | null;
25
+ };
26
+ export declare function prepareSymbol(task: SymbolTask, pathkit: PathKitModule): Promise<SymbolResult>;
@@ -0,0 +1,79 @@
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.prepareSymbol = prepareSymbol;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const parse_1 = require("../glyph/parse");
9
+ const contents_1 = require("../symbols/contents");
10
+ const layers_1 = require("../symbols/layers");
11
+ const template_1 = require("../symbols/template");
12
+ const vectorDrawable_1 = require("../symbols/vectorDrawable");
13
+ const prepareIcon_1 = require("./prepareIcon");
14
+ const prepare_1 = require("./prepare");
15
+ async function prepareSymbol(task, pathkit) {
16
+ const logs = [];
17
+ const logger = (0, prepareIcon_1.collectingLogger)(logs);
18
+ const iconName = node_path_1.default.parse(task.file).name;
19
+ const fileLabel = `${task.setName}:${task.file}`;
20
+ const result = {
21
+ file: task.file,
22
+ iconName,
23
+ asset: null,
24
+ logs,
25
+ error: null,
26
+ };
27
+ logger.info(`Processing ${task.file}`);
28
+ let prepared;
29
+ try {
30
+ prepared = await (0, prepare_1.prepareSvgLayers)({
31
+ filePath: task.filePath,
32
+ fileLabel,
33
+ pathkit,
34
+ logger,
35
+ tagKnockouts: true,
36
+ });
37
+ }
38
+ catch (err) {
39
+ result.error = err instanceof Error ? err.message : String(err);
40
+ return result;
41
+ }
42
+ if (!prepared)
43
+ return result;
44
+ const drawable = prepared.paths.filter((p) => !(0, parse_1.shouldSkipPath)(p.d, p.fill));
45
+ if (drawable.length === 0) {
46
+ logger.warn(`Skipping "${fileLabel}": no drawable paths`);
47
+ return result;
48
+ }
49
+ const assetName = `${task.prefix}.${iconName}`;
50
+ const svgFilename = `${assetName}.svg`;
51
+ const { layers, monochrome } = (0, layers_1.resolveSymbolLayers)(pathkit, drawable, {
52
+ onKnockoutLayer: () => logger.info(` ⊖ Knockout layer: hole in monochrome, own fill in original`),
53
+ });
54
+ const bounds = (0, layers_1.contentBounds)(pathkit, layers.map((l) => l.d)) ?? undefined;
55
+ result.asset = {
56
+ assetName,
57
+ assetDirName: `${assetName}.symbolset`,
58
+ svgFilename,
59
+ svg: (0, template_1.buildSymbolTemplate)({
60
+ layers,
61
+ viewBox: prepared.viewBox,
62
+ contentBounds: bounds,
63
+ descriptiveName: assetName,
64
+ logger,
65
+ }),
66
+ contents: (0, contents_1.symbolsetContentsJson)(svgFilename),
67
+ vdXml: (0, vectorDrawable_1.buildVectorDrawableXml)({
68
+ layers: [{ d: monochrome, fill: null }],
69
+ viewBox: prepared.viewBox,
70
+ contentBounds: bounds,
71
+ }),
72
+ vdOriginalXml: (0, vectorDrawable_1.buildVectorDrawableXml)({
73
+ layers,
74
+ viewBox: prepared.viewBox,
75
+ contentBounds: bounds,
76
+ }),
77
+ };
78
+ return result;
79
+ }
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_worker_threads_1 = require("node:worker_threads");
4
4
  const load_1 = require("../pathkit/load");
5
- const prepareIcon_1 = require("./prepareIcon");
5
+ const prepareSvg_1 = require("./prepareSvg");
6
6
  const port = node_worker_threads_1.parentPort;
7
7
  if (!port)
8
8
  throw new Error('prepareWorker must run inside a worker thread');
9
+ const pathkitReady = (0, load_1.loadPathKit)();
9
10
  port.on('message', async (task) => {
10
- const pathkit = await (0, load_1.loadPathKit)();
11
- port.postMessage(await (0, prepareIcon_1.prepareIcon)(task, pathkit));
11
+ port.postMessage(await (0, prepareSvg_1.prepareSvg)(task, await pathkitReady));
12
12
  });
@@ -0,0 +1,6 @@
1
+ import { type SvgWorkerPool } from './iconPool';
2
+ import type { IconTask } from './prepareIcon';
3
+ import type { SvgPrepareTask, SvgPrepareResult } from './prepareSvg';
4
+ export type PreparedSvgCache<T extends SvgPrepareTask = IconTask> = Map<string, SvgPrepareResult<T>>;
5
+ export declare function preparedSvgCacheKey(task: SvgPrepareTask, hash?: string): string;
6
+ export declare function prepareIconsWithCache<T extends SvgPrepareTask>(tasks: T[], concurrency: number, cache: PreparedSvgCache<T> | undefined, pool?: SvgWorkerPool, svgHashByFile?: Map<string, string>): Promise<SvgPrepareResult<T>[]>;