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,750 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
//** */
|
|
4
|
-
|
|
5
|
-
// ----- numeric helpers -----
|
|
6
|
-
const EPS = 1e-2;
|
|
7
|
-
|
|
8
|
-
// ✅ round-half-to-even (banker's rounding) at ndigits
|
|
9
|
-
function roundN(x, ndigits = 3) {
|
|
10
|
-
const m = 10 ** ndigits;
|
|
11
|
-
const s = x * m;
|
|
12
|
-
|
|
13
|
-
// Handle very large values safely
|
|
14
|
-
if (!Number.isFinite(s)) return x;
|
|
15
|
-
const floor = Math.floor(s);
|
|
16
|
-
const frac = s - floor;
|
|
17
|
-
|
|
18
|
-
// floating tolerance for "exactly .5"
|
|
19
|
-
const TIE_EPS = 1e-12;
|
|
20
|
-
let roundedInt;
|
|
21
|
-
if (Math.abs(frac - 0.5) < TIE_EPS) {
|
|
22
|
-
// tie -> choose even
|
|
23
|
-
roundedInt = floor % 2 === 0 ? floor : floor + 1;
|
|
24
|
-
} else if (Math.abs(frac + 0.5) < TIE_EPS) {
|
|
25
|
-
// negative tie case (rare due to floor behavior, but keep for completeness)
|
|
26
|
-
const ceil = Math.ceil(s);
|
|
27
|
-
roundedInt = ceil % 2 === 0 ? ceil : ceil - 1;
|
|
28
|
-
} else {
|
|
29
|
-
roundedInt = Math.round(s);
|
|
30
|
-
}
|
|
31
|
-
return roundedInt / m;
|
|
32
|
-
}
|
|
33
|
-
function normPt(p) {
|
|
34
|
-
return [Math.round(p[0] * 10000) / 10000, Math.round(p[1] * 10000) / 10000];
|
|
35
|
-
}
|
|
36
|
-
function eqPt(a, b) {
|
|
37
|
-
const aa = normPt(a);
|
|
38
|
-
const bb = normPt(b);
|
|
39
|
-
return Math.abs(aa[0] - bb[0]) < EPS && Math.abs(aa[1] - bb[1]) < EPS;
|
|
40
|
-
}
|
|
41
|
-
function signedAreaPolyline(points) {
|
|
42
|
-
if (points.length < 3) return 0;
|
|
43
|
-
let a = 0;
|
|
44
|
-
for (let i = 0; i < points.length; i++) {
|
|
45
|
-
const [x1, y1] = points[i];
|
|
46
|
-
const [x2, y2] = points[(i + 1) % points.length];
|
|
47
|
-
a += x1 * y2 - x2 * y1;
|
|
48
|
-
}
|
|
49
|
-
return a / 2;
|
|
50
|
-
}
|
|
51
|
-
function approxSignedAreaFromContourCmds(contourCmds, VERB, steps = 24) {
|
|
52
|
-
let cx = 0,
|
|
53
|
-
cy = 0;
|
|
54
|
-
let sx = 0,
|
|
55
|
-
sy = 0;
|
|
56
|
-
const pts = [];
|
|
57
|
-
const add = (x, y) => pts.push([x, y]);
|
|
58
|
-
for (const cmd of contourCmds) {
|
|
59
|
-
const v = cmd[0];
|
|
60
|
-
if (v === VERB.MOVE) {
|
|
61
|
-
cx = cmd[1];
|
|
62
|
-
cy = cmd[2];
|
|
63
|
-
sx = cx;
|
|
64
|
-
sy = cy;
|
|
65
|
-
add(cx, cy);
|
|
66
|
-
} else if (v === VERB.LINE) {
|
|
67
|
-
cx = cmd[1];
|
|
68
|
-
cy = cmd[2];
|
|
69
|
-
add(cx, cy);
|
|
70
|
-
} else if (v === VERB.QUAD) {
|
|
71
|
-
const x0 = cx,
|
|
72
|
-
y0 = cy;
|
|
73
|
-
const x1 = cmd[1],
|
|
74
|
-
y1 = cmd[2];
|
|
75
|
-
const x2 = cmd[3],
|
|
76
|
-
y2 = cmd[4];
|
|
77
|
-
for (let i = 1; i <= steps; i++) {
|
|
78
|
-
const t = i / steps;
|
|
79
|
-
const mt = 1 - t;
|
|
80
|
-
const x = mt * mt * x0 + 2 * mt * t * x1 + t * t * x2;
|
|
81
|
-
const y = mt * mt * y0 + 2 * mt * t * y1 + t * t * y2;
|
|
82
|
-
add(x, y);
|
|
83
|
-
}
|
|
84
|
-
cx = x2;
|
|
85
|
-
cy = y2;
|
|
86
|
-
} else if (v === VERB.CUBIC) {
|
|
87
|
-
const x0 = cx,
|
|
88
|
-
y0 = cy;
|
|
89
|
-
const x1 = cmd[1],
|
|
90
|
-
y1 = cmd[2];
|
|
91
|
-
const x2 = cmd[3],
|
|
92
|
-
y2 = cmd[4];
|
|
93
|
-
const x3 = cmd[5],
|
|
94
|
-
y3 = cmd[6];
|
|
95
|
-
for (let i = 1; i <= steps; i++) {
|
|
96
|
-
const t = i / steps;
|
|
97
|
-
const mt = 1 - t;
|
|
98
|
-
const x = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
|
|
99
|
-
const y = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
|
|
100
|
-
add(x, y);
|
|
101
|
-
}
|
|
102
|
-
cx = x3;
|
|
103
|
-
cy = y3;
|
|
104
|
-
} else if (v === VERB.CLOSE) {
|
|
105
|
-
add(sx, sy);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (pts.length && (pts[0][0] !== pts[pts.length - 1][0] || pts[0][1] !== pts[pts.length - 1][1])) {
|
|
109
|
-
pts.push([pts[0][0], pts[0][1]]);
|
|
110
|
-
}
|
|
111
|
-
return signedAreaPolyline(pts);
|
|
112
|
-
}
|
|
113
|
-
function splitContours(cmds, VERB) {
|
|
114
|
-
const contours = [];
|
|
115
|
-
let cur = null;
|
|
116
|
-
for (const cmd of cmds) {
|
|
117
|
-
const v = cmd[0];
|
|
118
|
-
if (v === VERB.MOVE) {
|
|
119
|
-
if (cur && cur.length) contours.push(cur);
|
|
120
|
-
cur = [cmd];
|
|
121
|
-
} else if (cur) {
|
|
122
|
-
cur.push(cmd);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (cur && cur.length) contours.push(cur);
|
|
126
|
-
return contours;
|
|
127
|
-
}
|
|
128
|
-
function ensureClosed(contourCmds, VERB) {
|
|
129
|
-
return contourCmds.some(c => c[0] === VERB.CLOSE) ? [...contourCmds] : [...contourCmds, [VERB.CLOSE]];
|
|
130
|
-
}
|
|
131
|
-
function explicitCloseWantedFromCmds(contourCmds, VERB) {
|
|
132
|
-
if (!contourCmds?.length) return false;
|
|
133
|
-
const m = contourCmds[0];
|
|
134
|
-
if (m[0] !== VERB.MOVE) return false;
|
|
135
|
-
const start = [m[1], m[2]];
|
|
136
|
-
for (let i = contourCmds.length - 1; i >= 1; i--) {
|
|
137
|
-
const cmd = contourCmds[i];
|
|
138
|
-
const v = cmd[0];
|
|
139
|
-
if (v === VERB.CLOSE) continue;
|
|
140
|
-
let end = null;
|
|
141
|
-
if (v === VERB.LINE) end = [cmd[1], cmd[2]];else if (v === VERB.QUAD) end = [cmd[3], cmd[4]];else if (v === VERB.CUBIC) end = [cmd[5], cmd[6]];else continue;
|
|
142
|
-
return eqPt(end, start);
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
function contourToSegments(contourCmds, VERB) {
|
|
147
|
-
const c = ensureClosed(contourCmds, VERB);
|
|
148
|
-
const move = c[0];
|
|
149
|
-
const sx = move[1],
|
|
150
|
-
sy = move[2];
|
|
151
|
-
let last = [sx, sy];
|
|
152
|
-
const segs = [];
|
|
153
|
-
for (let i = 1; i < c.length; i++) {
|
|
154
|
-
const cmd = c[i];
|
|
155
|
-
const v = cmd[0];
|
|
156
|
-
if (v === VERB.LINE) {
|
|
157
|
-
const end = [cmd[1], cmd[2]];
|
|
158
|
-
segs.push({
|
|
159
|
-
type: 'L',
|
|
160
|
-
start: last,
|
|
161
|
-
end,
|
|
162
|
-
synthetic: false
|
|
163
|
-
});
|
|
164
|
-
last = end;
|
|
165
|
-
} else if (v === VERB.QUAD) {
|
|
166
|
-
const ctrl = [cmd[1], cmd[2]];
|
|
167
|
-
const end = [cmd[3], cmd[4]];
|
|
168
|
-
segs.push({
|
|
169
|
-
type: 'Q',
|
|
170
|
-
start: last,
|
|
171
|
-
ctrl,
|
|
172
|
-
end,
|
|
173
|
-
synthetic: false
|
|
174
|
-
});
|
|
175
|
-
last = end;
|
|
176
|
-
} else if (v === VERB.CUBIC) {
|
|
177
|
-
const c1 = [cmd[1], cmd[2]];
|
|
178
|
-
const c2 = [cmd[3], cmd[4]];
|
|
179
|
-
const end = [cmd[5], cmd[6]];
|
|
180
|
-
segs.push({
|
|
181
|
-
type: 'C',
|
|
182
|
-
start: last,
|
|
183
|
-
c1,
|
|
184
|
-
c2,
|
|
185
|
-
end,
|
|
186
|
-
synthetic: false
|
|
187
|
-
});
|
|
188
|
-
last = end;
|
|
189
|
-
} else if (v === VERB.CLOSE) {
|
|
190
|
-
const end = [sx, sy];
|
|
191
|
-
if (!eqPt(last, end)) {
|
|
192
|
-
segs.push({
|
|
193
|
-
type: 'L',
|
|
194
|
-
start: last,
|
|
195
|
-
end,
|
|
196
|
-
synthetic: true
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
last = end;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
start: [sx, sy],
|
|
204
|
-
segs
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function applyClosePolicy(segs, startPt, explicitCloseWanted) {
|
|
208
|
-
if (!segs.length) return segs;
|
|
209
|
-
for (const s of segs) s.synthetic = false;
|
|
210
|
-
const last = segs[segs.length - 1];
|
|
211
|
-
const lastEnd = last.end;
|
|
212
|
-
if (!eqPt(lastEnd, startPt)) {
|
|
213
|
-
segs.push({
|
|
214
|
-
type: 'L',
|
|
215
|
-
start: lastEnd,
|
|
216
|
-
end: startPt,
|
|
217
|
-
synthetic: false
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
if (!explicitCloseWanted) {
|
|
221
|
-
segs[segs.length - 1].synthetic = true;
|
|
222
|
-
}
|
|
223
|
-
return segs;
|
|
224
|
-
}
|
|
225
|
-
function segmentsToContourCmds(startPt, segs, VERB) {
|
|
226
|
-
const out = [[VERB.MOVE, roundN(startPt[0]), roundN(startPt[1])]];
|
|
227
|
-
for (const s of segs) {
|
|
228
|
-
if (s.synthetic) continue;
|
|
229
|
-
if (s.type === 'L') {
|
|
230
|
-
out.push([VERB.LINE, roundN(s.end[0]), roundN(s.end[1])]);
|
|
231
|
-
} else if (s.type === 'Q') {
|
|
232
|
-
out.push([VERB.QUAD, roundN(s.ctrl[0]), roundN(s.ctrl[1]), roundN(s.end[0]), roundN(s.end[1])]);
|
|
233
|
-
} else {
|
|
234
|
-
out.push([VERB.CUBIC, roundN(s.c1[0]), roundN(s.c1[1]), roundN(s.c2[0]), roundN(s.c2[1]), roundN(s.end[0]), roundN(s.end[1])]);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
out.push([VERB.CLOSE]);
|
|
238
|
-
return out;
|
|
239
|
-
}
|
|
240
|
-
function reverseClosedContourKeepStart(contourCmds, explicitCloseWanted, VERB) {
|
|
241
|
-
const {
|
|
242
|
-
start,
|
|
243
|
-
segs
|
|
244
|
-
} = contourToSegments(contourCmds, VERB);
|
|
245
|
-
const reversed = segs.slice().reverse().map(s => {
|
|
246
|
-
if (s.type === 'L') {
|
|
247
|
-
return {
|
|
248
|
-
type: 'L',
|
|
249
|
-
start: s.end,
|
|
250
|
-
end: s.start,
|
|
251
|
-
synthetic: false
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
if (s.type === 'Q') {
|
|
255
|
-
return {
|
|
256
|
-
type: 'Q',
|
|
257
|
-
start: s.end,
|
|
258
|
-
ctrl: s.ctrl,
|
|
259
|
-
end: s.start,
|
|
260
|
-
synthetic: false
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
type: 'C',
|
|
265
|
-
start: s.end,
|
|
266
|
-
c1: s.c2,
|
|
267
|
-
c2: s.c1,
|
|
268
|
-
end: s.start,
|
|
269
|
-
synthetic: false
|
|
270
|
-
};
|
|
271
|
-
});
|
|
272
|
-
applyClosePolicy(reversed, start, explicitCloseWanted);
|
|
273
|
-
return segmentsToContourCmds(start, reversed, VERB);
|
|
274
|
-
}
|
|
275
|
-
function rotateClosedContourToStart(contourCmds, desiredStart, explicitCloseWanted, VERB) {
|
|
276
|
-
const {
|
|
277
|
-
segs
|
|
278
|
-
} = contourToSegments(contourCmds, VERB);
|
|
279
|
-
let idx = -1;
|
|
280
|
-
for (let i = 0; i < segs.length; i++) {
|
|
281
|
-
if (eqPt(segs[i].start, desiredStart)) {
|
|
282
|
-
idx = i;
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (idx === -1) {
|
|
287
|
-
for (let i = 0; i < segs.length; i++) {
|
|
288
|
-
if (eqPt(segs[i].end, desiredStart)) {
|
|
289
|
-
idx = (i + 1) % segs.length;
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (idx === -1) return [...contourCmds];
|
|
295
|
-
const rotated = segs.slice(idx).concat(segs.slice(0, idx));
|
|
296
|
-
applyClosePolicy(rotated, desiredStart, explicitCloseWanted);
|
|
297
|
-
return segmentsToContourCmds(desiredStart, rotated, VERB);
|
|
298
|
-
}
|
|
299
|
-
function cmdsToVerbPoints(cmds, VERB) {
|
|
300
|
-
const out = [];
|
|
301
|
-
for (const cmd of cmds) {
|
|
302
|
-
const v = cmd[0];
|
|
303
|
-
if (v === VERB.MOVE) out.push([0, [[cmd[1], cmd[2]]]]);else if (v === VERB.LINE) out.push([1, [[cmd[1], cmd[2]]]]);else if (v === VERB.QUAD) out.push([2, [[cmd[1], cmd[2]], [cmd[3], cmd[4]]]]);else if (v === VERB.CUBIC) out.push([3, [[cmd[1], cmd[2]], [cmd[3], cmd[4]], [cmd[5], cmd[6]]]]);else if (v === VERB.CLOSE) out.push([4, []]);else throw new Error(`Unexpected verb in cmds: ${v}`);
|
|
304
|
-
}
|
|
305
|
-
return out;
|
|
306
|
-
}
|
|
307
|
-
function wrapPath(pathkitPath) {
|
|
308
|
-
return {
|
|
309
|
-
p: pathkitPath,
|
|
310
|
-
meta: {
|
|
311
|
-
moves: []
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
function cloneWrap(h, PathKit) {
|
|
316
|
-
const p2 = PathKit.NewPath(h.p);
|
|
317
|
-
const out = wrapPath(p2);
|
|
318
|
-
out.meta.moves = h.meta?.moves ? h.meta.moves.map(m => [m[0], m[1]]) : [];
|
|
319
|
-
return out;
|
|
320
|
-
}
|
|
321
|
-
function mergeMoves(aMoves, bMoves) {
|
|
322
|
-
const out = [];
|
|
323
|
-
const pushUnique = pt => {
|
|
324
|
-
for (const existing of out) {
|
|
325
|
-
if (eqPt(existing, pt)) return;
|
|
326
|
-
}
|
|
327
|
-
out.push(pt);
|
|
328
|
-
};
|
|
329
|
-
for (const m of aMoves || []) pushUnique(normPt(m));
|
|
330
|
-
for (const m of bMoves || []) pushUnique(normPt(m));
|
|
331
|
-
return out;
|
|
332
|
-
}
|
|
333
|
-
function bestStartMinYMinX(contourCmds, VERB) {
|
|
334
|
-
let best = null;
|
|
335
|
-
for (const cmd of contourCmds) {
|
|
336
|
-
const v = cmd[0];
|
|
337
|
-
const add = (x, y) => {
|
|
338
|
-
const p = [x, y];
|
|
339
|
-
if (!best) {
|
|
340
|
-
best = p;
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (p[1] < best[1] - 1e-9) best = p;else if (Math.abs(p[1] - best[1]) < 1e-9 && p[0] < best[0] - 1e-9) best = p;
|
|
344
|
-
};
|
|
345
|
-
if (v === VERB.MOVE) add(cmd[1], cmd[2]);else if (v === VERB.LINE) add(cmd[1], cmd[2]);else if (v === VERB.QUAD) add(cmd[3], cmd[4]);else if (v === VERB.CUBIC) add(cmd[5], cmd[6]);
|
|
346
|
-
}
|
|
347
|
-
return best;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// ---------------------------------------------------------------------------
|
|
351
|
-
// Containment helpers (module-level for reuse by fixPathWinding)
|
|
352
|
-
// ---------------------------------------------------------------------------
|
|
353
|
-
|
|
354
|
-
function buildVerbMap(PathKit) {
|
|
355
|
-
return {
|
|
356
|
-
MOVE: PathKit.MOVE_VERB ?? 0,
|
|
357
|
-
LINE: PathKit.LINE_VERB ?? 1,
|
|
358
|
-
QUAD: PathKit.QUAD_VERB ?? 2,
|
|
359
|
-
CONIC: PathKit.CONIC_VERB ?? 3,
|
|
360
|
-
CUBIC: PathKit.CUBIC_VERB ?? 4,
|
|
361
|
-
CLOSE: PathKit.CLOSE_VERB ?? 5
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Convert contour commands to a polyline by sampling curves.
|
|
367
|
-
* Used for ray-casting containment tests.
|
|
368
|
-
*/
|
|
369
|
-
function contourToPolyline(contourCmds, V, steps = 8) {
|
|
370
|
-
let cx = 0,
|
|
371
|
-
cy = 0;
|
|
372
|
-
let sx = 0,
|
|
373
|
-
sy = 0;
|
|
374
|
-
const pts = [];
|
|
375
|
-
for (const cmd of contourCmds) {
|
|
376
|
-
const v = cmd[0];
|
|
377
|
-
if (v === V.MOVE) {
|
|
378
|
-
cx = cmd[1];
|
|
379
|
-
cy = cmd[2];
|
|
380
|
-
sx = cx;
|
|
381
|
-
sy = cy;
|
|
382
|
-
pts.push([cx, cy]);
|
|
383
|
-
} else if (v === V.LINE) {
|
|
384
|
-
cx = cmd[1];
|
|
385
|
-
cy = cmd[2];
|
|
386
|
-
pts.push([cx, cy]);
|
|
387
|
-
} else if (v === V.QUAD) {
|
|
388
|
-
const x0 = cx,
|
|
389
|
-
y0 = cy;
|
|
390
|
-
const x1 = cmd[1],
|
|
391
|
-
y1 = cmd[2];
|
|
392
|
-
const x2 = cmd[3],
|
|
393
|
-
y2 = cmd[4];
|
|
394
|
-
for (let i = 1; i <= steps; i++) {
|
|
395
|
-
const t = i / steps;
|
|
396
|
-
const mt = 1 - t;
|
|
397
|
-
pts.push([mt * mt * x0 + 2 * mt * t * x1 + t * t * x2, mt * mt * y0 + 2 * mt * t * y1 + t * t * y2]);
|
|
398
|
-
}
|
|
399
|
-
cx = x2;
|
|
400
|
-
cy = y2;
|
|
401
|
-
} else if (v === V.CUBIC) {
|
|
402
|
-
const x0 = cx,
|
|
403
|
-
y0 = cy;
|
|
404
|
-
const x1 = cmd[1],
|
|
405
|
-
y1 = cmd[2];
|
|
406
|
-
const x2 = cmd[3],
|
|
407
|
-
y2 = cmd[4];
|
|
408
|
-
const x3 = cmd[5],
|
|
409
|
-
y3 = cmd[6];
|
|
410
|
-
for (let i = 1; i <= steps; i++) {
|
|
411
|
-
const t = i / steps;
|
|
412
|
-
const mt = 1 - t;
|
|
413
|
-
pts.push([mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3, mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3]);
|
|
414
|
-
}
|
|
415
|
-
cx = x3;
|
|
416
|
-
cy = y3;
|
|
417
|
-
} else if (v === V.CLOSE) {
|
|
418
|
-
if (cx !== sx || cy !== sy) pts.push([sx, sy]);
|
|
419
|
-
cx = sx;
|
|
420
|
-
cy = sy;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return pts;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Ray-casting point-in-polygon test.
|
|
428
|
-
*/
|
|
429
|
-
function pointInPolygon(px, py, poly) {
|
|
430
|
-
let inside = false;
|
|
431
|
-
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
432
|
-
const [xi, yi] = poly[i];
|
|
433
|
-
const [xj, yj] = poly[j];
|
|
434
|
-
if (yi > py !== yj > py && px < (xj - xi) * (py - yi) / (yj - yi) + xi) {
|
|
435
|
-
inside = !inside;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return inside;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Get a representative point on the contour boundary (midpoint of first segment).
|
|
443
|
-
*/
|
|
444
|
-
function getContourSamplePoint(contourCmds, V) {
|
|
445
|
-
let cx = 0,
|
|
446
|
-
cy = 0;
|
|
447
|
-
for (const cmd of contourCmds) {
|
|
448
|
-
const v = cmd[0];
|
|
449
|
-
if (v === V.MOVE) {
|
|
450
|
-
cx = cmd[1];
|
|
451
|
-
cy = cmd[2];
|
|
452
|
-
} else if (v === V.LINE) {
|
|
453
|
-
return [(cx + cmd[1]) / 2, (cy + cmd[2]) / 2];
|
|
454
|
-
} else if (v === V.QUAD) {
|
|
455
|
-
const t = 0.5,
|
|
456
|
-
mt = 0.5;
|
|
457
|
-
return [mt * mt * cx + 2 * mt * t * cmd[1] + t * t * cmd[3], mt * mt * cy + 2 * mt * t * cmd[2] + t * t * cmd[4]];
|
|
458
|
-
} else if (v === V.CUBIC) {
|
|
459
|
-
const t = 0.5,
|
|
460
|
-
mt = 0.5;
|
|
461
|
-
return [mt ** 3 * cx + 3 * mt ** 2 * t * cmd[1] + 3 * mt * t ** 2 * cmd[3] + t ** 3 * cmd[5], mt ** 3 * cy + 3 * mt ** 2 * t * cmd[2] + 3 * mt * t ** 2 * cmd[4] + t ** 3 * cmd[6]];
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return null;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Apply containment-based winding fix to contour objects.
|
|
469
|
-
* Even nesting depth = CCW (outer), odd = CW (hole).
|
|
470
|
-
*/
|
|
471
|
-
function applyContainmentWinding(contourObjs, V) {
|
|
472
|
-
const n = contourObjs.length;
|
|
473
|
-
if (n === 0) return;
|
|
474
|
-
const polylines = contourObjs.map(obj => contourToPolyline(obj.cmds, V));
|
|
475
|
-
const samplePts = contourObjs.map(obj => getContourSamplePoint(obj.cmds, V));
|
|
476
|
-
const depths = new Array(n).fill(0);
|
|
477
|
-
for (let i = 0; i < n; i++) {
|
|
478
|
-
const pt = samplePts[i];
|
|
479
|
-
if (!pt) continue;
|
|
480
|
-
for (let j = 0; j < n; j++) {
|
|
481
|
-
if (i === j) continue;
|
|
482
|
-
if (pointInPolygon(pt[0], pt[1], polylines[j])) {
|
|
483
|
-
depths[i] = (depths[i] ?? 0) + 1;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
const ensureOrient = (obj, wantCCW) => {
|
|
488
|
-
const a = approxSignedAreaFromContourCmds(obj.cmds, V);
|
|
489
|
-
const isCCW = a > 0;
|
|
490
|
-
if (wantCCW !== isCCW) {
|
|
491
|
-
obj.cmds = reverseClosedContourKeepStart(obj.cmds, obj.explicitCloseWanted, V);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
for (let i = 0; i < n; i++) {
|
|
495
|
-
ensureOrient(contourObjs[i], depths[i] % 2 === 0);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Convert a path `d` string with evenodd fill semantics to an equivalent
|
|
501
|
-
* path that renders identically under nonzero winding.
|
|
502
|
-
*
|
|
503
|
-
* Steps:
|
|
504
|
-
* 1. Parse via PathKit, set fill type to EVENODD, simplify (resolve topology)
|
|
505
|
-
* 2. Split into contours, compute containment depths
|
|
506
|
-
* 3. Fix winding: even depth = CCW (outer), odd depth = CW (hole)
|
|
507
|
-
* 4. Reconstruct d string
|
|
508
|
-
*/
|
|
509
|
-
export function convertEvenoddToWinding(PathKit, d) {
|
|
510
|
-
const V = buildVerbMap(PathKit);
|
|
511
|
-
|
|
512
|
-
// 1. Parse and simplify with EVENODD fill type
|
|
513
|
-
const p = PathKit.FromSVGString(d);
|
|
514
|
-
if (!p) return d;
|
|
515
|
-
const FILL_EVENODD = PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
|
|
516
|
-
p.setFillType(FILL_EVENODD);
|
|
517
|
-
p.simplify();
|
|
518
|
-
|
|
519
|
-
// Get the simplified SVG string and re-parse for command access
|
|
520
|
-
const simplified = p.toSVGString();
|
|
521
|
-
p.delete?.();
|
|
522
|
-
const p2 = PathKit.FromSVGString(simplified);
|
|
523
|
-
if (!p2) return simplified;
|
|
524
|
-
const cmds = p2.toCmds();
|
|
525
|
-
p2.delete?.();
|
|
526
|
-
if (cmds.length === 0) return simplified;
|
|
527
|
-
|
|
528
|
-
// 2. Split into contours
|
|
529
|
-
const contourObjs = splitContours(cmds, V).map(c => {
|
|
530
|
-
const explicitCloseWanted = explicitCloseWantedFromCmds(c, V);
|
|
531
|
-
const cc = ensureClosed(c, V);
|
|
532
|
-
const a = approxSignedAreaFromContourCmds(cc, V);
|
|
533
|
-
return {
|
|
534
|
-
cmds: cc,
|
|
535
|
-
absA: Math.abs(a),
|
|
536
|
-
explicitCloseWanted
|
|
537
|
-
};
|
|
538
|
-
});
|
|
539
|
-
contourObjs.sort((x, y) => y.absA - x.absA);
|
|
540
|
-
|
|
541
|
-
// 3. Fix winding via containment analysis
|
|
542
|
-
applyContainmentWinding(contourObjs, V);
|
|
543
|
-
|
|
544
|
-
// 4. Reconstruct d string from fixed commands
|
|
545
|
-
const allCmds = contourObjs.flatMap(x => x.cmds);
|
|
546
|
-
const parts = [];
|
|
547
|
-
for (const cmd of allCmds) {
|
|
548
|
-
const v = cmd[0];
|
|
549
|
-
if (v === V.MOVE) parts.push(`M${roundN(cmd[1])} ${roundN(cmd[2])}`);else if (v === V.LINE) parts.push(`L${roundN(cmd[1])} ${roundN(cmd[2])}`);else if (v === V.QUAD) parts.push(`Q${roundN(cmd[1])} ${roundN(cmd[2])} ${roundN(cmd[3])} ${roundN(cmd[4])}`);else if (v === V.CUBIC) parts.push(`C${roundN(cmd[1])} ${roundN(cmd[2])} ${roundN(cmd[3])} ${roundN(cmd[4])} ${roundN(cmd[5])} ${roundN(cmd[6])}`);else if (v === V.CLOSE) parts.push('Z');
|
|
550
|
-
}
|
|
551
|
-
return parts.join(' ');
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// proxy to for picosvg to interatc with pathkit
|
|
555
|
-
export function buildPathopsBackend(PathKit) {
|
|
556
|
-
const VERB = buildVerbMap(PathKit);
|
|
557
|
-
const FILL_EVENODD = PathKit?.FillType?.EVENODD ?? PathKit?.FillType?.EVEN_ODD ?? 1;
|
|
558
|
-
const FILL_WINDING = PathKit?.FillType?.WINDING ?? PathKit?.FillType?.NONZERO ?? 0;
|
|
559
|
-
function cmdsViaSvgRoundtrip(h) {
|
|
560
|
-
const svg = h.p.toSVGString();
|
|
561
|
-
const p2 = PathKit.FromSVGString(svg);
|
|
562
|
-
const cmds = p2 ? p2.toCmds() : [];
|
|
563
|
-
if (p2) p2.delete?.();
|
|
564
|
-
return cmds;
|
|
565
|
-
}
|
|
566
|
-
function normalizeSortRotateContours(cmds, h, preferStrokeCanonical = false) {
|
|
567
|
-
const moves = (h.meta?.moves || []).map(m => normPt([m[0], m[1]]));
|
|
568
|
-
const used = new Array(moves.length).fill(false);
|
|
569
|
-
|
|
570
|
-
// Build contour objects, but DO NOT normalize orientation yet.
|
|
571
|
-
const contourObjs = splitContours(cmds, VERB).map(c => {
|
|
572
|
-
const explicitCloseWanted = explicitCloseWantedFromCmds(c, VERB);
|
|
573
|
-
const cc = ensureClosed(c, VERB);
|
|
574
|
-
const a = approxSignedAreaFromContourCmds(cc, VERB); // signed
|
|
575
|
-
return {
|
|
576
|
-
cmds: cc,
|
|
577
|
-
absA: Math.abs(a),
|
|
578
|
-
explicitCloseWanted
|
|
579
|
-
};
|
|
580
|
-
});
|
|
581
|
-
|
|
582
|
-
// Big-to-small ordering gives deterministic outer→inner ordering.
|
|
583
|
-
contourObjs.sort((x, y) => y.absA - x.absA);
|
|
584
|
-
|
|
585
|
-
// Containment-based winding: compute nesting depth per contour via
|
|
586
|
-
// ray-casting point-in-polygon. Even depth = outer (CCW), odd = hole (CW).
|
|
587
|
-
applyContainmentWinding(contourObjs, VERB);
|
|
588
|
-
|
|
589
|
-
// Rotate starts deterministically:
|
|
590
|
-
// 1) If we have recorded MOVE points, try to rotate contour to a move point that lies on it.
|
|
591
|
-
// 2) Otherwise, rotate to minY/minX point (helps stroke-ish paths)
|
|
592
|
-
for (const obj of contourObjs) {
|
|
593
|
-
let cc = obj.cmds;
|
|
594
|
-
for (let i = 0; i < moves.length; i++) {
|
|
595
|
-
if (used[i]) continue;
|
|
596
|
-
const target = moves[i];
|
|
597
|
-
const {
|
|
598
|
-
segs
|
|
599
|
-
} = contourToSegments(cc, VERB);
|
|
600
|
-
const found = segs.some(s => eqPt(s.start, target) || eqPt(s.end, target));
|
|
601
|
-
if (found) {
|
|
602
|
-
used[i] = true;
|
|
603
|
-
cc = rotateClosedContourToStart(cc, target, obj.explicitCloseWanted, VERB);
|
|
604
|
-
break;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// If no move point was used, apply the deterministic start heuristic
|
|
609
|
-
if (preferStrokeCanonical) {
|
|
610
|
-
const best = bestStartMinYMinX(cc, VERB);
|
|
611
|
-
if (best) {
|
|
612
|
-
cc = rotateClosedContourToStart(cc, best, obj.explicitCloseWanted, VERB);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
obj.cmds = cc;
|
|
616
|
-
}
|
|
617
|
-
return contourObjs.flatMap(x => x.cmds);
|
|
618
|
-
}
|
|
619
|
-
return {
|
|
620
|
-
create_path(fillTypeInt) {
|
|
621
|
-
const p = PathKit.NewPath();
|
|
622
|
-
p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
|
|
623
|
-
return wrapPath(p);
|
|
624
|
-
},
|
|
625
|
-
clone_path(h) {
|
|
626
|
-
return cloneWrap(h, PathKit);
|
|
627
|
-
},
|
|
628
|
-
delete_path(h) {
|
|
629
|
-
h?.p?.delete?.();
|
|
630
|
-
},
|
|
631
|
-
get_fill_type(h) {
|
|
632
|
-
const ft = h.p.getFillType?.();
|
|
633
|
-
return ft === FILL_EVENODD ? 1 : 0;
|
|
634
|
-
},
|
|
635
|
-
set_fill_type(h, fillTypeInt) {
|
|
636
|
-
h.p.setFillType(fillTypeInt === 1 ? FILL_EVENODD : FILL_WINDING);
|
|
637
|
-
return true;
|
|
638
|
-
},
|
|
639
|
-
move_to(h, x, y) {
|
|
640
|
-
h.p.moveTo(x, y);
|
|
641
|
-
h.meta.moves.push(normPt([x, y]));
|
|
642
|
-
},
|
|
643
|
-
line_to(h, x, y) {
|
|
644
|
-
h.p.lineTo(x, y);
|
|
645
|
-
},
|
|
646
|
-
quad_to(h, x1, y1, x2, y2) {
|
|
647
|
-
h.p.quadTo(x1, y1, x2, y2);
|
|
648
|
-
},
|
|
649
|
-
cubic_to(h, x1, y1, x2, y2, x3, y3) {
|
|
650
|
-
h.p.cubicTo(x1, y1, x2, y2, x3, y3);
|
|
651
|
-
},
|
|
652
|
-
close(h) {
|
|
653
|
-
h.p.close();
|
|
654
|
-
},
|
|
655
|
-
simplify(h, fixWinding = false) {
|
|
656
|
-
try {
|
|
657
|
-
// 1) simplify in place
|
|
658
|
-
h.p.simplify();
|
|
659
|
-
|
|
660
|
-
// 2) normalize representation via SVG roundtrip
|
|
661
|
-
const svg = h.p.toSVGString();
|
|
662
|
-
const p2 = PathKit.FromSVGString(svg);
|
|
663
|
-
if (p2) {
|
|
664
|
-
// replace underlying path handle
|
|
665
|
-
h.p.delete?.();
|
|
666
|
-
h.p = p2;
|
|
667
|
-
}
|
|
668
|
-
if (fixWinding) h.p.setFillType(FILL_WINDING);
|
|
669
|
-
return true;
|
|
670
|
-
} catch {
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
|
-
},
|
|
674
|
-
stroke(h, width, capInt, joinInt, miterLimit, dashArray, dashOffset) {
|
|
675
|
-
const Caps = PathKit.StrokeCap ?? {};
|
|
676
|
-
const Joins = PathKit.StrokeJoin ?? {};
|
|
677
|
-
const cap = capInt === 1 ? Caps.ROUND ?? 1 : capInt === 2 ? Caps.SQUARE ?? 2 : Caps.BUTT ?? 0;
|
|
678
|
-
const join = joinInt === 1 ? Joins.ROUND ?? 1 : joinInt === 2 ? Joins.BEVEL ?? 2 : Joins.MITER ?? 0;
|
|
679
|
-
const work = PathKit.NewPath(h.p);
|
|
680
|
-
try {
|
|
681
|
-
if (Array.isArray(dashArray) && dashArray.length === 2 && typeof work.dash === 'function') {
|
|
682
|
-
work.dash(Number(dashArray[0]), Number(dashArray[1]), dashOffset || 0);
|
|
683
|
-
}
|
|
684
|
-
let stroked = work.stroke({
|
|
685
|
-
width,
|
|
686
|
-
cap,
|
|
687
|
-
join,
|
|
688
|
-
miter_limit: miterLimit
|
|
689
|
-
});
|
|
690
|
-
if (!stroked || typeof stroked.toCmds !== 'function') stroked = work;
|
|
691
|
-
if (stroked !== work) work.delete?.();
|
|
692
|
-
const wrapped = wrapPath(stroked);
|
|
693
|
-
wrapped.meta.moves = [];
|
|
694
|
-
return wrapped;
|
|
695
|
-
} catch {
|
|
696
|
-
const wrapped = wrapPath(work);
|
|
697
|
-
wrapped.meta.moves = [];
|
|
698
|
-
return wrapped;
|
|
699
|
-
}
|
|
700
|
-
},
|
|
701
|
-
convert_conics_to_quads(_h, _tol) {
|
|
702
|
-
// intentionally no-op
|
|
703
|
-
},
|
|
704
|
-
transform(h, a, b, c, d, e, f) {
|
|
705
|
-
const p = PathKit.NewPath(h.p);
|
|
706
|
-
p.transform(a, c, e, b, d, f, 0, 0, 1);
|
|
707
|
-
const wrapped = wrapPath(p);
|
|
708
|
-
wrapped.meta.moves = (h.meta?.moves || []).map(([x, y]) => normPt([a * x + c * y + e, b * x + d * y + f]));
|
|
709
|
-
return wrapped;
|
|
710
|
-
},
|
|
711
|
-
op(aHandle, bHandle, opInt) {
|
|
712
|
-
try {
|
|
713
|
-
const Ops = PathKit.PathOp ?? {};
|
|
714
|
-
const op = opInt === 1 ? Ops.INTERSECT ?? 1 : opInt === 2 ? Ops.DIFFERENCE ?? 2 : Ops.UNION ?? 0;
|
|
715
|
-
const out = PathKit.MakeFromOp(aHandle.p, bHandle.p, op);
|
|
716
|
-
if (!out) return null;
|
|
717
|
-
const wrapped = wrapPath(out);
|
|
718
|
-
wrapped.meta.moves = mergeMoves(aHandle.meta?.moves, bHandle.meta?.moves);
|
|
719
|
-
return wrapped;
|
|
720
|
-
} catch {
|
|
721
|
-
return null;
|
|
722
|
-
}
|
|
723
|
-
},
|
|
724
|
-
bounds(h) {
|
|
725
|
-
const r = h.p.getBounds();
|
|
726
|
-
return [r.fLeft, r.fTop, r.fRight, r.fBottom];
|
|
727
|
-
},
|
|
728
|
-
area(h) {
|
|
729
|
-
try {
|
|
730
|
-
const cmds = cmdsViaSvgRoundtrip(h);
|
|
731
|
-
const contours = splitContours(cmds, VERB);
|
|
732
|
-
let total = 0;
|
|
733
|
-
for (const c of contours) {
|
|
734
|
-
const cc = ensureClosed(c, VERB);
|
|
735
|
-
total += Math.abs(approxSignedAreaFromContourCmds(cc, VERB));
|
|
736
|
-
}
|
|
737
|
-
return total;
|
|
738
|
-
} catch {
|
|
739
|
-
return 0.0;
|
|
740
|
-
}
|
|
741
|
-
},
|
|
742
|
-
iter_segments(h) {
|
|
743
|
-
const cmds = cmdsViaSvgRoundtrip(h);
|
|
744
|
-
const preferStrokeCanonical = (h.meta?.moves?.length || 0) === 0;
|
|
745
|
-
const normalized = normalizeSortRotateContours(cmds, h, preferStrokeCanonical);
|
|
746
|
-
return cmdsToVerbPoints(normalized, VERB);
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
//# sourceMappingURL=svg_pathops.js.map
|