@ibodr/draw 0.2.3 → 0.2.4
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/dist/index.d.ts +8 -2
- package/dist/index.mjs +58 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -76,13 +76,17 @@ interface SolidPathBuilderOpts extends BasePathBuilderOpts {
|
|
|
76
76
|
}
|
|
77
77
|
/** @public */
|
|
78
78
|
interface DashedPathBuilderOpts extends BasePathBuilderOpts {
|
|
79
|
-
style: 'dashed' | 'dotted';
|
|
79
|
+
style: 'dashed' | 'dotted' | 'sparse';
|
|
80
80
|
snap?: number;
|
|
81
81
|
end?: PerfectDashTerminal;
|
|
82
82
|
start?: PerfectDashTerminal;
|
|
83
83
|
lengthRatio?: number;
|
|
84
84
|
}
|
|
85
85
|
/** @public */
|
|
86
|
+
interface DoublePathBuilderOpts extends BasePathBuilderOpts {
|
|
87
|
+
style: 'double';
|
|
88
|
+
}
|
|
89
|
+
/** @public */
|
|
86
90
|
interface DrawPathBuilderDOpts {
|
|
87
91
|
strokeWidth: number;
|
|
88
92
|
randomSeed: string;
|
|
@@ -100,7 +104,7 @@ interface NonePathBuilderOpts extends BasePathBuilderOpts {
|
|
|
100
104
|
style: 'none';
|
|
101
105
|
}
|
|
102
106
|
/** @public */
|
|
103
|
-
type PathBuilderOpts = SolidPathBuilderOpts | DashedPathBuilderOpts | DrawPathBuilderOpts | NonePathBuilderOpts;
|
|
107
|
+
type PathBuilderOpts = SolidPathBuilderOpts | DashedPathBuilderOpts | DoublePathBuilderOpts | DrawPathBuilderOpts | NonePathBuilderOpts;
|
|
104
108
|
/** @public */
|
|
105
109
|
interface PathBuilderCommandOpts {
|
|
106
110
|
/**
|
|
@@ -190,6 +194,8 @@ declare class PathBuilder {
|
|
|
190
194
|
toPath2D(opts: PathBuilderOpts): Path2D;
|
|
191
195
|
toGeometry(): PathBuilderGeometry2d | Group2d;
|
|
192
196
|
private toSolidSvg;
|
|
197
|
+
/** Two parallel strokes: a thick stroke with the center cut out by a mask. */
|
|
198
|
+
private toDoubleSvg;
|
|
193
199
|
private toDashedSvg;
|
|
194
200
|
private toDrawSvg;
|
|
195
201
|
toDrawD(opts: DrawPathBuilderDOpts): string;
|
package/dist/index.mjs
CHANGED
|
@@ -728,6 +728,8 @@ function getDrawShapeStrokeDashArray(shape, strokeWidth, dotAdjustment) {
|
|
|
728
728
|
solid: `none`,
|
|
729
729
|
dotted: `${dotAdjustment} ${strokeWidth * 2}`,
|
|
730
730
|
dashed: `${strokeWidth * 2} ${strokeWidth * 2}`,
|
|
731
|
+
sparse: `${strokeWidth * 4} ${strokeWidth * 10}`,
|
|
732
|
+
double: `none`,
|
|
731
733
|
none: `none`
|
|
732
734
|
}[shape.props.dash];
|
|
733
735
|
}
|
|
@@ -988,7 +990,10 @@ var PathBuilder = class _PathBuilder {
|
|
|
988
990
|
return this.toSolidSvg(opts);
|
|
989
991
|
case "dashed":
|
|
990
992
|
case "dotted":
|
|
993
|
+
case "sparse":
|
|
991
994
|
return this.toDashedSvg(opts);
|
|
995
|
+
case "double":
|
|
996
|
+
return this.toDoubleSvg(opts);
|
|
992
997
|
case "draw": {
|
|
993
998
|
const d = this.toDrawSvg(opts);
|
|
994
999
|
return d;
|
|
@@ -1048,6 +1053,51 @@ var PathBuilder = class _PathBuilder {
|
|
|
1048
1053
|
const { strokeWidth, props } = opts;
|
|
1049
1054
|
return /* @__PURE__ */ jsx("path", { strokeWidth, d: this.toD({ onlyFilled: opts.onlyFilled }), ...props });
|
|
1050
1055
|
}
|
|
1056
|
+
/** Two parallel strokes: a thick stroke with the center cut out by a mask. */
|
|
1057
|
+
toDoubleSvg(opts) {
|
|
1058
|
+
const { strokeWidth, props = {} } = opts;
|
|
1059
|
+
const d = this.toD({ onlyFilled: opts.onlyFilled });
|
|
1060
|
+
const outer = strokeWidth * 3;
|
|
1061
|
+
const inner = strokeWidth;
|
|
1062
|
+
const maskId = doubleLineMaskId(d);
|
|
1063
|
+
return /* @__PURE__ */ jsxs("g", { ...props, children: [
|
|
1064
|
+
/* @__PURE__ */ jsxs("mask", { id: maskId, maskUnits: "userSpaceOnUse", children: [
|
|
1065
|
+
/* @__PURE__ */ jsx(
|
|
1066
|
+
"path",
|
|
1067
|
+
{
|
|
1068
|
+
d,
|
|
1069
|
+
fill: "none",
|
|
1070
|
+
stroke: "#fff",
|
|
1071
|
+
strokeWidth: outer,
|
|
1072
|
+
strokeLinecap: "round",
|
|
1073
|
+
strokeLinejoin: "round"
|
|
1074
|
+
}
|
|
1075
|
+
),
|
|
1076
|
+
/* @__PURE__ */ jsx(
|
|
1077
|
+
"path",
|
|
1078
|
+
{
|
|
1079
|
+
d,
|
|
1080
|
+
fill: "none",
|
|
1081
|
+
stroke: "#000",
|
|
1082
|
+
strokeWidth: inner,
|
|
1083
|
+
strokeLinecap: "round",
|
|
1084
|
+
strokeLinejoin: "round"
|
|
1085
|
+
}
|
|
1086
|
+
)
|
|
1087
|
+
] }),
|
|
1088
|
+
/* @__PURE__ */ jsx(
|
|
1089
|
+
"path",
|
|
1090
|
+
{
|
|
1091
|
+
d,
|
|
1092
|
+
fill: "none",
|
|
1093
|
+
strokeWidth: outer,
|
|
1094
|
+
strokeLinecap: "round",
|
|
1095
|
+
strokeLinejoin: "round",
|
|
1096
|
+
mask: `url(#${maskId})`
|
|
1097
|
+
}
|
|
1098
|
+
)
|
|
1099
|
+
] });
|
|
1100
|
+
}
|
|
1051
1101
|
toDashedSvg(opts) {
|
|
1052
1102
|
const {
|
|
1053
1103
|
style,
|
|
@@ -1491,6 +1541,11 @@ var CubicBezier = {
|
|
|
1491
1541
|
0.0472
|
|
1492
1542
|
]
|
|
1493
1543
|
};
|
|
1544
|
+
function doubleLineMaskId(d) {
|
|
1545
|
+
let hash = 0;
|
|
1546
|
+
for (let i = 0; i < d.length; i++) hash = Math.imul(31, hash) + d.charCodeAt(i) | 0;
|
|
1547
|
+
return `dr-double-${(hash >>> 0).toString(36)}`;
|
|
1548
|
+
}
|
|
1494
1549
|
function usePrefersReducedMotion() {
|
|
1495
1550
|
const editor = useMaybeEditor();
|
|
1496
1551
|
const animationSpeed = useValue("animationSpeed", () => editor?.user.getAnimationSpeed(), [
|
|
@@ -13550,6 +13605,8 @@ var STYLES = {
|
|
|
13550
13605
|
{ value: "draw", icon: "dash-draw" },
|
|
13551
13606
|
{ value: "dashed", icon: "dash-dashed" },
|
|
13552
13607
|
{ value: "dotted", icon: "dash-dotted" },
|
|
13608
|
+
{ value: "sparse", icon: "dash-dashed" },
|
|
13609
|
+
{ value: "double", icon: "dash-solid" },
|
|
13553
13610
|
{ value: "solid", icon: "dash-solid" }
|
|
13554
13611
|
],
|
|
13555
13612
|
size: [
|
|
@@ -38471,7 +38528,7 @@ async function extractAssets(editor, snapshot, msg, addToast) {
|
|
|
38471
38528
|
// src/index.ts
|
|
38472
38529
|
registerDrawLibraryVersion(
|
|
38473
38530
|
"@ibodr/draw",
|
|
38474
|
-
"0.2.
|
|
38531
|
+
"0.2.4",
|
|
38475
38532
|
"esm"
|
|
38476
38533
|
);
|
|
38477
38534
|
/*!
|