react-native-nano-icons 0.2.1 → 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 +72 -11
- 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
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
# shims/pathops.py
|
|
2
|
-
#
|
|
3
|
-
# Minimal skia-pathops-compatible API backed by a JS module registered as "_pathops_js".
|
|
4
|
-
# This is designed to satisfy picosvg's usage of pathops (Path, op, enums, iteration).
|
|
5
|
-
#
|
|
6
|
-
# IMPORTANT BEHAVIOR:
|
|
7
|
-
# - skia-pathops simplify(fix_winding=True) forces fillType to WINDING.
|
|
8
|
-
# PathKit does not do that, so we emulate it here by explicitly setting fillType.
|
|
9
|
-
|
|
10
|
-
from __future__ import annotations
|
|
11
|
-
from dataclasses import dataclass
|
|
12
|
-
from typing import Iterable, Iterator, List, Sequence, Tuple, Optional, Any
|
|
13
|
-
|
|
14
|
-
try:
|
|
15
|
-
import _pathops_js # provided via pyodide.registerJsModule(...)
|
|
16
|
-
except Exception as e:
|
|
17
|
-
raise ImportError("Missing JS backend module _pathops_js") from e
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# ---- Exceptions ----
|
|
21
|
-
class PathOpsError(RuntimeError):
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# ---- Enums (values chosen to match our JS backend verb mapping) ----
|
|
26
|
-
class PathVerb:
|
|
27
|
-
MOVE = 0
|
|
28
|
-
LINE = 1
|
|
29
|
-
QUAD = 2
|
|
30
|
-
CUBIC = 3
|
|
31
|
-
CLOSE = 4
|
|
32
|
-
CONIC = 5 # should not occur for picosvg after conversions
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class FillType:
|
|
36
|
-
WINDING = 0
|
|
37
|
-
EVEN_ODD = 1
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class PathOp:
|
|
41
|
-
UNION = 0
|
|
42
|
-
INTERSECTION = 1
|
|
43
|
-
DIFFERENCE = 2
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class LineCap:
|
|
47
|
-
BUTT_CAP = 0
|
|
48
|
-
ROUND_CAP = 1
|
|
49
|
-
SQUARE_CAP = 2
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class LineJoin:
|
|
53
|
-
MITER_JOIN = 0
|
|
54
|
-
ROUND_JOIN = 1
|
|
55
|
-
BEVEL_JOIN = 2
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Point = Tuple[float, float]
|
|
59
|
-
SvgCmd = Tuple[str, Tuple[float, ...]]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@dataclass
|
|
63
|
-
class _Handle:
|
|
64
|
-
h: Any # opaque handle owned by JS backend
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
class Path:
|
|
68
|
-
def __init__(self, other: "Path" = None, *, fillType: int = FillType.WINDING):
|
|
69
|
-
if other is not None:
|
|
70
|
-
self._handle = _Handle(_pathops_js.clone_path(other._handle.h))
|
|
71
|
-
else:
|
|
72
|
-
self._handle = _Handle(_pathops_js.create_path(int(fillType)))
|
|
73
|
-
|
|
74
|
-
# ---- fillType property ----
|
|
75
|
-
@property
|
|
76
|
-
def fillType(self) -> int:
|
|
77
|
-
return int(_pathops_js.get_fill_type(self._handle.h))
|
|
78
|
-
|
|
79
|
-
@fillType.setter
|
|
80
|
-
def fillType(self, ft: int) -> None:
|
|
81
|
-
_pathops_js.set_fill_type(self._handle.h, int(ft))
|
|
82
|
-
|
|
83
|
-
# ---- drawing commands ----
|
|
84
|
-
def moveTo(self, x: float, y: float) -> None:
|
|
85
|
-
_pathops_js.move_to(self._handle.h, float(x), float(y))
|
|
86
|
-
|
|
87
|
-
def lineTo(self, x: float, y: float) -> None:
|
|
88
|
-
_pathops_js.line_to(self._handle.h, float(x), float(y))
|
|
89
|
-
|
|
90
|
-
def quadTo(self, x1: float, y1: float, x2: float, y2: float) -> None:
|
|
91
|
-
_pathops_js.quad_to(self._handle.h, float(x1), float(y1), float(x2), float(y2))
|
|
92
|
-
|
|
93
|
-
def cubicTo(self, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float) -> None:
|
|
94
|
-
_pathops_js.cubic_to(self._handle.h, float(x1), float(y1), float(x2), float(y2), float(x3), float(y3))
|
|
95
|
-
|
|
96
|
-
def close(self) -> None:
|
|
97
|
-
_pathops_js.close(self._handle.h)
|
|
98
|
-
|
|
99
|
-
# ---- transforms ----
|
|
100
|
-
def transform(self, a: float, b: float, c: float, d: float, e: float, f: float) -> "Path":
|
|
101
|
-
out_h = _pathops_js.transform(self._handle.h, float(a), float(b), float(c), float(d), float(e), float(f))
|
|
102
|
-
out = Path.__new__(Path)
|
|
103
|
-
out._handle = _Handle(out_h)
|
|
104
|
-
return out
|
|
105
|
-
|
|
106
|
-
# ---- simplify / stroke ----
|
|
107
|
-
def simplify(self, fix_winding: bool = False) -> None:
|
|
108
|
-
ok = bool(_pathops_js.simplify(self._handle.h, bool(fix_winding)))
|
|
109
|
-
# In skia-pathops, simplify(fix_winding=True) forces WINDING fill type.
|
|
110
|
-
if fix_winding:
|
|
111
|
-
_pathops_js.set_fill_type(self._handle.h, int(FillType.WINDING))
|
|
112
|
-
if not ok:
|
|
113
|
-
# skia-pathops may throw PathOpsError; picosvg usually expects simplify to succeed
|
|
114
|
-
# but some paths can be tricky. We'll be conservative and not throw.
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
def stroke(
|
|
118
|
-
self,
|
|
119
|
-
stroke_width: float,
|
|
120
|
-
cap: int,
|
|
121
|
-
join: int,
|
|
122
|
-
miter_limit: float,
|
|
123
|
-
dash_array: Sequence[float] = (),
|
|
124
|
-
dash_offset: float = 0.0,
|
|
125
|
-
) -> None:
|
|
126
|
-
out_h = _pathops_js.stroke(
|
|
127
|
-
self._handle.h,
|
|
128
|
-
float(stroke_width),
|
|
129
|
-
int(cap),
|
|
130
|
-
int(join),
|
|
131
|
-
float(miter_limit),
|
|
132
|
-
list(map(float, dash_array)) if dash_array else [],
|
|
133
|
-
float(dash_offset),
|
|
134
|
-
)
|
|
135
|
-
if out_h is None:
|
|
136
|
-
raise PathOpsError("stroke failed")
|
|
137
|
-
# Replace in-place (matches typical expectations)
|
|
138
|
-
self._handle = _Handle(out_h)
|
|
139
|
-
|
|
140
|
-
def convertConicsToQuads(self, tolerance: float = 0.25) -> None:
|
|
141
|
-
# PathKit roundtrip already avoids conics for our use cases
|
|
142
|
-
_pathops_js.convert_conics_to_quads(self._handle.h, float(tolerance))
|
|
143
|
-
|
|
144
|
-
# ---- geometry ----
|
|
145
|
-
@property
|
|
146
|
-
def bounds(self) -> Tuple[float, float, float, float]:
|
|
147
|
-
b = _pathops_js.bounds(self._handle.h)
|
|
148
|
-
return (float(b[0]), float(b[1]), float(b[2]), float(b[3]))
|
|
149
|
-
|
|
150
|
-
@property
|
|
151
|
-
def area(self) -> float:
|
|
152
|
-
return float(_pathops_js.area(self._handle.h))
|
|
153
|
-
|
|
154
|
-
# ---- iteration ----
|
|
155
|
-
def __iter__(self) -> Iterator[Tuple[int, List[Point]]]:
|
|
156
|
-
# JS backend returns list of [verbInt, [[x,y], ...]]
|
|
157
|
-
segs = _pathops_js.iter_segments(self._handle.h)
|
|
158
|
-
for verb, pts in segs:
|
|
159
|
-
out_pts: List[Point] = [(float(p[0]), float(p[1])) for p in pts]
|
|
160
|
-
yield int(verb), out_pts
|
|
161
|
-
|
|
162
|
-
# ---- cleanup ----
|
|
163
|
-
def __del__(self):
|
|
164
|
-
try:
|
|
165
|
-
_pathops_js.delete_path(self._handle.h)
|
|
166
|
-
except Exception:
|
|
167
|
-
pass
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def op(path1: Path, path2: Path, op: int, fix_winding: bool = False) -> Path:
|
|
171
|
-
out_h = _pathops_js.op(path1._handle.h, path2._handle.h, int(op))
|
|
172
|
-
if out_h is None:
|
|
173
|
-
raise PathOpsError("operation did not succeed")
|
|
174
|
-
|
|
175
|
-
out = Path.__new__(Path)
|
|
176
|
-
out._handle = _Handle(out_h)
|
|
177
|
-
|
|
178
|
-
if fix_winding:
|
|
179
|
-
_pathops_js.set_fill_type(out._handle.h, int(FillType.WINDING))
|
|
180
|
-
|
|
181
|
-
return out
|
|
Binary file
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import fsp from 'node:fs/promises';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
function roundInt(n) {
|
|
6
|
-
return Math.round(n);
|
|
7
|
-
}
|
|
8
|
-
export function computePlacement(opts) {
|
|
9
|
-
const [vx, vy, vw, vh] = opts.viewBox;
|
|
10
|
-
|
|
11
|
-
// Guard against invalid viewBox height from source svg
|
|
12
|
-
const safeVh = vh === 0 ? 1 : vh;
|
|
13
|
-
|
|
14
|
-
// ✅ Fit-to-height (same visual height for all glyphs)
|
|
15
|
-
const scale = opts.safeZone / safeVh;
|
|
16
|
-
const totalPadding = (opts.upm - opts.safeZone) / 2;
|
|
17
|
-
|
|
18
|
-
// Scaled dimensions in font units
|
|
19
|
-
const scaledW = vw * scale;
|
|
20
|
-
const scaledH = vh * scale; // ~= safeZone
|
|
21
|
-
|
|
22
|
-
// ✅ proportional advance width (includes same padding concept as vertical)
|
|
23
|
-
// This is the width of the glyph coordinate space we will emit in the layer SVG.
|
|
24
|
-
const adv = Math.max(1, roundInt(scaledW + totalPadding * 2));
|
|
25
|
-
|
|
26
|
-
// Center scaled content within (adv x upm)
|
|
27
|
-
// (when adv == scaledW + 2*padding, xOff is basically padding, with rounding compensation)
|
|
28
|
-
const xOff = (adv - scaledW) / 2;
|
|
29
|
-
const yOff = (opts.upm - scaledH) / 2; // ~= totalPadding
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
vx,
|
|
33
|
-
vy,
|
|
34
|
-
scale,
|
|
35
|
-
xOff,
|
|
36
|
-
yOff,
|
|
37
|
-
adv
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export async function writeLayerSvg(opts) {
|
|
41
|
-
const hex = opts.codepoint.toString(16).padStart(4, '0');
|
|
42
|
-
const layerSvg = `
|
|
43
|
-
<svg viewBox="0 0 ${opts.adv} ${opts.upm}" xmlns="http://www.w3.org/2000/svg">
|
|
44
|
-
<rect width="${opts.adv}" height="${opts.upm}" fill="none" />
|
|
45
|
-
<g transform="translate(${opts.xOff}, ${opts.yOff}) scale(${opts.scale}) translate(${-opts.vx}, ${-opts.vy})">
|
|
46
|
-
<path d="${opts.d}" fill="black" />
|
|
47
|
-
</g>
|
|
48
|
-
</svg>`.trim();
|
|
49
|
-
await fsp.writeFile(path.join(opts.tempDir, `u${hex}.svg`), layerSvg, 'utf8');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Transform an SVG path `d` string from source SVG coordinates into font
|
|
54
|
-
* glyph coordinates (Y-up, with placement scaling and centering applied).
|
|
55
|
-
*
|
|
56
|
-
* Combines placement transform (translate + scale + translate) with the
|
|
57
|
-
* SVG→font Y-axis flip into a single affine transform applied via PathKit.
|
|
58
|
-
*/
|
|
59
|
-
export function transformPathForFont(PathKit, d, opts) {
|
|
60
|
-
const {
|
|
61
|
-
vx,
|
|
62
|
-
vy,
|
|
63
|
-
scale,
|
|
64
|
-
xOff,
|
|
65
|
-
yOff,
|
|
66
|
-
upm
|
|
67
|
-
} = opts;
|
|
68
|
-
const p = PathKit.FromSVGString(d);
|
|
69
|
-
if (!p) return d;
|
|
70
|
-
|
|
71
|
-
// Combined affine: placement + Y-flip for font coordinates.
|
|
72
|
-
// x' = scale * (x - vx) + xOff
|
|
73
|
-
// y' = upm - (scale * (y - vy) + yOff)
|
|
74
|
-
//
|
|
75
|
-
// SkMatrix row-major: [scaleX, skewX, transX, skewY, scaleY, transY, 0,0,1]
|
|
76
|
-
const scaleX = scale;
|
|
77
|
-
const scaleY = -scale;
|
|
78
|
-
const transX = xOff - vx * scale;
|
|
79
|
-
const transY = upm - yOff + vy * scale;
|
|
80
|
-
p.transform(scaleX, 0, transX, 0, scaleY, transY, 0, 0, 1);
|
|
81
|
-
const result = p.toSVGString();
|
|
82
|
-
p.delete?.();
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=layers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fsp","path","roundInt","n","Math","round","computePlacement","opts","vx","vy","vw","vh","viewBox","safeVh","scale","safeZone","totalPadding","upm","scaledW","scaledH","adv","max","xOff","yOff","writeLayerSvg","hex","codepoint","toString","padStart","layerSvg","d","trim","writeFile","join","tempDir","transformPathForFont","PathKit","p","FromSVGString","scaleX","scaleY","transX","transY","transform","result","toSVGString","delete"],"sourceRoot":"../../../../src","sources":["core/svg/layers.ts"],"mappings":";;AAAA,OAAOA,GAAG,MAAM,kBAAkB;AAClC,OAAOC,IAAI,MAAM,WAAW;AAI5B,SAASC,QAAQA,CAACC,CAAS,EAAU;EACnC,OAAOC,IAAI,CAACC,KAAK,CAACF,CAAC,CAAC;AACtB;AAEA,OAAO,SAASG,gBAAgBA,CAACC,IAIhC,EAAE;EACD,MAAM,CAACC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,CAAC,GAAGJ,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;AAC1C,mBAAmBF,IAAI,CAACuB,CAAC;AACzB;AACA,WAAW,CAACC,IAAI,CAAC,CAAC;EAEhB,MAAM/B,GAAG,CAACgC,SAAS,CAAC/B,IAAI,CAACgC,IAAI,CAAC1B,IAAI,CAAC2B,OAAO,EAAE,IAAIT,GAAG,MAAM,CAAC,EAAEI,QAAQ,EAAE,MAAM,CAAC;AAC/E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,oBAAoBA,CAClCC,OAAsB,EACtBN,CAAS,EACTvB,IAOC,EACO;EACR,MAAM;IAAEC,EAAE;IAAEC,EAAE;IAAEK,KAAK;IAAEQ,IAAI;IAAEC,IAAI;IAAEN;EAAI,CAAC,GAAGV,IAAI;EAE/C,MAAM8B,CAAC,GAAGD,OAAO,CAACE,aAAa,CAACR,CAAC,CAAC;EAClC,IAAI,CAACO,CAAC,EAAE,OAAOP,CAAC;;EAEhB;EACA;EACA;EACA;EACA;EACA,MAAMS,MAAM,GAAGzB,KAAK;EACpB,MAAM0B,MAAM,GAAG,CAAC1B,KAAK;EACrB,MAAM2B,MAAM,GAAGnB,IAAI,GAAGd,EAAE,GAAGM,KAAK;EAChC,MAAM4B,MAAM,GAAGzB,GAAG,GAAGM,IAAI,GAAGd,EAAE,GAAGK,KAAK;EAEtCuB,CAAC,CAACM,SAAS,CAACJ,MAAM,EAAE,CAAC,EAAEE,MAAM,EAAE,CAAC,EAAED,MAAM,EAAEE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EAE1D,MAAME,MAAM,GAAGP,CAAC,CAACQ,WAAW,CAAC,CAAC;EAC9BR,CAAC,CAACS,MAAM,GAAG,CAAC;EAEZ,OAAOF,MAAM;AACf","ignoreList":[]}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { DOMParser } from '@xmldom/xmldom';
|
|
4
|
-
import { parseColor } from "../../utils/parse.js";
|
|
5
|
-
// if the fill is implicit, walk ancestors for the first explicit fill value
|
|
6
|
-
function resolveInheritedFill(el) {
|
|
7
|
-
let current = el.parentElement;
|
|
8
|
-
while (current !== null) {
|
|
9
|
-
const fill = current.getAttribute('fill');
|
|
10
|
-
if (fill !== null && fill !== 'inherit') return fill;
|
|
11
|
-
current = current.parentElement;
|
|
12
|
-
}
|
|
13
|
-
return 'black';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// bake opacity into the fill as an rgba(...)
|
|
17
|
-
export function calculateOpColor(fill, opacity, el) {
|
|
18
|
-
const resolvedFill = fill ?? resolveInheritedFill(el);
|
|
19
|
-
const [r, g, b, a] = parseColor(resolvedFill);
|
|
20
|
-
const finalAlpha = +(a * opacity).toFixed(4);
|
|
21
|
-
return `rgba(${r},${g},${b},${finalAlpha})`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* If a flattened path lost its initial moveto (e.g. picosvg dropped an empty
|
|
26
|
-
* `Mx y z` subpath), prepend `M` using the path's last coordinate pair.
|
|
27
|
-
* For closed icon shapes the endpoint equals the start point.
|
|
28
|
-
*/
|
|
29
|
-
export function sanitizePathData(d) {
|
|
30
|
-
const trimmed = d.trim();
|
|
31
|
-
if (!trimmed || /^[Mm]/.test(trimmed)) {
|
|
32
|
-
return {
|
|
33
|
-
d: trimmed,
|
|
34
|
-
sanitized: false
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Strip trailing close commands, then grab the last two numbers as x,y
|
|
39
|
-
const withoutClose = trimmed.replace(/[Zz]\s*$/, '');
|
|
40
|
-
const nums = withoutClose.match(/-?\d+(?:\.\d+)?/g);
|
|
41
|
-
if (!nums || nums.length < 2) {
|
|
42
|
-
return {
|
|
43
|
-
d: trimmed,
|
|
44
|
-
sanitized: false
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const x = nums[nums.length - 2];
|
|
48
|
-
const y = nums[nums.length - 1];
|
|
49
|
-
return {
|
|
50
|
-
d: `M${x},${y} ${trimmed}`,
|
|
51
|
-
sanitized: true
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export const parsePath = p => {
|
|
55
|
-
const d = p.getAttribute('d') ?? '';
|
|
56
|
-
const op = p.getAttribute('opacity');
|
|
57
|
-
const fillOp = p.getAttribute('fill-opacity');
|
|
58
|
-
const fill = p.getAttribute('fill');
|
|
59
|
-
// picosvg may drop fill-rule but preserve clip-rule; treat either as evenodd
|
|
60
|
-
const fillRule = p.getAttribute('fill-rule') === 'evenodd' || p.getAttribute('clip-rule') === 'evenodd' ? 'evenodd' : undefined;
|
|
61
|
-
if (op !== null || fillOp !== null) {
|
|
62
|
-
const opVal = op !== null ? parseFloat(op) : 1;
|
|
63
|
-
const fillOpVal = fillOp !== null ? parseFloat(fillOp) : 1;
|
|
64
|
-
const combinedOpacity = opVal * fillOpVal;
|
|
65
|
-
return {
|
|
66
|
-
d,
|
|
67
|
-
fill: calculateOpColor(fill, combinedOpacity, p),
|
|
68
|
-
fillRule
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
d,
|
|
73
|
-
fill,
|
|
74
|
-
fillRule
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
export function parseFlattenedSvg(flattenedSvg, options) {
|
|
78
|
-
const doc = new DOMParser().parseFromString(flattenedSvg, 'image/svg+xml');
|
|
79
|
-
const svgEl = doc.documentElement;
|
|
80
|
-
const viewBoxRaw = svgEl?.getAttribute('viewBox')?.split(/\s+/).map(Number) ?? [0, 0, 100, 100];
|
|
81
|
-
const viewBox = viewBoxRaw.length === 4 && viewBoxRaw.every(Number.isFinite) ? [viewBoxRaw[0], viewBoxRaw[1], viewBoxRaw[2], viewBoxRaw[3]] : [0, 0, 100, 100];
|
|
82
|
-
const pathEls = svgEl ? Array.from(svgEl.getElementsByTagName('path')) : [];
|
|
83
|
-
const paths = pathEls.map(parsePath).filter(p => p.d.trim() !== '').map(p => {
|
|
84
|
-
const {
|
|
85
|
-
d,
|
|
86
|
-
sanitized
|
|
87
|
-
} = sanitizePathData(p.d);
|
|
88
|
-
if (sanitized) options?.onSanitize?.(p.d);
|
|
89
|
-
return {
|
|
90
|
-
...p,
|
|
91
|
-
d
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
return {
|
|
95
|
-
viewBox,
|
|
96
|
-
paths
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
export function shouldSkipPath(d, fill) {
|
|
100
|
-
if (!d || d.trim() === '') return true;
|
|
101
|
-
const f = (fill ?? '').trim().toLowerCase();
|
|
102
|
-
return f === 'transparent' || f === 'none';
|
|
103
|
-
}
|
|
104
|
-
export function validateSvg(content) {
|
|
105
|
-
if (/<mask[\s>]/i.test(content)) {
|
|
106
|
-
return {
|
|
107
|
-
valid: false,
|
|
108
|
-
reason: '<mask> is not supported yet'
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (/<filter[\s>]/i.test(content)) {
|
|
112
|
-
return {
|
|
113
|
-
valid: false,
|
|
114
|
-
reason: '<filter> is not supported yet'
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
if (/<image[\s>]/i.test(content)) {
|
|
118
|
-
return {
|
|
119
|
-
valid: false,
|
|
120
|
-
reason: 'embedded raster <image> is not supported yet'
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
valid: true
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Extract the original `d` strings of evenodd paths from the raw SVG
|
|
130
|
-
* BEFORE picosvg processes it. Picosvg's simplify (via our PathKit shim)
|
|
131
|
-
* can drop contours from multi-subpath evenodd paths, so we preserve
|
|
132
|
-
* the originals and apply our own winding conversion later.
|
|
133
|
-
*
|
|
134
|
-
* Returns one `d` string per evenodd path, in document order.
|
|
135
|
-
*/
|
|
136
|
-
export function extractOriginalEvenoddDs(svgContent) {
|
|
137
|
-
if (!/<[^>]*fill-rule\s*=\s*["']evenodd/i.test(svgContent)) {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
const doc = new DOMParser().parseFromString(svgContent, 'image/svg+xml');
|
|
141
|
-
return Array.from(doc.getElementsByTagName('path')).reduce((acc, el) => {
|
|
142
|
-
const isEvenOdd = el.getAttribute('fill-rule') === 'evenodd' || el.getAttribute('clip-rule') === 'evenodd';
|
|
143
|
-
if (!isEvenOdd) return acc;
|
|
144
|
-
const d = el.getAttribute('d');
|
|
145
|
-
if (d !== null && d !== '') acc.push(d);
|
|
146
|
-
return acc;
|
|
147
|
-
}, []);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Replace picosvg's (potentially damaged) evenodd path data with the
|
|
152
|
-
* preserved originals. Matches by position: the Nth evenodd path in
|
|
153
|
-
* the parsed output gets the Nth original `d` string.
|
|
154
|
-
*/
|
|
155
|
-
export function restoreOriginalEvenoddDs(paths, originalDs) {
|
|
156
|
-
let oi = 0;
|
|
157
|
-
for (const p of paths) {
|
|
158
|
-
if (p.fillRule === 'evenodd' && oi < originalDs.length) {
|
|
159
|
-
p.d = originalDs[oi];
|
|
160
|
-
oi++;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// ensure the svg has a xmlns attribute
|
|
166
|
-
export function preprocessSvg(content) {
|
|
167
|
-
if (/xmlns\s*=/.test(content)) return content;
|
|
168
|
-
return content.replace(/<svg\b/, '<svg xmlns="http://www.w3.org/2000/svg"');
|
|
169
|
-
}
|
|
170
|
-
//# sourceMappingURL=svg_dom.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["DOMParser","parseColor","resolveInheritedFill","el","current","parentElement","fill","getAttribute","calculateOpColor","opacity","resolvedFill","r","g","b","a","finalAlpha","toFixed","sanitizePathData","d","trimmed","trim","test","sanitized","withoutClose","replace","nums","match","length","x","y","parsePath","p","op","fillOp","fillRule","undefined","opVal","parseFloat","fillOpVal","combinedOpacity","parseFlattenedSvg","flattenedSvg","options","doc","parseFromString","svgEl","documentElement","viewBoxRaw","split","map","Number","viewBox","every","isFinite","pathEls","Array","from","getElementsByTagName","paths","filter","onSanitize","shouldSkipPath","f","toLowerCase","validateSvg","content","valid","reason","extractOriginalEvenoddDs","svgContent","reduce","acc","isEvenOdd","push","restoreOriginalEvenoddDs","originalDs","oi","preprocessSvg"],"sourceRoot":"../../../../src","sources":["core/svg/svg_dom.ts"],"mappings":";;AAAA,SAASA,SAAS,QAAsB,gBAAgB;AACxD,SAASC,UAAU,QAAQ,sBAAmB;AAO9C;AACA,SAASC,oBAAoBA,CAACC,EAAW,EAAU;EACjD,IAAIC,OAAO,GAAGD,EAAE,CAACE,aAAa;EAC9B,OAAOD,OAAO,KAAK,IAAI,EAAE;IACvB,MAAME,IAAI,GAAGF,OAAO,CAACG,YAAY,CAAC,MAAM,CAAC;IACzC,IAAID,IAAI,KAAK,IAAI,IAAIA,IAAI,KAAK,SAAS,EAAE,OAAOA,IAAI;IACpDF,OAAO,GAAGA,OAAO,CAACC,aAAa;EACjC;EACA,OAAO,OAAO;AAChB;;AAEA;AACA,OAAO,SAASG,gBAAgBA,CAC9BF,IAAmB,EACnBG,OAAe,EACfN,EAAW,EACsC;EACjD,MAAMO,YAAY,GAAGJ,IAAI,IAAIJ,oBAAoB,CAACC,EAAE,CAAC;EACrD,MAAM,CAACQ,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAEC,CAAC,CAAC,GAAGb,UAAU,CAACS,YAAY,CAAC;EAC7C,MAAMK,UAAU,GAAG,CAAC,CAACD,CAAC,GAAGL,OAAO,EAAEO,OAAO,CAAC,CAAC,CAAC;EAC5C,OAAO,QAAQL,CAAC,IAAIC,CAAC,IAAIC,CAAC,IAAIE,UAAU,GAAG;AAC7C;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,gBAAgBA,CAACC,CAAS,EAAqC;EAC7E,MAAMC,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