@knotx/render 0.0.6 → 0.0.8
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.cjs +71 -73
- package/dist/index.d.cts +33 -16
- package/dist/index.d.mts +33 -16
- package/dist/index.d.ts +33 -16
- package/dist/index.mjs +69 -74
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,25 @@ function _interopNamespaceCompat(e) {
|
|
|
18
18
|
|
|
19
19
|
const BezierJS__namespace = /*#__PURE__*/_interopNamespaceCompat(BezierJS);
|
|
20
20
|
|
|
21
|
+
var __defProp$4 = Object.defineProperty;
|
|
22
|
+
var __defProps$2 = Object.defineProperties;
|
|
23
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
24
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
25
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
26
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
27
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
28
|
+
var __spreadValues$3 = (a, b) => {
|
|
29
|
+
for (var prop in b || (b = {}))
|
|
30
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
31
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
32
|
+
if (__getOwnPropSymbols$3)
|
|
33
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
34
|
+
if (__propIsEnum$3.call(b, prop))
|
|
35
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
36
|
+
}
|
|
37
|
+
return a;
|
|
38
|
+
};
|
|
39
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
21
40
|
var MarkerType = /* @__PURE__ */ ((MarkerType2) => {
|
|
22
41
|
MarkerType2["Arrow"] = "arrow";
|
|
23
42
|
MarkerType2["ArrowClosed"] = "arrowclosed";
|
|
@@ -29,14 +48,18 @@ function BaseEdge({
|
|
|
29
48
|
sourceY,
|
|
30
49
|
targetX,
|
|
31
50
|
targetY,
|
|
51
|
+
edge,
|
|
52
|
+
className,
|
|
53
|
+
style,
|
|
32
54
|
interactionWidth = 20,
|
|
33
55
|
label,
|
|
34
56
|
markerEnd,
|
|
35
|
-
markerStart
|
|
57
|
+
markerStart,
|
|
58
|
+
context
|
|
36
59
|
}) {
|
|
37
60
|
const path = new PathBuilder(sourceX, sourceY, targetX, targetY);
|
|
38
|
-
const pathString = path.buildPath();
|
|
39
|
-
const labelPosition = label ? path.interpolate(0.5) : void 0;
|
|
61
|
+
const pathString = path.buildPath(context);
|
|
62
|
+
const labelPosition = label ? path.interpolate(0.5, context) : void 0;
|
|
40
63
|
const getMarkerUrl = (marker) => {
|
|
41
64
|
if (!marker)
|
|
42
65
|
return void 0;
|
|
@@ -50,18 +73,22 @@ function BaseEdge({
|
|
|
50
73
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
51
74
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
52
75
|
"svg",
|
|
53
|
-
{
|
|
54
|
-
className: core.bem("edge", "wrapper")
|
|
55
|
-
style: {
|
|
76
|
+
__spreadProps$2(__spreadValues$3({
|
|
77
|
+
className: `${core.bem("edge", "wrapper")}${className ? ` ${className}` : ""}`,
|
|
78
|
+
style: __spreadValues$3({
|
|
56
79
|
position: "absolute",
|
|
57
80
|
left: 0,
|
|
58
81
|
top: 0,
|
|
59
82
|
overflow: "visible",
|
|
60
83
|
pointerEvents: "none",
|
|
61
84
|
stroke: "currentColor"
|
|
62
|
-
},
|
|
85
|
+
}, style)
|
|
86
|
+
}, edge ? {
|
|
87
|
+
"data-edge-source": edge.source,
|
|
88
|
+
"data-edge-target": edge.target
|
|
89
|
+
} : {}), {
|
|
63
90
|
children: [
|
|
64
|
-
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
91
|
+
Boolean(markerEnd || markerStart) && /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
65
92
|
markerEnd && typeof markerEnd === "object" && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
66
93
|
"marker",
|
|
67
94
|
{
|
|
@@ -166,7 +193,7 @@ function BaseEdge({
|
|
|
166
193
|
}
|
|
167
194
|
)
|
|
168
195
|
]
|
|
169
|
-
}
|
|
196
|
+
})
|
|
170
197
|
),
|
|
171
198
|
label && labelPosition && /* @__PURE__ */ jsxRuntime.jsx(
|
|
172
199
|
"div",
|
|
@@ -185,17 +212,13 @@ function BaseEdge({
|
|
|
185
212
|
|
|
186
213
|
var __defProp$3 = Object.defineProperty;
|
|
187
214
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
188
|
-
var __publicField = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
|
|
215
|
+
var __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
189
216
|
class PathBuilder {
|
|
190
217
|
constructor(sourceX, sourceY, targetX, targetY) {
|
|
191
218
|
this.sourceX = sourceX;
|
|
192
219
|
this.sourceY = sourceY;
|
|
193
220
|
this.targetX = targetX;
|
|
194
221
|
this.targetY = targetY;
|
|
195
|
-
this.sourceX = sourceX;
|
|
196
|
-
this.sourceY = sourceY;
|
|
197
|
-
this.targetX = targetX;
|
|
198
|
-
this.targetY = targetY;
|
|
199
222
|
}
|
|
200
223
|
}
|
|
201
224
|
class StraightPathBuilder extends PathBuilder {
|
|
@@ -214,33 +237,37 @@ class BezierPathBuilder extends PathBuilder {
|
|
|
214
237
|
constructor() {
|
|
215
238
|
super(...arguments);
|
|
216
239
|
__publicField(this, "type", "bezier");
|
|
217
|
-
|
|
218
|
-
getBezierInstance() {
|
|
219
|
-
const midX = (this.targetX - this.sourceX) / 2;
|
|
220
|
-
const controlPoint1X = this.sourceX + midX;
|
|
221
|
-
const controlPoint1Y = this.sourceY;
|
|
222
|
-
const controlPoint2X = this.targetX - midX;
|
|
223
|
-
const controlPoint2Y = this.targetY;
|
|
224
|
-
return new BezierJS__namespace.Bezier(
|
|
225
|
-
this.sourceX,
|
|
226
|
-
this.sourceY,
|
|
227
|
-
controlPoint1X,
|
|
228
|
-
controlPoint1Y,
|
|
229
|
-
controlPoint2X,
|
|
230
|
-
controlPoint2Y,
|
|
231
|
-
this.targetX,
|
|
232
|
-
this.targetY
|
|
233
|
-
);
|
|
240
|
+
__publicField(this, "bezier");
|
|
234
241
|
}
|
|
235
242
|
buildPath() {
|
|
236
|
-
const bezier = this.
|
|
243
|
+
const bezier = this.requireBezierInstance();
|
|
237
244
|
return bezier.toSVG();
|
|
238
245
|
}
|
|
239
246
|
interpolate(t) {
|
|
240
|
-
const bezier = this.
|
|
247
|
+
const bezier = this.requireBezierInstance();
|
|
241
248
|
const point = bezier.get(t);
|
|
242
249
|
return { x: point.x, y: point.y };
|
|
243
250
|
}
|
|
251
|
+
requireBezierInstance() {
|
|
252
|
+
if (!this.bezier) {
|
|
253
|
+
const midX = (this.targetX - this.sourceX) / 2;
|
|
254
|
+
const controlPoint1X = this.sourceX + midX;
|
|
255
|
+
const controlPoint1Y = this.sourceY;
|
|
256
|
+
const controlPoint2X = this.targetX - midX;
|
|
257
|
+
const controlPoint2Y = this.targetY;
|
|
258
|
+
this.bezier = new BezierJS__namespace.Bezier(
|
|
259
|
+
this.sourceX,
|
|
260
|
+
this.sourceY,
|
|
261
|
+
controlPoint1X,
|
|
262
|
+
controlPoint1Y,
|
|
263
|
+
controlPoint2X,
|
|
264
|
+
controlPoint2Y,
|
|
265
|
+
this.targetX,
|
|
266
|
+
this.targetY
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
return this.bezier;
|
|
270
|
+
}
|
|
244
271
|
}
|
|
245
272
|
|
|
246
273
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -262,28 +289,12 @@ var __spreadValues$2 = (a, b) => {
|
|
|
262
289
|
return a;
|
|
263
290
|
};
|
|
264
291
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
265
|
-
|
|
266
|
-
var target = {};
|
|
267
|
-
for (var prop in source)
|
|
268
|
-
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
269
|
-
target[prop] = source[prop];
|
|
270
|
-
if (source != null && __getOwnPropSymbols$2)
|
|
271
|
-
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
272
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
273
|
-
target[prop] = source[prop];
|
|
274
|
-
}
|
|
275
|
-
return target;
|
|
276
|
-
};
|
|
277
|
-
function BezierEdge(_a) {
|
|
278
|
-
var _b = _a, {
|
|
279
|
-
edge: _edge
|
|
280
|
-
} = _b, rest = __objRest$1(_b, [
|
|
281
|
-
"edge"
|
|
282
|
-
]);
|
|
292
|
+
function BezierEdge(props) {
|
|
283
293
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
284
294
|
BaseEdge,
|
|
285
|
-
__spreadProps$1(__spreadValues$2({},
|
|
286
|
-
pathBuilder: BezierPathBuilder
|
|
295
|
+
__spreadProps$1(__spreadValues$2({}, props), {
|
|
296
|
+
pathBuilder: BezierPathBuilder,
|
|
297
|
+
context: void 0
|
|
287
298
|
})
|
|
288
299
|
);
|
|
289
300
|
}
|
|
@@ -404,37 +415,24 @@ var __spreadValues = (a, b) => {
|
|
|
404
415
|
return a;
|
|
405
416
|
};
|
|
406
417
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
407
|
-
|
|
408
|
-
var target = {};
|
|
409
|
-
for (var prop in source)
|
|
410
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
411
|
-
target[prop] = source[prop];
|
|
412
|
-
if (source != null && __getOwnPropSymbols)
|
|
413
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
414
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
415
|
-
target[prop] = source[prop];
|
|
416
|
-
}
|
|
417
|
-
return target;
|
|
418
|
-
};
|
|
419
|
-
function StraightEdge(_a) {
|
|
420
|
-
var _b = _a, {
|
|
421
|
-
edge: _edge
|
|
422
|
-
} = _b, rest = __objRest(_b, [
|
|
423
|
-
"edge"
|
|
424
|
-
]);
|
|
418
|
+
function StraightEdge(props) {
|
|
425
419
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
426
420
|
BaseEdge,
|
|
427
|
-
__spreadProps(__spreadValues({},
|
|
428
|
-
pathBuilder: StraightPathBuilder
|
|
421
|
+
__spreadProps(__spreadValues({}, props), {
|
|
422
|
+
pathBuilder: StraightPathBuilder,
|
|
423
|
+
context: void 0
|
|
429
424
|
})
|
|
430
425
|
);
|
|
431
426
|
}
|
|
432
427
|
|
|
433
428
|
exports.BaseEdge = BaseEdge;
|
|
434
429
|
exports.BezierEdge = BezierEdge;
|
|
430
|
+
exports.BezierPathBuilder = BezierPathBuilder;
|
|
435
431
|
exports.MarkerDefinitions = MarkerDefinitions;
|
|
436
432
|
exports.MarkerType = MarkerType;
|
|
433
|
+
exports.PathBuilder = PathBuilder;
|
|
437
434
|
exports.StraightEdge = StraightEdge;
|
|
435
|
+
exports.StraightPathBuilder = StraightPathBuilder;
|
|
438
436
|
exports.getArrowClosedMarker = getArrowClosedMarker;
|
|
439
437
|
exports.getArrowHeadMarkers = getArrowHeadMarkers;
|
|
440
438
|
exports.getArrowMarker = getArrowMarker;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EdgeProps } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
declare abstract class PathBuilder<TType extends string> {
|
|
3
|
+
declare abstract class PathBuilder<TType extends string, TContext = never> {
|
|
4
4
|
readonly sourceX: number;
|
|
5
5
|
readonly sourceY: number;
|
|
6
6
|
readonly targetX: number;
|
|
@@ -10,18 +10,36 @@ declare abstract class PathBuilder<TType extends string> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Builds the svg string for the path.
|
|
12
12
|
*/
|
|
13
|
-
abstract buildPath(): string;
|
|
13
|
+
abstract buildPath(context: TContext): string;
|
|
14
14
|
/**
|
|
15
15
|
* Interpolates the position for the path at a given t value.
|
|
16
16
|
* @param t - The t value to interpolate at.
|
|
17
17
|
* @returns The interpolated position.
|
|
18
18
|
*/
|
|
19
|
-
abstract interpolate(t: number): {
|
|
19
|
+
abstract interpolate(t: number, context: TContext): {
|
|
20
20
|
x: number;
|
|
21
21
|
y: number;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
type PathBuilderType<T extends string = any> = new (...args: ConstructorParameters<typeof PathBuilder<T>>) => PathBuilder<T>;
|
|
24
|
+
type PathBuilderType<T extends string = any, TContext = void> = new (...args: ConstructorParameters<typeof PathBuilder<T, TContext>>) => PathBuilder<T, TContext>;
|
|
25
|
+
declare class StraightPathBuilder extends PathBuilder<'straight'> {
|
|
26
|
+
type: "straight";
|
|
27
|
+
buildPath(): string;
|
|
28
|
+
interpolate(t: number): {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
declare class BezierPathBuilder extends PathBuilder<'bezier'> {
|
|
34
|
+
type: "bezier";
|
|
35
|
+
private bezier?;
|
|
36
|
+
buildPath(): string;
|
|
37
|
+
interpolate(t: number): {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
private requireBezierInstance;
|
|
42
|
+
}
|
|
25
43
|
|
|
26
44
|
declare enum MarkerType {
|
|
27
45
|
Arrow = "arrow",
|
|
@@ -37,22 +55,21 @@ interface MarkerProps {
|
|
|
37
55
|
orient?: string;
|
|
38
56
|
strokeWidth?: number;
|
|
39
57
|
}
|
|
40
|
-
interface BaseEdgeProps {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sourceY: number;
|
|
44
|
-
targetX: number;
|
|
45
|
-
targetY: number;
|
|
58
|
+
interface BaseEdgeProps<TPathBuilderContext = void> extends EdgeProps {
|
|
59
|
+
className?: string;
|
|
60
|
+
style?: Record<string, any>;
|
|
46
61
|
interactionWidth?: number;
|
|
47
62
|
label?: string;
|
|
48
63
|
markerEnd?: string | MarkerProps;
|
|
49
64
|
markerStart?: string | MarkerProps;
|
|
65
|
+
pathBuilder: PathBuilderType<any, TPathBuilderContext>;
|
|
66
|
+
context: TPathBuilderContext;
|
|
50
67
|
}
|
|
51
|
-
declare function BaseEdge({ pathBuilder: PathBuilder, sourceX, sourceY, targetX, targetY, interactionWidth, label, markerEnd, markerStart, }: BaseEdgeProps): JSX.Element;
|
|
68
|
+
declare function BaseEdge<TPathBuilderContext = never>({ pathBuilder: PathBuilder, sourceX, sourceY, targetX, targetY, edge, className, style, interactionWidth, label, markerEnd, markerStart, context, }: BaseEdgeProps<TPathBuilderContext>): JSX.Element;
|
|
52
69
|
|
|
53
|
-
interface
|
|
70
|
+
interface BezierEdgeProps extends Omit<BaseEdgeProps, 'pathBuilder' | 'context'> {
|
|
54
71
|
}
|
|
55
|
-
declare function BezierEdge(
|
|
72
|
+
declare function BezierEdge(props: BezierEdgeProps): JSX.Element;
|
|
56
73
|
|
|
57
74
|
/**
|
|
58
75
|
* 创建一个标准的箭头 marker
|
|
@@ -90,8 +107,8 @@ interface MarkerDefinitionsProps {
|
|
|
90
107
|
}
|
|
91
108
|
declare function MarkerDefinitions({ markers }: MarkerDefinitionsProps): JSX.Element;
|
|
92
109
|
|
|
93
|
-
interface
|
|
110
|
+
interface StraightEdgeProps extends Omit<BaseEdgeProps, 'pathBuilder' | 'context'> {
|
|
94
111
|
}
|
|
95
|
-
declare function StraightEdge(
|
|
112
|
+
declare function StraightEdge(props: StraightEdgeProps): JSX.Element;
|
|
96
113
|
|
|
97
|
-
export { BaseEdge, type BaseEdgeProps, BezierEdge, type
|
|
114
|
+
export { BaseEdge, type BaseEdgeProps, BezierEdge, type BezierEdgeProps, BezierPathBuilder, MarkerDefinitions, type MarkerDefinitionsProps, type MarkerProps, MarkerType, PathBuilder, type PathBuilderType, StraightEdge, type StraightEdgeProps, StraightPathBuilder, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EdgeProps } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
declare abstract class PathBuilder<TType extends string> {
|
|
3
|
+
declare abstract class PathBuilder<TType extends string, TContext = never> {
|
|
4
4
|
readonly sourceX: number;
|
|
5
5
|
readonly sourceY: number;
|
|
6
6
|
readonly targetX: number;
|
|
@@ -10,18 +10,36 @@ declare abstract class PathBuilder<TType extends string> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Builds the svg string for the path.
|
|
12
12
|
*/
|
|
13
|
-
abstract buildPath(): string;
|
|
13
|
+
abstract buildPath(context: TContext): string;
|
|
14
14
|
/**
|
|
15
15
|
* Interpolates the position for the path at a given t value.
|
|
16
16
|
* @param t - The t value to interpolate at.
|
|
17
17
|
* @returns The interpolated position.
|
|
18
18
|
*/
|
|
19
|
-
abstract interpolate(t: number): {
|
|
19
|
+
abstract interpolate(t: number, context: TContext): {
|
|
20
20
|
x: number;
|
|
21
21
|
y: number;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
type PathBuilderType<T extends string = any> = new (...args: ConstructorParameters<typeof PathBuilder<T>>) => PathBuilder<T>;
|
|
24
|
+
type PathBuilderType<T extends string = any, TContext = void> = new (...args: ConstructorParameters<typeof PathBuilder<T, TContext>>) => PathBuilder<T, TContext>;
|
|
25
|
+
declare class StraightPathBuilder extends PathBuilder<'straight'> {
|
|
26
|
+
type: "straight";
|
|
27
|
+
buildPath(): string;
|
|
28
|
+
interpolate(t: number): {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
declare class BezierPathBuilder extends PathBuilder<'bezier'> {
|
|
34
|
+
type: "bezier";
|
|
35
|
+
private bezier?;
|
|
36
|
+
buildPath(): string;
|
|
37
|
+
interpolate(t: number): {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
private requireBezierInstance;
|
|
42
|
+
}
|
|
25
43
|
|
|
26
44
|
declare enum MarkerType {
|
|
27
45
|
Arrow = "arrow",
|
|
@@ -37,22 +55,21 @@ interface MarkerProps {
|
|
|
37
55
|
orient?: string;
|
|
38
56
|
strokeWidth?: number;
|
|
39
57
|
}
|
|
40
|
-
interface BaseEdgeProps {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sourceY: number;
|
|
44
|
-
targetX: number;
|
|
45
|
-
targetY: number;
|
|
58
|
+
interface BaseEdgeProps<TPathBuilderContext = void> extends EdgeProps {
|
|
59
|
+
className?: string;
|
|
60
|
+
style?: Record<string, any>;
|
|
46
61
|
interactionWidth?: number;
|
|
47
62
|
label?: string;
|
|
48
63
|
markerEnd?: string | MarkerProps;
|
|
49
64
|
markerStart?: string | MarkerProps;
|
|
65
|
+
pathBuilder: PathBuilderType<any, TPathBuilderContext>;
|
|
66
|
+
context: TPathBuilderContext;
|
|
50
67
|
}
|
|
51
|
-
declare function BaseEdge({ pathBuilder: PathBuilder, sourceX, sourceY, targetX, targetY, interactionWidth, label, markerEnd, markerStart, }: BaseEdgeProps): JSX.Element;
|
|
68
|
+
declare function BaseEdge<TPathBuilderContext = never>({ pathBuilder: PathBuilder, sourceX, sourceY, targetX, targetY, edge, className, style, interactionWidth, label, markerEnd, markerStart, context, }: BaseEdgeProps<TPathBuilderContext>): JSX.Element;
|
|
52
69
|
|
|
53
|
-
interface
|
|
70
|
+
interface BezierEdgeProps extends Omit<BaseEdgeProps, 'pathBuilder' | 'context'> {
|
|
54
71
|
}
|
|
55
|
-
declare function BezierEdge(
|
|
72
|
+
declare function BezierEdge(props: BezierEdgeProps): JSX.Element;
|
|
56
73
|
|
|
57
74
|
/**
|
|
58
75
|
* 创建一个标准的箭头 marker
|
|
@@ -90,8 +107,8 @@ interface MarkerDefinitionsProps {
|
|
|
90
107
|
}
|
|
91
108
|
declare function MarkerDefinitions({ markers }: MarkerDefinitionsProps): JSX.Element;
|
|
92
109
|
|
|
93
|
-
interface
|
|
110
|
+
interface StraightEdgeProps extends Omit<BaseEdgeProps, 'pathBuilder' | 'context'> {
|
|
94
111
|
}
|
|
95
|
-
declare function StraightEdge(
|
|
112
|
+
declare function StraightEdge(props: StraightEdgeProps): JSX.Element;
|
|
96
113
|
|
|
97
|
-
export { BaseEdge, type BaseEdgeProps, BezierEdge, type
|
|
114
|
+
export { BaseEdge, type BaseEdgeProps, BezierEdge, type BezierEdgeProps, BezierPathBuilder, MarkerDefinitions, type MarkerDefinitionsProps, type MarkerProps, MarkerType, PathBuilder, type PathBuilderType, StraightEdge, type StraightEdgeProps, StraightPathBuilder, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EdgeProps } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
declare abstract class PathBuilder<TType extends string> {
|
|
3
|
+
declare abstract class PathBuilder<TType extends string, TContext = never> {
|
|
4
4
|
readonly sourceX: number;
|
|
5
5
|
readonly sourceY: number;
|
|
6
6
|
readonly targetX: number;
|
|
@@ -10,18 +10,36 @@ declare abstract class PathBuilder<TType extends string> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Builds the svg string for the path.
|
|
12
12
|
*/
|
|
13
|
-
abstract buildPath(): string;
|
|
13
|
+
abstract buildPath(context: TContext): string;
|
|
14
14
|
/**
|
|
15
15
|
* Interpolates the position for the path at a given t value.
|
|
16
16
|
* @param t - The t value to interpolate at.
|
|
17
17
|
* @returns The interpolated position.
|
|
18
18
|
*/
|
|
19
|
-
abstract interpolate(t: number): {
|
|
19
|
+
abstract interpolate(t: number, context: TContext): {
|
|
20
20
|
x: number;
|
|
21
21
|
y: number;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
type PathBuilderType<T extends string = any> = new (...args: ConstructorParameters<typeof PathBuilder<T>>) => PathBuilder<T>;
|
|
24
|
+
type PathBuilderType<T extends string = any, TContext = void> = new (...args: ConstructorParameters<typeof PathBuilder<T, TContext>>) => PathBuilder<T, TContext>;
|
|
25
|
+
declare class StraightPathBuilder extends PathBuilder<'straight'> {
|
|
26
|
+
type: "straight";
|
|
27
|
+
buildPath(): string;
|
|
28
|
+
interpolate(t: number): {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
declare class BezierPathBuilder extends PathBuilder<'bezier'> {
|
|
34
|
+
type: "bezier";
|
|
35
|
+
private bezier?;
|
|
36
|
+
buildPath(): string;
|
|
37
|
+
interpolate(t: number): {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
private requireBezierInstance;
|
|
42
|
+
}
|
|
25
43
|
|
|
26
44
|
declare enum MarkerType {
|
|
27
45
|
Arrow = "arrow",
|
|
@@ -37,22 +55,21 @@ interface MarkerProps {
|
|
|
37
55
|
orient?: string;
|
|
38
56
|
strokeWidth?: number;
|
|
39
57
|
}
|
|
40
|
-
interface BaseEdgeProps {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sourceY: number;
|
|
44
|
-
targetX: number;
|
|
45
|
-
targetY: number;
|
|
58
|
+
interface BaseEdgeProps<TPathBuilderContext = void> extends EdgeProps {
|
|
59
|
+
className?: string;
|
|
60
|
+
style?: Record<string, any>;
|
|
46
61
|
interactionWidth?: number;
|
|
47
62
|
label?: string;
|
|
48
63
|
markerEnd?: string | MarkerProps;
|
|
49
64
|
markerStart?: string | MarkerProps;
|
|
65
|
+
pathBuilder: PathBuilderType<any, TPathBuilderContext>;
|
|
66
|
+
context: TPathBuilderContext;
|
|
50
67
|
}
|
|
51
|
-
declare function BaseEdge({ pathBuilder: PathBuilder, sourceX, sourceY, targetX, targetY, interactionWidth, label, markerEnd, markerStart, }: BaseEdgeProps): JSX.Element;
|
|
68
|
+
declare function BaseEdge<TPathBuilderContext = never>({ pathBuilder: PathBuilder, sourceX, sourceY, targetX, targetY, edge, className, style, interactionWidth, label, markerEnd, markerStart, context, }: BaseEdgeProps<TPathBuilderContext>): JSX.Element;
|
|
52
69
|
|
|
53
|
-
interface
|
|
70
|
+
interface BezierEdgeProps extends Omit<BaseEdgeProps, 'pathBuilder' | 'context'> {
|
|
54
71
|
}
|
|
55
|
-
declare function BezierEdge(
|
|
72
|
+
declare function BezierEdge(props: BezierEdgeProps): JSX.Element;
|
|
56
73
|
|
|
57
74
|
/**
|
|
58
75
|
* 创建一个标准的箭头 marker
|
|
@@ -90,8 +107,8 @@ interface MarkerDefinitionsProps {
|
|
|
90
107
|
}
|
|
91
108
|
declare function MarkerDefinitions({ markers }: MarkerDefinitionsProps): JSX.Element;
|
|
92
109
|
|
|
93
|
-
interface
|
|
110
|
+
interface StraightEdgeProps extends Omit<BaseEdgeProps, 'pathBuilder' | 'context'> {
|
|
94
111
|
}
|
|
95
|
-
declare function StraightEdge(
|
|
112
|
+
declare function StraightEdge(props: StraightEdgeProps): JSX.Element;
|
|
96
113
|
|
|
97
|
-
export { BaseEdge, type BaseEdgeProps, BezierEdge, type
|
|
114
|
+
export { BaseEdge, type BaseEdgeProps, BezierEdge, type BezierEdgeProps, BezierPathBuilder, MarkerDefinitions, type MarkerDefinitionsProps, type MarkerProps, MarkerType, PathBuilder, type PathBuilderType, StraightEdge, type StraightEdgeProps, StraightPathBuilder, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,25 @@ import { jsxs, Fragment, jsx } from '@knotx/jsx/jsx-runtime';
|
|
|
2
2
|
import { bem } from '@knotx/core';
|
|
3
3
|
import * as BezierJS from 'bezier-js';
|
|
4
4
|
|
|
5
|
+
var __defProp$4 = Object.defineProperty;
|
|
6
|
+
var __defProps$2 = Object.defineProperties;
|
|
7
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues$3 = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
15
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols$3)
|
|
17
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
18
|
+
if (__propIsEnum$3.call(b, prop))
|
|
19
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
5
24
|
var MarkerType = /* @__PURE__ */ ((MarkerType2) => {
|
|
6
25
|
MarkerType2["Arrow"] = "arrow";
|
|
7
26
|
MarkerType2["ArrowClosed"] = "arrowclosed";
|
|
@@ -13,14 +32,18 @@ function BaseEdge({
|
|
|
13
32
|
sourceY,
|
|
14
33
|
targetX,
|
|
15
34
|
targetY,
|
|
35
|
+
edge,
|
|
36
|
+
className,
|
|
37
|
+
style,
|
|
16
38
|
interactionWidth = 20,
|
|
17
39
|
label,
|
|
18
40
|
markerEnd,
|
|
19
|
-
markerStart
|
|
41
|
+
markerStart,
|
|
42
|
+
context
|
|
20
43
|
}) {
|
|
21
44
|
const path = new PathBuilder(sourceX, sourceY, targetX, targetY);
|
|
22
|
-
const pathString = path.buildPath();
|
|
23
|
-
const labelPosition = label ? path.interpolate(0.5) : void 0;
|
|
45
|
+
const pathString = path.buildPath(context);
|
|
46
|
+
const labelPosition = label ? path.interpolate(0.5, context) : void 0;
|
|
24
47
|
const getMarkerUrl = (marker) => {
|
|
25
48
|
if (!marker)
|
|
26
49
|
return void 0;
|
|
@@ -34,18 +57,22 @@ function BaseEdge({
|
|
|
34
57
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
58
|
/* @__PURE__ */ jsxs(
|
|
36
59
|
"svg",
|
|
37
|
-
{
|
|
38
|
-
className: bem("edge", "wrapper")
|
|
39
|
-
style: {
|
|
60
|
+
__spreadProps$2(__spreadValues$3({
|
|
61
|
+
className: `${bem("edge", "wrapper")}${className ? ` ${className}` : ""}`,
|
|
62
|
+
style: __spreadValues$3({
|
|
40
63
|
position: "absolute",
|
|
41
64
|
left: 0,
|
|
42
65
|
top: 0,
|
|
43
66
|
overflow: "visible",
|
|
44
67
|
pointerEvents: "none",
|
|
45
68
|
stroke: "currentColor"
|
|
46
|
-
},
|
|
69
|
+
}, style)
|
|
70
|
+
}, edge ? {
|
|
71
|
+
"data-edge-source": edge.source,
|
|
72
|
+
"data-edge-target": edge.target
|
|
73
|
+
} : {}), {
|
|
47
74
|
children: [
|
|
48
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
75
|
+
Boolean(markerEnd || markerStart) && /* @__PURE__ */ jsxs("defs", { children: [
|
|
49
76
|
markerEnd && typeof markerEnd === "object" && /* @__PURE__ */ jsxs(
|
|
50
77
|
"marker",
|
|
51
78
|
{
|
|
@@ -150,7 +177,7 @@ function BaseEdge({
|
|
|
150
177
|
}
|
|
151
178
|
)
|
|
152
179
|
]
|
|
153
|
-
}
|
|
180
|
+
})
|
|
154
181
|
),
|
|
155
182
|
label && labelPosition && /* @__PURE__ */ jsx(
|
|
156
183
|
"div",
|
|
@@ -169,17 +196,13 @@ function BaseEdge({
|
|
|
169
196
|
|
|
170
197
|
var __defProp$3 = Object.defineProperty;
|
|
171
198
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
172
|
-
var __publicField = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
|
|
199
|
+
var __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
173
200
|
class PathBuilder {
|
|
174
201
|
constructor(sourceX, sourceY, targetX, targetY) {
|
|
175
202
|
this.sourceX = sourceX;
|
|
176
203
|
this.sourceY = sourceY;
|
|
177
204
|
this.targetX = targetX;
|
|
178
205
|
this.targetY = targetY;
|
|
179
|
-
this.sourceX = sourceX;
|
|
180
|
-
this.sourceY = sourceY;
|
|
181
|
-
this.targetX = targetX;
|
|
182
|
-
this.targetY = targetY;
|
|
183
206
|
}
|
|
184
207
|
}
|
|
185
208
|
class StraightPathBuilder extends PathBuilder {
|
|
@@ -198,33 +221,37 @@ class BezierPathBuilder extends PathBuilder {
|
|
|
198
221
|
constructor() {
|
|
199
222
|
super(...arguments);
|
|
200
223
|
__publicField(this, "type", "bezier");
|
|
201
|
-
|
|
202
|
-
getBezierInstance() {
|
|
203
|
-
const midX = (this.targetX - this.sourceX) / 2;
|
|
204
|
-
const controlPoint1X = this.sourceX + midX;
|
|
205
|
-
const controlPoint1Y = this.sourceY;
|
|
206
|
-
const controlPoint2X = this.targetX - midX;
|
|
207
|
-
const controlPoint2Y = this.targetY;
|
|
208
|
-
return new BezierJS.Bezier(
|
|
209
|
-
this.sourceX,
|
|
210
|
-
this.sourceY,
|
|
211
|
-
controlPoint1X,
|
|
212
|
-
controlPoint1Y,
|
|
213
|
-
controlPoint2X,
|
|
214
|
-
controlPoint2Y,
|
|
215
|
-
this.targetX,
|
|
216
|
-
this.targetY
|
|
217
|
-
);
|
|
224
|
+
__publicField(this, "bezier");
|
|
218
225
|
}
|
|
219
226
|
buildPath() {
|
|
220
|
-
const bezier = this.
|
|
227
|
+
const bezier = this.requireBezierInstance();
|
|
221
228
|
return bezier.toSVG();
|
|
222
229
|
}
|
|
223
230
|
interpolate(t) {
|
|
224
|
-
const bezier = this.
|
|
231
|
+
const bezier = this.requireBezierInstance();
|
|
225
232
|
const point = bezier.get(t);
|
|
226
233
|
return { x: point.x, y: point.y };
|
|
227
234
|
}
|
|
235
|
+
requireBezierInstance() {
|
|
236
|
+
if (!this.bezier) {
|
|
237
|
+
const midX = (this.targetX - this.sourceX) / 2;
|
|
238
|
+
const controlPoint1X = this.sourceX + midX;
|
|
239
|
+
const controlPoint1Y = this.sourceY;
|
|
240
|
+
const controlPoint2X = this.targetX - midX;
|
|
241
|
+
const controlPoint2Y = this.targetY;
|
|
242
|
+
this.bezier = new BezierJS.Bezier(
|
|
243
|
+
this.sourceX,
|
|
244
|
+
this.sourceY,
|
|
245
|
+
controlPoint1X,
|
|
246
|
+
controlPoint1Y,
|
|
247
|
+
controlPoint2X,
|
|
248
|
+
controlPoint2Y,
|
|
249
|
+
this.targetX,
|
|
250
|
+
this.targetY
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
return this.bezier;
|
|
254
|
+
}
|
|
228
255
|
}
|
|
229
256
|
|
|
230
257
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -246,28 +273,12 @@ var __spreadValues$2 = (a, b) => {
|
|
|
246
273
|
return a;
|
|
247
274
|
};
|
|
248
275
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
249
|
-
|
|
250
|
-
var target = {};
|
|
251
|
-
for (var prop in source)
|
|
252
|
-
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
253
|
-
target[prop] = source[prop];
|
|
254
|
-
if (source != null && __getOwnPropSymbols$2)
|
|
255
|
-
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
256
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
257
|
-
target[prop] = source[prop];
|
|
258
|
-
}
|
|
259
|
-
return target;
|
|
260
|
-
};
|
|
261
|
-
function BezierEdge(_a) {
|
|
262
|
-
var _b = _a, {
|
|
263
|
-
edge: _edge
|
|
264
|
-
} = _b, rest = __objRest$1(_b, [
|
|
265
|
-
"edge"
|
|
266
|
-
]);
|
|
276
|
+
function BezierEdge(props) {
|
|
267
277
|
return /* @__PURE__ */ jsx(
|
|
268
278
|
BaseEdge,
|
|
269
|
-
__spreadProps$1(__spreadValues$2({},
|
|
270
|
-
pathBuilder: BezierPathBuilder
|
|
279
|
+
__spreadProps$1(__spreadValues$2({}, props), {
|
|
280
|
+
pathBuilder: BezierPathBuilder,
|
|
281
|
+
context: void 0
|
|
271
282
|
})
|
|
272
283
|
);
|
|
273
284
|
}
|
|
@@ -388,30 +399,14 @@ var __spreadValues = (a, b) => {
|
|
|
388
399
|
return a;
|
|
389
400
|
};
|
|
390
401
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
391
|
-
|
|
392
|
-
var target = {};
|
|
393
|
-
for (var prop in source)
|
|
394
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
395
|
-
target[prop] = source[prop];
|
|
396
|
-
if (source != null && __getOwnPropSymbols)
|
|
397
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
398
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
399
|
-
target[prop] = source[prop];
|
|
400
|
-
}
|
|
401
|
-
return target;
|
|
402
|
-
};
|
|
403
|
-
function StraightEdge(_a) {
|
|
404
|
-
var _b = _a, {
|
|
405
|
-
edge: _edge
|
|
406
|
-
} = _b, rest = __objRest(_b, [
|
|
407
|
-
"edge"
|
|
408
|
-
]);
|
|
402
|
+
function StraightEdge(props) {
|
|
409
403
|
return /* @__PURE__ */ jsx(
|
|
410
404
|
BaseEdge,
|
|
411
|
-
__spreadProps(__spreadValues({},
|
|
412
|
-
pathBuilder: StraightPathBuilder
|
|
405
|
+
__spreadProps(__spreadValues({}, props), {
|
|
406
|
+
pathBuilder: StraightPathBuilder,
|
|
407
|
+
context: void 0
|
|
413
408
|
})
|
|
414
409
|
);
|
|
415
410
|
}
|
|
416
411
|
|
|
417
|
-
export { BaseEdge, BezierEdge, MarkerDefinitions, MarkerType, StraightEdge, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
|
412
|
+
export { BaseEdge, BezierEdge, BezierPathBuilder, MarkerDefinitions, MarkerType, PathBuilder, StraightEdge, StraightPathBuilder, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/render",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"description": "Render for Knotx",
|
|
6
6
|
"author": "boenfu",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"bezier-js": "^6.1.4",
|
|
33
|
-
"@knotx/core": "0.0.
|
|
33
|
+
"@knotx/core": "0.0.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/bezier-js": "^4.1.3",
|
|
37
|
-
"@knotx/build-config": "0.0.
|
|
38
|
-
"@knotx/eslint-config": "0.0.
|
|
39
|
-
"@knotx/jsx": "0.0.
|
|
40
|
-
"@knotx/typescript-config": "0.0.
|
|
37
|
+
"@knotx/build-config": "0.0.6",
|
|
38
|
+
"@knotx/eslint-config": "0.0.6",
|
|
39
|
+
"@knotx/jsx": "0.0.6",
|
|
40
|
+
"@knotx/typescript-config": "0.0.6"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "unbuild --failOnWarn=false",
|