react-native-nano-icons 0.2.0 → 1.0.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.
- package/LICENSES.md +40 -0
- package/README.md +41 -10
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +50 -15
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +78 -12
- package/ios/NanoIconFontResolver.h +5 -0
- package/ios/NanoIconFontResolver.mm +32 -0
- package/ios/NanoIconView.h +0 -4
- package/ios/NanoIconView.mm +62 -57
- package/ios/NanoIconsFontLoader.mm +10 -32
- package/lib/commonjs/cli/build.d.ts +11 -3
- package/lib/commonjs/cli/build.js +86 -25
- package/lib/commonjs/cli/config.d.ts +1 -1
- package/lib/commonjs/cli/config.js +1 -1
- package/lib/commonjs/cli/expoConfig.d.ts +3 -2
- package/lib/commonjs/cli/expoConfig.js +22 -9
- package/lib/commonjs/cli/index.d.ts +5 -5
- package/lib/commonjs/cli/index.js +16 -14
- package/lib/commonjs/cli/link.d.ts +4 -3
- package/lib/commonjs/cli/link.js +127 -45
- package/lib/commonjs/cli/logger.js +9 -7
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
- package/lib/commonjs/plugin/src/buildFonts.js +5 -15
- package/lib/commonjs/plugin/src/index.d.ts +2 -2
- package/lib/commonjs/plugin/src/index.js +2 -2
- package/lib/commonjs/plugin/src/types.d.ts +10 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
- package/lib/commonjs/scripts/cli.js +46 -23
- package/lib/commonjs/src/core/flatten/arcs.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/arcs.js +136 -0
- package/lib/commonjs/src/core/flatten/document.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/document.js +164 -0
- package/lib/commonjs/src/core/flatten/dom.d.ts +24 -0
- package/lib/commonjs/src/core/flatten/dom.js +221 -0
- package/lib/commonjs/src/core/flatten/element.d.ts +12 -0
- package/lib/commonjs/src/core/flatten/element.js +97 -0
- package/lib/commonjs/src/core/flatten/geometry.d.ts +21 -0
- package/lib/commonjs/src/core/flatten/geometry.js +85 -0
- package/lib/commonjs/src/core/flatten/index.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/index.js +11 -0
- package/lib/commonjs/src/core/flatten/inherit.d.ts +13 -0
- package/lib/commonjs/src/core/flatten/inherit.js +249 -0
- package/lib/commonjs/src/core/flatten/path.d.ts +19 -0
- package/lib/commonjs/src/core/flatten/path.js +439 -0
- package/lib/commonjs/src/core/flatten/pathops.d.ts +14 -0
- package/lib/commonjs/src/core/flatten/pathops.js +236 -0
- package/lib/commonjs/src/core/flatten/shape.d.ts +29 -0
- package/lib/commonjs/src/core/flatten/shape.js +415 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.js +20 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.js +86 -0
- package/lib/commonjs/src/core/flatten/stages/defs.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/defs.js +49 -0
- package/lib/commonjs/src/core/flatten/stages/discard.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/discard.js +50 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.js +131 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.d.ts +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.js +37 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.d.ts +3 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.js +34 -0
- package/lib/commonjs/src/core/flatten/stages/styles.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/styles.js +29 -0
- package/lib/commonjs/src/core/flatten/stages/use.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/use.js +80 -0
- package/lib/commonjs/src/core/flatten/stages/validate.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/validate.js +39 -0
- package/lib/commonjs/src/core/flatten/stages.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages.js +40 -0
- package/lib/commonjs/src/core/flatten/transform.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/transform.js +221 -0
- package/lib/commonjs/src/core/font/compile.d.ts +2 -1
- package/lib/commonjs/src/core/font/compile.js +21 -7
- package/lib/commonjs/src/core/font/metrics.js +7 -0
- package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
- package/lib/commonjs/src/core/font/quadratic.js +31 -0
- package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
- package/lib/commonjs/src/core/glyph/merge.js +57 -0
- package/lib/commonjs/src/core/glyph/parse.d.ts +26 -0
- package/lib/commonjs/src/core/{svg/svg_dom.js → glyph/parse.js} +21 -77
- package/lib/commonjs/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +1 -13
- package/lib/commonjs/src/core/{svg/layers.js → glyph/placement.js} +0 -17
- package/lib/commonjs/src/core/glyph/validate.d.ts +8 -0
- package/lib/commonjs/src/core/glyph/validate.js +33 -0
- package/lib/commonjs/src/core/pathkit/contours.d.ts +74 -0
- package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +72 -312
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
- package/lib/commonjs/src/core/pathkit/evenodd.js +51 -0
- package/lib/commonjs/src/core/pathkit/load.d.ts +2 -0
- package/lib/commonjs/src/core/pathkit/load.js +26 -0
- package/lib/commonjs/src/core/pathkit/types.d.ts +69 -0
- package/lib/commonjs/src/core/pathkit/types.js +2 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/iconPool.d.ts +3 -0
- package/lib/commonjs/src/core/pipeline/iconPool.js +51 -0
- package/lib/commonjs/src/core/pipeline/index.d.ts +3 -3
- package/lib/commonjs/src/core/pipeline/index.js +6 -5
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +19 -0
- package/lib/commonjs/src/core/pipeline/prepare.js +56 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +22 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +78 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.js +12 -0
- package/lib/commonjs/src/core/pipeline/{run.d.ts → runFontPipeline.d.ts} +7 -4
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +109 -0
- package/lib/commonjs/src/core/types.d.ts +3 -92
- package/lib/commonjs/src/utils/fingerPrint.d.ts +8 -1
- package/lib/commonjs/src/utils/fingerPrint.js +8 -1
- package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
- package/lib/commonjs/src/utils/fontIdentity.js +24 -0
- package/lib/commonjs/src/utils/packageVersion.d.ts +2 -0
- package/lib/commonjs/src/utils/packageVersion.js +37 -0
- package/lib/commonjs/src/utils/parse.d.ts +0 -1
- package/lib/commonjs/src/utils/parse.js +0 -8
- package/lib/commonjs/src/utils/svgPatterns.d.ts +38 -0
- package/lib/commonjs/src/utils/svgPatterns.js +46 -0
- package/lib/module/const/codegenPrimitives.js +1 -2
- package/lib/module/const/colors.js +1 -2
- package/lib/module/createNanoIconsSet.js +1 -2
- package/lib/module/createNanoIconsSet.native.js +11 -4
- package/lib/module/createNanoIconsSet.shared.js +12 -7
- package/lib/module/createNanoIconsSet.web.js +7 -5
- package/lib/module/fontIntegrity.js +99 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.node.js +1 -2
- package/lib/module/loadDynamicFont.js +14 -7
- package/lib/module/nativeFontLoader.js +3 -0
- package/lib/module/nativeFontLoader.web.js +3 -0
- package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
- package/lib/module/types.js +1 -2
- package/lib/module/utils/fingerPrint.js +3 -3
- package/lib/module/utils/fontIdentity.js +20 -0
- package/lib/module/utils/glyphRuntime.js +1 -2
- package/lib/module/utils/packageVersion.js +29 -0
- package/lib/module/utils/parse.js +1 -9
- package/lib/module/utils/runtimeLog.js +12 -0
- package/lib/module/utils/shallowEqualColor.js +1 -2
- package/lib/module/utils/svgPatterns.js +49 -0
- package/lib/typescript/src/core/flatten/arcs.d.ts +3 -0
- package/lib/typescript/src/core/flatten/document.d.ts +36 -0
- package/lib/typescript/src/core/flatten/dom.d.ts +25 -0
- package/lib/typescript/src/core/flatten/element.d.ts +13 -0
- package/lib/typescript/src/core/flatten/geometry.d.ts +22 -0
- package/lib/typescript/src/core/flatten/index.d.ts +3 -0
- package/lib/typescript/src/core/flatten/inherit.d.ts +14 -0
- package/lib/typescript/src/core/flatten/path.d.ts +20 -0
- package/lib/typescript/src/core/flatten/pathops.d.ts +15 -0
- package/lib/typescript/src/core/flatten/shape.d.ts +30 -0
- package/lib/typescript/src/core/flatten/stages/clip-path.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/collapse.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/defs.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/discard.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/fill-rule.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/nested-svg.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/opacity.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/shapes.d.ts +8 -0
- package/lib/typescript/src/core/flatten/stages/stroke.d.ts +4 -0
- package/lib/typescript/src/core/flatten/stages/styles.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/use.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/validate.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages.d.ts +3 -0
- package/lib/typescript/src/core/flatten/transform.d.ts +36 -0
- package/lib/typescript/src/core/glyph/merge.d.ts +8 -0
- package/lib/typescript/src/core/glyph/parse.d.ts +27 -0
- package/lib/typescript/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +2 -14
- package/lib/typescript/src/core/glyph/validate.d.ts +9 -0
- package/lib/typescript/src/core/pathkit/contours.d.ts +75 -0
- package/lib/typescript/src/core/pathkit/evenodd.d.ts +13 -0
- package/lib/typescript/src/core/pathkit/load.d.ts +3 -0
- package/lib/typescript/src/core/pathkit/types.d.ts +70 -0
- package/lib/typescript/src/core/types.d.ts +3 -92
- package/lib/typescript/src/fontIntegrity.d.ts +24 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/nativeFontLoader.d.ts +2 -0
- package/lib/typescript/src/nativeFontLoader.web.d.ts +3 -0
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/types.d.ts +5 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +8 -1
- package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
- package/lib/typescript/src/utils/packageVersion.d.ts +3 -0
- package/lib/typescript/src/utils/parse.d.ts +0 -1
- package/lib/typescript/src/utils/runtimeLog.d.ts +5 -0
- package/lib/typescript/src/utils/svgPatterns.d.ts +39 -0
- package/package.json +13 -11
- package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
- package/lib/commonjs/src/core/pipeline/managers.d.ts +0 -11
- package/lib/commonjs/src/core/pipeline/managers.js +0 -104
- package/lib/commonjs/src/core/pipeline/run.js +0 -189
- package/lib/commonjs/src/core/svg/svg_dom.d.ts +0 -51
- package/lib/commonjs/src/core/svg/svg_pathops.d.ts +0 -32
- package/lib/module/const/codegenPrimitives.js.map +0 -1
- package/lib/module/const/colors.js.map +0 -1
- package/lib/module/core/font/compile.js +0 -81
- package/lib/module/core/font/compile.js.map +0 -1
- package/lib/module/core/font/metrics.js +0 -37
- package/lib/module/core/font/metrics.js.map +0 -1
- package/lib/module/core/pipeline/config.js +0 -20
- package/lib/module/core/pipeline/config.js.map +0 -1
- package/lib/module/core/pipeline/index.js +0 -5
- package/lib/module/core/pipeline/index.js.map +0 -1
- package/lib/module/core/pipeline/managers.js +0 -94
- package/lib/module/core/pipeline/managers.js.map +0 -1
- package/lib/module/core/pipeline/run.js +0 -204
- package/lib/module/core/pipeline/run.js.map +0 -1
- package/lib/module/core/shims/pathops.py +0 -181
- package/lib/module/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/lib/module/core/svg/layers.js +0 -85
- package/lib/module/core/svg/layers.js.map +0 -1
- package/lib/module/core/svg/svg_dom.js +0 -170
- package/lib/module/core/svg/svg_dom.js.map +0 -1
- package/lib/module/core/svg/svg_pathops.js +0 -750
- package/lib/module/core/svg/svg_pathops.js.map +0 -1
- package/lib/module/core/tsconfig.json +0 -32
- package/lib/module/core/types.js +0 -2
- package/lib/module/core/types.js.map +0 -1
- package/lib/module/createNanoIconsSet.js.map +0 -1
- package/lib/module/createNanoIconsSet.native.js.map +0 -1
- package/lib/module/createNanoIconsSet.shared.js.map +0 -1
- package/lib/module/createNanoIconsSet.web.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.node.js.map +0 -1
- package/lib/module/loadDynamicFont.js.map +0 -1
- package/lib/module/specs/NativeNanoIconsFontLoader.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/fingerPrint.js.map +0 -1
- package/lib/module/utils/glyphRuntime.js.map +0 -1
- package/lib/module/utils/parse.js.map +0 -1
- package/lib/module/utils/shallowEqualColor.js.map +0 -1
- package/lib/typescript/__tests__/build.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/build.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/link.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/link.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/placement.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/placement.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts.map +0 -1
- package/lib/typescript/cli/build.d.ts +0 -32
- package/lib/typescript/cli/build.d.ts.map +0 -1
- package/lib/typescript/cli/link.d.ts +0 -12
- package/lib/typescript/cli/link.d.ts.map +0 -1
- package/lib/typescript/cli/logger.d.ts +0 -28
- package/lib/typescript/cli/logger.d.ts.map +0 -1
- package/lib/typescript/src/const/codegenPrimitives.d.ts.map +0 -1
- package/lib/typescript/src/const/colors.d.ts.map +0 -1
- package/lib/typescript/src/core/font/compile.d.ts +0 -21
- package/lib/typescript/src/core/font/compile.d.ts.map +0 -1
- package/lib/typescript/src/core/font/metrics.d.ts +0 -2
- package/lib/typescript/src/core/font/metrics.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/config.d.ts +0 -16
- package/lib/typescript/src/core/pipeline/config.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/index.d.ts +0 -4
- package/lib/typescript/src/core/pipeline/index.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/managers.d.ts +0 -12
- package/lib/typescript/src/core/pipeline/managers.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/run.d.ts +0 -15
- package/lib/typescript/src/core/pipeline/run.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/layers.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_dom.d.ts +0 -52
- package/lib/typescript/src/core/svg/svg_dom.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_pathops.d.ts +0 -33
- package/lib/typescript/src/core/svg/svg_pathops.d.ts.map +0 -1
- package/lib/typescript/src/core/types.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.native.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.shared.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.web.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/index.node.d.ts.map +0 -1
- package/lib/typescript/src/loadDynamicFont.d.ts.map +0 -1
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts.map +0 -1
- package/lib/typescript/src/types.d.ts.map +0 -1
- package/lib/typescript/src/utils/fingerPrint.d.ts.map +0 -1
- package/lib/typescript/src/utils/glyphRuntime.d.ts.map +0 -1
- package/lib/typescript/src/utils/parse.d.ts.map +0 -1
- package/lib/typescript/src/utils/shallowEqualColor.d.ts.map +0 -1
- package/plugin/src/buildFonts.ts +0 -42
- package/plugin/src/index.ts +0 -21
- package/plugin/src/types.ts +0 -42
- package/plugin/src/withNanoIconsFontLinking.ts +0 -136
- package/plugin/tsconfig.json +0 -9
- package/scripts/cli.ts +0 -63
- package/scripts/tsconfig.json +0 -25
- package/src/const/colors.ts +0 -150
- package/src/core/font/compile.ts +0 -99
- package/src/core/font/metrics.ts +0 -44
- package/src/core/pipeline/config.ts +0 -25
- package/src/core/pipeline/index.ts +0 -3
- package/src/core/pipeline/managers.ts +0 -132
- package/src/core/pipeline/run.ts +0 -274
- package/src/core/shims/pathops.py +0 -181
- package/src/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/src/core/svg/layers.ts +0 -110
- package/src/core/svg/svg_dom.ts +0 -194
- package/src/core/svg/svg_pathops.ts +0 -1040
- package/src/core/tsconfig.json +0 -32
- package/src/core/types.ts +0 -157
- package/src/createNanoIconsSet.native.tsx +0 -192
- package/src/createNanoIconsSet.shared.tsx +0 -174
- package/src/createNanoIconsSet.tsx +0 -20
- package/src/createNanoIconsSet.web.tsx +0 -109
- package/src/index.node.ts +0 -14
- package/src/index.ts +0 -6
- package/src/loadDynamicFont.ts +0 -162
- package/src/types.ts +0 -31
- package/src/utils/fingerPrint.ts +0 -20
- package/src/utils/glyphRuntime.ts +0 -46
- package/src/utils/parse.ts +0 -67
- package/src/utils/shallowEqualColor.ts +0 -17
|
@@ -30,13 +30,15 @@ async function createOraLogger(level) {
|
|
|
30
30
|
spinner.fail(chalk.red(msg));
|
|
31
31
|
},
|
|
32
32
|
info(msg) {
|
|
33
|
-
if (level
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
33
|
+
if (level !== 'verbose')
|
|
34
|
+
return;
|
|
35
|
+
spinner.clear();
|
|
36
|
+
process.stdout.write(`${dimPrefix}${chalk.dim(msg)}\n`);
|
|
37
|
+
if (spinner.isSpinning && process.stdout.isTTY)
|
|
38
|
+
spinner.render();
|
|
37
39
|
},
|
|
38
40
|
warn(msg) {
|
|
39
|
-
spinner.warn(chalk.
|
|
41
|
+
spinner.warn(chalk.dim(msg));
|
|
40
42
|
},
|
|
41
43
|
};
|
|
42
44
|
}
|
|
@@ -63,14 +65,14 @@ async function createQuietLogger(level) {
|
|
|
63
65
|
console.log(`${dimPrefix} ${tick} ${msg}`);
|
|
64
66
|
},
|
|
65
67
|
fail(msg) {
|
|
66
|
-
console.error(`${dimPrefix} ${cross} ${msg}`);
|
|
68
|
+
console.error(`${dimPrefix} ${cross} ${chalk.red(msg)}`);
|
|
67
69
|
},
|
|
68
70
|
info(msg) {
|
|
69
71
|
if (level === 'verbose')
|
|
70
72
|
console.log(`${dimPrefix} ${info} ${msg}`);
|
|
71
73
|
},
|
|
72
74
|
warn(msg) {
|
|
73
|
-
console.warn(`${dimPrefix} ${warning} ${msg}`);
|
|
75
|
+
console.warn(`${dimPrefix} ${warning} ${chalk.dim(msg)}`);
|
|
74
76
|
},
|
|
75
77
|
};
|
|
76
78
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { IconSetConfig, BuiltFont } from './types
|
|
1
|
+
import type { IconSetConfig, BuiltFont } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Build TTF + glyphmap for all icon sets.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Reports every broken icon, then fails the prebuild so no set is silently left unlinked.
|
|
5
|
+
* EXPO_DEBUG adds the per-file processing details.
|
|
6
6
|
*/
|
|
7
7
|
export declare function buildAllFonts(iconSets: IconSetConfig[], projectRoot: string): Promise<BuiltFont[]>;
|
|
8
8
|
export declare function getOrBuildFonts(projectRoot: string, iconSets: IconSetConfig[]): Promise<BuiltFont[]>;
|
|
@@ -2,25 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildAllFonts = buildAllFonts;
|
|
4
4
|
exports.getOrBuildFonts = getOrBuildFonts;
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../../cli/index");
|
|
6
6
|
/**
|
|
7
7
|
* Build TTF + glyphmap for all icon sets.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Reports every broken icon, then fails the prebuild so no set is silently left unlinked.
|
|
9
|
+
* EXPO_DEBUG adds the per-file processing details.
|
|
10
10
|
*/
|
|
11
11
|
async function buildAllFonts(iconSets, projectRoot) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
return await (0, index_js_1.buildAllFonts)(iconSets, projectRoot, { logger });
|
|
16
|
-
}
|
|
17
|
-
catch (err) {
|
|
18
|
-
if (level === 'verbose') {
|
|
19
|
-
throw err;
|
|
20
|
-
}
|
|
21
|
-
logger.fail('Error optimizing icons. Run with EXPO_DEBUG=1 for more logs.');
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
12
|
+
const logger = await (0, index_1.createQuietLogger)((0, index_1.detectExpoLogLevel)());
|
|
13
|
+
return (0, index_1.buildAllFonts)(iconSets, projectRoot, { logger });
|
|
24
14
|
}
|
|
25
15
|
// Single build run per process; reused across ios/android mods.
|
|
26
16
|
let _buildPromise = null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
-
import type { NanoIconsPluginOptions } from './types
|
|
2
|
+
import type { NanoIconsPluginOptions } from './types';
|
|
3
3
|
declare const withNanoIcons: ConfigPlugin<NanoIconsPluginOptions>;
|
|
4
4
|
export default withNanoIcons;
|
|
5
|
-
export type { NanoIconsPluginOptions, IconSetConfig, BuiltFont
|
|
5
|
+
export type { NanoIconsPluginOptions, IconSetConfig, BuiltFont } from './types';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const withNanoIconsFontLinking_1 = require("./withNanoIconsFontLinking");
|
|
4
4
|
const withNanoIcons = (config, options) => {
|
|
5
5
|
if (!options?.iconSets?.length)
|
|
6
6
|
return config;
|
|
7
|
-
config = (0,
|
|
7
|
+
config = (0, withNanoIconsFontLinking_1.withNanoIconsFontLinking)(config, options.iconSets);
|
|
8
8
|
return config;
|
|
9
9
|
};
|
|
10
10
|
exports.default = withNanoIcons;
|
|
@@ -10,7 +10,7 @@ export interface IconSetConfig {
|
|
|
10
10
|
outputDir?: string;
|
|
11
11
|
/** Units per em (default 1024). */
|
|
12
12
|
upm?: number;
|
|
13
|
-
/** Safe zone inside UPM for glyphs (default 1020). */
|
|
13
|
+
/** Safe zone inside UPM for glyphs (default upm * 1020 / 1024, i.e. 1020 at the default upm). Must not exceed upm. */
|
|
14
14
|
safeZone?: number;
|
|
15
15
|
/** First Unicode codepoint for glyphs (default 0xe900). Hex string or number. */
|
|
16
16
|
startUnicode?: number | string;
|
|
@@ -22,6 +22,13 @@ export interface IconSetConfig {
|
|
|
22
22
|
* delivering it (e.g. via OTA) and registering it under the same font family name.
|
|
23
23
|
*/
|
|
24
24
|
linking?: 'static' | 'dynamic';
|
|
25
|
+
/**
|
|
26
|
+
* Also emit `<fontFamily>.woff2` into `outputDir` for web. Defaults to `false`.
|
|
27
|
+
*
|
|
28
|
+
* The file is rebuilt together with the TTF on every change and is never linked
|
|
29
|
+
* natively; the host app links it like any other web font, under `fontFamily`.
|
|
30
|
+
*/
|
|
31
|
+
web?: boolean;
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* plugins: [ [ "react-native-nano-icons", { iconSets: [...] } ] ]
|
|
@@ -34,7 +41,9 @@ export interface NanoIconsPluginOptions {
|
|
|
34
41
|
*/
|
|
35
42
|
export interface BuiltFont {
|
|
36
43
|
fontFamily: string;
|
|
44
|
+
family: string;
|
|
37
45
|
ttfPath: string;
|
|
38
46
|
glyphmapPath: string;
|
|
39
47
|
linking: 'static' | 'dynamic';
|
|
48
|
+
woff2Path?: string;
|
|
40
49
|
}
|
|
@@ -9,7 +9,8 @@ exports.withNanoIconsFontLinking = withNanoIconsFontLinking;
|
|
|
9
9
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
10
10
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const
|
|
12
|
+
const buildFonts_1 = require("./buildFonts");
|
|
13
|
+
const index_1 = require("../../cli/index");
|
|
13
14
|
const ANDROID_ASSETS_FONTS_DIR = 'app/src/main/assets/fonts';
|
|
14
15
|
const IOS_FONTS_GROUP = 'Resources';
|
|
15
16
|
/**
|
|
@@ -22,7 +23,7 @@ const IOS_FONTS_GROUP = 'Resources';
|
|
|
22
23
|
*/
|
|
23
24
|
function withNanoIconsIos(config, iconSets) {
|
|
24
25
|
config = (0, config_plugins_1.withXcodeProject)(config, async (config) => {
|
|
25
|
-
const built = await (0,
|
|
26
|
+
const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
|
|
26
27
|
const bundled = built?.filter((b) => b.linking !== 'dynamic') ?? [];
|
|
27
28
|
if (!bundled.length)
|
|
28
29
|
return config;
|
|
@@ -48,7 +49,7 @@ function withNanoIconsIos(config, iconSets) {
|
|
|
48
49
|
return config;
|
|
49
50
|
});
|
|
50
51
|
config = (0, config_plugins_1.withInfoPlist)(config, async (config) => {
|
|
51
|
-
const built = await (0,
|
|
52
|
+
const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
|
|
52
53
|
const bundled = built?.filter((b) => b.linking !== 'dynamic') ?? [];
|
|
53
54
|
if (!bundled.length)
|
|
54
55
|
return config;
|
|
@@ -77,17 +78,9 @@ function withNanoIconsAndroid(config, iconSets) {
|
|
|
77
78
|
return (0, config_plugins_1.withDangerousMod)(config, [
|
|
78
79
|
'android',
|
|
79
80
|
async (config) => {
|
|
80
|
-
const built = await (0,
|
|
81
|
+
const built = await (0, buildFonts_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
|
|
81
82
|
const bundled = built?.filter((b) => b.linking !== 'dynamic') ?? [];
|
|
82
|
-
|
|
83
|
-
return config;
|
|
84
|
-
const fontsDir = path_1.default.join(config.modRequest.platformProjectRoot, ANDROID_ASSETS_FONTS_DIR);
|
|
85
|
-
await promises_1.default.mkdir(fontsDir, { recursive: true });
|
|
86
|
-
for (const b of bundled) {
|
|
87
|
-
const filename = path_1.default.basename(b.ttfPath);
|
|
88
|
-
const dest = path_1.default.join(fontsDir, filename);
|
|
89
|
-
await promises_1.default.copyFile(b.ttfPath, dest);
|
|
90
|
-
}
|
|
83
|
+
(0, index_1.syncAndroidFontAssets)(path_1.default.join(config.modRequest.platformProjectRoot, ANDROID_ASSETS_FONTS_DIR), bundled, built?.map((b) => b.fontFamily) ?? []);
|
|
91
84
|
return config;
|
|
92
85
|
},
|
|
93
86
|
]);
|
|
@@ -4,47 +4,70 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.main = main;
|
|
7
8
|
/**
|
|
8
|
-
* Run from your app root: npx react-native-nano-icons [--verbose] [--path <dir>] [--dynamic] [--app-config]
|
|
9
|
+
* Run from your app root: npx react-native-nano-icons [--verbose] [--path <dir|file>] [--dynamic] [--app-config]
|
|
9
10
|
*
|
|
10
11
|
* Flags:
|
|
11
12
|
* --verbose Show per-SVG processing details and pipeline timing
|
|
12
|
-
* --path <dir>
|
|
13
|
+
* --path <dir|file> An app folder (has a package.json): read the config, build and link there.
|
|
14
|
+
* Any other folder or .nanoicons.json: read the config there, build and link
|
|
15
|
+
* in the current directory. Default: cwd.
|
|
13
16
|
* --dynamic Rebuild only icon sets with linking: 'dynamic'. Skips native linking —
|
|
14
17
|
* use this for OTA font regeneration without running expo prebuild.
|
|
15
18
|
* --app-config Read config from Expo app config (app.json / app.config.js / app.config.ts)
|
|
16
19
|
* instead of .nanoicons.json. Must be combined with --dynamic.
|
|
17
20
|
*/
|
|
21
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
18
22
|
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
-
const
|
|
20
|
-
async function main() {
|
|
21
|
-
const verbose = process.argv.includes('--verbose');
|
|
23
|
+
const index_1 = require("../cli/index");
|
|
24
|
+
async function main(logger) {
|
|
22
25
|
const dynamic = process.argv.includes('--dynamic');
|
|
23
26
|
const appConfig = process.argv.includes('--app-config');
|
|
24
|
-
const
|
|
25
|
-
const pathIdx = process.argv.indexOf('--path');
|
|
26
|
-
const projectRoot = process.cwd();
|
|
27
|
-
const configRoot = pathIdx !== -1 && process.argv[pathIdx + 1]
|
|
28
|
-
? node_path_1.default.resolve(projectRoot, process.argv[pathIdx + 1])
|
|
29
|
-
: projectRoot;
|
|
30
|
-
const logger = await (0, index_js_1.createOraLogger)(level);
|
|
27
|
+
const { appRoot, configRoot } = resolveRoots(process.argv);
|
|
31
28
|
if (dynamic) {
|
|
32
29
|
const source = appConfig ? 'Expo app config' : '.nanoicons.json';
|
|
33
30
|
logger.start(`Reading dynamic icon sets from ${source}...`);
|
|
34
31
|
const dynamicIconSets = appConfig
|
|
35
|
-
? (0,
|
|
36
|
-
: (0,
|
|
32
|
+
? (0, index_1.loadDynamicSetsFromAppConfig)(appRoot)
|
|
33
|
+
: (0, index_1.loadDynamicIconSets)(configRoot);
|
|
37
34
|
logger.succeed(`Found ${dynamicIconSets.length} dynamic icon set(s) — skipping native linking.`);
|
|
38
|
-
await (0,
|
|
35
|
+
await (0, index_1.buildAllFonts)(dynamicIconSets, appRoot, { logger });
|
|
39
36
|
}
|
|
40
37
|
else {
|
|
41
|
-
const config = (0,
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const config = (0, index_1.loadNanoIconsConfig)(configRoot);
|
|
39
|
+
let built;
|
|
40
|
+
let buildError;
|
|
41
|
+
try {
|
|
42
|
+
built = await (0, index_1.buildAllFonts)(config.iconSets, appRoot, { logger });
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (!(err instanceof index_1.IconSetBuildError))
|
|
46
|
+
throw err;
|
|
47
|
+
buildError = err;
|
|
48
|
+
built = err.built;
|
|
49
|
+
}
|
|
50
|
+
await (0, index_1.linkBare)(appRoot, built, logger, config.iconSets.length);
|
|
51
|
+
if (buildError)
|
|
52
|
+
throw buildError;
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
function resolveRoots(argv) {
|
|
56
|
+
const cwd = process.cwd();
|
|
57
|
+
const pathIdx = argv.indexOf('--path');
|
|
58
|
+
const target = pathIdx !== -1 ? argv[pathIdx + 1] : undefined;
|
|
59
|
+
if (!target)
|
|
60
|
+
return { appRoot: cwd, configRoot: cwd };
|
|
61
|
+
const resolved = node_path_1.default.resolve(cwd, target);
|
|
62
|
+
const configRoot = node_fs_1.default.existsSync(resolved) && node_fs_1.default.statSync(resolved).isFile()
|
|
63
|
+
? node_path_1.default.dirname(resolved)
|
|
64
|
+
: resolved;
|
|
65
|
+
const isApp = node_fs_1.default.existsSync(node_path_1.default.join(configRoot, 'package.json'));
|
|
66
|
+
return { appRoot: isApp ? configRoot : cwd, configRoot };
|
|
67
|
+
}
|
|
68
|
+
if (require.main === module) {
|
|
69
|
+
(0, index_1.createOraLogger)(process.argv.includes('--verbose') ? 'verbose' : 'normal').then((logger) => main(logger).catch((err) => {
|
|
70
|
+
logger.fail(err instanceof Error ? err.message : String(err));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arcToCubic = arcToCubic;
|
|
4
|
+
const geometry_1 = require("./geometry");
|
|
5
|
+
const transform_1 = require("./transform");
|
|
6
|
+
const TWO_PI = 2 * Math.PI;
|
|
7
|
+
const PI_OVER_TWO = 0.5 * Math.PI;
|
|
8
|
+
function isStraightLine(arc) {
|
|
9
|
+
// If rx = 0 or ry = 0 then this arc is treated as a straight line segment (a
|
|
10
|
+
// "lineto") joining the endpoints.
|
|
11
|
+
// http://www.w3.org/TR/SVG/implnote.html#ArcOutOfRangeParameters
|
|
12
|
+
const rx = Math.abs(arc.rx);
|
|
13
|
+
const ry = Math.abs(arc.ry);
|
|
14
|
+
return !(rx && ry);
|
|
15
|
+
}
|
|
16
|
+
function isZeroLength(arc) {
|
|
17
|
+
return (0, geometry_1.ptEquals)(arc.endPoint, arc.startPoint);
|
|
18
|
+
}
|
|
19
|
+
// http://www.w3.org/TR/SVG/implnote.html#ArcCorrectionOutOfRangeRadii
|
|
20
|
+
function correctOutOfRangeRadii(arc) {
|
|
21
|
+
if (isStraightLine(arc) || isZeroLength(arc)) {
|
|
22
|
+
return arc;
|
|
23
|
+
}
|
|
24
|
+
const midPointDistance = (0, geometry_1.ptMul)((0, geometry_1.ptSub)(arc.startPoint, arc.endPoint), 0.5);
|
|
25
|
+
const angle = (arc.rotation * Math.PI) / 180;
|
|
26
|
+
const pointTransform = transform_1.Affine2D.identity().rotate(-angle);
|
|
27
|
+
const transformedMidPoint = pointTransform.mapVector(midPointDistance);
|
|
28
|
+
let rx = arc.rx;
|
|
29
|
+
let ry = arc.ry;
|
|
30
|
+
const squareRx = rx * rx;
|
|
31
|
+
const squareRy = ry * ry;
|
|
32
|
+
const squareX = transformedMidPoint.x * transformedMidPoint.x;
|
|
33
|
+
const squareY = transformedMidPoint.y * transformedMidPoint.y;
|
|
34
|
+
const radiiScale = squareX / squareRx + squareY / squareRy;
|
|
35
|
+
if (radiiScale > 1) {
|
|
36
|
+
rx *= Math.sqrt(radiiScale);
|
|
37
|
+
ry *= Math.sqrt(radiiScale);
|
|
38
|
+
return { ...arc, rx, ry };
|
|
39
|
+
}
|
|
40
|
+
return arc;
|
|
41
|
+
}
|
|
42
|
+
// https://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter
|
|
43
|
+
function endToCenterParametrization(arc) {
|
|
44
|
+
const angle = (arc.rotation * Math.PI) / 180;
|
|
45
|
+
const pointTransform = transform_1.Affine2D.identity()
|
|
46
|
+
.scale(1 / arc.rx, 1 / arc.ry)
|
|
47
|
+
.rotate(-angle);
|
|
48
|
+
const point1 = pointTransform.mapPoint(arc.startPoint);
|
|
49
|
+
const point2 = pointTransform.mapPoint(arc.endPoint);
|
|
50
|
+
let delta = (0, geometry_1.ptSub)(point2, point1);
|
|
51
|
+
const d = delta.x * delta.x + delta.y * delta.y;
|
|
52
|
+
const scaleFactorSquared = Math.max(1 / d - 0.25, 0.0);
|
|
53
|
+
let scaleFactor = Math.sqrt(scaleFactorSquared);
|
|
54
|
+
if (arc.sweep === arc.large) {
|
|
55
|
+
scaleFactor = -scaleFactor;
|
|
56
|
+
}
|
|
57
|
+
delta = (0, geometry_1.ptMul)(delta, scaleFactor);
|
|
58
|
+
let centerPoint = (0, geometry_1.ptAdd)((0, geometry_1.ptAdd)(point1, (0, geometry_1.ptMul)((0, geometry_1.ptSub)(point2, point1), 0.5)), (0, geometry_1.pt)(-delta.y, delta.x));
|
|
59
|
+
const v1 = (0, geometry_1.ptSub)(point1, centerPoint);
|
|
60
|
+
const v2 = (0, geometry_1.ptSub)(point2, centerPoint);
|
|
61
|
+
const theta1 = Math.atan2(v1.y, v1.x);
|
|
62
|
+
const theta2 = Math.atan2(v2.y, v2.x);
|
|
63
|
+
let thetaArc = theta2 - theta1;
|
|
64
|
+
if (thetaArc < 0 && arc.sweep) {
|
|
65
|
+
thetaArc += TWO_PI;
|
|
66
|
+
}
|
|
67
|
+
else if (thetaArc > 0 && !arc.sweep) {
|
|
68
|
+
thetaArc -= TWO_PI;
|
|
69
|
+
}
|
|
70
|
+
centerPoint = pointTransform.inverse().mapPoint(centerPoint);
|
|
71
|
+
return { theta1, thetaArc, centerPoint };
|
|
72
|
+
}
|
|
73
|
+
function* ellipticalArcToCubic(arc) {
|
|
74
|
+
arc = correctOutOfRangeRadii(arc);
|
|
75
|
+
const arcParams = endToCenterParametrization(arc);
|
|
76
|
+
const pointTransform = transform_1.Affine2D.identity()
|
|
77
|
+
.translate(arcParams.centerPoint.x, arcParams.centerPoint.y)
|
|
78
|
+
.rotate((arc.rotation * Math.PI) / 180)
|
|
79
|
+
.scale(arc.rx, arc.ry);
|
|
80
|
+
// Some results of atan2 on some platform implementations are not exact
|
|
81
|
+
// enough. So that we get more cubic curves than expected here. Adding 0.001f
|
|
82
|
+
// reduces the count of segments to the correct count.
|
|
83
|
+
const numSegments = Math.ceil(Math.abs(arcParams.thetaArc / (PI_OVER_TWO + 0.001)));
|
|
84
|
+
for (let i = 0; i < numSegments; i++) {
|
|
85
|
+
const startTheta = arcParams.theta1 + (i * arcParams.thetaArc) / numSegments;
|
|
86
|
+
const endTheta = arcParams.theta1 + ((i + 1) * arcParams.thetaArc) / numSegments;
|
|
87
|
+
const t = (4 / 3) * Math.tan(0.25 * (endTheta - startTheta));
|
|
88
|
+
if (!Number.isFinite(t)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const sinStartTheta = Math.sin(startTheta);
|
|
92
|
+
const cosStartTheta = Math.cos(startTheta);
|
|
93
|
+
const sinEndTheta = Math.sin(endTheta);
|
|
94
|
+
const cosEndTheta = Math.cos(endTheta);
|
|
95
|
+
let point1 = (0, geometry_1.pt)(cosStartTheta - t * sinStartTheta, sinStartTheta + t * cosStartTheta);
|
|
96
|
+
let endPoint = (0, geometry_1.pt)(cosEndTheta, sinEndTheta);
|
|
97
|
+
let point2 = (0, geometry_1.ptAdd)(endPoint, (0, geometry_1.pt)(t * sinEndTheta, -t * cosEndTheta));
|
|
98
|
+
point1 = pointTransform.mapPoint(point1);
|
|
99
|
+
point2 = pointTransform.mapPoint(point2);
|
|
100
|
+
// by definition, the last bezier's end point == the arc end point
|
|
101
|
+
// by directly taking the end point we avoid floating point imprecision
|
|
102
|
+
if (i === numSegments - 1) {
|
|
103
|
+
endPoint = arc.endPoint;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
endPoint = pointTransform.mapPoint(endPoint);
|
|
107
|
+
}
|
|
108
|
+
yield [point1, point2, endPoint];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Convert arc to cubic(s).
|
|
112
|
+
//
|
|
113
|
+
// Yields [p1, p2, endPoint] per cubic bezier (two off-curve, one on-curve).
|
|
114
|
+
// If either rx or ry is 0 the arc is a straight line joining the end points
|
|
115
|
+
// and a [null, null, endPoint] tuple is yielded.
|
|
116
|
+
// Yields nothing if the arc has zero length.
|
|
117
|
+
function* arcToCubic(startPoint, rx, ry, rotation, large, sweep, endPoint) {
|
|
118
|
+
const arc = {
|
|
119
|
+
startPoint,
|
|
120
|
+
rx,
|
|
121
|
+
ry,
|
|
122
|
+
rotation,
|
|
123
|
+
large,
|
|
124
|
+
sweep,
|
|
125
|
+
endPoint,
|
|
126
|
+
};
|
|
127
|
+
if (isZeroLength(arc)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
else if (isStraightLine(arc)) {
|
|
131
|
+
yield [null, null, arc.endPoint];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
yield* ellipticalArcToCubic(arc);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Rect } from './geometry';
|
|
2
|
+
import { XEl } from './dom';
|
|
3
|
+
import type { PathOps } from './pathops';
|
|
4
|
+
import type { Shape } from './shape';
|
|
5
|
+
import { Affine2D } from './transform';
|
|
6
|
+
export type TraverseContext = {
|
|
7
|
+
nthOfType: number;
|
|
8
|
+
element: XEl;
|
|
9
|
+
path: string;
|
|
10
|
+
transform: Affine2D;
|
|
11
|
+
clips: Shape[];
|
|
12
|
+
attrib: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
export type ShapeEntry = [XEl, Shape[]];
|
|
15
|
+
export declare class SvgDocument {
|
|
16
|
+
readonly root: XEl;
|
|
17
|
+
readonly ops: PathOps;
|
|
18
|
+
private shapeCache;
|
|
19
|
+
constructor(root: XEl, ops: PathOps);
|
|
20
|
+
static parse(content: string, ops: PathOps): SvgDocument;
|
|
21
|
+
hasShapes(): boolean;
|
|
22
|
+
shapeEntries(): ShapeEntry[];
|
|
23
|
+
invalidateShapes(): void;
|
|
24
|
+
mapShapes(fn: (shape: Shape) => Shape): void;
|
|
25
|
+
forEachShape(fn: (shape: Shape) => void): void;
|
|
26
|
+
private inheritedAttrib;
|
|
27
|
+
syncTree(): void;
|
|
28
|
+
viewBox(): Rect | null;
|
|
29
|
+
get tolerance(): number;
|
|
30
|
+
resolveUrl(url: string, elTag: string): XEl;
|
|
31
|
+
private traverse;
|
|
32
|
+
depthFirst(resolveClipPaths?: boolean): Generator<TraverseContext, void, void>;
|
|
33
|
+
breadthFirst(resolveClipPaths?: boolean): Generator<TraverseContext, void, void>;
|
|
34
|
+
serialize(): string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SvgDocument = void 0;
|
|
4
|
+
const dom_1 = require("./dom");
|
|
5
|
+
const inherit_1 = require("./inherit");
|
|
6
|
+
const shape_1 = require("./shape");
|
|
7
|
+
const transform_1 = require("./transform");
|
|
8
|
+
const element_1 = require("./element");
|
|
9
|
+
const clip_path_1 = require("./stages/clip-path");
|
|
10
|
+
// How much error, as pct of viewbox max(w,h), is allowed on lossy ops
|
|
11
|
+
const MAX_PCT_ERROR = 0.1;
|
|
12
|
+
// When you have no viewbox, use this. Absolute value in svg units.
|
|
13
|
+
const DEFAULT_DEFAULT_TOLERANCE = 0.1;
|
|
14
|
+
class SvgDocument {
|
|
15
|
+
root;
|
|
16
|
+
ops;
|
|
17
|
+
shapeCache = null;
|
|
18
|
+
constructor(root, ops) {
|
|
19
|
+
this.root = root;
|
|
20
|
+
this.ops = ops;
|
|
21
|
+
}
|
|
22
|
+
static parse(content, ops) {
|
|
23
|
+
return new SvgDocument((0, dom_1.parseSvgDocument)(content), ops);
|
|
24
|
+
}
|
|
25
|
+
// ---- shape/element cache sync ----
|
|
26
|
+
hasShapes() {
|
|
27
|
+
return this.shapeCache !== null;
|
|
28
|
+
}
|
|
29
|
+
shapeEntries() {
|
|
30
|
+
if (this.shapeCache) {
|
|
31
|
+
return this.shapeCache;
|
|
32
|
+
}
|
|
33
|
+
const entries = [];
|
|
34
|
+
for (const context of this.depthFirst(false)) {
|
|
35
|
+
const el = context.element;
|
|
36
|
+
if (!(0, shape_1.isShapeTag)(el.tag))
|
|
37
|
+
continue;
|
|
38
|
+
entries.push([el, [(0, shape_1.fromElement)(el, context.attrib)]]);
|
|
39
|
+
}
|
|
40
|
+
this.shapeCache = entries;
|
|
41
|
+
return this.shapeCache;
|
|
42
|
+
}
|
|
43
|
+
invalidateShapes() {
|
|
44
|
+
this.shapeCache = null;
|
|
45
|
+
}
|
|
46
|
+
mapShapes(fn) {
|
|
47
|
+
const entries = this.shapeEntries();
|
|
48
|
+
entries.forEach(([el, shapes], idx) => {
|
|
49
|
+
entries[idx] = [el, shapes.map(fn)];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
forEachShape(fn) {
|
|
53
|
+
for (const [, shapes] of this.shapeEntries()) {
|
|
54
|
+
for (const shape of shapes) {
|
|
55
|
+
fn(shape);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
inheritedAttrib(el) {
|
|
60
|
+
const parents = [];
|
|
61
|
+
let current = el.parent;
|
|
62
|
+
while (current !== null) {
|
|
63
|
+
parents.push(current);
|
|
64
|
+
current = current.parent;
|
|
65
|
+
}
|
|
66
|
+
let attrib = { ...inherit_1.INHERITABLE_ATTRIB_DEFAULTS };
|
|
67
|
+
for (const parent of parents.reverse()) {
|
|
68
|
+
attrib = (0, inherit_1.attribToPassOn)(attrib, parent);
|
|
69
|
+
}
|
|
70
|
+
return attrib;
|
|
71
|
+
}
|
|
72
|
+
syncTree() {
|
|
73
|
+
if (!this.shapeCache)
|
|
74
|
+
return;
|
|
75
|
+
for (const [oldEl, shapes] of this.shapeCache) {
|
|
76
|
+
const inherited = this.inheritedAttrib(oldEl);
|
|
77
|
+
(0, dom_1.replaceEl)(oldEl, shapes.map((s) => (0, shape_1.toElement)(s, inherited)));
|
|
78
|
+
}
|
|
79
|
+
this.shapeCache = null;
|
|
80
|
+
}
|
|
81
|
+
// ---- geometry context ----
|
|
82
|
+
viewBox() {
|
|
83
|
+
const raw = this.root.attrib.get('viewBox');
|
|
84
|
+
if (raw === undefined) {
|
|
85
|
+
const w = this.root.attrib.get('width');
|
|
86
|
+
const h = this.root.attrib.get('height');
|
|
87
|
+
if (w && h) {
|
|
88
|
+
return { x: 0, y: 0, w: parseFloat(w), h: parseFloat(h) };
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return (0, element_1.parseViewBox)(raw);
|
|
93
|
+
}
|
|
94
|
+
get tolerance() {
|
|
95
|
+
const vbox = this.viewBox();
|
|
96
|
+
if (vbox === null)
|
|
97
|
+
return DEFAULT_DEFAULT_TOLERANCE;
|
|
98
|
+
return (Math.min(vbox.w, vbox.h) * MAX_PCT_ERROR) / 100;
|
|
99
|
+
}
|
|
100
|
+
// ---- lookups ----
|
|
101
|
+
resolveUrl(url, elTag) {
|
|
102
|
+
const id = (0, element_1.idOfTarget)(url);
|
|
103
|
+
const matches = (0, dom_1.findAll)(this.root, (el) => el.attrib.get('id') === id &&
|
|
104
|
+
(elTag === '*' || (0, dom_1.stripNs)(el.tag) === elTag));
|
|
105
|
+
if (matches.length !== 1) {
|
|
106
|
+
const what = elTag === '*' ? 'element' : `<${elTag}>`;
|
|
107
|
+
throw new Error(matches.length === 0
|
|
108
|
+
? `${url} references ${what} with id "${id}", but no such element exists`
|
|
109
|
+
: `${url} matches ${matches.length} ${what} elements with id "${id}", expected exactly one`);
|
|
110
|
+
}
|
|
111
|
+
return matches[0];
|
|
112
|
+
}
|
|
113
|
+
// ---- traversal ----
|
|
114
|
+
*traverse(nextFn, appendFn, resolveClipPaths) {
|
|
115
|
+
const frontier = [
|
|
116
|
+
{
|
|
117
|
+
nthOfType: 0,
|
|
118
|
+
element: this.root,
|
|
119
|
+
path: '/svg[0]',
|
|
120
|
+
transform: transform_1.Affine2D.identity(),
|
|
121
|
+
clips: [],
|
|
122
|
+
attrib: (0, inherit_1.attribToPassOn)({ ...inherit_1.INHERITABLE_ATTRIB_DEFAULTS }, this.root),
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
while (frontier.length) {
|
|
126
|
+
const context = nextFn(frontier);
|
|
127
|
+
yield context;
|
|
128
|
+
const childIdxs = {};
|
|
129
|
+
const newEntries = [];
|
|
130
|
+
for (const child of context.element.children) {
|
|
131
|
+
const transform = (0, element_1.elementTransform)(child, context.transform);
|
|
132
|
+
let clips = context.clips;
|
|
133
|
+
const clipPathAttr = child.attrib.get('clip-path');
|
|
134
|
+
if (resolveClipPaths && clipPathAttr && clipPathAttr !== 'none') {
|
|
135
|
+
clips = [...clips, (0, clip_path_1.resolveClipPath)(this, clipPathAttr, transform)];
|
|
136
|
+
}
|
|
137
|
+
const localName = (0, dom_1.stripNs)(child.tag);
|
|
138
|
+
const nthOfType = childIdxs[localName] ?? 0;
|
|
139
|
+
childIdxs[localName] = nthOfType + 1;
|
|
140
|
+
newEntries.push({
|
|
141
|
+
nthOfType,
|
|
142
|
+
element: child,
|
|
143
|
+
path: `${context.path}/${localName}[${nthOfType}]`,
|
|
144
|
+
transform,
|
|
145
|
+
clips,
|
|
146
|
+
attrib: (0, inherit_1.attribToPassOn)(context.attrib, child),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
appendFn(frontier, newEntries);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
depthFirst(resolveClipPaths = true) {
|
|
153
|
+
// dfs takes from the back; reverse so children still yield in order
|
|
154
|
+
return this.traverse((f) => f.pop(), (f, e) => f.push(...e.reverse()), resolveClipPaths);
|
|
155
|
+
}
|
|
156
|
+
breadthFirst(resolveClipPaths = true) {
|
|
157
|
+
return this.traverse((f) => f.shift(), (f, e) => f.push(...e), resolveClipPaths);
|
|
158
|
+
}
|
|
159
|
+
serialize() {
|
|
160
|
+
this.syncTree();
|
|
161
|
+
return (0, dom_1.serializeSvg)(this.root);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.SvgDocument = SvgDocument;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const SVG_NS = "http://www.w3.org/2000/svg";
|
|
2
|
+
export declare const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
3
|
+
export declare function svgTag(local: string): string;
|
|
4
|
+
export declare function xlinkHrefAttr(): string;
|
|
5
|
+
export declare function splitNs(name: string): [string | null, string];
|
|
6
|
+
export declare function stripNs(name: string): string;
|
|
7
|
+
export declare class XEl {
|
|
8
|
+
tag: string;
|
|
9
|
+
attrib: Map<string, string>;
|
|
10
|
+
children: XEl[];
|
|
11
|
+
parent: XEl | null;
|
|
12
|
+
constructor(tag: string, attrib?: Iterable<[string, string]>);
|
|
13
|
+
append(child: XEl): void;
|
|
14
|
+
insert(index: number, child: XEl): void;
|
|
15
|
+
detach(): void;
|
|
16
|
+
index(child: XEl): number;
|
|
17
|
+
deepClone(): XEl;
|
|
18
|
+
iter(): Generator<XEl, void, void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function findAll(root: XEl, pred: (el: XEl) => boolean): XEl[];
|
|
21
|
+
export declare function replaceEl(el: XEl, replacements: XEl[]): void;
|
|
22
|
+
export declare function delAttrs(el: XEl, ...attrNames: string[]): void;
|
|
23
|
+
export declare function parseSvgDocument(content: string): XEl;
|
|
24
|
+
export declare function serializeSvg(root: XEl): string;
|