@pixerate/editor 0.35.0 → 0.37.0
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/THIRD_PARTY_NOTICES.md +17 -0
- package/dist/canvas/index.cjs +25 -25
- package/dist/canvas/index.d.cts +3 -217
- package/dist/canvas/index.d.ts +3 -217
- package/dist/canvas/index.js +1 -1
- package/dist/{chunk-BGNPT5PE.cjs → chunk-GVB7ZPLZ.cjs} +24 -3
- package/dist/chunk-GVB7ZPLZ.cjs.map +1 -0
- package/dist/{chunk-EGPIVUEF.js → chunk-HPEKB352.js} +23 -2
- package/dist/chunk-HPEKB352.js.map +1 -0
- package/dist/{bezier-D8bsO-L0.d.cts → stroke-CWjFKal4.d.cts} +215 -1
- package/dist/{bezier-BvqVmWMg.d.ts → stroke-ysgaPpAo.d.ts} +215 -1
- package/dist/vector/index.cjs +2262 -388
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.cts +704 -25
- package/dist/vector/index.d.ts +704 -25
- package/dist/vector/index.js +2107 -233
- package/dist/vector/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BGNPT5PE.cjs.map +0 -1
- package/dist/chunk-EGPIVUEF.js.map +0 -1
|
@@ -544,4 +544,218 @@ declare function pointInBezierPath(input: BezierPathInput, point: Point, fillRul
|
|
|
544
544
|
/** Distance from `point` to the path outline (closing lines of closed subpaths included). */
|
|
545
545
|
declare function distanceToBezierPath(input: BezierPathInput | readonly BezierContour[], point: Point): number;
|
|
546
546
|
|
|
547
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Curve-preserving boolean operations (union, intersection, difference, xor and divide) on
|
|
549
|
+
* Bézier paths.
|
|
550
|
+
*
|
|
551
|
+
* Algorithm (planar arrangement of curve pieces + winding classification):
|
|
552
|
+
* 1. Every segment of every operand (open subpaths closed for filling) is a *source*; it is
|
|
553
|
+
* cut into pieces monotone in x and y. Each piece remembers its source and its parameter
|
|
554
|
+
* range there, so results can be rebuilt from exact sub-curves of the inputs.
|
|
555
|
+
* 2. Pieces are intersected pairwise (pruned by a sweep on x): lines analytically, curves by
|
|
556
|
+
* recursive subdivision down to flat sub-curves, chord intersection and Newton polishing.
|
|
557
|
+
* Endpoints lying on another piece (T-junctions, tangent touches), collinear / coincident
|
|
558
|
+
* overlaps and clusters of hits along a tangency are resolved first. Points closer than
|
|
559
|
+
* `epsilon` share one vertex. Splitting repeats until no piece crosses another.
|
|
560
|
+
* 3. Coincident pieces (shared edges, identical curves) merge into one edge carrying every
|
|
561
|
+
* operand's signed multiplicity.
|
|
562
|
+
* 4. Each edge is classified by casting a horizontal or vertical ray from its midpoint (the
|
|
563
|
+
* pieces are monotone, so a ray crosses each at most once); the operands' fill rules turn
|
|
564
|
+
* the winding numbers on both sides into inside flags and the operation picks the edges
|
|
565
|
+
* with the result on exactly one side.
|
|
566
|
+
* 5. The kept edges are traced into rings, taking the sharpest left turn at each vertex
|
|
567
|
+
* (ties between tangent curves broken by a short chord along each curve), and consecutive
|
|
568
|
+
* pieces of one source are merged back into one exact sub-curve, so circles stay four
|
|
569
|
+
* cubics and rectangles four lines.
|
|
570
|
+
*
|
|
571
|
+
* When the curve engine fails (non-converging intersections on near-coincident curves,
|
|
572
|
+
* an inconsistent arrangement) the operation falls back to the polygon engine
|
|
573
|
+
* (`polygonBoolean`) on flattened input and reports it (`engine: 'polygon'`).
|
|
574
|
+
*
|
|
575
|
+
* Portions ported from vectorcraft-main/crates/pathops/src/boolean.rs (MIT OR Apache-2.0,
|
|
576
|
+
* © ArtCraft Team and contributors). See THIRD_PARTY_NOTICES.md.
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/** Boolean operations (same names as `polygonBoolean`). `xor` is Exclude. */
|
|
580
|
+
type PathBooleanOperation = PolygonBooleanOperation;
|
|
581
|
+
/** A path with the fill rule it is read with (default `nonzero`). */
|
|
582
|
+
interface PathOperand {
|
|
583
|
+
path: BezierPathInput;
|
|
584
|
+
fillRule?: PolygonFillRule;
|
|
585
|
+
}
|
|
586
|
+
type PathOperandInput = BezierPathInput | PathOperand;
|
|
587
|
+
interface PathOpsOptions {
|
|
588
|
+
/**
|
|
589
|
+
* Distance below which points are treated as equal. Defaults to `1e-9` times the
|
|
590
|
+
* largest coordinate magnitude (at least `1e-9`).
|
|
591
|
+
*/
|
|
592
|
+
epsilon?: number;
|
|
593
|
+
/** Fall back to the polygon engine when the curve engine fails (default `true`). */
|
|
594
|
+
fallback?: boolean;
|
|
595
|
+
/** Flattening tolerance used by the polygon fallback (default 0.05). */
|
|
596
|
+
fallbackTolerance?: number;
|
|
597
|
+
/** Called with the reason whenever the polygon fallback is used. */
|
|
598
|
+
onFallback?: (reason: string) => void;
|
|
599
|
+
/**
|
|
600
|
+
* Work budget of the curve–curve intersection search (flat sub-curve pairs per pair of
|
|
601
|
+
* pieces, default 20,000). Exceeding it (nearly coincident curves) falls back.
|
|
602
|
+
*/
|
|
603
|
+
subdivisionBudget?: number;
|
|
604
|
+
}
|
|
605
|
+
/** Which engine produced a result, and why the curve engine was not used. */
|
|
606
|
+
interface PathOpsReport {
|
|
607
|
+
engine: 'curve' | 'polygon';
|
|
608
|
+
fallbackReason?: string;
|
|
609
|
+
/** Set when the input cannot be processed at all (non-finite coordinates); the result is empty. */
|
|
610
|
+
error?: string;
|
|
611
|
+
}
|
|
612
|
+
interface PathBooleanResult extends PathOpsReport {
|
|
613
|
+
path: BezierPath;
|
|
614
|
+
}
|
|
615
|
+
/** One region of `dividePaths`, with the indices of the operands that cover it. */
|
|
616
|
+
interface PathPiece {
|
|
617
|
+
path: BezierPath;
|
|
618
|
+
operands: number[];
|
|
619
|
+
}
|
|
620
|
+
interface DividePathsResult extends PathOpsReport {
|
|
621
|
+
pieces: PathPiece[];
|
|
622
|
+
}
|
|
623
|
+
/** Raised by the curve engine when it cannot produce a reliable arrangement. */
|
|
624
|
+
declare class PathOpsError extends Error {
|
|
625
|
+
constructor(message: string);
|
|
626
|
+
}
|
|
627
|
+
/** A crossing or touch of two segments: the parameter on each and the point. */
|
|
628
|
+
interface SegmentIntersection {
|
|
629
|
+
ta: number;
|
|
630
|
+
tb: number;
|
|
631
|
+
point: Point;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Every point where two segments (lines, quadratics or cubics, as control points) cross or
|
|
635
|
+
* touch, by the same subdivision search the boolean operations use: flat sub-curves, chord
|
|
636
|
+
* intersection, Newton polishing. Hits closer than `epsilon` (default: 1e-9 of the segments'
|
|
637
|
+
* size) are one. Coincident stretches report the hits the search finds along them.
|
|
638
|
+
*/
|
|
639
|
+
declare function segmentIntersections(a: BezierSegment, b: BezierSegment, options?: {
|
|
640
|
+
epsilon?: number;
|
|
641
|
+
budget?: number;
|
|
642
|
+
}): SegmentIntersection[];
|
|
643
|
+
/**
|
|
644
|
+
* Applies a boolean operation to any number of path operands, keeping curves:
|
|
645
|
+
* - `union`: covered by any operand.
|
|
646
|
+
* - `intersection`: covered by every operand.
|
|
647
|
+
* - `difference`: the first operand minus all others.
|
|
648
|
+
* - `xor`: covered by an odd number of operands (Exclude).
|
|
649
|
+
*
|
|
650
|
+
* Open subpaths are closed for filling. Non-finite input gives an empty path (`error`); with
|
|
651
|
+
* `fallback: false` a failure of the curve engine throws a `PathOpsError`. The result is a set of simple closed subpaths that
|
|
652
|
+
* never cross (they may touch at points): outer subpaths run counter-clockwise in a y-up
|
|
653
|
+
* frame (clockwise on screen), holes the other way, so it fills the same with `nonzero`
|
|
654
|
+
* and `evenodd`. Segments of the inputs are kept as exact sub-curves.
|
|
655
|
+
*/
|
|
656
|
+
declare function pathBoolean(operation: PathBooleanOperation, operands: PathOperandInput[], options?: PathOpsOptions): PathBooleanResult;
|
|
657
|
+
declare const unitePaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
658
|
+
declare const intersectPaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
659
|
+
declare const subtractPaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
660
|
+
declare const excludePaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
661
|
+
/**
|
|
662
|
+
* Splits the arrangement of the operands into its regions (Divide): every connected area
|
|
663
|
+
* covered by the same set of operands becomes one piece (an outer subpath with its holes).
|
|
664
|
+
* Pieces are ordered by operand set, then by area (largest first).
|
|
665
|
+
*/
|
|
666
|
+
declare function dividePaths(operands: PathOperandInput[], options?: PathOpsOptions): DividePathsResult;
|
|
667
|
+
/**
|
|
668
|
+
* Resolves self-intersections and overlaps of one filled path into simple, consistently
|
|
669
|
+
* oriented subpaths (outer subpaths and holes) under its fill rule.
|
|
670
|
+
*/
|
|
671
|
+
declare function normalizeBezierPath(path: BezierPathInput, fillRule?: PolygonFillRule, options?: PathOpsOptions): BezierPath;
|
|
672
|
+
/** Filled area of a path under its fill rule (overlaps counted once; exact for curves). */
|
|
673
|
+
declare function bezierPathArea(path: BezierPathInput, fillRule?: PolygonFillRule, options?: PathOpsOptions): number;
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Offset Path and Outline Stroke on Bézier paths.
|
|
677
|
+
*
|
|
678
|
+
* The stroker offsets every segment by ± half the width (lines exactly, curves by cubic
|
|
679
|
+
* approximations refined until they stay within `tolerance` of the true offset), joins the
|
|
680
|
+
* pieces (miter with a miter limit, round or bevel on the outer side of a turn; through the
|
|
681
|
+
* vertex on the inner side) and adds caps (butt, round, square) to open subpaths. Dashes
|
|
682
|
+
* follow arc length, restart on every subpath and join across the start of a closed
|
|
683
|
+
* subpath. The raw outline overlaps itself, so it is filled with the non-zero rule and
|
|
684
|
+
* normalised with the curve boolean engine.
|
|
685
|
+
*
|
|
686
|
+
* When the stroke is wider than a curve's radius of curvature the inner offset turns inside
|
|
687
|
+
* out and its loops cancel winding, leaving holes that are really covered. Every face of
|
|
688
|
+
* the true result is bounded by the arrangement, so a face is spurious exactly when a point
|
|
689
|
+
* deep inside it is closer to the path than the offset distance (holes when growing,
|
|
690
|
+
* islands when insetting); such faces are dropped.
|
|
691
|
+
*
|
|
692
|
+
* Portions ported from vectorcraft-main/crates/pathops/src/offset.rs,
|
|
693
|
+
* vectorcraft-main/crates/pathops/src/boolean.rs (`try_merge`) and
|
|
694
|
+
* vectorcraft-main/crates/effects/src/stroke/dash.rs (MIT OR Apache-2.0, © ArtCraft Team
|
|
695
|
+
* and contributors). See THIRD_PARTY_NOTICES.md.
|
|
696
|
+
*/
|
|
697
|
+
|
|
698
|
+
/** Line join (as SVG `stroke-linejoin`). */
|
|
699
|
+
type StrokeJoin = 'miter' | 'round' | 'bevel';
|
|
700
|
+
/** Line cap (as SVG `stroke-linecap`). */
|
|
701
|
+
type StrokeCap = 'butt' | 'round' | 'square';
|
|
702
|
+
interface OutlineStrokeOptions extends PathOpsOptions {
|
|
703
|
+
/** Stroke width. Non-positive or non-finite widths give an empty result. */
|
|
704
|
+
width: number;
|
|
705
|
+
/** Default `miter` (as SVG). */
|
|
706
|
+
join?: StrokeJoin;
|
|
707
|
+
/** Default `butt` (as SVG). */
|
|
708
|
+
cap?: StrokeCap;
|
|
709
|
+
/** Miter length / stroke width above which a miter join is bevelled (default 4, as SVG). */
|
|
710
|
+
miterLimit?: number;
|
|
711
|
+
/** Dash pattern (as SVG `stroke-dasharray`); odd patterns repeat twice. */
|
|
712
|
+
dash?: readonly number[];
|
|
713
|
+
/** Distance into the dash pattern at the start of each subpath (as `stroke-dashoffset`). */
|
|
714
|
+
dashOffset?: number;
|
|
715
|
+
/** Maximum distance between the approximated and the true offset curve (default 0.01). */
|
|
716
|
+
tolerance?: number;
|
|
717
|
+
}
|
|
718
|
+
interface OffsetPathOptions extends PathOpsOptions {
|
|
719
|
+
/** Corner style of the grown / shrunk outline (default `miter`). */
|
|
720
|
+
join?: StrokeJoin;
|
|
721
|
+
/** Miter limit (default 4). */
|
|
722
|
+
miterLimit?: number;
|
|
723
|
+
/** Fill rule of the input (default `nonzero`). */
|
|
724
|
+
fillRule?: PolygonFillRule;
|
|
725
|
+
/** Maximum distance between the approximated and the true offset curve (default 0.01). */
|
|
726
|
+
tolerance?: number;
|
|
727
|
+
}
|
|
728
|
+
interface DashedPath {
|
|
729
|
+
/** The dashes, as open subpaths. */
|
|
730
|
+
contours: BezierContour[];
|
|
731
|
+
/** Zero-length dashes: where they sit and the path direction there. */
|
|
732
|
+
dots: {
|
|
733
|
+
point: Point;
|
|
734
|
+
tangent: Point;
|
|
735
|
+
}[];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Applies a dash pattern (SVG `stroke-dasharray` / `stroke-dashoffset` semantics) to the
|
|
739
|
+
* subpaths. Returns `null` when the pattern is invalid (negative or non-finite entries),
|
|
740
|
+
* has no positive entry, or would make more than 200,000 dashes: the line is solid.
|
|
741
|
+
*/
|
|
742
|
+
declare function dashContours(contours: readonly BezierContour[], pattern: readonly number[], offset?: number): DashedPath | null;
|
|
743
|
+
/**
|
|
744
|
+
* The raw (overlapping) outline of a stroke as closed subpaths to fill with `nonzero`.
|
|
745
|
+
* `outlineStroke` normalises it; this is useful for previews.
|
|
746
|
+
*/
|
|
747
|
+
declare function strokeOutlineRings(input: BezierPathInput, options: OutlineStrokeOptions): BezierPath;
|
|
748
|
+
/**
|
|
749
|
+
* Outline Stroke: the filled area painted by stroking `path`, as one clean path (overlaps
|
|
750
|
+
* removed, consistently oriented). Joins, caps, miter limit and dashes follow SVG.
|
|
751
|
+
*/
|
|
752
|
+
declare function outlineStroke(input: BezierPathInput, options: OutlineStrokeOptions): BezierPath;
|
|
753
|
+
/**
|
|
754
|
+
* Offset Path: grows (`distance > 0`) or shrinks (`distance < 0`) the filled area by
|
|
755
|
+
* `distance`. Closed subpaths are a filled region (read with `fillRule`); open subpaths are
|
|
756
|
+
* outlined with a stroke of width `2·|distance|` and butt caps (when growing). Loops of the
|
|
757
|
+
* offset curves are removed.
|
|
758
|
+
*/
|
|
759
|
+
declare function offsetPath(input: BezierPathInput, distance: number, options?: OffsetPathOptions): BezierPath;
|
|
760
|
+
|
|
761
|
+
export { type SvgGradientStop as $, type AffineMatrix as A, type BezierPathInput as B, type CanvasGradientDef as C, type DashedPath as D, type EllipseShape as E, type FlattenOptions as F, type GetShapeRenderDataOptions as G, type PathShape as H, type PolygonBooleanOperation as I, type PolygonBooleanOptions as J, type PolygonInput as K, type PolygonOperand as L, type MultiPolygon as M, type PolygonPiece as N, type OffsetPathOptions as O, type PolygonFillRule as P, type PolygonToPathOptions as Q, type PolygonWithHoles as R, type SvgGradientDef as S, type RectShape as T, type RegularPolygonShape as U, SHAPE_KINDS as V, type SegmentIntersection as W, type ShapeKind as X, type ShapePaint as Y, type ShapeRenderData as Z, type StarShape as _, type BezierPath as a, unionPolygons as a$, angleToSvgLinearCoords as a0, arcToCubics as a1, bezierPathArea as a2, bezierPathBounds as a3, bezierPathLength as a4, bezierPathPointAtLength as a5, bezierPathSignedArea as a6, bezierPathToSvg as a7, closeContour as a8, contourSignedArea as a9, pointInMultiPolygon as aA, pointInRings as aB, polygonArea as aC, polygonBoolean as aD, polygonToSvgPath as aE, resolveCanvasGradient as aF, ringSignedArea as aG, segmentBounds as aH, segmentCurvature as aI, segmentDerivative as aJ, segmentExtrema as aK, segmentIntersections as aL, segmentLength as aM, segmentNearest as aN, segmentParamAtLength as aO, segmentPoint as aP, segmentTangent as aQ, shapeToPolygon as aR, simplifyRing as aS, splitSegment as aT, strokeOutlineRings as aU, subSegment as aV, subtractPaths as aW, subtractPolygons as aX, toBezierPath as aY, transformBezierPath as aZ, trimSegments as a_, contoursToPath as aa, countPathSegments as ab, dashContours as ac, distanceToBezierPath as ad, dividePaths as ae, dividePolygons as af, excludePaths as ag, flattenSvgPath as ah, formatNumber as ai, getShapeRenderData as aj, getShapeSvg as ak, gradientToSvgDef as al, intersectPaths as am, intersectPolygons as an, isCanvasGradient as ao, isShapeDescription as ap, multiPolygonArea as aq, multiPolygonBounds as ar, normalizeBezierPath as as, offsetPath as at, outlineStroke as au, parseCssGradient as av, parseSvgPath as aw, pathBoolean as ax, pathToContours as ay, pointInBezierPath as az, type StrokeJoin as b, unitePaths as b0, windingNumber as b1, xorPolygons as b2, type StrokeCap as c, type ShapeDescription as d, type PolygonRing as e, type ShapeSize as f, type BezierCommand as g, type BezierContour as h, type BezierPathToSvgOptions as i, type BezierSegment as j, CANVAS_GRADIENT_PRESETS as k, type CanvasLinearGradient as l, type CanvasRadialGradient as m, type DividePathsResult as n, type GradientStop as o, type OutlineStrokeOptions as p, type PathBooleanOperation as q, type PathBooleanResult as r, type PathCommand as s, type PathOperand as t, type PathOperandInput as u, PathOpsError as v, type PathOpsOptions as w, type PathOpsReport as x, type PathPiece as y, type PathPointAtLength as z };
|
|
@@ -544,4 +544,218 @@ declare function pointInBezierPath(input: BezierPathInput, point: Point, fillRul
|
|
|
544
544
|
/** Distance from `point` to the path outline (closing lines of closed subpaths included). */
|
|
545
545
|
declare function distanceToBezierPath(input: BezierPathInput | readonly BezierContour[], point: Point): number;
|
|
546
546
|
|
|
547
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Curve-preserving boolean operations (union, intersection, difference, xor and divide) on
|
|
549
|
+
* Bézier paths.
|
|
550
|
+
*
|
|
551
|
+
* Algorithm (planar arrangement of curve pieces + winding classification):
|
|
552
|
+
* 1. Every segment of every operand (open subpaths closed for filling) is a *source*; it is
|
|
553
|
+
* cut into pieces monotone in x and y. Each piece remembers its source and its parameter
|
|
554
|
+
* range there, so results can be rebuilt from exact sub-curves of the inputs.
|
|
555
|
+
* 2. Pieces are intersected pairwise (pruned by a sweep on x): lines analytically, curves by
|
|
556
|
+
* recursive subdivision down to flat sub-curves, chord intersection and Newton polishing.
|
|
557
|
+
* Endpoints lying on another piece (T-junctions, tangent touches), collinear / coincident
|
|
558
|
+
* overlaps and clusters of hits along a tangency are resolved first. Points closer than
|
|
559
|
+
* `epsilon` share one vertex. Splitting repeats until no piece crosses another.
|
|
560
|
+
* 3. Coincident pieces (shared edges, identical curves) merge into one edge carrying every
|
|
561
|
+
* operand's signed multiplicity.
|
|
562
|
+
* 4. Each edge is classified by casting a horizontal or vertical ray from its midpoint (the
|
|
563
|
+
* pieces are monotone, so a ray crosses each at most once); the operands' fill rules turn
|
|
564
|
+
* the winding numbers on both sides into inside flags and the operation picks the edges
|
|
565
|
+
* with the result on exactly one side.
|
|
566
|
+
* 5. The kept edges are traced into rings, taking the sharpest left turn at each vertex
|
|
567
|
+
* (ties between tangent curves broken by a short chord along each curve), and consecutive
|
|
568
|
+
* pieces of one source are merged back into one exact sub-curve, so circles stay four
|
|
569
|
+
* cubics and rectangles four lines.
|
|
570
|
+
*
|
|
571
|
+
* When the curve engine fails (non-converging intersections on near-coincident curves,
|
|
572
|
+
* an inconsistent arrangement) the operation falls back to the polygon engine
|
|
573
|
+
* (`polygonBoolean`) on flattened input and reports it (`engine: 'polygon'`).
|
|
574
|
+
*
|
|
575
|
+
* Portions ported from vectorcraft-main/crates/pathops/src/boolean.rs (MIT OR Apache-2.0,
|
|
576
|
+
* © ArtCraft Team and contributors). See THIRD_PARTY_NOTICES.md.
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/** Boolean operations (same names as `polygonBoolean`). `xor` is Exclude. */
|
|
580
|
+
type PathBooleanOperation = PolygonBooleanOperation;
|
|
581
|
+
/** A path with the fill rule it is read with (default `nonzero`). */
|
|
582
|
+
interface PathOperand {
|
|
583
|
+
path: BezierPathInput;
|
|
584
|
+
fillRule?: PolygonFillRule;
|
|
585
|
+
}
|
|
586
|
+
type PathOperandInput = BezierPathInput | PathOperand;
|
|
587
|
+
interface PathOpsOptions {
|
|
588
|
+
/**
|
|
589
|
+
* Distance below which points are treated as equal. Defaults to `1e-9` times the
|
|
590
|
+
* largest coordinate magnitude (at least `1e-9`).
|
|
591
|
+
*/
|
|
592
|
+
epsilon?: number;
|
|
593
|
+
/** Fall back to the polygon engine when the curve engine fails (default `true`). */
|
|
594
|
+
fallback?: boolean;
|
|
595
|
+
/** Flattening tolerance used by the polygon fallback (default 0.05). */
|
|
596
|
+
fallbackTolerance?: number;
|
|
597
|
+
/** Called with the reason whenever the polygon fallback is used. */
|
|
598
|
+
onFallback?: (reason: string) => void;
|
|
599
|
+
/**
|
|
600
|
+
* Work budget of the curve–curve intersection search (flat sub-curve pairs per pair of
|
|
601
|
+
* pieces, default 20,000). Exceeding it (nearly coincident curves) falls back.
|
|
602
|
+
*/
|
|
603
|
+
subdivisionBudget?: number;
|
|
604
|
+
}
|
|
605
|
+
/** Which engine produced a result, and why the curve engine was not used. */
|
|
606
|
+
interface PathOpsReport {
|
|
607
|
+
engine: 'curve' | 'polygon';
|
|
608
|
+
fallbackReason?: string;
|
|
609
|
+
/** Set when the input cannot be processed at all (non-finite coordinates); the result is empty. */
|
|
610
|
+
error?: string;
|
|
611
|
+
}
|
|
612
|
+
interface PathBooleanResult extends PathOpsReport {
|
|
613
|
+
path: BezierPath;
|
|
614
|
+
}
|
|
615
|
+
/** One region of `dividePaths`, with the indices of the operands that cover it. */
|
|
616
|
+
interface PathPiece {
|
|
617
|
+
path: BezierPath;
|
|
618
|
+
operands: number[];
|
|
619
|
+
}
|
|
620
|
+
interface DividePathsResult extends PathOpsReport {
|
|
621
|
+
pieces: PathPiece[];
|
|
622
|
+
}
|
|
623
|
+
/** Raised by the curve engine when it cannot produce a reliable arrangement. */
|
|
624
|
+
declare class PathOpsError extends Error {
|
|
625
|
+
constructor(message: string);
|
|
626
|
+
}
|
|
627
|
+
/** A crossing or touch of two segments: the parameter on each and the point. */
|
|
628
|
+
interface SegmentIntersection {
|
|
629
|
+
ta: number;
|
|
630
|
+
tb: number;
|
|
631
|
+
point: Point;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Every point where two segments (lines, quadratics or cubics, as control points) cross or
|
|
635
|
+
* touch, by the same subdivision search the boolean operations use: flat sub-curves, chord
|
|
636
|
+
* intersection, Newton polishing. Hits closer than `epsilon` (default: 1e-9 of the segments'
|
|
637
|
+
* size) are one. Coincident stretches report the hits the search finds along them.
|
|
638
|
+
*/
|
|
639
|
+
declare function segmentIntersections(a: BezierSegment, b: BezierSegment, options?: {
|
|
640
|
+
epsilon?: number;
|
|
641
|
+
budget?: number;
|
|
642
|
+
}): SegmentIntersection[];
|
|
643
|
+
/**
|
|
644
|
+
* Applies a boolean operation to any number of path operands, keeping curves:
|
|
645
|
+
* - `union`: covered by any operand.
|
|
646
|
+
* - `intersection`: covered by every operand.
|
|
647
|
+
* - `difference`: the first operand minus all others.
|
|
648
|
+
* - `xor`: covered by an odd number of operands (Exclude).
|
|
649
|
+
*
|
|
650
|
+
* Open subpaths are closed for filling. Non-finite input gives an empty path (`error`); with
|
|
651
|
+
* `fallback: false` a failure of the curve engine throws a `PathOpsError`. The result is a set of simple closed subpaths that
|
|
652
|
+
* never cross (they may touch at points): outer subpaths run counter-clockwise in a y-up
|
|
653
|
+
* frame (clockwise on screen), holes the other way, so it fills the same with `nonzero`
|
|
654
|
+
* and `evenodd`. Segments of the inputs are kept as exact sub-curves.
|
|
655
|
+
*/
|
|
656
|
+
declare function pathBoolean(operation: PathBooleanOperation, operands: PathOperandInput[], options?: PathOpsOptions): PathBooleanResult;
|
|
657
|
+
declare const unitePaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
658
|
+
declare const intersectPaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
659
|
+
declare const subtractPaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
660
|
+
declare const excludePaths: (a: PathOperandInput, b: PathOperandInput, options?: PathOpsOptions) => BezierPath;
|
|
661
|
+
/**
|
|
662
|
+
* Splits the arrangement of the operands into its regions (Divide): every connected area
|
|
663
|
+
* covered by the same set of operands becomes one piece (an outer subpath with its holes).
|
|
664
|
+
* Pieces are ordered by operand set, then by area (largest first).
|
|
665
|
+
*/
|
|
666
|
+
declare function dividePaths(operands: PathOperandInput[], options?: PathOpsOptions): DividePathsResult;
|
|
667
|
+
/**
|
|
668
|
+
* Resolves self-intersections and overlaps of one filled path into simple, consistently
|
|
669
|
+
* oriented subpaths (outer subpaths and holes) under its fill rule.
|
|
670
|
+
*/
|
|
671
|
+
declare function normalizeBezierPath(path: BezierPathInput, fillRule?: PolygonFillRule, options?: PathOpsOptions): BezierPath;
|
|
672
|
+
/** Filled area of a path under its fill rule (overlaps counted once; exact for curves). */
|
|
673
|
+
declare function bezierPathArea(path: BezierPathInput, fillRule?: PolygonFillRule, options?: PathOpsOptions): number;
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Offset Path and Outline Stroke on Bézier paths.
|
|
677
|
+
*
|
|
678
|
+
* The stroker offsets every segment by ± half the width (lines exactly, curves by cubic
|
|
679
|
+
* approximations refined until they stay within `tolerance` of the true offset), joins the
|
|
680
|
+
* pieces (miter with a miter limit, round or bevel on the outer side of a turn; through the
|
|
681
|
+
* vertex on the inner side) and adds caps (butt, round, square) to open subpaths. Dashes
|
|
682
|
+
* follow arc length, restart on every subpath and join across the start of a closed
|
|
683
|
+
* subpath. The raw outline overlaps itself, so it is filled with the non-zero rule and
|
|
684
|
+
* normalised with the curve boolean engine.
|
|
685
|
+
*
|
|
686
|
+
* When the stroke is wider than a curve's radius of curvature the inner offset turns inside
|
|
687
|
+
* out and its loops cancel winding, leaving holes that are really covered. Every face of
|
|
688
|
+
* the true result is bounded by the arrangement, so a face is spurious exactly when a point
|
|
689
|
+
* deep inside it is closer to the path than the offset distance (holes when growing,
|
|
690
|
+
* islands when insetting); such faces are dropped.
|
|
691
|
+
*
|
|
692
|
+
* Portions ported from vectorcraft-main/crates/pathops/src/offset.rs,
|
|
693
|
+
* vectorcraft-main/crates/pathops/src/boolean.rs (`try_merge`) and
|
|
694
|
+
* vectorcraft-main/crates/effects/src/stroke/dash.rs (MIT OR Apache-2.0, © ArtCraft Team
|
|
695
|
+
* and contributors). See THIRD_PARTY_NOTICES.md.
|
|
696
|
+
*/
|
|
697
|
+
|
|
698
|
+
/** Line join (as SVG `stroke-linejoin`). */
|
|
699
|
+
type StrokeJoin = 'miter' | 'round' | 'bevel';
|
|
700
|
+
/** Line cap (as SVG `stroke-linecap`). */
|
|
701
|
+
type StrokeCap = 'butt' | 'round' | 'square';
|
|
702
|
+
interface OutlineStrokeOptions extends PathOpsOptions {
|
|
703
|
+
/** Stroke width. Non-positive or non-finite widths give an empty result. */
|
|
704
|
+
width: number;
|
|
705
|
+
/** Default `miter` (as SVG). */
|
|
706
|
+
join?: StrokeJoin;
|
|
707
|
+
/** Default `butt` (as SVG). */
|
|
708
|
+
cap?: StrokeCap;
|
|
709
|
+
/** Miter length / stroke width above which a miter join is bevelled (default 4, as SVG). */
|
|
710
|
+
miterLimit?: number;
|
|
711
|
+
/** Dash pattern (as SVG `stroke-dasharray`); odd patterns repeat twice. */
|
|
712
|
+
dash?: readonly number[];
|
|
713
|
+
/** Distance into the dash pattern at the start of each subpath (as `stroke-dashoffset`). */
|
|
714
|
+
dashOffset?: number;
|
|
715
|
+
/** Maximum distance between the approximated and the true offset curve (default 0.01). */
|
|
716
|
+
tolerance?: number;
|
|
717
|
+
}
|
|
718
|
+
interface OffsetPathOptions extends PathOpsOptions {
|
|
719
|
+
/** Corner style of the grown / shrunk outline (default `miter`). */
|
|
720
|
+
join?: StrokeJoin;
|
|
721
|
+
/** Miter limit (default 4). */
|
|
722
|
+
miterLimit?: number;
|
|
723
|
+
/** Fill rule of the input (default `nonzero`). */
|
|
724
|
+
fillRule?: PolygonFillRule;
|
|
725
|
+
/** Maximum distance between the approximated and the true offset curve (default 0.01). */
|
|
726
|
+
tolerance?: number;
|
|
727
|
+
}
|
|
728
|
+
interface DashedPath {
|
|
729
|
+
/** The dashes, as open subpaths. */
|
|
730
|
+
contours: BezierContour[];
|
|
731
|
+
/** Zero-length dashes: where they sit and the path direction there. */
|
|
732
|
+
dots: {
|
|
733
|
+
point: Point;
|
|
734
|
+
tangent: Point;
|
|
735
|
+
}[];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Applies a dash pattern (SVG `stroke-dasharray` / `stroke-dashoffset` semantics) to the
|
|
739
|
+
* subpaths. Returns `null` when the pattern is invalid (negative or non-finite entries),
|
|
740
|
+
* has no positive entry, or would make more than 200,000 dashes: the line is solid.
|
|
741
|
+
*/
|
|
742
|
+
declare function dashContours(contours: readonly BezierContour[], pattern: readonly number[], offset?: number): DashedPath | null;
|
|
743
|
+
/**
|
|
744
|
+
* The raw (overlapping) outline of a stroke as closed subpaths to fill with `nonzero`.
|
|
745
|
+
* `outlineStroke` normalises it; this is useful for previews.
|
|
746
|
+
*/
|
|
747
|
+
declare function strokeOutlineRings(input: BezierPathInput, options: OutlineStrokeOptions): BezierPath;
|
|
748
|
+
/**
|
|
749
|
+
* Outline Stroke: the filled area painted by stroking `path`, as one clean path (overlaps
|
|
750
|
+
* removed, consistently oriented). Joins, caps, miter limit and dashes follow SVG.
|
|
751
|
+
*/
|
|
752
|
+
declare function outlineStroke(input: BezierPathInput, options: OutlineStrokeOptions): BezierPath;
|
|
753
|
+
/**
|
|
754
|
+
* Offset Path: grows (`distance > 0`) or shrinks (`distance < 0`) the filled area by
|
|
755
|
+
* `distance`. Closed subpaths are a filled region (read with `fillRule`); open subpaths are
|
|
756
|
+
* outlined with a stroke of width `2·|distance|` and butt caps (when growing). Loops of the
|
|
757
|
+
* offset curves are removed.
|
|
758
|
+
*/
|
|
759
|
+
declare function offsetPath(input: BezierPathInput, distance: number, options?: OffsetPathOptions): BezierPath;
|
|
760
|
+
|
|
761
|
+
export { type SvgGradientStop as $, type AffineMatrix as A, type BezierPathInput as B, type CanvasGradientDef as C, type DashedPath as D, type EllipseShape as E, type FlattenOptions as F, type GetShapeRenderDataOptions as G, type PathShape as H, type PolygonBooleanOperation as I, type PolygonBooleanOptions as J, type PolygonInput as K, type PolygonOperand as L, type MultiPolygon as M, type PolygonPiece as N, type OffsetPathOptions as O, type PolygonFillRule as P, type PolygonToPathOptions as Q, type PolygonWithHoles as R, type SvgGradientDef as S, type RectShape as T, type RegularPolygonShape as U, SHAPE_KINDS as V, type SegmentIntersection as W, type ShapeKind as X, type ShapePaint as Y, type ShapeRenderData as Z, type StarShape as _, type BezierPath as a, unionPolygons as a$, angleToSvgLinearCoords as a0, arcToCubics as a1, bezierPathArea as a2, bezierPathBounds as a3, bezierPathLength as a4, bezierPathPointAtLength as a5, bezierPathSignedArea as a6, bezierPathToSvg as a7, closeContour as a8, contourSignedArea as a9, pointInMultiPolygon as aA, pointInRings as aB, polygonArea as aC, polygonBoolean as aD, polygonToSvgPath as aE, resolveCanvasGradient as aF, ringSignedArea as aG, segmentBounds as aH, segmentCurvature as aI, segmentDerivative as aJ, segmentExtrema as aK, segmentIntersections as aL, segmentLength as aM, segmentNearest as aN, segmentParamAtLength as aO, segmentPoint as aP, segmentTangent as aQ, shapeToPolygon as aR, simplifyRing as aS, splitSegment as aT, strokeOutlineRings as aU, subSegment as aV, subtractPaths as aW, subtractPolygons as aX, toBezierPath as aY, transformBezierPath as aZ, trimSegments as a_, contoursToPath as aa, countPathSegments as ab, dashContours as ac, distanceToBezierPath as ad, dividePaths as ae, dividePolygons as af, excludePaths as ag, flattenSvgPath as ah, formatNumber as ai, getShapeRenderData as aj, getShapeSvg as ak, gradientToSvgDef as al, intersectPaths as am, intersectPolygons as an, isCanvasGradient as ao, isShapeDescription as ap, multiPolygonArea as aq, multiPolygonBounds as ar, normalizeBezierPath as as, offsetPath as at, outlineStroke as au, parseCssGradient as av, parseSvgPath as aw, pathBoolean as ax, pathToContours as ay, pointInBezierPath as az, type StrokeJoin as b, unitePaths as b0, windingNumber as b1, xorPolygons as b2, type StrokeCap as c, type ShapeDescription as d, type PolygonRing as e, type ShapeSize as f, type BezierCommand as g, type BezierContour as h, type BezierPathToSvgOptions as i, type BezierSegment as j, CANVAS_GRADIENT_PRESETS as k, type CanvasLinearGradient as l, type CanvasRadialGradient as m, type DividePathsResult as n, type GradientStop as o, type OutlineStrokeOptions as p, type PathBooleanOperation as q, type PathBooleanResult as r, type PathCommand as s, type PathOperand as t, type PathOperandInput as u, PathOpsError as v, type PathOpsOptions as w, type PathOpsReport as x, type PathPiece as y, type PathPointAtLength as z };
|