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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PathKitModule } from '../types
|
|
1
|
+
import type { PathKitModule } from '../pathkit/types';
|
|
2
2
|
export declare function computePlacement(opts: {
|
|
3
3
|
upm: number;
|
|
4
4
|
safeZone: number;
|
|
@@ -11,18 +11,6 @@ export declare function computePlacement(opts: {
|
|
|
11
11
|
yOff: number;
|
|
12
12
|
adv: number;
|
|
13
13
|
};
|
|
14
|
-
export declare function writeLayerSvg(opts: {
|
|
15
|
-
tempDir: string;
|
|
16
|
-
upm: number;
|
|
17
|
-
adv: number;
|
|
18
|
-
vx: number;
|
|
19
|
-
vy: number;
|
|
20
|
-
scale: number;
|
|
21
|
-
xOff: number;
|
|
22
|
-
yOff: number;
|
|
23
|
-
d: string;
|
|
24
|
-
codepoint: number;
|
|
25
|
-
}): Promise<void>;
|
|
26
14
|
/**
|
|
27
15
|
* Transform an SVG path `d` string from source SVG coordinates into font
|
|
28
16
|
* glyph coordinates (Y-up, with placement scaling and centering applied).
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.computePlacement = computePlacement;
|
|
7
|
-
exports.writeLayerSvg = writeLayerSvg;
|
|
8
4
|
exports.transformPathForFont = transformPathForFont;
|
|
9
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
5
|
function roundInt(n) {
|
|
12
6
|
return Math.round(n);
|
|
13
7
|
}
|
|
@@ -30,17 +24,6 @@ function computePlacement(opts) {
|
|
|
30
24
|
const yOff = (opts.upm - scaledH) / 2; // ~= totalPadding
|
|
31
25
|
return { vx, vy, scale, xOff, yOff, adv };
|
|
32
26
|
}
|
|
33
|
-
async function writeLayerSvg(opts) {
|
|
34
|
-
const hex = opts.codepoint.toString(16).padStart(4, '0');
|
|
35
|
-
const layerSvg = `
|
|
36
|
-
<svg viewBox="0 0 ${opts.adv} ${opts.upm}" xmlns="http://www.w3.org/2000/svg">
|
|
37
|
-
<rect width="${opts.adv}" height="${opts.upm}" fill="none" />
|
|
38
|
-
<g transform="translate(${opts.xOff}, ${opts.yOff}) scale(${opts.scale}) translate(${-opts.vx}, ${-opts.vy})">
|
|
39
|
-
<path d="${opts.d}" fill="black" />
|
|
40
|
-
</g>
|
|
41
|
-
</svg>`.trim();
|
|
42
|
-
await promises_1.default.writeFile(node_path_1.default.join(opts.tempDir, `u${hex}.svg`), layerSvg, 'utf8');
|
|
43
|
-
}
|
|
44
27
|
/**
|
|
45
28
|
* Transform an SVG path `d` string from source SVG coordinates into font
|
|
46
29
|
* glyph coordinates (Y-up, with placement scaling and centering applied).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSvg = validateSvg;
|
|
4
|
+
exports.preprocessSvg = preprocessSvg;
|
|
5
|
+
const svgPatterns_1 = require("../../utils/svgPatterns");
|
|
6
|
+
const dom_1 = require("../flatten/dom");
|
|
7
|
+
function validateSvg(content) {
|
|
8
|
+
if (svgPatterns_1.XML_MASK.test(content)) {
|
|
9
|
+
return { valid: false, reason: '<mask> is not supported yet' };
|
|
10
|
+
}
|
|
11
|
+
if (svgPatterns_1.XML_FILTER.test(content)) {
|
|
12
|
+
return { valid: false, reason: '<filter> is not supported yet' };
|
|
13
|
+
}
|
|
14
|
+
if (svgPatterns_1.XML_IMAGE.test(content)) {
|
|
15
|
+
return {
|
|
16
|
+
valid: false,
|
|
17
|
+
reason: 'embedded raster <image> is not supported yet',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return { valid: true };
|
|
21
|
+
}
|
|
22
|
+
function stripPxUnits(content) {
|
|
23
|
+
return content
|
|
24
|
+
.replace(svgPatterns_1.PX_ATTRIBUTE_VALUE, '=$1$2$1')
|
|
25
|
+
.replace(svgPatterns_1.PX_STYLE_VALUE, '$1');
|
|
26
|
+
}
|
|
27
|
+
// ensure the svg has a xmlns attribute
|
|
28
|
+
function preprocessSvg(content) {
|
|
29
|
+
const withUnits = stripPxUnits(content);
|
|
30
|
+
if (svgPatterns_1.XML_XMLNS.test(withUnits))
|
|
31
|
+
return withUnits;
|
|
32
|
+
return withUnits.replace(svgPatterns_1.SVG_OPEN_TAG, `<svg xmlns="${dom_1.SVG_NS}"`);
|
|
33
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Cmd, PathKitModule, Point, VerbMap } from './types';
|
|
2
|
+
export declare function verbMap(PathKit: PathKitModule): VerbMap;
|
|
3
|
+
export declare function fillTypes(PathKit: PathKitModule): {
|
|
4
|
+
EVENODD: number;
|
|
5
|
+
WINDING: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function roundN(x: number, ndigits?: number): number;
|
|
8
|
+
export declare function normPt(p: Point): [number, number];
|
|
9
|
+
export declare function eqPt(a: Point, b: Point): boolean;
|
|
10
|
+
export declare function approxSignedAreaFromContourCmds(contourCmds: readonly Cmd[], VERB: VerbMap, steps?: number): number;
|
|
11
|
+
export declare function splitContours(cmds: readonly Cmd[], VERB: VerbMap): Cmd[][];
|
|
12
|
+
export declare function ensureClosed(contourCmds: readonly Cmd[], VERB: VerbMap): Cmd[];
|
|
13
|
+
export declare function explicitCloseWantedFromCmds(contourCmds: readonly Cmd[] | undefined, VERB: VerbMap): boolean;
|
|
14
|
+
type SegmentL = {
|
|
15
|
+
type: 'L';
|
|
16
|
+
start: Point;
|
|
17
|
+
end: Point;
|
|
18
|
+
synthetic: boolean;
|
|
19
|
+
};
|
|
20
|
+
type SegmentQ = {
|
|
21
|
+
type: 'Q';
|
|
22
|
+
start: Point;
|
|
23
|
+
ctrl: Point;
|
|
24
|
+
end: Point;
|
|
25
|
+
synthetic: boolean;
|
|
26
|
+
};
|
|
27
|
+
type SegmentC = {
|
|
28
|
+
type: 'C';
|
|
29
|
+
start: Point;
|
|
30
|
+
c1: Point;
|
|
31
|
+
c2: Point;
|
|
32
|
+
end: Point;
|
|
33
|
+
synthetic: boolean;
|
|
34
|
+
};
|
|
35
|
+
type Segment = SegmentL | SegmentQ | SegmentC;
|
|
36
|
+
export declare function contourToSegments(contourCmds: readonly Cmd[], VERB: VerbMap): {
|
|
37
|
+
start: Point;
|
|
38
|
+
segs: Segment[];
|
|
39
|
+
};
|
|
40
|
+
export declare function reverseClosedContourKeepStart(contourCmds: readonly Cmd[], explicitCloseWanted: boolean, VERB: VerbMap): Cmd[];
|
|
41
|
+
export declare function rotateClosedContourToStart(contourCmds: readonly Cmd[], desiredStart: Point, explicitCloseWanted: boolean, VERB: VerbMap): Cmd[];
|
|
42
|
+
export declare function mergeMoves(aMoves: readonly Point[] | undefined, bMoves: readonly Point[] | undefined): Point[];
|
|
43
|
+
export declare function bestStartMinYMinX(contourCmds: readonly Cmd[], VERB: VerbMap): Point | null;
|
|
44
|
+
/**
|
|
45
|
+
* Convert contour commands to a polyline by sampling curves.
|
|
46
|
+
* Used for ray-casting containment tests.
|
|
47
|
+
*/
|
|
48
|
+
export declare function contourToPolyline(contourCmds: readonly Cmd[], V: VerbMap, steps?: number): Point[];
|
|
49
|
+
/**
|
|
50
|
+
* Ray-casting point-in-polygon test.
|
|
51
|
+
*/
|
|
52
|
+
export declare function pointInPolygon(px: number, py: number, poly: Point[]): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Get a representative point on the contour boundary (midpoint of first segment).
|
|
55
|
+
*/
|
|
56
|
+
export declare function getContourSamplePoint(contourCmds: readonly Cmd[], V: VerbMap): Point | null;
|
|
57
|
+
/**
|
|
58
|
+
* Apply containment-based winding fix to contour objects.
|
|
59
|
+
* Even nesting depth = CCW (outer), odd = CW (hole).
|
|
60
|
+
*/
|
|
61
|
+
export declare function applyContainmentWinding(contourObjs: Array<{
|
|
62
|
+
cmds: Cmd[];
|
|
63
|
+
explicitCloseWanted: boolean;
|
|
64
|
+
absA: number;
|
|
65
|
+
}>, V: VerbMap): void;
|
|
66
|
+
export type Contour = {
|
|
67
|
+
cmds: Cmd[];
|
|
68
|
+
explicitCloseWanted: boolean;
|
|
69
|
+
absA: number;
|
|
70
|
+
};
|
|
71
|
+
export declare function orientedContours(cmds: readonly Cmd[], V: VerbMap): Contour[];
|
|
72
|
+
export declare function canonicalContourCmds(cmds: readonly Cmd[], recordedMoves: readonly Point[], preferMinYMinXStart: boolean, V: VerbMap): Cmd[];
|
|
73
|
+
export declare function contoursArea(cmds: readonly Cmd[], V: VerbMap): number;
|
|
74
|
+
export {};
|
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.verbMap = verbMap;
|
|
4
|
+
exports.fillTypes = fillTypes;
|
|
5
|
+
exports.roundN = roundN;
|
|
6
|
+
exports.normPt = normPt;
|
|
7
|
+
exports.eqPt = eqPt;
|
|
8
|
+
exports.approxSignedAreaFromContourCmds = approxSignedAreaFromContourCmds;
|
|
9
|
+
exports.splitContours = splitContours;
|
|
10
|
+
exports.ensureClosed = ensureClosed;
|
|
11
|
+
exports.explicitCloseWantedFromCmds = explicitCloseWantedFromCmds;
|
|
12
|
+
exports.contourToSegments = contourToSegments;
|
|
13
|
+
exports.reverseClosedContourKeepStart = reverseClosedContourKeepStart;
|
|
14
|
+
exports.rotateClosedContourToStart = rotateClosedContourToStart;
|
|
15
|
+
exports.mergeMoves = mergeMoves;
|
|
16
|
+
exports.bestStartMinYMinX = bestStartMinYMinX;
|
|
17
|
+
exports.contourToPolyline = contourToPolyline;
|
|
18
|
+
exports.pointInPolygon = pointInPolygon;
|
|
19
|
+
exports.getContourSamplePoint = getContourSamplePoint;
|
|
20
|
+
exports.applyContainmentWinding = applyContainmentWinding;
|
|
21
|
+
exports.orientedContours = orientedContours;
|
|
22
|
+
exports.canonicalContourCmds = canonicalContourCmds;
|
|
23
|
+
exports.contoursArea = contoursArea;
|
|
24
|
+
function verbMap(PathKit) {
|
|
25
|
+
return {
|
|
26
|
+
MOVE: PathKit.MOVE_VERB ?? 0,
|
|
27
|
+
LINE: PathKit.LINE_VERB ?? 1,
|
|
28
|
+
QUAD: PathKit.QUAD_VERB ?? 2,
|
|
29
|
+
CONIC: PathKit.CONIC_VERB ?? 3,
|
|
30
|
+
CUBIC: PathKit.CUBIC_VERB ?? 4,
|
|
31
|
+
CLOSE: PathKit.CLOSE_VERB ?? 5,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function fillTypes(PathKit) {
|
|
35
|
+
return {
|
|
36
|
+
EVENODD: PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1,
|
|
37
|
+
WINDING: PathKit?.FillType?.WINDING ?? PathKit?.FillType?.NONZERO ?? 0,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
7
40
|
const EPS = 1e-2;
|
|
8
41
|
// ✅ round-half-to-even (banker's rounding) at ndigits
|
|
9
42
|
function roundN(x, ndigits = 3) {
|
|
@@ -300,47 +333,6 @@ function rotateClosedContourToStart(contourCmds, desiredStart, explicitCloseWant
|
|
|
300
333
|
applyClosePolicy(rotated, desiredStart, explicitCloseWanted);
|
|
301
334
|
return segmentsToContourCmds(desiredStart, rotated, VERB);
|
|
302
335
|
}
|
|
303
|
-
function cmdsToVerbPoints(cmds, VERB) {
|
|
304
|
-
const out = [];
|
|
305
|
-
for (const cmd of cmds) {
|
|
306
|
-
const v = cmd[0];
|
|
307
|
-
if (v === VERB.MOVE)
|
|
308
|
-
out.push([0, [[cmd[1], cmd[2]]]]);
|
|
309
|
-
else if (v === VERB.LINE)
|
|
310
|
-
out.push([1, [[cmd[1], cmd[2]]]]);
|
|
311
|
-
else if (v === VERB.QUAD)
|
|
312
|
-
out.push([
|
|
313
|
-
2,
|
|
314
|
-
[
|
|
315
|
-
[cmd[1], cmd[2]],
|
|
316
|
-
[cmd[3], cmd[4]],
|
|
317
|
-
],
|
|
318
|
-
]);
|
|
319
|
-
else if (v === VERB.CUBIC)
|
|
320
|
-
out.push([
|
|
321
|
-
3,
|
|
322
|
-
[
|
|
323
|
-
[cmd[1], cmd[2]],
|
|
324
|
-
[cmd[3], cmd[4]],
|
|
325
|
-
[cmd[5], cmd[6]],
|
|
326
|
-
],
|
|
327
|
-
]);
|
|
328
|
-
else if (v === VERB.CLOSE)
|
|
329
|
-
out.push([4, []]);
|
|
330
|
-
else
|
|
331
|
-
throw new Error(`Unexpected verb in cmds: ${v}`);
|
|
332
|
-
}
|
|
333
|
-
return out;
|
|
334
|
-
}
|
|
335
|
-
function wrapPath(pathkitPath) {
|
|
336
|
-
return { p: pathkitPath, meta: { moves: [] } };
|
|
337
|
-
}
|
|
338
|
-
function cloneWrap(h, PathKit) {
|
|
339
|
-
const p2 = PathKit.NewPath(h.p);
|
|
340
|
-
const out = wrapPath(p2);
|
|
341
|
-
out.meta.moves = h.meta?.moves ? h.meta.moves.map((m) => [m[0], m[1]]) : [];
|
|
342
|
-
return out;
|
|
343
|
-
}
|
|
344
336
|
function mergeMoves(aMoves, bMoves) {
|
|
345
337
|
const out = [];
|
|
346
338
|
const pushUnique = (pt) => {
|
|
@@ -382,19 +374,6 @@ function bestStartMinYMinX(contourCmds, VERB) {
|
|
|
382
374
|
}
|
|
383
375
|
return best;
|
|
384
376
|
}
|
|
385
|
-
// ---------------------------------------------------------------------------
|
|
386
|
-
// Containment helpers (module-level for reuse by fixPathWinding)
|
|
387
|
-
// ---------------------------------------------------------------------------
|
|
388
|
-
function buildVerbMap(PathKit) {
|
|
389
|
-
return {
|
|
390
|
-
MOVE: PathKit.MOVE_VERB ?? 0,
|
|
391
|
-
LINE: PathKit.LINE_VERB ?? 1,
|
|
392
|
-
QUAD: PathKit.QUAD_VERB ?? 2,
|
|
393
|
-
CONIC: PathKit.CONIC_VERB ?? 3,
|
|
394
|
-
CUBIC: PathKit.CUBIC_VERB ?? 4,
|
|
395
|
-
CLOSE: PathKit.CLOSE_VERB ?? 5,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
377
|
/**
|
|
399
378
|
* Convert contour commands to a polyline by sampling curves.
|
|
400
379
|
* Used for ray-casting containment tests.
|
|
@@ -548,268 +527,49 @@ function applyContainmentWinding(contourObjs, V) {
|
|
|
548
527
|
ensureOrient(contourObjs[i], depths[i] % 2 === 0);
|
|
549
528
|
}
|
|
550
529
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
* path that renders identically under nonzero winding.
|
|
554
|
-
*
|
|
555
|
-
* Steps:
|
|
556
|
-
* 1. Parse via PathKit, set fill type to EVENODD, simplify (resolve topology)
|
|
557
|
-
* 2. Split into contours, compute containment depths
|
|
558
|
-
* 3. Fix winding: even depth = CCW (outer), odd depth = CW (hole)
|
|
559
|
-
* 4. Reconstruct d string
|
|
560
|
-
*/
|
|
561
|
-
function convertEvenoddToWinding(PathKit, d) {
|
|
562
|
-
const V = buildVerbMap(PathKit);
|
|
563
|
-
// 1. Parse and simplify with EVENODD fill type
|
|
564
|
-
const p = PathKit.FromSVGString(d);
|
|
565
|
-
if (!p)
|
|
566
|
-
return d;
|
|
567
|
-
const FILL_EVENODD = PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
|
|
568
|
-
p.setFillType(FILL_EVENODD);
|
|
569
|
-
p.simplify();
|
|
570
|
-
// Get the simplified SVG string and re-parse for command access
|
|
571
|
-
const simplified = p.toSVGString();
|
|
572
|
-
p.delete?.();
|
|
573
|
-
const p2 = PathKit.FromSVGString(simplified);
|
|
574
|
-
if (!p2)
|
|
575
|
-
return simplified;
|
|
576
|
-
const cmds = p2.toCmds();
|
|
577
|
-
p2.delete?.();
|
|
578
|
-
if (cmds.length === 0)
|
|
579
|
-
return simplified;
|
|
580
|
-
// 2. Split into contours
|
|
581
|
-
const contourObjs = splitContours(cmds, V).map((c) => {
|
|
530
|
+
function orientedContours(cmds, V) {
|
|
531
|
+
const contours = splitContours(cmds, V).map((c) => {
|
|
582
532
|
const explicitCloseWanted = explicitCloseWantedFromCmds(c, V);
|
|
583
533
|
const cc = ensureClosed(c, V);
|
|
584
534
|
const a = approxSignedAreaFromContourCmds(cc, V);
|
|
585
535
|
return { cmds: cc, absA: Math.abs(a), explicitCloseWanted };
|
|
586
536
|
});
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
// 4. Reconstruct d string from fixed commands
|
|
591
|
-
const allCmds = contourObjs.flatMap((x) => x.cmds);
|
|
592
|
-
const parts = [];
|
|
593
|
-
for (const cmd of allCmds) {
|
|
594
|
-
const v = cmd[0];
|
|
595
|
-
if (v === V.MOVE)
|
|
596
|
-
parts.push(`M${roundN(cmd[1])} ${roundN(cmd[2])}`);
|
|
597
|
-
else if (v === V.LINE)
|
|
598
|
-
parts.push(`L${roundN(cmd[1])} ${roundN(cmd[2])}`);
|
|
599
|
-
else if (v === V.QUAD)
|
|
600
|
-
parts.push(`Q${roundN(cmd[1])} ${roundN(cmd[2])} ${roundN(cmd[3])} ${roundN(cmd[4])}`);
|
|
601
|
-
else if (v === V.CUBIC)
|
|
602
|
-
parts.push(`C${roundN(cmd[1])} ${roundN(cmd[2])} ${roundN(cmd[3])} ${roundN(cmd[4])} ${roundN(cmd[5])} ${roundN(cmd[6])}`);
|
|
603
|
-
else if (v === V.CLOSE)
|
|
604
|
-
parts.push('Z');
|
|
605
|
-
}
|
|
606
|
-
return parts.join(' ');
|
|
537
|
+
contours.sort((x, y) => y.absA - x.absA);
|
|
538
|
+
applyContainmentWinding(contours, V);
|
|
539
|
+
return contours;
|
|
607
540
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
const
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
// Build contour objects, but DO NOT normalize orientation yet.
|
|
625
|
-
const contourObjs = splitContours(cmds, VERB).map((c) => {
|
|
626
|
-
const explicitCloseWanted = explicitCloseWantedFromCmds(c, VERB);
|
|
627
|
-
const cc = ensureClosed(c, VERB);
|
|
628
|
-
const a = approxSignedAreaFromContourCmds(cc, VERB); // signed
|
|
629
|
-
return { cmds: cc, absA: Math.abs(a), explicitCloseWanted };
|
|
630
|
-
});
|
|
631
|
-
// Big-to-small ordering gives deterministic outer→inner ordering.
|
|
632
|
-
contourObjs.sort((x, y) => y.absA - x.absA);
|
|
633
|
-
// Containment-based winding: compute nesting depth per contour via
|
|
634
|
-
// ray-casting point-in-polygon. Even depth = outer (CCW), odd = hole (CW).
|
|
635
|
-
applyContainmentWinding(contourObjs, VERB);
|
|
636
|
-
// Rotate starts deterministically:
|
|
637
|
-
// 1) If we have recorded MOVE points, try to rotate contour to a move point that lies on it.
|
|
638
|
-
// 2) Otherwise, rotate to minY/minX point (helps stroke-ish paths)
|
|
639
|
-
for (const obj of contourObjs) {
|
|
640
|
-
let cc = obj.cmds;
|
|
641
|
-
for (let i = 0; i < moves.length; i++) {
|
|
642
|
-
if (used[i])
|
|
643
|
-
continue;
|
|
644
|
-
const target = moves[i];
|
|
645
|
-
const { segs } = contourToSegments(cc, VERB);
|
|
646
|
-
const found = segs.some((s) => eqPt(s.start, target) || eqPt(s.end, target));
|
|
647
|
-
if (found) {
|
|
648
|
-
used[i] = true;
|
|
649
|
-
cc = rotateClosedContourToStart(cc, target, obj.explicitCloseWanted, VERB);
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
541
|
+
function canonicalContourCmds(cmds, recordedMoves, preferMinYMinXStart, V) {
|
|
542
|
+
const moves = recordedMoves.map((m) => normPt([m[0], m[1]]));
|
|
543
|
+
const used = new Array(moves.length).fill(false);
|
|
544
|
+
const contours = orientedContours(cmds, V);
|
|
545
|
+
for (const obj of contours) {
|
|
546
|
+
let cc = obj.cmds;
|
|
547
|
+
for (let i = 0; i < moves.length; i++) {
|
|
548
|
+
if (used[i])
|
|
549
|
+
continue;
|
|
550
|
+
const target = moves[i];
|
|
551
|
+
const { segs } = contourToSegments(cc, V);
|
|
552
|
+
const found = segs.some((s) => eqPt(s.start, target) || eqPt(s.end, target));
|
|
553
|
+
if (found) {
|
|
554
|
+
used[i] = true;
|
|
555
|
+
cc = rotateClosedContourToStart(cc, target, obj.explicitCloseWanted, V);
|
|
556
|
+
break;
|
|
652
557
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
}
|
|
558
|
+
}
|
|
559
|
+
if (preferMinYMinXStart) {
|
|
560
|
+
const best = bestStartMinYMinX(cc, V);
|
|
561
|
+
if (best) {
|
|
562
|
+
cc = rotateClosedContourToStart(cc, best, obj.explicitCloseWanted, V);
|
|
659
563
|
}
|
|
660
|
-
obj.cmds = cc;
|
|
661
564
|
}
|
|
662
|
-
|
|
565
|
+
obj.cmds = cc;
|
|
663
566
|
}
|
|
664
|
-
return
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
},
|
|
673
|
-
delete_path(h) {
|
|
674
|
-
h?.p?.delete?.();
|
|
675
|
-
},
|
|
676
|
-
get_fill_type(h) {
|
|
677
|
-
const ft = h.p.getFillType?.();
|
|
678
|
-
return ft === FILL_EVENODD ? 1 : 0;
|
|
679
|
-
},
|
|
680
|
-
set_fill_type(h, fillTypeInt) {
|
|
681
|
-
h.p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
|
|
682
|
-
return true;
|
|
683
|
-
},
|
|
684
|
-
move_to(h, x, y) {
|
|
685
|
-
h.p.moveTo(x, y);
|
|
686
|
-
h.meta.moves.push(normPt([x, y]));
|
|
687
|
-
},
|
|
688
|
-
line_to(h, x, y) {
|
|
689
|
-
h.p.lineTo(x, y);
|
|
690
|
-
},
|
|
691
|
-
quad_to(h, x1, y1, x2, y2) {
|
|
692
|
-
h.p.quadTo(x1, y1, x2, y2);
|
|
693
|
-
},
|
|
694
|
-
cubic_to(h, x1, y1, x2, y2, x3, y3) {
|
|
695
|
-
h.p.cubicTo(x1, y1, x2, y2, x3, y3);
|
|
696
|
-
},
|
|
697
|
-
close(h) {
|
|
698
|
-
h.p.close();
|
|
699
|
-
},
|
|
700
|
-
simplify(h, fixWinding = false) {
|
|
701
|
-
try {
|
|
702
|
-
// 1) simplify in place
|
|
703
|
-
h.p.simplify();
|
|
704
|
-
// 2) normalize representation via SVG roundtrip
|
|
705
|
-
const svg = h.p.toSVGString();
|
|
706
|
-
const p2 = PathKit.FromSVGString(svg);
|
|
707
|
-
if (p2) {
|
|
708
|
-
// replace underlying path handle
|
|
709
|
-
h.p.delete?.();
|
|
710
|
-
h.p = p2;
|
|
711
|
-
}
|
|
712
|
-
if (fixWinding)
|
|
713
|
-
h.p.setFillType(FILL_WINDING);
|
|
714
|
-
return true;
|
|
715
|
-
}
|
|
716
|
-
catch {
|
|
717
|
-
return false;
|
|
718
|
-
}
|
|
719
|
-
},
|
|
720
|
-
stroke(h, width, capInt, joinInt, miterLimit, dashArray, dashOffset) {
|
|
721
|
-
const Caps = PathKit.StrokeCap ?? {};
|
|
722
|
-
const Joins = PathKit.StrokeJoin ?? {};
|
|
723
|
-
const cap = capInt === 1
|
|
724
|
-
? (Caps.ROUND ?? 1)
|
|
725
|
-
: capInt === 2
|
|
726
|
-
? (Caps.SQUARE ?? 2)
|
|
727
|
-
: (Caps.BUTT ?? 0);
|
|
728
|
-
const join = joinInt === 1
|
|
729
|
-
? (Joins.ROUND ?? 1)
|
|
730
|
-
: joinInt === 2
|
|
731
|
-
? (Joins.BEVEL ?? 2)
|
|
732
|
-
: (Joins.MITER ?? 0);
|
|
733
|
-
const work = PathKit.NewPath(h.p);
|
|
734
|
-
try {
|
|
735
|
-
if (Array.isArray(dashArray) &&
|
|
736
|
-
dashArray.length === 2 &&
|
|
737
|
-
typeof work.dash === 'function') {
|
|
738
|
-
work.dash(Number(dashArray[0]), Number(dashArray[1]), dashOffset || 0);
|
|
739
|
-
}
|
|
740
|
-
let stroked = work.stroke({
|
|
741
|
-
width,
|
|
742
|
-
cap,
|
|
743
|
-
join,
|
|
744
|
-
miter_limit: miterLimit,
|
|
745
|
-
});
|
|
746
|
-
if (!stroked || typeof stroked.toCmds !== 'function')
|
|
747
|
-
stroked = work;
|
|
748
|
-
if (stroked !== work)
|
|
749
|
-
work.delete?.();
|
|
750
|
-
const wrapped = wrapPath(stroked);
|
|
751
|
-
wrapped.meta.moves = [];
|
|
752
|
-
return wrapped;
|
|
753
|
-
}
|
|
754
|
-
catch {
|
|
755
|
-
const wrapped = wrapPath(work);
|
|
756
|
-
wrapped.meta.moves = [];
|
|
757
|
-
return wrapped;
|
|
758
|
-
}
|
|
759
|
-
},
|
|
760
|
-
convert_conics_to_quads(_h, _tol) {
|
|
761
|
-
// intentionally no-op
|
|
762
|
-
},
|
|
763
|
-
transform(h, a, b, c, d, e, f) {
|
|
764
|
-
const p = PathKit.NewPath(h.p);
|
|
765
|
-
p.transform(a, c, e, b, d, f, 0, 0, 1);
|
|
766
|
-
const wrapped = wrapPath(p);
|
|
767
|
-
wrapped.meta.moves = (h.meta?.moves || []).map(([x, y]) => normPt([a * x + c * y + e, b * x + d * y + f]));
|
|
768
|
-
return wrapped;
|
|
769
|
-
},
|
|
770
|
-
op(aHandle, bHandle, opInt) {
|
|
771
|
-
try {
|
|
772
|
-
const Ops = PathKit.PathOp ?? {};
|
|
773
|
-
const op = opInt === 1
|
|
774
|
-
? (Ops.INTERSECT ?? 1)
|
|
775
|
-
: opInt === 2
|
|
776
|
-
? (Ops.DIFFERENCE ?? 2)
|
|
777
|
-
: (Ops.UNION ?? 0);
|
|
778
|
-
const out = PathKit.MakeFromOp(aHandle.p, bHandle.p, op);
|
|
779
|
-
if (!out)
|
|
780
|
-
return null;
|
|
781
|
-
const wrapped = wrapPath(out);
|
|
782
|
-
wrapped.meta.moves = mergeMoves(aHandle.meta?.moves, bHandle.meta?.moves);
|
|
783
|
-
return wrapped;
|
|
784
|
-
}
|
|
785
|
-
catch {
|
|
786
|
-
return null;
|
|
787
|
-
}
|
|
788
|
-
},
|
|
789
|
-
bounds(h) {
|
|
790
|
-
const r = h.p.getBounds();
|
|
791
|
-
return [r.fLeft, r.fTop, r.fRight, r.fBottom];
|
|
792
|
-
},
|
|
793
|
-
area(h) {
|
|
794
|
-
try {
|
|
795
|
-
const cmds = cmdsViaSvgRoundtrip(h);
|
|
796
|
-
const contours = splitContours(cmds, VERB);
|
|
797
|
-
let total = 0;
|
|
798
|
-
for (const c of contours) {
|
|
799
|
-
const cc = ensureClosed(c, VERB);
|
|
800
|
-
total += Math.abs(approxSignedAreaFromContourCmds(cc, VERB));
|
|
801
|
-
}
|
|
802
|
-
return total;
|
|
803
|
-
}
|
|
804
|
-
catch {
|
|
805
|
-
return 0.0;
|
|
806
|
-
}
|
|
807
|
-
},
|
|
808
|
-
iter_segments(h) {
|
|
809
|
-
const cmds = cmdsViaSvgRoundtrip(h);
|
|
810
|
-
const preferStrokeCanonical = (h.meta?.moves?.length || 0) === 0;
|
|
811
|
-
const normalized = normalizeSortRotateContours(cmds, h, preferStrokeCanonical);
|
|
812
|
-
return cmdsToVerbPoints(normalized, VERB);
|
|
813
|
-
},
|
|
814
|
-
};
|
|
567
|
+
return contours.flatMap((x) => x.cmds);
|
|
568
|
+
}
|
|
569
|
+
function contoursArea(cmds, V) {
|
|
570
|
+
let total = 0;
|
|
571
|
+
for (const c of splitContours(cmds, V)) {
|
|
572
|
+
total += Math.abs(approxSignedAreaFromContourCmds(ensureClosed(c, V), V));
|
|
573
|
+
}
|
|
574
|
+
return total;
|
|
815
575
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PathKitModule } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a path `d` string with evenodd fill semantics to an equivalent
|
|
4
|
+
* path that renders identically under nonzero winding.
|
|
5
|
+
*
|
|
6
|
+
* Steps:
|
|
7
|
+
* 1. Parse via PathKit, set fill type to EVENODD, simplify (resolve topology)
|
|
8
|
+
* 2. Split into contours, compute containment depths
|
|
9
|
+
* 3. Fix winding: even depth = CCW (outer), odd depth = CW (hole)
|
|
10
|
+
* 4. Reconstruct d string
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertEvenoddToWinding(PathKit: PathKitModule, d: string): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertEvenoddToWinding = convertEvenoddToWinding;
|
|
4
|
+
const contours_1 = require("./contours");
|
|
5
|
+
/**
|
|
6
|
+
* Convert a path `d` string with evenodd fill semantics to an equivalent
|
|
7
|
+
* path that renders identically under nonzero winding.
|
|
8
|
+
*
|
|
9
|
+
* Steps:
|
|
10
|
+
* 1. Parse via PathKit, set fill type to EVENODD, simplify (resolve topology)
|
|
11
|
+
* 2. Split into contours, compute containment depths
|
|
12
|
+
* 3. Fix winding: even depth = CCW (outer), odd depth = CW (hole)
|
|
13
|
+
* 4. Reconstruct d string
|
|
14
|
+
*/
|
|
15
|
+
function convertEvenoddToWinding(PathKit, d) {
|
|
16
|
+
const V = (0, contours_1.verbMap)(PathKit);
|
|
17
|
+
// 1. Parse and simplify with EVENODD fill type
|
|
18
|
+
const p = PathKit.FromSVGString(d);
|
|
19
|
+
if (!p)
|
|
20
|
+
return d;
|
|
21
|
+
p.setFillType((0, contours_1.fillTypes)(PathKit).EVENODD);
|
|
22
|
+
p.simplify();
|
|
23
|
+
// Get the simplified SVG string and re-parse for command access
|
|
24
|
+
const simplified = p.toSVGString();
|
|
25
|
+
p.delete?.();
|
|
26
|
+
const p2 = PathKit.FromSVGString(simplified);
|
|
27
|
+
if (!p2)
|
|
28
|
+
return simplified;
|
|
29
|
+
const cmds = p2.toCmds();
|
|
30
|
+
p2.delete?.();
|
|
31
|
+
if (cmds.length === 0)
|
|
32
|
+
return simplified;
|
|
33
|
+
// 2.+3. Split into contours and fix winding via containment analysis
|
|
34
|
+
const allCmds = (0, contours_1.orientedContours)(cmds, V).flatMap((x) => x.cmds);
|
|
35
|
+
// 4. Reconstruct d string from fixed commands
|
|
36
|
+
const parts = [];
|
|
37
|
+
for (const cmd of allCmds) {
|
|
38
|
+
const v = cmd[0];
|
|
39
|
+
if (v === V.MOVE)
|
|
40
|
+
parts.push(`M${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])}`);
|
|
41
|
+
else if (v === V.LINE)
|
|
42
|
+
parts.push(`L${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])}`);
|
|
43
|
+
else if (v === V.QUAD)
|
|
44
|
+
parts.push(`Q${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])} ${(0, contours_1.roundN)(cmd[3])} ${(0, contours_1.roundN)(cmd[4])}`);
|
|
45
|
+
else if (v === V.CUBIC)
|
|
46
|
+
parts.push(`C${(0, contours_1.roundN)(cmd[1])} ${(0, contours_1.roundN)(cmd[2])} ${(0, contours_1.roundN)(cmd[3])} ${(0, contours_1.roundN)(cmd[4])} ${(0, contours_1.roundN)(cmd[5])} ${(0, contours_1.roundN)(cmd[6])}`);
|
|
47
|
+
else if (v === V.CLOSE)
|
|
48
|
+
parts.push('Z');
|
|
49
|
+
}
|
|
50
|
+
return parts.join(' ');
|
|
51
|
+
}
|