@knotx/render 0.0.3 → 0.0.5
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 +420 -28
- package/dist/index.d.cts +91 -5
- package/dist/index.d.mts +91 -5
- package/dist/index.d.ts +91 -5
- package/dist/index.mjs +402 -30
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -1,48 +1,440 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const jsxRuntime = require('@knotx/jsx/jsx-runtime');
|
|
4
|
+
const core = require('@knotx/core');
|
|
5
|
+
const BezierJS = require('bezier-js');
|
|
4
6
|
|
|
5
|
-
function
|
|
7
|
+
function _interopNamespaceCompat(e) {
|
|
8
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
9
|
+
const n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
n[k] = e[k];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
n.default = e;
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const BezierJS__namespace = /*#__PURE__*/_interopNamespaceCompat(BezierJS);
|
|
20
|
+
|
|
21
|
+
var MarkerType = /* @__PURE__ */ ((MarkerType2) => {
|
|
22
|
+
MarkerType2["Arrow"] = "arrow";
|
|
23
|
+
MarkerType2["ArrowClosed"] = "arrowclosed";
|
|
24
|
+
return MarkerType2;
|
|
25
|
+
})(MarkerType || {});
|
|
26
|
+
function BaseEdge({
|
|
27
|
+
pathBuilder: PathBuilder,
|
|
6
28
|
sourceX,
|
|
7
29
|
sourceY,
|
|
8
30
|
targetX,
|
|
9
31
|
targetY,
|
|
10
|
-
|
|
32
|
+
interactionWidth = 20,
|
|
33
|
+
label,
|
|
34
|
+
markerEnd,
|
|
35
|
+
markerStart
|
|
11
36
|
}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
controlPoint2X = targetX - midX;
|
|
21
|
-
controlPoint2Y = targetY;
|
|
22
|
-
}
|
|
23
|
-
const path = `M ${sourceX} ${sourceY} C ${controlPoint1X} ${controlPoint1Y}, ${controlPoint2X} ${controlPoint2Y}, ${targetX} ${targetY}`;
|
|
24
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
25
|
-
"path",
|
|
26
|
-
{
|
|
27
|
-
d: path,
|
|
28
|
-
fill: "none",
|
|
29
|
-
stroke: "currentColor"
|
|
37
|
+
const path = new PathBuilder(sourceX, sourceY, targetX, targetY);
|
|
38
|
+
const pathString = path.buildPath();
|
|
39
|
+
const labelPosition = label ? path.interpolate(0.5) : void 0;
|
|
40
|
+
const getMarkerUrl = (marker) => {
|
|
41
|
+
if (!marker)
|
|
42
|
+
return void 0;
|
|
43
|
+
if (typeof marker === "string") {
|
|
44
|
+
return `url(#${marker})`;
|
|
30
45
|
}
|
|
31
|
-
|
|
46
|
+
return `url(#${marker.id})`;
|
|
47
|
+
};
|
|
48
|
+
const markerEndUrl = getMarkerUrl(markerEnd);
|
|
49
|
+
const markerStartUrl = getMarkerUrl(markerStart);
|
|
50
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
51
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
52
|
+
"svg",
|
|
53
|
+
{
|
|
54
|
+
className: core.bem("edge", "wrapper"),
|
|
55
|
+
style: {
|
|
56
|
+
position: "absolute",
|
|
57
|
+
left: 0,
|
|
58
|
+
top: 0,
|
|
59
|
+
overflow: "visible",
|
|
60
|
+
pointerEvents: "none",
|
|
61
|
+
stroke: "currentColor"
|
|
62
|
+
},
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
|
|
65
|
+
markerEnd && typeof markerEnd === "object" && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
66
|
+
"marker",
|
|
67
|
+
{
|
|
68
|
+
id: markerEnd.id,
|
|
69
|
+
markerWidth: markerEnd.width || 10,
|
|
70
|
+
markerHeight: markerEnd.height || 10,
|
|
71
|
+
refX: markerEnd.width || 10,
|
|
72
|
+
refY: (markerEnd.height || 10) / 2,
|
|
73
|
+
markerUnits: markerEnd.markerUnits || "strokeWidth",
|
|
74
|
+
orient: markerEnd.orient || "auto",
|
|
75
|
+
children: [
|
|
76
|
+
markerEnd.type === "arrow" /* Arrow */ && /* @__PURE__ */ jsxRuntime.jsx(
|
|
77
|
+
"path",
|
|
78
|
+
{
|
|
79
|
+
d: "M 0 0 L 10 5 L 0 10",
|
|
80
|
+
fill: "none",
|
|
81
|
+
stroke: markerEnd.color || "currentColor",
|
|
82
|
+
strokeWidth: markerEnd.strokeWidth || 1
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
markerEnd.type === "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsxRuntime.jsx(
|
|
86
|
+
"path",
|
|
87
|
+
{
|
|
88
|
+
d: "M 0 0 L 10 5 L 0 10 z",
|
|
89
|
+
fill: markerEnd.color || "currentColor",
|
|
90
|
+
stroke: markerEnd.color || "currentColor",
|
|
91
|
+
strokeWidth: markerEnd.strokeWidth || 1
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
markerEnd.type !== "arrow" /* Arrow */ && markerEnd.type !== "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsxRuntime.jsx(
|
|
95
|
+
"path",
|
|
96
|
+
{
|
|
97
|
+
d: "M 0 0 L 10 5 L 0 10",
|
|
98
|
+
fill: "none",
|
|
99
|
+
stroke: markerEnd.color || "currentColor",
|
|
100
|
+
strokeWidth: markerEnd.strokeWidth || 1
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
markerStart && typeof markerStart === "object" && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
107
|
+
"marker",
|
|
108
|
+
{
|
|
109
|
+
id: markerStart.id,
|
|
110
|
+
markerWidth: markerStart.width || 10,
|
|
111
|
+
markerHeight: markerStart.height || 10,
|
|
112
|
+
refX: 0,
|
|
113
|
+
refY: (markerStart.height || 10) / 2,
|
|
114
|
+
markerUnits: markerStart.markerUnits || "strokeWidth",
|
|
115
|
+
orient: markerStart.orient || "auto",
|
|
116
|
+
children: [
|
|
117
|
+
markerStart.type === "arrow" /* Arrow */ && /* @__PURE__ */ jsxRuntime.jsx(
|
|
118
|
+
"path",
|
|
119
|
+
{
|
|
120
|
+
d: "M 10 0 L 0 5 L 10 10",
|
|
121
|
+
fill: "none",
|
|
122
|
+
stroke: markerStart.color || "currentColor",
|
|
123
|
+
strokeWidth: markerStart.strokeWidth || 1
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
markerStart.type === "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsxRuntime.jsx(
|
|
127
|
+
"path",
|
|
128
|
+
{
|
|
129
|
+
d: "M 10 0 L 0 5 L 10 10 z",
|
|
130
|
+
fill: markerStart.color || "currentColor",
|
|
131
|
+
stroke: markerStart.color || "currentColor",
|
|
132
|
+
strokeWidth: markerStart.strokeWidth || 1
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
markerStart.type !== "arrow" /* Arrow */ && markerStart.type !== "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsxRuntime.jsx(
|
|
136
|
+
"path",
|
|
137
|
+
{
|
|
138
|
+
d: "M 10 0 L 0 5 L 10 10",
|
|
139
|
+
fill: "none",
|
|
140
|
+
stroke: markerStart.color || "currentColor",
|
|
141
|
+
strokeWidth: markerStart.strokeWidth || 1
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
149
|
+
"path",
|
|
150
|
+
{
|
|
151
|
+
d: pathString,
|
|
152
|
+
fill: "none",
|
|
153
|
+
className: core.bem("edge", "path"),
|
|
154
|
+
markerEnd: markerEndUrl,
|
|
155
|
+
markerStart: markerStartUrl
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
interactionWidth && /* @__PURE__ */ jsxRuntime.jsx(
|
|
159
|
+
"path",
|
|
160
|
+
{
|
|
161
|
+
d: pathString,
|
|
162
|
+
fill: "none",
|
|
163
|
+
strokeOpacity: 0,
|
|
164
|
+
strokeWidth: interactionWidth,
|
|
165
|
+
className: core.bem("edge", "interaction")
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
label && labelPosition && /* @__PURE__ */ jsxRuntime.jsx(
|
|
172
|
+
"div",
|
|
173
|
+
{
|
|
174
|
+
style: {
|
|
175
|
+
position: "absolute",
|
|
176
|
+
left: labelPosition.x,
|
|
177
|
+
top: labelPosition.y,
|
|
178
|
+
transform: "translate(-50%, -50%)"
|
|
179
|
+
},
|
|
180
|
+
children: label
|
|
181
|
+
}
|
|
182
|
+
)
|
|
183
|
+
] });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var __defProp$3 = Object.defineProperty;
|
|
187
|
+
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);
|
|
189
|
+
class PathBuilder {
|
|
190
|
+
constructor(sourceX, sourceY, targetX, targetY) {
|
|
191
|
+
this.sourceX = sourceX;
|
|
192
|
+
this.sourceY = sourceY;
|
|
193
|
+
this.targetX = targetX;
|
|
194
|
+
this.targetY = targetY;
|
|
195
|
+
this.sourceX = sourceX;
|
|
196
|
+
this.sourceY = sourceY;
|
|
197
|
+
this.targetX = targetX;
|
|
198
|
+
this.targetY = targetY;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
class StraightPathBuilder extends PathBuilder {
|
|
202
|
+
constructor() {
|
|
203
|
+
super(...arguments);
|
|
204
|
+
__publicField(this, "type", "straight");
|
|
205
|
+
}
|
|
206
|
+
buildPath() {
|
|
207
|
+
return `M ${this.sourceX} ${this.sourceY} L ${this.targetX} ${this.targetY}`;
|
|
208
|
+
}
|
|
209
|
+
interpolate(t) {
|
|
210
|
+
return { x: this.sourceX + t * (this.targetX - this.sourceX), y: this.sourceY + t * (this.targetY - this.sourceY) };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
class BezierPathBuilder extends PathBuilder {
|
|
214
|
+
constructor() {
|
|
215
|
+
super(...arguments);
|
|
216
|
+
__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
|
+
);
|
|
234
|
+
}
|
|
235
|
+
buildPath() {
|
|
236
|
+
const bezier = this.getBezierInstance();
|
|
237
|
+
return bezier.toSVG();
|
|
238
|
+
}
|
|
239
|
+
interpolate(t) {
|
|
240
|
+
const bezier = this.getBezierInstance();
|
|
241
|
+
const point = bezier.get(t);
|
|
242
|
+
return { x: point.x, y: point.y };
|
|
243
|
+
}
|
|
32
244
|
}
|
|
33
245
|
|
|
34
|
-
|
|
246
|
+
var __defProp$2 = Object.defineProperty;
|
|
247
|
+
var __defProps$1 = Object.defineProperties;
|
|
248
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
249
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
250
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
251
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
252
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
253
|
+
var __spreadValues$2 = (a, b) => {
|
|
254
|
+
for (var prop in b || (b = {}))
|
|
255
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
256
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
257
|
+
if (__getOwnPropSymbols$2)
|
|
258
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
259
|
+
if (__propIsEnum$2.call(b, prop))
|
|
260
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
261
|
+
}
|
|
262
|
+
return a;
|
|
263
|
+
};
|
|
264
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
265
|
+
var __objRest$1 = (source, exclude) => {
|
|
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
|
+
]);
|
|
35
283
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
36
|
-
|
|
284
|
+
BaseEdge,
|
|
285
|
+
__spreadProps$1(__spreadValues$2({}, rest), {
|
|
286
|
+
pathBuilder: BezierPathBuilder
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
var __defProp$1 = Object.defineProperty;
|
|
292
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
293
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
294
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
295
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
296
|
+
var __spreadValues$1 = (a, b) => {
|
|
297
|
+
for (var prop in b || (b = {}))
|
|
298
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
299
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
300
|
+
if (__getOwnPropSymbols$1)
|
|
301
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
302
|
+
if (__propIsEnum$1.call(b, prop))
|
|
303
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
304
|
+
}
|
|
305
|
+
return a;
|
|
306
|
+
};
|
|
307
|
+
let markerCounter = 0;
|
|
308
|
+
function getArrowMarker(color) {
|
|
309
|
+
const id = `arrow-${markerCounter++}`;
|
|
310
|
+
return {
|
|
311
|
+
id,
|
|
312
|
+
type: MarkerType.Arrow,
|
|
313
|
+
color,
|
|
314
|
+
width: 10,
|
|
315
|
+
height: 10
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function getArrowClosedMarker(color) {
|
|
319
|
+
const id = `arrowclosed-${markerCounter++}`;
|
|
320
|
+
return {
|
|
321
|
+
id,
|
|
322
|
+
type: MarkerType.ArrowClosed,
|
|
323
|
+
color,
|
|
324
|
+
width: 10,
|
|
325
|
+
height: 10
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function getCustomMarker(type, options = {}) {
|
|
329
|
+
const id = `custom-${type}-${markerCounter++}`;
|
|
330
|
+
return __spreadValues$1({
|
|
331
|
+
id,
|
|
332
|
+
type
|
|
333
|
+
}, options);
|
|
334
|
+
}
|
|
335
|
+
function getArrowHeadMarkers(color) {
|
|
336
|
+
const markerStart = getArrowClosedMarker(color);
|
|
337
|
+
const markerEnd = getArrowClosedMarker(color);
|
|
338
|
+
return {
|
|
339
|
+
markerStart,
|
|
340
|
+
markerEnd
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function MarkerDefinitions({ markers }) {
|
|
344
|
+
return /* @__PURE__ */ jsxRuntime.jsx("defs", { children: markers.map((marker) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
345
|
+
"marker",
|
|
37
346
|
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
347
|
+
id: marker.id,
|
|
348
|
+
markerWidth: marker.width || 10,
|
|
349
|
+
markerHeight: marker.height || 10,
|
|
350
|
+
refX: marker.type.includes("start") ? 0 : marker.width || 10,
|
|
351
|
+
refY: (marker.height || 10) / 2,
|
|
352
|
+
markerUnits: marker.markerUnits || "strokeWidth",
|
|
353
|
+
orient: marker.orient || "auto",
|
|
354
|
+
children: [
|
|
355
|
+
marker.type === MarkerType.Arrow && /* @__PURE__ */ jsxRuntime.jsx(
|
|
356
|
+
"path",
|
|
357
|
+
{
|
|
358
|
+
d: marker.type.includes("start") ? "M 10 0 L 0 5 L 10 10" : "M 0 0 L 10 5 L 0 10",
|
|
359
|
+
fill: "none",
|
|
360
|
+
stroke: marker.color || "currentColor",
|
|
361
|
+
strokeWidth: marker.strokeWidth || 1
|
|
362
|
+
}
|
|
363
|
+
),
|
|
364
|
+
marker.type === MarkerType.ArrowClosed && /* @__PURE__ */ jsxRuntime.jsx(
|
|
365
|
+
"path",
|
|
366
|
+
{
|
|
367
|
+
d: marker.type.includes("start") ? "M 10 0 L 0 5 L 10 10 z" : "M 0 0 L 10 5 L 0 10 z",
|
|
368
|
+
fill: marker.color || "currentColor",
|
|
369
|
+
stroke: marker.color || "currentColor",
|
|
370
|
+
strokeWidth: marker.strokeWidth || 1
|
|
371
|
+
}
|
|
372
|
+
),
|
|
373
|
+
marker.type !== MarkerType.Arrow && marker.type !== MarkerType.ArrowClosed && /* @__PURE__ */ jsxRuntime.jsx(
|
|
374
|
+
"path",
|
|
375
|
+
{
|
|
376
|
+
d: marker.type.includes("start") ? "M 10 0 L 0 5 L 10 10" : "M 0 0 L 10 5 L 0 10",
|
|
377
|
+
fill: "none",
|
|
378
|
+
stroke: marker.color || "currentColor",
|
|
379
|
+
strokeWidth: marker.strokeWidth || 1
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
]
|
|
383
|
+
},
|
|
384
|
+
marker.id
|
|
385
|
+
)) });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
var __defProp = Object.defineProperty;
|
|
389
|
+
var __defProps = Object.defineProperties;
|
|
390
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
391
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
392
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
393
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
394
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
395
|
+
var __spreadValues = (a, b) => {
|
|
396
|
+
for (var prop in b || (b = {}))
|
|
397
|
+
if (__hasOwnProp.call(b, prop))
|
|
398
|
+
__defNormalProp(a, prop, b[prop]);
|
|
399
|
+
if (__getOwnPropSymbols)
|
|
400
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
401
|
+
if (__propIsEnum.call(b, prop))
|
|
402
|
+
__defNormalProp(a, prop, b[prop]);
|
|
43
403
|
}
|
|
404
|
+
return a;
|
|
405
|
+
};
|
|
406
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
407
|
+
var __objRest = (source, exclude) => {
|
|
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
|
+
]);
|
|
425
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
426
|
+
BaseEdge,
|
|
427
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
428
|
+
pathBuilder: StraightPathBuilder
|
|
429
|
+
})
|
|
44
430
|
);
|
|
45
431
|
}
|
|
46
432
|
|
|
47
433
|
exports.BezierEdge = BezierEdge;
|
|
434
|
+
exports.MarkerDefinitions = MarkerDefinitions;
|
|
435
|
+
exports.MarkerType = MarkerType;
|
|
48
436
|
exports.StraightEdge = StraightEdge;
|
|
437
|
+
exports.getArrowClosedMarker = getArrowClosedMarker;
|
|
438
|
+
exports.getArrowHeadMarkers = getArrowHeadMarkers;
|
|
439
|
+
exports.getArrowMarker = getArrowMarker;
|
|
440
|
+
exports.getCustomMarker = getCustomMarker;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,96 @@
|
|
|
1
1
|
import { EdgeProps } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare abstract class PathBuilder<TType extends string> {
|
|
4
|
+
readonly sourceX: number;
|
|
5
|
+
readonly sourceY: number;
|
|
6
|
+
readonly targetX: number;
|
|
7
|
+
readonly targetY: number;
|
|
8
|
+
constructor(sourceX: number, sourceY: number, targetX: number, targetY: number);
|
|
9
|
+
abstract type: TType;
|
|
10
|
+
/**
|
|
11
|
+
* Builds the svg string for the path.
|
|
12
|
+
*/
|
|
13
|
+
abstract buildPath(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Interpolates the position for the path at a given t value.
|
|
16
|
+
* @param t - The t value to interpolate at.
|
|
17
|
+
* @returns The interpolated position.
|
|
18
|
+
*/
|
|
19
|
+
abstract interpolate(t: number): {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|
|
5
23
|
}
|
|
6
|
-
|
|
24
|
+
type PathBuilderType<T extends string = any> = new (...args: ConstructorParameters<typeof PathBuilder<T>>) => PathBuilder<T>;
|
|
7
25
|
|
|
8
|
-
declare
|
|
26
|
+
declare enum MarkerType {
|
|
27
|
+
Arrow = "arrow",
|
|
28
|
+
ArrowClosed = "arrowclosed"
|
|
29
|
+
}
|
|
30
|
+
interface MarkerProps {
|
|
31
|
+
id: string;
|
|
32
|
+
type: MarkerType | string;
|
|
33
|
+
color?: string;
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
markerUnits?: string;
|
|
37
|
+
orient?: string;
|
|
38
|
+
strokeWidth?: number;
|
|
39
|
+
}
|
|
40
|
+
interface BaseEdgeProps {
|
|
41
|
+
pathBuilder: PathBuilderType;
|
|
42
|
+
sourceX: number;
|
|
43
|
+
sourceY: number;
|
|
44
|
+
targetX: number;
|
|
45
|
+
targetY: number;
|
|
46
|
+
interactionWidth?: number;
|
|
47
|
+
label?: string;
|
|
48
|
+
markerEnd?: string | MarkerProps;
|
|
49
|
+
markerStart?: string | MarkerProps;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BezierEdgeOptions extends EdgeProps, Omit<BaseEdgeProps, 'pathBuilder'> {
|
|
53
|
+
}
|
|
54
|
+
declare function BezierEdge({ edge: _edge, ...rest }: BezierEdgeOptions): JSX.Element;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 创建一个标准的箭头 marker
|
|
58
|
+
* @param color - marker 的颜色
|
|
59
|
+
* @returns marker 配置
|
|
60
|
+
*/
|
|
61
|
+
declare function getArrowMarker(color?: string): MarkerProps;
|
|
62
|
+
/**
|
|
63
|
+
* 创建一个实心箭头 marker
|
|
64
|
+
* @param color - marker 的颜色
|
|
65
|
+
* @returns marker 配置
|
|
66
|
+
*/
|
|
67
|
+
declare function getArrowClosedMarker(color?: string): MarkerProps;
|
|
68
|
+
/**
|
|
69
|
+
* 创建自定义 marker
|
|
70
|
+
* @param type - marker 类型
|
|
71
|
+
* @param options - marker 选项
|
|
72
|
+
* @returns marker 配置
|
|
73
|
+
*/
|
|
74
|
+
declare function getCustomMarker(type: string, options?: Omit<Partial<MarkerProps>, 'id' | 'type'>): MarkerProps;
|
|
75
|
+
/**
|
|
76
|
+
* 创建两个实心箭头作为起点和终点的marker
|
|
77
|
+
* @param color - marker 的颜色
|
|
78
|
+
* @returns 包含开始和结束marker的对象
|
|
79
|
+
*/
|
|
80
|
+
declare function getArrowHeadMarkers(color?: string): {
|
|
81
|
+
markerStart: MarkerProps;
|
|
82
|
+
markerEnd: MarkerProps;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Marker 注册表组件,可以集中管理并重用 marker
|
|
86
|
+
*/
|
|
87
|
+
interface MarkerDefinitionsProps {
|
|
88
|
+
markers: MarkerProps[];
|
|
89
|
+
}
|
|
90
|
+
declare function MarkerDefinitions({ markers }: MarkerDefinitionsProps): JSX.Element;
|
|
91
|
+
|
|
92
|
+
interface StraightEdgeOptions extends EdgeProps, Omit<BaseEdgeProps, 'pathBuilder'> {
|
|
93
|
+
}
|
|
94
|
+
declare function StraightEdge({ edge: _edge, ...rest }: StraightEdgeOptions): JSX.Element;
|
|
9
95
|
|
|
10
|
-
export { BezierEdge, type BezierEdgeOptions, StraightEdge };
|
|
96
|
+
export { BezierEdge, type BezierEdgeOptions, MarkerDefinitions, type MarkerDefinitionsProps, MarkerType, StraightEdge, type StraightEdgeOptions, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,96 @@
|
|
|
1
1
|
import { EdgeProps } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare abstract class PathBuilder<TType extends string> {
|
|
4
|
+
readonly sourceX: number;
|
|
5
|
+
readonly sourceY: number;
|
|
6
|
+
readonly targetX: number;
|
|
7
|
+
readonly targetY: number;
|
|
8
|
+
constructor(sourceX: number, sourceY: number, targetX: number, targetY: number);
|
|
9
|
+
abstract type: TType;
|
|
10
|
+
/**
|
|
11
|
+
* Builds the svg string for the path.
|
|
12
|
+
*/
|
|
13
|
+
abstract buildPath(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Interpolates the position for the path at a given t value.
|
|
16
|
+
* @param t - The t value to interpolate at.
|
|
17
|
+
* @returns The interpolated position.
|
|
18
|
+
*/
|
|
19
|
+
abstract interpolate(t: number): {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|
|
5
23
|
}
|
|
6
|
-
|
|
24
|
+
type PathBuilderType<T extends string = any> = new (...args: ConstructorParameters<typeof PathBuilder<T>>) => PathBuilder<T>;
|
|
7
25
|
|
|
8
|
-
declare
|
|
26
|
+
declare enum MarkerType {
|
|
27
|
+
Arrow = "arrow",
|
|
28
|
+
ArrowClosed = "arrowclosed"
|
|
29
|
+
}
|
|
30
|
+
interface MarkerProps {
|
|
31
|
+
id: string;
|
|
32
|
+
type: MarkerType | string;
|
|
33
|
+
color?: string;
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
markerUnits?: string;
|
|
37
|
+
orient?: string;
|
|
38
|
+
strokeWidth?: number;
|
|
39
|
+
}
|
|
40
|
+
interface BaseEdgeProps {
|
|
41
|
+
pathBuilder: PathBuilderType;
|
|
42
|
+
sourceX: number;
|
|
43
|
+
sourceY: number;
|
|
44
|
+
targetX: number;
|
|
45
|
+
targetY: number;
|
|
46
|
+
interactionWidth?: number;
|
|
47
|
+
label?: string;
|
|
48
|
+
markerEnd?: string | MarkerProps;
|
|
49
|
+
markerStart?: string | MarkerProps;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BezierEdgeOptions extends EdgeProps, Omit<BaseEdgeProps, 'pathBuilder'> {
|
|
53
|
+
}
|
|
54
|
+
declare function BezierEdge({ edge: _edge, ...rest }: BezierEdgeOptions): JSX.Element;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 创建一个标准的箭头 marker
|
|
58
|
+
* @param color - marker 的颜色
|
|
59
|
+
* @returns marker 配置
|
|
60
|
+
*/
|
|
61
|
+
declare function getArrowMarker(color?: string): MarkerProps;
|
|
62
|
+
/**
|
|
63
|
+
* 创建一个实心箭头 marker
|
|
64
|
+
* @param color - marker 的颜色
|
|
65
|
+
* @returns marker 配置
|
|
66
|
+
*/
|
|
67
|
+
declare function getArrowClosedMarker(color?: string): MarkerProps;
|
|
68
|
+
/**
|
|
69
|
+
* 创建自定义 marker
|
|
70
|
+
* @param type - marker 类型
|
|
71
|
+
* @param options - marker 选项
|
|
72
|
+
* @returns marker 配置
|
|
73
|
+
*/
|
|
74
|
+
declare function getCustomMarker(type: string, options?: Omit<Partial<MarkerProps>, 'id' | 'type'>): MarkerProps;
|
|
75
|
+
/**
|
|
76
|
+
* 创建两个实心箭头作为起点和终点的marker
|
|
77
|
+
* @param color - marker 的颜色
|
|
78
|
+
* @returns 包含开始和结束marker的对象
|
|
79
|
+
*/
|
|
80
|
+
declare function getArrowHeadMarkers(color?: string): {
|
|
81
|
+
markerStart: MarkerProps;
|
|
82
|
+
markerEnd: MarkerProps;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Marker 注册表组件,可以集中管理并重用 marker
|
|
86
|
+
*/
|
|
87
|
+
interface MarkerDefinitionsProps {
|
|
88
|
+
markers: MarkerProps[];
|
|
89
|
+
}
|
|
90
|
+
declare function MarkerDefinitions({ markers }: MarkerDefinitionsProps): JSX.Element;
|
|
91
|
+
|
|
92
|
+
interface StraightEdgeOptions extends EdgeProps, Omit<BaseEdgeProps, 'pathBuilder'> {
|
|
93
|
+
}
|
|
94
|
+
declare function StraightEdge({ edge: _edge, ...rest }: StraightEdgeOptions): JSX.Element;
|
|
9
95
|
|
|
10
|
-
export { BezierEdge, type BezierEdgeOptions, StraightEdge };
|
|
96
|
+
export { BezierEdge, type BezierEdgeOptions, MarkerDefinitions, type MarkerDefinitionsProps, MarkerType, StraightEdge, type StraightEdgeOptions, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,96 @@
|
|
|
1
1
|
import { EdgeProps } from '@knotx/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare abstract class PathBuilder<TType extends string> {
|
|
4
|
+
readonly sourceX: number;
|
|
5
|
+
readonly sourceY: number;
|
|
6
|
+
readonly targetX: number;
|
|
7
|
+
readonly targetY: number;
|
|
8
|
+
constructor(sourceX: number, sourceY: number, targetX: number, targetY: number);
|
|
9
|
+
abstract type: TType;
|
|
10
|
+
/**
|
|
11
|
+
* Builds the svg string for the path.
|
|
12
|
+
*/
|
|
13
|
+
abstract buildPath(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Interpolates the position for the path at a given t value.
|
|
16
|
+
* @param t - The t value to interpolate at.
|
|
17
|
+
* @returns The interpolated position.
|
|
18
|
+
*/
|
|
19
|
+
abstract interpolate(t: number): {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|
|
5
23
|
}
|
|
6
|
-
|
|
24
|
+
type PathBuilderType<T extends string = any> = new (...args: ConstructorParameters<typeof PathBuilder<T>>) => PathBuilder<T>;
|
|
7
25
|
|
|
8
|
-
declare
|
|
26
|
+
declare enum MarkerType {
|
|
27
|
+
Arrow = "arrow",
|
|
28
|
+
ArrowClosed = "arrowclosed"
|
|
29
|
+
}
|
|
30
|
+
interface MarkerProps {
|
|
31
|
+
id: string;
|
|
32
|
+
type: MarkerType | string;
|
|
33
|
+
color?: string;
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
markerUnits?: string;
|
|
37
|
+
orient?: string;
|
|
38
|
+
strokeWidth?: number;
|
|
39
|
+
}
|
|
40
|
+
interface BaseEdgeProps {
|
|
41
|
+
pathBuilder: PathBuilderType;
|
|
42
|
+
sourceX: number;
|
|
43
|
+
sourceY: number;
|
|
44
|
+
targetX: number;
|
|
45
|
+
targetY: number;
|
|
46
|
+
interactionWidth?: number;
|
|
47
|
+
label?: string;
|
|
48
|
+
markerEnd?: string | MarkerProps;
|
|
49
|
+
markerStart?: string | MarkerProps;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BezierEdgeOptions extends EdgeProps, Omit<BaseEdgeProps, 'pathBuilder'> {
|
|
53
|
+
}
|
|
54
|
+
declare function BezierEdge({ edge: _edge, ...rest }: BezierEdgeOptions): JSX.Element;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 创建一个标准的箭头 marker
|
|
58
|
+
* @param color - marker 的颜色
|
|
59
|
+
* @returns marker 配置
|
|
60
|
+
*/
|
|
61
|
+
declare function getArrowMarker(color?: string): MarkerProps;
|
|
62
|
+
/**
|
|
63
|
+
* 创建一个实心箭头 marker
|
|
64
|
+
* @param color - marker 的颜色
|
|
65
|
+
* @returns marker 配置
|
|
66
|
+
*/
|
|
67
|
+
declare function getArrowClosedMarker(color?: string): MarkerProps;
|
|
68
|
+
/**
|
|
69
|
+
* 创建自定义 marker
|
|
70
|
+
* @param type - marker 类型
|
|
71
|
+
* @param options - marker 选项
|
|
72
|
+
* @returns marker 配置
|
|
73
|
+
*/
|
|
74
|
+
declare function getCustomMarker(type: string, options?: Omit<Partial<MarkerProps>, 'id' | 'type'>): MarkerProps;
|
|
75
|
+
/**
|
|
76
|
+
* 创建两个实心箭头作为起点和终点的marker
|
|
77
|
+
* @param color - marker 的颜色
|
|
78
|
+
* @returns 包含开始和结束marker的对象
|
|
79
|
+
*/
|
|
80
|
+
declare function getArrowHeadMarkers(color?: string): {
|
|
81
|
+
markerStart: MarkerProps;
|
|
82
|
+
markerEnd: MarkerProps;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Marker 注册表组件,可以集中管理并重用 marker
|
|
86
|
+
*/
|
|
87
|
+
interface MarkerDefinitionsProps {
|
|
88
|
+
markers: MarkerProps[];
|
|
89
|
+
}
|
|
90
|
+
declare function MarkerDefinitions({ markers }: MarkerDefinitionsProps): JSX.Element;
|
|
91
|
+
|
|
92
|
+
interface StraightEdgeOptions extends EdgeProps, Omit<BaseEdgeProps, 'pathBuilder'> {
|
|
93
|
+
}
|
|
94
|
+
declare function StraightEdge({ edge: _edge, ...rest }: StraightEdgeOptions): JSX.Element;
|
|
9
95
|
|
|
10
|
-
export { BezierEdge, type BezierEdgeOptions, StraightEdge };
|
|
96
|
+
export { BezierEdge, type BezierEdgeOptions, MarkerDefinitions, type MarkerDefinitionsProps, MarkerType, StraightEdge, type StraightEdgeOptions, getArrowClosedMarker, getArrowHeadMarkers, getArrowMarker, getCustomMarker };
|
package/dist/index.mjs
CHANGED
|
@@ -1,45 +1,417 @@
|
|
|
1
|
-
import { jsx } from '@knotx/jsx/jsx-runtime';
|
|
1
|
+
import { jsxs, Fragment, jsx } from '@knotx/jsx/jsx-runtime';
|
|
2
|
+
import { bem } from '@knotx/core';
|
|
3
|
+
import * as BezierJS from 'bezier-js';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
var MarkerType = /* @__PURE__ */ ((MarkerType2) => {
|
|
6
|
+
MarkerType2["Arrow"] = "arrow";
|
|
7
|
+
MarkerType2["ArrowClosed"] = "arrowclosed";
|
|
8
|
+
return MarkerType2;
|
|
9
|
+
})(MarkerType || {});
|
|
10
|
+
function BaseEdge({
|
|
11
|
+
pathBuilder: PathBuilder,
|
|
4
12
|
sourceX,
|
|
5
13
|
sourceY,
|
|
6
14
|
targetX,
|
|
7
15
|
targetY,
|
|
8
|
-
|
|
16
|
+
interactionWidth = 20,
|
|
17
|
+
label,
|
|
18
|
+
markerEnd,
|
|
19
|
+
markerStart
|
|
9
20
|
}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
controlPoint2X = targetX - midX;
|
|
19
|
-
controlPoint2Y = targetY;
|
|
20
|
-
}
|
|
21
|
-
const path = `M ${sourceX} ${sourceY} C ${controlPoint1X} ${controlPoint1Y}, ${controlPoint2X} ${controlPoint2Y}, ${targetX} ${targetY}`;
|
|
22
|
-
return /* @__PURE__ */ jsx(
|
|
23
|
-
"path",
|
|
24
|
-
{
|
|
25
|
-
d: path,
|
|
26
|
-
fill: "none",
|
|
27
|
-
stroke: "currentColor"
|
|
21
|
+
const path = new PathBuilder(sourceX, sourceY, targetX, targetY);
|
|
22
|
+
const pathString = path.buildPath();
|
|
23
|
+
const labelPosition = label ? path.interpolate(0.5) : void 0;
|
|
24
|
+
const getMarkerUrl = (marker) => {
|
|
25
|
+
if (!marker)
|
|
26
|
+
return void 0;
|
|
27
|
+
if (typeof marker === "string") {
|
|
28
|
+
return `url(#${marker})`;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
return `url(#${marker.id})`;
|
|
31
|
+
};
|
|
32
|
+
const markerEndUrl = getMarkerUrl(markerEnd);
|
|
33
|
+
const markerStartUrl = getMarkerUrl(markerStart);
|
|
34
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
+
/* @__PURE__ */ jsxs(
|
|
36
|
+
"svg",
|
|
37
|
+
{
|
|
38
|
+
className: bem("edge", "wrapper"),
|
|
39
|
+
style: {
|
|
40
|
+
position: "absolute",
|
|
41
|
+
left: 0,
|
|
42
|
+
top: 0,
|
|
43
|
+
overflow: "visible",
|
|
44
|
+
pointerEvents: "none",
|
|
45
|
+
stroke: "currentColor"
|
|
46
|
+
},
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
49
|
+
markerEnd && typeof markerEnd === "object" && /* @__PURE__ */ jsxs(
|
|
50
|
+
"marker",
|
|
51
|
+
{
|
|
52
|
+
id: markerEnd.id,
|
|
53
|
+
markerWidth: markerEnd.width || 10,
|
|
54
|
+
markerHeight: markerEnd.height || 10,
|
|
55
|
+
refX: markerEnd.width || 10,
|
|
56
|
+
refY: (markerEnd.height || 10) / 2,
|
|
57
|
+
markerUnits: markerEnd.markerUnits || "strokeWidth",
|
|
58
|
+
orient: markerEnd.orient || "auto",
|
|
59
|
+
children: [
|
|
60
|
+
markerEnd.type === "arrow" /* Arrow */ && /* @__PURE__ */ jsx(
|
|
61
|
+
"path",
|
|
62
|
+
{
|
|
63
|
+
d: "M 0 0 L 10 5 L 0 10",
|
|
64
|
+
fill: "none",
|
|
65
|
+
stroke: markerEnd.color || "currentColor",
|
|
66
|
+
strokeWidth: markerEnd.strokeWidth || 1
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
markerEnd.type === "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsx(
|
|
70
|
+
"path",
|
|
71
|
+
{
|
|
72
|
+
d: "M 0 0 L 10 5 L 0 10 z",
|
|
73
|
+
fill: markerEnd.color || "currentColor",
|
|
74
|
+
stroke: markerEnd.color || "currentColor",
|
|
75
|
+
strokeWidth: markerEnd.strokeWidth || 1
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
markerEnd.type !== "arrow" /* Arrow */ && markerEnd.type !== "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsx(
|
|
79
|
+
"path",
|
|
80
|
+
{
|
|
81
|
+
d: "M 0 0 L 10 5 L 0 10",
|
|
82
|
+
fill: "none",
|
|
83
|
+
stroke: markerEnd.color || "currentColor",
|
|
84
|
+
strokeWidth: markerEnd.strokeWidth || 1
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
markerStart && typeof markerStart === "object" && /* @__PURE__ */ jsxs(
|
|
91
|
+
"marker",
|
|
92
|
+
{
|
|
93
|
+
id: markerStart.id,
|
|
94
|
+
markerWidth: markerStart.width || 10,
|
|
95
|
+
markerHeight: markerStart.height || 10,
|
|
96
|
+
refX: 0,
|
|
97
|
+
refY: (markerStart.height || 10) / 2,
|
|
98
|
+
markerUnits: markerStart.markerUnits || "strokeWidth",
|
|
99
|
+
orient: markerStart.orient || "auto",
|
|
100
|
+
children: [
|
|
101
|
+
markerStart.type === "arrow" /* Arrow */ && /* @__PURE__ */ jsx(
|
|
102
|
+
"path",
|
|
103
|
+
{
|
|
104
|
+
d: "M 10 0 L 0 5 L 10 10",
|
|
105
|
+
fill: "none",
|
|
106
|
+
stroke: markerStart.color || "currentColor",
|
|
107
|
+
strokeWidth: markerStart.strokeWidth || 1
|
|
108
|
+
}
|
|
109
|
+
),
|
|
110
|
+
markerStart.type === "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsx(
|
|
111
|
+
"path",
|
|
112
|
+
{
|
|
113
|
+
d: "M 10 0 L 0 5 L 10 10 z",
|
|
114
|
+
fill: markerStart.color || "currentColor",
|
|
115
|
+
stroke: markerStart.color || "currentColor",
|
|
116
|
+
strokeWidth: markerStart.strokeWidth || 1
|
|
117
|
+
}
|
|
118
|
+
),
|
|
119
|
+
markerStart.type !== "arrow" /* Arrow */ && markerStart.type !== "arrowclosed" /* ArrowClosed */ && /* @__PURE__ */ jsx(
|
|
120
|
+
"path",
|
|
121
|
+
{
|
|
122
|
+
d: "M 10 0 L 0 5 L 10 10",
|
|
123
|
+
fill: "none",
|
|
124
|
+
stroke: markerStart.color || "currentColor",
|
|
125
|
+
strokeWidth: markerStart.strokeWidth || 1
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ jsx(
|
|
133
|
+
"path",
|
|
134
|
+
{
|
|
135
|
+
d: pathString,
|
|
136
|
+
fill: "none",
|
|
137
|
+
className: bem("edge", "path"),
|
|
138
|
+
markerEnd: markerEndUrl,
|
|
139
|
+
markerStart: markerStartUrl
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
interactionWidth && /* @__PURE__ */ jsx(
|
|
143
|
+
"path",
|
|
144
|
+
{
|
|
145
|
+
d: pathString,
|
|
146
|
+
fill: "none",
|
|
147
|
+
strokeOpacity: 0,
|
|
148
|
+
strokeWidth: interactionWidth,
|
|
149
|
+
className: bem("edge", "interaction")
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
),
|
|
155
|
+
label && labelPosition && /* @__PURE__ */ jsx(
|
|
156
|
+
"div",
|
|
157
|
+
{
|
|
158
|
+
style: {
|
|
159
|
+
position: "absolute",
|
|
160
|
+
left: labelPosition.x,
|
|
161
|
+
top: labelPosition.y,
|
|
162
|
+
transform: "translate(-50%, -50%)"
|
|
163
|
+
},
|
|
164
|
+
children: label
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
] });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var __defProp$3 = Object.defineProperty;
|
|
171
|
+
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);
|
|
173
|
+
class PathBuilder {
|
|
174
|
+
constructor(sourceX, sourceY, targetX, targetY) {
|
|
175
|
+
this.sourceX = sourceX;
|
|
176
|
+
this.sourceY = sourceY;
|
|
177
|
+
this.targetX = targetX;
|
|
178
|
+
this.targetY = targetY;
|
|
179
|
+
this.sourceX = sourceX;
|
|
180
|
+
this.sourceY = sourceY;
|
|
181
|
+
this.targetX = targetX;
|
|
182
|
+
this.targetY = targetY;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
class StraightPathBuilder extends PathBuilder {
|
|
186
|
+
constructor() {
|
|
187
|
+
super(...arguments);
|
|
188
|
+
__publicField(this, "type", "straight");
|
|
189
|
+
}
|
|
190
|
+
buildPath() {
|
|
191
|
+
return `M ${this.sourceX} ${this.sourceY} L ${this.targetX} ${this.targetY}`;
|
|
192
|
+
}
|
|
193
|
+
interpolate(t) {
|
|
194
|
+
return { x: this.sourceX + t * (this.targetX - this.sourceX), y: this.sourceY + t * (this.targetY - this.sourceY) };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
class BezierPathBuilder extends PathBuilder {
|
|
198
|
+
constructor() {
|
|
199
|
+
super(...arguments);
|
|
200
|
+
__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
|
+
);
|
|
218
|
+
}
|
|
219
|
+
buildPath() {
|
|
220
|
+
const bezier = this.getBezierInstance();
|
|
221
|
+
return bezier.toSVG();
|
|
222
|
+
}
|
|
223
|
+
interpolate(t) {
|
|
224
|
+
const bezier = this.getBezierInstance();
|
|
225
|
+
const point = bezier.get(t);
|
|
226
|
+
return { x: point.x, y: point.y };
|
|
227
|
+
}
|
|
30
228
|
}
|
|
31
229
|
|
|
32
|
-
|
|
230
|
+
var __defProp$2 = Object.defineProperty;
|
|
231
|
+
var __defProps$1 = Object.defineProperties;
|
|
232
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
233
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
234
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
235
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
236
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
237
|
+
var __spreadValues$2 = (a, b) => {
|
|
238
|
+
for (var prop in b || (b = {}))
|
|
239
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
240
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
241
|
+
if (__getOwnPropSymbols$2)
|
|
242
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
243
|
+
if (__propIsEnum$2.call(b, prop))
|
|
244
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
245
|
+
}
|
|
246
|
+
return a;
|
|
247
|
+
};
|
|
248
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
249
|
+
var __objRest$1 = (source, exclude) => {
|
|
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
|
+
]);
|
|
33
267
|
return /* @__PURE__ */ jsx(
|
|
34
|
-
|
|
268
|
+
BaseEdge,
|
|
269
|
+
__spreadProps$1(__spreadValues$2({}, rest), {
|
|
270
|
+
pathBuilder: BezierPathBuilder
|
|
271
|
+
})
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
var __defProp$1 = Object.defineProperty;
|
|
276
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
277
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
278
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
279
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
280
|
+
var __spreadValues$1 = (a, b) => {
|
|
281
|
+
for (var prop in b || (b = {}))
|
|
282
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
283
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
284
|
+
if (__getOwnPropSymbols$1)
|
|
285
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
286
|
+
if (__propIsEnum$1.call(b, prop))
|
|
287
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
288
|
+
}
|
|
289
|
+
return a;
|
|
290
|
+
};
|
|
291
|
+
let markerCounter = 0;
|
|
292
|
+
function getArrowMarker(color) {
|
|
293
|
+
const id = `arrow-${markerCounter++}`;
|
|
294
|
+
return {
|
|
295
|
+
id,
|
|
296
|
+
type: MarkerType.Arrow,
|
|
297
|
+
color,
|
|
298
|
+
width: 10,
|
|
299
|
+
height: 10
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function getArrowClosedMarker(color) {
|
|
303
|
+
const id = `arrowclosed-${markerCounter++}`;
|
|
304
|
+
return {
|
|
305
|
+
id,
|
|
306
|
+
type: MarkerType.ArrowClosed,
|
|
307
|
+
color,
|
|
308
|
+
width: 10,
|
|
309
|
+
height: 10
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function getCustomMarker(type, options = {}) {
|
|
313
|
+
const id = `custom-${type}-${markerCounter++}`;
|
|
314
|
+
return __spreadValues$1({
|
|
315
|
+
id,
|
|
316
|
+
type
|
|
317
|
+
}, options);
|
|
318
|
+
}
|
|
319
|
+
function getArrowHeadMarkers(color) {
|
|
320
|
+
const markerStart = getArrowClosedMarker(color);
|
|
321
|
+
const markerEnd = getArrowClosedMarker(color);
|
|
322
|
+
return {
|
|
323
|
+
markerStart,
|
|
324
|
+
markerEnd
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function MarkerDefinitions({ markers }) {
|
|
328
|
+
return /* @__PURE__ */ jsx("defs", { children: markers.map((marker) => /* @__PURE__ */ jsxs(
|
|
329
|
+
"marker",
|
|
35
330
|
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
331
|
+
id: marker.id,
|
|
332
|
+
markerWidth: marker.width || 10,
|
|
333
|
+
markerHeight: marker.height || 10,
|
|
334
|
+
refX: marker.type.includes("start") ? 0 : marker.width || 10,
|
|
335
|
+
refY: (marker.height || 10) / 2,
|
|
336
|
+
markerUnits: marker.markerUnits || "strokeWidth",
|
|
337
|
+
orient: marker.orient || "auto",
|
|
338
|
+
children: [
|
|
339
|
+
marker.type === MarkerType.Arrow && /* @__PURE__ */ jsx(
|
|
340
|
+
"path",
|
|
341
|
+
{
|
|
342
|
+
d: marker.type.includes("start") ? "M 10 0 L 0 5 L 10 10" : "M 0 0 L 10 5 L 0 10",
|
|
343
|
+
fill: "none",
|
|
344
|
+
stroke: marker.color || "currentColor",
|
|
345
|
+
strokeWidth: marker.strokeWidth || 1
|
|
346
|
+
}
|
|
347
|
+
),
|
|
348
|
+
marker.type === MarkerType.ArrowClosed && /* @__PURE__ */ jsx(
|
|
349
|
+
"path",
|
|
350
|
+
{
|
|
351
|
+
d: marker.type.includes("start") ? "M 10 0 L 0 5 L 10 10 z" : "M 0 0 L 10 5 L 0 10 z",
|
|
352
|
+
fill: marker.color || "currentColor",
|
|
353
|
+
stroke: marker.color || "currentColor",
|
|
354
|
+
strokeWidth: marker.strokeWidth || 1
|
|
355
|
+
}
|
|
356
|
+
),
|
|
357
|
+
marker.type !== MarkerType.Arrow && marker.type !== MarkerType.ArrowClosed && /* @__PURE__ */ jsx(
|
|
358
|
+
"path",
|
|
359
|
+
{
|
|
360
|
+
d: marker.type.includes("start") ? "M 10 0 L 0 5 L 10 10" : "M 0 0 L 10 5 L 0 10",
|
|
361
|
+
fill: "none",
|
|
362
|
+
stroke: marker.color || "currentColor",
|
|
363
|
+
strokeWidth: marker.strokeWidth || 1
|
|
364
|
+
}
|
|
365
|
+
)
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
marker.id
|
|
369
|
+
)) });
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
var __defProp = Object.defineProperty;
|
|
373
|
+
var __defProps = Object.defineProperties;
|
|
374
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
375
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
376
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
377
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
378
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
379
|
+
var __spreadValues = (a, b) => {
|
|
380
|
+
for (var prop in b || (b = {}))
|
|
381
|
+
if (__hasOwnProp.call(b, prop))
|
|
382
|
+
__defNormalProp(a, prop, b[prop]);
|
|
383
|
+
if (__getOwnPropSymbols)
|
|
384
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
385
|
+
if (__propIsEnum.call(b, prop))
|
|
386
|
+
__defNormalProp(a, prop, b[prop]);
|
|
387
|
+
}
|
|
388
|
+
return a;
|
|
389
|
+
};
|
|
390
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
391
|
+
var __objRest = (source, exclude) => {
|
|
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];
|
|
41
400
|
}
|
|
401
|
+
return target;
|
|
402
|
+
};
|
|
403
|
+
function StraightEdge(_a) {
|
|
404
|
+
var _b = _a, {
|
|
405
|
+
edge: _edge
|
|
406
|
+
} = _b, rest = __objRest(_b, [
|
|
407
|
+
"edge"
|
|
408
|
+
]);
|
|
409
|
+
return /* @__PURE__ */ jsx(
|
|
410
|
+
BaseEdge,
|
|
411
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
412
|
+
pathBuilder: StraightPathBuilder
|
|
413
|
+
})
|
|
42
414
|
);
|
|
43
415
|
}
|
|
44
416
|
|
|
45
|
-
export { BezierEdge, StraightEdge };
|
|
417
|
+
export { BezierEdge, MarkerDefinitions, MarkerType, StraightEdge, 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.5",
|
|
5
5
|
"description": "Render for Knotx",
|
|
6
6
|
"author": "boenfu",
|
|
7
7
|
"license": "MIT",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"directory": "packages/data"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
|
-
"access": "public"
|
|
16
|
-
"registry": "https://registry.npmjs.org/"
|
|
15
|
+
"access": "public"
|
|
17
16
|
},
|
|
18
17
|
"sideEffects": false,
|
|
19
18
|
"exports": {
|
|
@@ -30,13 +29,15 @@
|
|
|
30
29
|
"dist"
|
|
31
30
|
],
|
|
32
31
|
"dependencies": {
|
|
33
|
-
"
|
|
32
|
+
"bezier-js": "^6.1.4",
|
|
33
|
+
"@knotx/core": "0.0.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@knotx/build-config": "0.0.
|
|
38
|
-
"@knotx/
|
|
39
|
-
"@knotx/
|
|
36
|
+
"@types/bezier-js": "^4.1.3",
|
|
37
|
+
"@knotx/build-config": "0.0.5",
|
|
38
|
+
"@knotx/eslint-config": "0.0.5",
|
|
39
|
+
"@knotx/jsx": "0.0.5",
|
|
40
|
+
"@knotx/typescript-config": "0.0.5"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "unbuild --failOnWarn=false",
|