react-native-nano-icons 0.2.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.
- package/LICENSES.md +40 -0
- package/README.md +165 -12
- package/android/build.gradle +8 -1
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +103 -19
- package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +72 -11
- package/android/src/main/jni/CMakeLists.txt +38 -0
- package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
- package/ios/NanoIconFontResolver.h +5 -0
- package/ios/NanoIconFontResolver.mm +32 -0
- package/ios/NanoIconInlineBaseline.h +4 -0
- package/ios/NanoIconInlineBaseline.mm +190 -0
- package/ios/NanoIconView.h +1 -4
- package/ios/NanoIconView.mm +178 -162
- package/ios/NanoIconsFontLoader.mm +10 -32
- package/lib/commonjs/cli/build.d.ts +16 -3
- package/lib/commonjs/cli/build.js +108 -25
- package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
- package/lib/commonjs/cli/buildSymbols.js +134 -0
- package/lib/commonjs/cli/config.d.ts +4 -2
- package/lib/commonjs/cli/config.js +4 -4
- package/lib/commonjs/cli/expoConfig.d.ts +6 -2
- package/lib/commonjs/cli/expoConfig.js +37 -13
- package/lib/commonjs/cli/index.d.ts +7 -5
- package/lib/commonjs/cli/index.js +27 -14
- package/lib/commonjs/cli/link.d.ts +19 -3
- package/lib/commonjs/cli/link.js +311 -45
- package/lib/commonjs/cli/logger.js +9 -7
- package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
- package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
- package/lib/commonjs/metro/index.d.ts +35 -0
- package/lib/commonjs/metro/index.js +92 -0
- package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
- package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
- package/lib/commonjs/plugin/src/buildFonts.js +5 -15
- package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
- package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
- package/lib/commonjs/plugin/src/index.d.ts +2 -2
- package/lib/commonjs/plugin/src/index.js +10 -4
- package/lib/commonjs/plugin/src/types.d.ts +44 -3
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
- package/lib/commonjs/scripts/cli.js +64 -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 +19 -7
- package/lib/commonjs/src/core/font/metrics.js +7 -0
- package/lib/commonjs/src/core/font/quadratic.d.ts +2 -0
- package/lib/commonjs/src/core/font/quadratic.js +33 -0
- package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
- package/lib/commonjs/src/core/glyph/merge.js +59 -0
- package/lib/commonjs/src/core/glyph/parse.d.ts +27 -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 +75 -0
- package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +79 -301
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
- package/lib/commonjs/src/core/pathkit/evenodd.js +37 -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/pathkit/winding.d.ts +4 -0
- package/lib/commonjs/src/core/pathkit/winding.js +59 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/config.js +6 -0
- package/lib/commonjs/src/core/pipeline/iconPool.d.ts +14 -0
- package/lib/commonjs/src/core/pipeline/iconPool.js +109 -0
- package/lib/commonjs/src/core/pipeline/index.d.ts +5 -3
- package/lib/commonjs/src/core/pipeline/index.js +8 -5
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +20 -0
- package/lib/commonjs/src/core/pipeline/prepare.js +74 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +25 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +81 -0
- package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
- package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -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/preparedSvgCache.d.ts +6 -0
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
- package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +22 -0
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +111 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
- package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
- package/lib/commonjs/src/core/symbols/contents.js +15 -0
- package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
- package/lib/commonjs/src/core/symbols/knockout.js +51 -0
- package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
- package/lib/commonjs/src/core/symbols/layers.js +182 -0
- package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
- package/lib/commonjs/src/core/symbols/template.js +140 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
- package/lib/commonjs/src/core/types.d.ts +3 -92
- package/lib/commonjs/src/utils/fingerPrint.d.ts +19 -1
- package/lib/commonjs/src/utils/fingerPrint.js +29 -3
- package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
- package/lib/commonjs/src/utils/fontIdentity.js +24 -0
- package/lib/commonjs/src/utils/naming.d.ts +10 -0
- package/lib/commonjs/src/utils/naming.js +49 -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 +38 -28
- package/lib/module/createNanoIconsSet.shared.js +15 -9
- package/lib/module/createNanoIconsSet.web.js +22 -8
- package/lib/module/devServerFont.js +30 -0
- package/lib/module/devServerFont.web.js +25 -0
- 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 +20 -10
- package/lib/module/nativeFontLoader.js +3 -0
- package/lib/module/nativeFontLoader.web.js +3 -0
- package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
- package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
- package/lib/module/symbols/index.android.js +42 -0
- package/lib/module/symbols/index.ios.js +35 -0
- package/lib/module/symbols/index.js +35 -0
- package/lib/module/symbols/index.native.js +12 -0
- package/lib/module/symbols/types.js +1 -0
- package/lib/module/types.js +1 -2
- package/lib/module/utils/fingerPrint.js +20 -5
- package/lib/module/utils/fontIdentity.js +20 -0
- package/lib/module/utils/glyphRuntime.js +36 -3
- package/lib/module/utils/naming.js +46 -0
- 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/module/utils/validateLayerColor.js +24 -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 +28 -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 +76 -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/pathkit/winding.d.ts +5 -0
- package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
- package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
- package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
- package/lib/typescript/src/core/symbols/template.d.ts +23 -0
- package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
- package/lib/typescript/src/core/types.d.ts +3 -92
- package/lib/typescript/src/devServerFont.d.ts +4 -0
- package/lib/typescript/src/devServerFont.web.d.ts +4 -0
- package/lib/typescript/src/fontIntegrity.d.ts +24 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/loadDynamicFont.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/NanoIconViewNativeComponent.d.ts +6 -5
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/symbols/index.android.d.ts +33 -0
- package/lib/typescript/src/symbols/index.d.ts +31 -0
- package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
- package/lib/typescript/src/symbols/index.native.d.ts +8 -0
- package/lib/typescript/src/symbols/types.d.ts +24 -0
- package/lib/typescript/src/types.d.ts +7 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +19 -1
- package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
- package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
- package/lib/typescript/src/utils/naming.d.ts +11 -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/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
- package/metro.js +1 -0
- package/package.json +37 -11
- package/react-native-nano-icons.podspec +4 -1
- package/react-native.config.js +10 -0
- package/src/specs/NanoIconViewNativeComponent.ts +9 -6
- 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.d.ts +0 -14
- 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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveClipPath = resolveClipPath;
|
|
4
|
+
const element_1 = require("../element");
|
|
5
|
+
const shape_1 = require("../shape");
|
|
6
|
+
const transform_1 = require("../transform");
|
|
7
|
+
const use_1 = require("./use");
|
|
8
|
+
function resolveClipPath(doc, clipPathUrl, transform = transform_1.Affine2D.identity()) {
|
|
9
|
+
const clipPathEl = doc.resolveUrl(clipPathUrl, 'clipPath');
|
|
10
|
+
(0, use_1.expandUses)(doc, clipPathEl);
|
|
11
|
+
const clipTransform = (0, element_1.elementTransform)(clipPathEl, transform);
|
|
12
|
+
const clipShapes = clipPathEl.children.map((e) => (0, shape_1.applyTransform)((0, shape_1.fromElement)(e), (0, element_1.elementTransform)(e, clipTransform), doc.ops));
|
|
13
|
+
let clip = (0, shape_1.pathFromCommands)(doc.ops.union(clipShapes.map((s) => (0, shape_1.shapeCmdSeq)(s)), clipShapes.map((s) => (0, shape_1.shapeStr)(s, 'clip_rule'))));
|
|
14
|
+
const nestedClip = clipPathEl.attrib.get('clip-path');
|
|
15
|
+
if (nestedClip !== undefined) {
|
|
16
|
+
const clipClop = resolveClipPath(doc, nestedClip, clipTransform);
|
|
17
|
+
clip = (0, shape_1.pathFromCommands)(doc.ops.intersection([(0, shape_1.shapeCmdSeq)(clip), (0, shape_1.shapeCmdSeq)(clipClop)], [(0, shape_1.shapeStr)(clip, 'clip_rule'), (0, shape_1.shapeStr)(clipClop, 'clip_rule')]));
|
|
18
|
+
}
|
|
19
|
+
return clip;
|
|
20
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collapse = collapse;
|
|
4
|
+
const dom_1 = require("../dom");
|
|
5
|
+
const element_1 = require("../element");
|
|
6
|
+
const inherit_1 = require("../inherit");
|
|
7
|
+
const shape_1 = require("../shape");
|
|
8
|
+
const transform_1 = require("../transform");
|
|
9
|
+
const defs_1 = require("./defs");
|
|
10
|
+
const stroke_1 = require("./stroke");
|
|
11
|
+
function collapse(doc) {
|
|
12
|
+
doc.syncTree();
|
|
13
|
+
// Reversed: we want leaves first. Materialize BEFORE mutating.
|
|
14
|
+
const toProcess = [...doc.breadthFirst()].reverse();
|
|
15
|
+
const defs = new dom_1.XEl((0, dom_1.svgTag)('defs'));
|
|
16
|
+
doc.root.insert(0, defs);
|
|
17
|
+
for (const context of toProcess) {
|
|
18
|
+
if (context.path.includes('clipPath')) {
|
|
19
|
+
context.element.detach();
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const el = context.element;
|
|
23
|
+
(0, dom_1.delAttrs)(el, 'clip-path', 'transform'); // handled separately
|
|
24
|
+
(0, inherit_1.inheritAttrib)(context.attrib, el);
|
|
25
|
+
if ((0, shape_1.isShapeTag)(el.tag)) {
|
|
26
|
+
if (el.children.length) {
|
|
27
|
+
throw new Error("Shapes shouldn't have children");
|
|
28
|
+
}
|
|
29
|
+
const paths = [(0, shape_1.absoluteShape)((0, shape_1.asPath)((0, shape_1.fromElement)(el)))];
|
|
30
|
+
const initialPath = (0, shape_1.cloneShape)(paths[0]);
|
|
31
|
+
// stroke may introduce multiple paths
|
|
32
|
+
if ((0, shape_1.shapeStr)(paths[0], 'stroke') !== 'none') {
|
|
33
|
+
paths.splice(0, paths.length, ...(0, stroke_1.strokeToPaths)(doc, paths[0]));
|
|
34
|
+
}
|
|
35
|
+
// Any remaining stroke attributes don't do anything
|
|
36
|
+
for (const path of paths) {
|
|
37
|
+
(0, shape_1.resetFields)(path, (name) => name.startsWith('stroke'));
|
|
38
|
+
}
|
|
39
|
+
// Apply any transform
|
|
40
|
+
if (!context.transform.equals(transform_1.Affine2D.identity())) {
|
|
41
|
+
paths.forEach((p, i) => {
|
|
42
|
+
paths[i] = (0, shape_1.applyTransform)(p, context.transform, doc.ops);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (context.clips.length) {
|
|
46
|
+
for (const p of paths) {
|
|
47
|
+
// fill-rule for the shape to be clipped, clip-rule for the
|
|
48
|
+
// clipping paths themselves
|
|
49
|
+
const cmds = doc.ops.intersection([(0, shape_1.shapeCmdSeq)(p), ...context.clips.map((c) => (0, shape_1.shapeCmdSeq)(c))], [
|
|
50
|
+
(0, shape_1.shapeStr)(p, 'fill_rule'),
|
|
51
|
+
...context.clips.map((c) => (0, shape_1.shapeStr)(c, 'clip_rule')),
|
|
52
|
+
]);
|
|
53
|
+
p.fields.d = (0, shape_1.pathFromCommands)(cmds).fields.d;
|
|
54
|
+
// boolean operations always return nonzero winding paths
|
|
55
|
+
p.fields.fill_rule = 'nonzero';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (paths.length !== 1 || !(0, shape_1.shapesEqual)(paths[0], initialPath)) {
|
|
59
|
+
(0, dom_1.replaceEl)(el, paths.map((p) => (0, shape_1.toElement)(p)));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if ((0, element_1.isGradient)(el.tag)) {
|
|
63
|
+
el.detach();
|
|
64
|
+
(0, defs_1.addToDefs)(defs, el);
|
|
65
|
+
}
|
|
66
|
+
else if ((0, element_1.isDefs)(el.tag)) {
|
|
67
|
+
// children were already processed; move them to master defs
|
|
68
|
+
for (const childEl of [...el.children]) {
|
|
69
|
+
(0, defs_1.addToDefs)(defs, childEl);
|
|
70
|
+
}
|
|
71
|
+
el.detach();
|
|
72
|
+
}
|
|
73
|
+
else if ((0, element_1.isGroup)(el.tag)) {
|
|
74
|
+
(0, element_1.tryRemoveGroup)(el);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
(0, dom_1.delAttrs)(doc.root, ...inherit_1.INHERITABLE_ATTRIB);
|
|
78
|
+
(0, defs_1.removeOrphanedGradients)(doc);
|
|
79
|
+
// After simplification only gradient defs should be referenced
|
|
80
|
+
for (const unusedEl of [...defs.children]) {
|
|
81
|
+
if (!(0, element_1.isGradient)(unusedEl.tag)) {
|
|
82
|
+
unusedEl.detach();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
doc.invalidateShapes();
|
|
86
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addToDefs = addToDefs;
|
|
4
|
+
exports.removeOrphanedGradients = removeOrphanedGradients;
|
|
5
|
+
const dom_1 = require("../dom");
|
|
6
|
+
const element_1 = require("../element");
|
|
7
|
+
const shape_1 = require("../shape");
|
|
8
|
+
function addToDefs(defs, newEl) {
|
|
9
|
+
const newId = newEl.attrib.get('id');
|
|
10
|
+
if (newId === undefined)
|
|
11
|
+
return; // idless defs are useless
|
|
12
|
+
let insertAt = defs.children.length;
|
|
13
|
+
for (let i = 0; i < defs.children.length; i++) {
|
|
14
|
+
if (newId < (defs.children[i].attrib.get('id') ?? '')) {
|
|
15
|
+
insertAt = i;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
defs.insert(insertAt, newEl);
|
|
20
|
+
}
|
|
21
|
+
function removeOrphanedGradients(doc) {
|
|
22
|
+
// only keep gradients directly referenced by shapes
|
|
23
|
+
const usedGradientIds = new Set();
|
|
24
|
+
for (const [, shapes] of doc.shapeEntries()) {
|
|
25
|
+
for (const shape of shapes) {
|
|
26
|
+
const fill = (0, shape_1.shapeStr)(shape, 'fill');
|
|
27
|
+
if (!fill.startsWith('url('))
|
|
28
|
+
continue;
|
|
29
|
+
let el;
|
|
30
|
+
try {
|
|
31
|
+
el = doc.resolveUrl(fill, '*');
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
continue; // skip not found
|
|
35
|
+
}
|
|
36
|
+
if (!(0, element_1.isGradient)(el.tag))
|
|
37
|
+
continue;
|
|
38
|
+
const id = el.attrib.get('id');
|
|
39
|
+
if (id !== undefined)
|
|
40
|
+
usedGradientIds.add(id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const grad of (0, dom_1.findAll)(doc.root, (e) => (0, element_1.isGradient)(e.tag))) {
|
|
44
|
+
if (!usedGradientIds.has(grad.attrib.get('id') ?? '')) {
|
|
45
|
+
grad.detach();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
doc.invalidateShapes();
|
|
49
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeNonSvgContent = removeNonSvgContent;
|
|
4
|
+
exports.removeAnonymousSymbols = removeAnonymousSymbols;
|
|
5
|
+
exports.removeTitleMetaDesc = removeTitleMetaDesc;
|
|
6
|
+
const dom_1 = require("../dom");
|
|
7
|
+
function removeForeignAttrs(el, goodNs) {
|
|
8
|
+
const attrToRm = [];
|
|
9
|
+
for (const attr of el.attrib.keys()) {
|
|
10
|
+
if (!goodNs.has((0, dom_1.splitNs)(attr)[0])) {
|
|
11
|
+
attrToRm.push(attr);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
(0, dom_1.delAttrs)(el, ...attrToRm);
|
|
15
|
+
}
|
|
16
|
+
function removeNonSvgContent(doc) {
|
|
17
|
+
doc.syncTree();
|
|
18
|
+
const goodNs = new Set([dom_1.SVG_NS, dom_1.XLINK_NS]);
|
|
19
|
+
if ((0, dom_1.splitNs)(doc.root.tag)[0] === dom_1.SVG_NS) {
|
|
20
|
+
goodNs.add(null);
|
|
21
|
+
}
|
|
22
|
+
const elToRm = [];
|
|
23
|
+
for (const el of doc.root.iter()) {
|
|
24
|
+
if (el === doc.root)
|
|
25
|
+
continue;
|
|
26
|
+
if (!goodNs.has((0, dom_1.splitNs)(el.tag)[0])) {
|
|
27
|
+
elToRm.push(el);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
removeForeignAttrs(el, goodNs);
|
|
31
|
+
}
|
|
32
|
+
removeForeignAttrs(doc.root, goodNs);
|
|
33
|
+
for (const el of elToRm) {
|
|
34
|
+
el.detach();
|
|
35
|
+
}
|
|
36
|
+
doc.invalidateShapes();
|
|
37
|
+
}
|
|
38
|
+
function removeAnonymousSymbols(doc) {
|
|
39
|
+
doc.syncTree();
|
|
40
|
+
for (const el of (0, dom_1.findAll)(doc.root, (e) => (0, dom_1.stripNs)(e.tag) === 'symbol' && !e.attrib.has('id'))) {
|
|
41
|
+
el.detach();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function removeTitleMetaDesc(doc) {
|
|
45
|
+
doc.syncTree();
|
|
46
|
+
const tags = new Set(['title', 'desc', 'metadata', 'comment']);
|
|
47
|
+
for (const el of (0, dom_1.findAll)(doc.root, (e) => tags.has((0, dom_1.stripNs)(e.tag)))) {
|
|
48
|
+
el.detach();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evenoddToNonzeroWinding = evenoddToNonzeroWinding;
|
|
4
|
+
const shape_1 = require("../shape");
|
|
5
|
+
function evenoddToNonzeroWinding(doc) {
|
|
6
|
+
doc.mapShapes((s) => (0, shape_1.shapeStr)(s, 'fill_rule') === 'evenodd' ? (0, shape_1.removeOverlaps)(s, doc.ops) : s);
|
|
7
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveNestedSvgs = resolveNestedSvgs;
|
|
4
|
+
const geometry_1 = require("../geometry");
|
|
5
|
+
const dom_1 = require("../dom");
|
|
6
|
+
const element_1 = require("../element");
|
|
7
|
+
const shape_1 = require("../shape");
|
|
8
|
+
const transform_1 = require("../transform");
|
|
9
|
+
function rectEquals(a, b) {
|
|
10
|
+
return a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
|
|
11
|
+
}
|
|
12
|
+
// viewport/viewBox mapping a nested <svg> imposes on its children, plus the
|
|
13
|
+
// viewBox its children resolve against
|
|
14
|
+
function nestedSvgTransform(attrs, parentWidth, parentHeight) {
|
|
15
|
+
const num = (raw, fallback) => {
|
|
16
|
+
if (raw === null || raw === undefined || !raw.trim())
|
|
17
|
+
return fallback;
|
|
18
|
+
const value = parseFloat(raw);
|
|
19
|
+
return Number.isFinite(value) ? value : fallback;
|
|
20
|
+
};
|
|
21
|
+
const x = num(attrs.x, 0);
|
|
22
|
+
const y = num(attrs.y, 0);
|
|
23
|
+
const viewport = {
|
|
24
|
+
x,
|
|
25
|
+
y,
|
|
26
|
+
w: num(attrs.width, parentWidth),
|
|
27
|
+
h: num(attrs.height, parentHeight),
|
|
28
|
+
};
|
|
29
|
+
const viewBox = attrs.viewBox === null || attrs.viewBox === undefined
|
|
30
|
+
? viewport
|
|
31
|
+
: (0, element_1.parseViewBox)(attrs.viewBox);
|
|
32
|
+
let transform = rectEquals(viewport, viewBox)
|
|
33
|
+
? transform_1.Affine2D.identity().translate(x, y)
|
|
34
|
+
: transform_1.Affine2D.rectToRect(viewBox, viewport, attrs.preserveAspectRatio ?? 'xMidYMid');
|
|
35
|
+
if (attrs.transform !== null && attrs.transform !== undefined) {
|
|
36
|
+
transform = transform_1.Affine2D.composeLtr([
|
|
37
|
+
transform,
|
|
38
|
+
transform_1.Affine2D.fromString(attrs.transform),
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
return { transform, viewport, viewBox };
|
|
42
|
+
}
|
|
43
|
+
function viewportRect(x, y, width, height) {
|
|
44
|
+
const el = new dom_1.XEl((0, dom_1.svgTag)('rect'), [
|
|
45
|
+
['x', (0, geometry_1.ntos)(x)],
|
|
46
|
+
['y', (0, geometry_1.ntos)(y)],
|
|
47
|
+
['width', (0, geometry_1.ntos)(width)],
|
|
48
|
+
['height', (0, geometry_1.ntos)(height)],
|
|
49
|
+
]);
|
|
50
|
+
return (0, shape_1.toElement)((0, shape_1.fromElement)(el));
|
|
51
|
+
}
|
|
52
|
+
function newId(doc, template) {
|
|
53
|
+
for (let i = 0; i < 1 << 16; i++) {
|
|
54
|
+
const candidate = template(i);
|
|
55
|
+
if (!(0, dom_1.findAll)(doc.root, (el) => el.attrib.get('id') === candidate).length) {
|
|
56
|
+
return candidate;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new Error('No free id for nested svg viewport');
|
|
60
|
+
}
|
|
61
|
+
// immediate nested <svg> descendants, without descending into them
|
|
62
|
+
function nestedSvgs(root) {
|
|
63
|
+
const found = [];
|
|
64
|
+
const frontier = [...root.children];
|
|
65
|
+
while (frontier.length) {
|
|
66
|
+
const el = frontier.shift();
|
|
67
|
+
if ((0, element_1.isTag)(el, 'svg')) {
|
|
68
|
+
found.push(el);
|
|
69
|
+
}
|
|
70
|
+
else if (el.children.length) {
|
|
71
|
+
frontier.push(...el.children);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return found;
|
|
75
|
+
}
|
|
76
|
+
function unnestSvg(doc, svg, parentWidth, parentHeight) {
|
|
77
|
+
const { transform, viewport, viewBox } = nestedSvgTransform({
|
|
78
|
+
x: svg.attrib.get('x') ?? null,
|
|
79
|
+
y: svg.attrib.get('y') ?? null,
|
|
80
|
+
width: svg.attrib.get('width') ?? null,
|
|
81
|
+
height: svg.attrib.get('height') ?? null,
|
|
82
|
+
viewBox: svg.attrib.get('viewBox') ?? null,
|
|
83
|
+
transform: svg.attrib.get('transform') ?? null,
|
|
84
|
+
preserveAspectRatio: svg.attrib.get('preserveAspectRatio') ?? null,
|
|
85
|
+
}, parentWidth, parentHeight);
|
|
86
|
+
const { x, y, w: width, h: height } = viewport;
|
|
87
|
+
// un-nest any nested nested svgs first
|
|
88
|
+
for (const inner of nestedSvgs(svg)) {
|
|
89
|
+
(0, dom_1.replaceEl)(inner, unnestSvg(doc, inner, viewBox.w, viewBox.h));
|
|
90
|
+
}
|
|
91
|
+
const g = new dom_1.XEl((0, dom_1.svgTag)('g'));
|
|
92
|
+
for (const child of [...svg.children]) {
|
|
93
|
+
g.append(child);
|
|
94
|
+
}
|
|
95
|
+
if (!transform.equals(transform_1.Affine2D.identity())) {
|
|
96
|
+
g.attrib.set('transform', transform.toString());
|
|
97
|
+
}
|
|
98
|
+
// non-root <svg> defaults to overflow="hidden", i.e. clipped to its viewport
|
|
99
|
+
// https://www.w3.org/TR/SVG/render.html#OverflowAndClipProperties
|
|
100
|
+
const overflow = svg.attrib.get('overflow') ?? 'hidden';
|
|
101
|
+
if (overflow === 'visible') {
|
|
102
|
+
return [g];
|
|
103
|
+
}
|
|
104
|
+
if (overflow !== 'hidden') {
|
|
105
|
+
throw new Error(`overflow='${overflow}' is not supported`);
|
|
106
|
+
}
|
|
107
|
+
const clipId = newId(doc, (i) => `nested-svg-viewport-${i}`);
|
|
108
|
+
const clipPath = new dom_1.XEl((0, dom_1.svgTag)('clipPath'), [['id', clipId]]);
|
|
109
|
+
clipPath.append(viewportRect(x, y, width, height));
|
|
110
|
+
const clippedG = new dom_1.XEl((0, dom_1.svgTag)('g'), [['clip-path', `url(#${clipId})`]]);
|
|
111
|
+
clippedG.append(g);
|
|
112
|
+
return [clipPath, clippedG];
|
|
113
|
+
}
|
|
114
|
+
function resolveNestedSvgs(doc) {
|
|
115
|
+
doc.syncTree();
|
|
116
|
+
const nested = nestedSvgs(doc.root);
|
|
117
|
+
if (!nested.length) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const vbox = doc.viewBox();
|
|
121
|
+
if (vbox === null) {
|
|
122
|
+
throw new Error("Can't determine root SVG width/height, which is required for " +
|
|
123
|
+
'resolving nested SVGs');
|
|
124
|
+
}
|
|
125
|
+
// swap one at a time so each generated clip-path id is already in the
|
|
126
|
+
// tree before the next id is picked
|
|
127
|
+
for (const el of nested) {
|
|
128
|
+
(0, dom_1.replaceEl)(el, unnestSvg(doc, el, vbox.w, vbox.h));
|
|
129
|
+
}
|
|
130
|
+
doc.invalidateShapes();
|
|
131
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOpacities = normalizeOpacities;
|
|
4
|
+
const shape_1 = require("../shape");
|
|
5
|
+
function normalizeOpacities(doc) {
|
|
6
|
+
doc.forEachShape((s) => (0, shape_1.normalizeOpacity)(s));
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SvgDocument } from '../document';
|
|
2
|
+
export declare function shapesToPaths(doc: SvgDocument): void;
|
|
3
|
+
export declare function expandShorthandCommands(doc: SvgDocument): void;
|
|
4
|
+
export declare function absoluteCoordinates(doc: SvgDocument): void;
|
|
5
|
+
export declare function roundFloats(doc: SvgDocument, ndigits: number): void;
|
|
6
|
+
export declare function dropEmptySubpaths(doc: SvgDocument): void;
|
|
7
|
+
export declare function removeUnpaintedShapes(doc: SvgDocument): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shapesToPaths = shapesToPaths;
|
|
4
|
+
exports.expandShorthandCommands = expandShorthandCommands;
|
|
5
|
+
exports.absoluteCoordinates = absoluteCoordinates;
|
|
6
|
+
exports.roundFloats = roundFloats;
|
|
7
|
+
exports.dropEmptySubpaths = dropEmptySubpaths;
|
|
8
|
+
exports.removeUnpaintedShapes = removeUnpaintedShapes;
|
|
9
|
+
const shape_1 = require("../shape");
|
|
10
|
+
function shapesToPaths(doc) {
|
|
11
|
+
doc.mapShapes((s) => (0, shape_1.asPath)(s));
|
|
12
|
+
}
|
|
13
|
+
function expandShorthandCommands(doc) {
|
|
14
|
+
doc.mapShapes((s) => s.tag === 'path' ? (0, shape_1.explicitLinesExpandShorthand)(s) : s);
|
|
15
|
+
}
|
|
16
|
+
function absoluteCoordinates(doc) {
|
|
17
|
+
doc.mapShapes((s) => (0, shape_1.absoluteShape)(s));
|
|
18
|
+
}
|
|
19
|
+
function roundFloats(doc, ndigits) {
|
|
20
|
+
doc.forEachShape((s) => (0, shape_1.roundShapeFloats)(s, ndigits));
|
|
21
|
+
}
|
|
22
|
+
function dropEmptySubpaths(doc) {
|
|
23
|
+
doc.forEachShape((s) => (0, shape_1.removeEmptySubpaths)(s, doc.ops));
|
|
24
|
+
}
|
|
25
|
+
function removeUnpaintedShapes(doc) {
|
|
26
|
+
doc.syncTree();
|
|
27
|
+
const remove = [];
|
|
28
|
+
for (const [el, shapes] of doc.shapeEntries()) {
|
|
29
|
+
if (!(0, shape_1.mightPaint)(shapes[0], doc.ops)) {
|
|
30
|
+
remove.push(el);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const el of remove) {
|
|
34
|
+
el.detach();
|
|
35
|
+
}
|
|
36
|
+
doc.invalidateShapes();
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strokeToPaths = strokeToPaths;
|
|
4
|
+
const shape_1 = require("../shape");
|
|
5
|
+
// convert stroke to path; returns shapes in draw order
|
|
6
|
+
function strokeToPaths(doc, shape) {
|
|
7
|
+
const stroke = (0, shape_1.cloneShape)((0, shape_1.asPath)(shape));
|
|
8
|
+
stroke.fields.d = (0, shape_1.pathFromCommands)((0, shape_1.strokeCommands)(shape, doc.tolerance, doc.ops)).fields.d;
|
|
9
|
+
// the stroker returns paths with 'nonzero' winding fill rule
|
|
10
|
+
stroke.fields.fill_rule = 'nonzero';
|
|
11
|
+
stroke.fields.clip_rule = 'nonzero';
|
|
12
|
+
// a few attributes move in interesting ways
|
|
13
|
+
stroke.fields.opacity =
|
|
14
|
+
stroke.fields.opacity *
|
|
15
|
+
stroke.fields.stroke_opacity;
|
|
16
|
+
stroke.fields.fill = stroke.fields.stroke;
|
|
17
|
+
// fill and stroke are now different (filled) paths; fold fill_opacity
|
|
18
|
+
// into opacity on each
|
|
19
|
+
shape.fields.opacity =
|
|
20
|
+
shape.fields.opacity * shape.fields.fill_opacity;
|
|
21
|
+
shape.fields.fill_opacity = 1.0;
|
|
22
|
+
stroke.fields.fill_opacity = 1.0;
|
|
23
|
+
// remove all the stroke settings
|
|
24
|
+
for (const cleanmeup of [shape, stroke]) {
|
|
25
|
+
(0, shape_1.resetFields)(cleanmeup, (name) => name.startsWith('stroke'));
|
|
26
|
+
}
|
|
27
|
+
if (!(0, shape_1.mightPaint)(shape, doc.ops)) {
|
|
28
|
+
return [stroke];
|
|
29
|
+
}
|
|
30
|
+
// The original id doesn't correctly refer to either
|
|
31
|
+
shape.fields.id = '';
|
|
32
|
+
stroke.fields.id = '';
|
|
33
|
+
return [shape, stroke];
|
|
34
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyStyleAttributes = applyStyleAttributes;
|
|
4
|
+
const dom_1 = require("../dom");
|
|
5
|
+
const shape_1 = require("../shape");
|
|
6
|
+
const svgPatterns_1 = require("../../../utils/svgPatterns");
|
|
7
|
+
function applyStyles(el) {
|
|
8
|
+
const style = el.attrib.get('style') ?? '';
|
|
9
|
+
el.attrib.delete('style');
|
|
10
|
+
const parsed = {};
|
|
11
|
+
(0, shape_1.parseCssDeclarations)(style, parsed); // unparsed remnants are dropped here
|
|
12
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
13
|
+
// invalid attribute names (e.g. -inkscape-*) are dropped
|
|
14
|
+
if (svgPatterns_1.XML_ATTRIBUTE_NAME.test(name)) {
|
|
15
|
+
el.attrib.set(name, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function applyStyleAttributes(doc) {
|
|
20
|
+
if (doc.hasShapes()) {
|
|
21
|
+
// if we already parsed shapes, apply style attrs and sync tree
|
|
22
|
+
doc.mapShapes((s) => (0, shape_1.applyStyleAttribute)(s));
|
|
23
|
+
doc.syncTree();
|
|
24
|
+
}
|
|
25
|
+
const styled = [doc.root, ...(0, dom_1.findAll)(doc.root, (e) => e.attrib.has('style'))];
|
|
26
|
+
for (const el of styled) {
|
|
27
|
+
applyStyles(el);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expandUses = expandUses;
|
|
4
|
+
exports.resolveUse = resolveUse;
|
|
5
|
+
const dom_1 = require("../dom");
|
|
6
|
+
const element_1 = require("../element");
|
|
7
|
+
const inherit_1 = require("../inherit");
|
|
8
|
+
const transform_1 = require("../transform");
|
|
9
|
+
function expandUses(doc, scopeEl) {
|
|
10
|
+
const attribNotCopied = new Set([
|
|
11
|
+
'x',
|
|
12
|
+
'y',
|
|
13
|
+
'width',
|
|
14
|
+
'height',
|
|
15
|
+
'transform',
|
|
16
|
+
(0, dom_1.xlinkHrefAttr)(),
|
|
17
|
+
'href',
|
|
18
|
+
]);
|
|
19
|
+
// capture elements by id so even if we change it they remain stable
|
|
20
|
+
const elById = new Map();
|
|
21
|
+
for (const el of (0, dom_1.findAll)(doc.root, (e) => e.attrib.has('id'))) {
|
|
22
|
+
elById.set(el.attrib.get('id'), el);
|
|
23
|
+
}
|
|
24
|
+
for (;;) {
|
|
25
|
+
const useEls = (0, dom_1.findAll)(scopeEl, (e) => (0, element_1.isTag)(e, 'use'));
|
|
26
|
+
if (!useEls.length)
|
|
27
|
+
break;
|
|
28
|
+
const swaps = [];
|
|
29
|
+
for (const useEl of useEls) {
|
|
30
|
+
const ref = useEl.attrib.get((0, dom_1.xlinkHrefAttr)()) ?? useEl.attrib.get('href');
|
|
31
|
+
if (ref === undefined) {
|
|
32
|
+
throw new Error('<use> has no href attribute to resolve');
|
|
33
|
+
}
|
|
34
|
+
if (!ref.startsWith('#')) {
|
|
35
|
+
throw new Error(`<use> href "${ref}" is not supported: only same-document #id references are`);
|
|
36
|
+
}
|
|
37
|
+
const target = elById.get(ref.slice(1));
|
|
38
|
+
if (target === undefined) {
|
|
39
|
+
throw new Error(`<use> references ${ref}, but no element has id "${ref.slice(1)}"`);
|
|
40
|
+
}
|
|
41
|
+
const newEl = target.deepClone();
|
|
42
|
+
// leaving ids on <use> instantiated content duplicates ids
|
|
43
|
+
for (const el of newEl.iter()) {
|
|
44
|
+
el.attrib.delete('id');
|
|
45
|
+
}
|
|
46
|
+
const group = new dom_1.XEl((0, dom_1.svgTag)('g'));
|
|
47
|
+
let affine = transform_1.Affine2D.identity().translate((0, element_1.numberAttrib)(useEl, 'x', 0), (0, element_1.numberAttrib)(useEl, 'y', 0));
|
|
48
|
+
const useTransform = useEl.attrib.get('transform');
|
|
49
|
+
if (useTransform !== undefined) {
|
|
50
|
+
affine = transform_1.Affine2D.composeLtr([
|
|
51
|
+
affine,
|
|
52
|
+
transform_1.Affine2D.fromString(useTransform),
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
if (!affine.equals(transform_1.Affine2D.identity())) {
|
|
56
|
+
group.attrib.set('transform', affine.toString());
|
|
57
|
+
}
|
|
58
|
+
for (const [name, value] of useEl.attrib) {
|
|
59
|
+
if (attribNotCopied.has(name))
|
|
60
|
+
continue;
|
|
61
|
+
group.attrib.set(name, value);
|
|
62
|
+
}
|
|
63
|
+
group.append(newEl);
|
|
64
|
+
if ((0, element_1.tryRemoveGroup)(group, false)) {
|
|
65
|
+
(0, inherit_1.inheritAttrib)(group.attrib, newEl);
|
|
66
|
+
swaps.push([useEl, newEl]);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
swaps.push([useEl, group]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const [oldEl, newEl] of swaps) {
|
|
73
|
+
(0, dom_1.replaceEl)(oldEl, [newEl]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function resolveUse(doc) {
|
|
78
|
+
doc.syncTree();
|
|
79
|
+
expandUses(doc, doc.root);
|
|
80
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFlattened = validateFlattened;
|
|
4
|
+
const dom_1 = require("../dom");
|
|
5
|
+
const PATH_ALLOWLIST = [
|
|
6
|
+
/^\/svg\[0\]$/,
|
|
7
|
+
/^\/svg\[0\]\/defs\[0\]$/,
|
|
8
|
+
/^\/svg\[0\]\/defs\[0\]\/(linear|radial)Gradient\[\d+\](\/stop\[\d+\])?$/,
|
|
9
|
+
/^\/svg\[0\](\/(path|g)\[\d+\])+$/,
|
|
10
|
+
];
|
|
11
|
+
function validateFlattened(doc) {
|
|
12
|
+
doc.syncTree();
|
|
13
|
+
const errors = [];
|
|
14
|
+
const badPaths = new Set();
|
|
15
|
+
const pathsRequired = new Set(['/svg[0]', '/svg[0]/defs[0]']);
|
|
16
|
+
const ids = new Map();
|
|
17
|
+
for (const context of doc.breadthFirst()) {
|
|
18
|
+
if ([...badPaths].some((bp) => context.path.startsWith(bp))) {
|
|
19
|
+
continue; // no sense reporting all the children as bad
|
|
20
|
+
}
|
|
21
|
+
if (!PATH_ALLOWLIST.some((pat) => pat.test(context.path))) {
|
|
22
|
+
errors.push(`Unsupported element <${(0, dom_1.stripNs)(context.element.tag)}> at ${context.path}`);
|
|
23
|
+
badPaths.add(context.path);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
pathsRequired.delete(context.path);
|
|
27
|
+
const elId = context.element.attrib.get('id');
|
|
28
|
+
if (elId !== undefined) {
|
|
29
|
+
if (ids.has(elId)) {
|
|
30
|
+
errors.push(`Duplicate id "${elId}" at ${context.path}, first seen at ${ids.get(elId)}`);
|
|
31
|
+
}
|
|
32
|
+
ids.set(elId, context.path);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const path of pathsRequired) {
|
|
36
|
+
errors.push(`Missing element ${path}`);
|
|
37
|
+
}
|
|
38
|
+
return errors;
|
|
39
|
+
}
|