@knotx/plugins-minimap 0.0.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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/index.cjs +527 -0
- package/dist/index.d.cts +146 -0
- package/dist/index.d.mts +146 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.mjs +521 -0
- package/package.json +57 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { jsxs, jsx } from '@knotx/jsx/jsx-runtime';
|
|
2
|
+
import { bem, use, BasePlugin } from '@knotx/core';
|
|
3
|
+
import { inject, panel, OnInit, OnDestroy } from '@knotx/decorators';
|
|
4
|
+
import interact from 'interactjs';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
6
|
+
import { switchMap, map, tap, takeUntil } from 'rxjs/operators';
|
|
7
|
+
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defProps = Object.defineProperties;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
13
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
14
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
16
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
17
|
+
var __typeError = (msg) => {
|
|
18
|
+
throw TypeError(msg);
|
|
19
|
+
};
|
|
20
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
21
|
+
var __spreadValues = (a, b) => {
|
|
22
|
+
for (var prop in b || (b = {}))
|
|
23
|
+
if (__hasOwnProp.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
if (__getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
27
|
+
if (__propIsEnum.call(b, prop))
|
|
28
|
+
__defNormalProp(a, prop, b[prop]);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
};
|
|
32
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
33
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
34
|
+
var __decoratorStart = (base) => {
|
|
35
|
+
var _a2;
|
|
36
|
+
return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
|
|
37
|
+
};
|
|
38
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
39
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
40
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
41
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
42
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
43
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
44
|
+
return value;
|
|
45
|
+
};
|
|
46
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
47
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
48
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
49
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
50
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
51
|
+
return __privateGet(this, extra);
|
|
52
|
+
}, set [name](x) {
|
|
53
|
+
return __privateSet(this, extra, x);
|
|
54
|
+
} }, name));
|
|
55
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
56
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
57
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
58
|
+
if (k) {
|
|
59
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
60
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
61
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
62
|
+
}
|
|
63
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
64
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
65
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
66
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
67
|
+
}
|
|
68
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
69
|
+
};
|
|
70
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
71
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
72
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
73
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
74
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
75
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
76
|
+
var _render_dec, _destroy_dec, _init_dec, _nodes_dec, _canvasRef_dec, _transform_dec, _container_dec, _a, _init;
|
|
77
|
+
const defaultProps = {
|
|
78
|
+
width: 200,
|
|
79
|
+
height: 150,
|
|
80
|
+
maskColor: "rgba(240, 240, 240, 0.6)",
|
|
81
|
+
viewBoxColor: "#4752E6",
|
|
82
|
+
showControls: true,
|
|
83
|
+
zoomable: true,
|
|
84
|
+
pannable: true,
|
|
85
|
+
padding: 12,
|
|
86
|
+
nodeBorderRadius: 2,
|
|
87
|
+
nodeStrokeWidth: 1,
|
|
88
|
+
zoomStep: 0.2
|
|
89
|
+
};
|
|
90
|
+
function getNodesBounds(nodes) {
|
|
91
|
+
var _a2, _b;
|
|
92
|
+
if (!nodes.length)
|
|
93
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
94
|
+
let minX = Infinity;
|
|
95
|
+
let minY = Infinity;
|
|
96
|
+
let maxX = -Infinity;
|
|
97
|
+
let maxY = -Infinity;
|
|
98
|
+
for (const node of nodes) {
|
|
99
|
+
const { x, y } = node.position;
|
|
100
|
+
const width = ((_a2 = node.measured) == null ? void 0 : _a2.width) || 0;
|
|
101
|
+
const height = ((_b = node.measured) == null ? void 0 : _b.height) || 0;
|
|
102
|
+
minX = Math.min(minX, x);
|
|
103
|
+
minY = Math.min(minY, y);
|
|
104
|
+
maxX = Math.max(maxX, x + width);
|
|
105
|
+
maxY = Math.max(maxY, y + height);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
x: minX,
|
|
109
|
+
y: minY,
|
|
110
|
+
width: maxX - minX,
|
|
111
|
+
height: maxY - minY
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function getBoundsOfRects(bounds1, bounds2) {
|
|
115
|
+
const minX = Math.min(bounds1.x, bounds2.x);
|
|
116
|
+
const minY = Math.min(bounds1.y, bounds2.y);
|
|
117
|
+
const maxX = Math.max(bounds1.x + bounds1.width, bounds2.x + bounds2.width);
|
|
118
|
+
const maxY = Math.max(bounds1.y + bounds1.height, bounds2.y + bounds2.height);
|
|
119
|
+
return {
|
|
120
|
+
x: minX,
|
|
121
|
+
y: minY,
|
|
122
|
+
width: maxX - minX,
|
|
123
|
+
height: maxY - minY
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _transform_dec = [inject.canvas.transform()], _canvasRef_dec = [inject.canvas.ref()], _nodes_dec = [inject.nodes()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _render_dec = [panel("right-bottom")], _a) {
|
|
127
|
+
constructor(props = {}) {
|
|
128
|
+
super();
|
|
129
|
+
this.props = props;
|
|
130
|
+
__runInitializers(_init, 5, this);
|
|
131
|
+
__publicField(this, "name", "minimap");
|
|
132
|
+
__publicField(this, "options");
|
|
133
|
+
__publicField(this, "subscription");
|
|
134
|
+
__publicField(this, "currentInteractable");
|
|
135
|
+
__publicField(this, "dragStart$", new Subject());
|
|
136
|
+
__publicField(this, "dragMove$", new Subject());
|
|
137
|
+
__publicField(this, "dragEnd$", new Subject());
|
|
138
|
+
__publicField(this, "container", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
139
|
+
__publicField(this, "transform", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
140
|
+
__publicField(this, "canvasRef", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
|
|
141
|
+
__publicField(this, "nodes", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
|
|
142
|
+
/**
|
|
143
|
+
* 处理小地图上的点击事件,移动视图
|
|
144
|
+
*/
|
|
145
|
+
__publicField(this, "handleMinimapClick", (event) => {
|
|
146
|
+
if (!this.options.pannable || !this.canvasRef)
|
|
147
|
+
return;
|
|
148
|
+
const svg = event.currentTarget;
|
|
149
|
+
const svgRect = svg.getBoundingClientRect();
|
|
150
|
+
const { left, top } = svgRect;
|
|
151
|
+
const svgPoint = {
|
|
152
|
+
x: event.clientX - left,
|
|
153
|
+
y: event.clientY - top
|
|
154
|
+
};
|
|
155
|
+
const { pointX, pointY } = this.getSvgToGraphCoordinates(svgPoint, svgRect);
|
|
156
|
+
const { scale } = this.transform;
|
|
157
|
+
const newPositionX = -pointX * scale + this.container.width / 2;
|
|
158
|
+
const newPositionY = -pointY * scale + this.container.height / 2;
|
|
159
|
+
this.canvasRef.setTransform(newPositionX, newPositionY, scale, 300);
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* 处理缩放按钮点击事件
|
|
163
|
+
*/
|
|
164
|
+
__publicField(this, "handleZoom", (isZoomIn) => {
|
|
165
|
+
if (!this.options.zoomable || !this.canvasRef)
|
|
166
|
+
return;
|
|
167
|
+
const step = this.options.zoomStep;
|
|
168
|
+
if (isZoomIn) {
|
|
169
|
+
this.canvasRef.zoomIn(step, 300);
|
|
170
|
+
} else {
|
|
171
|
+
this.canvasRef.zoomOut(step, 300);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
/**
|
|
175
|
+
* 重置视图
|
|
176
|
+
*/
|
|
177
|
+
__publicField(this, "handleReset", () => {
|
|
178
|
+
if (!this.canvasRef)
|
|
179
|
+
return;
|
|
180
|
+
this.canvasRef.resetTransform(300);
|
|
181
|
+
});
|
|
182
|
+
this.options = __spreadProps(__spreadValues(__spreadValues({}, defaultProps), props), {
|
|
183
|
+
nodeColor: props.nodeColor || "#AB7BFE",
|
|
184
|
+
nodeStrokeColor: props.nodeStrokeColor || "transparent"
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
get classNames() {
|
|
188
|
+
return {
|
|
189
|
+
wrapper: bem(this.name, "wrapper"),
|
|
190
|
+
svg: bem(this.name, "svg"),
|
|
191
|
+
viewBox: bem(this.name, "view-box"),
|
|
192
|
+
mask: bem(this.name, "mask"),
|
|
193
|
+
node: bem(this.name, "node"),
|
|
194
|
+
control: bem(this.name, "control"),
|
|
195
|
+
zoomIn: bem(this.name, "zoom-in"),
|
|
196
|
+
zoomOut: bem(this.name, "zoom-out"),
|
|
197
|
+
reset: bem(this.name, "reset")
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* 计算视图变换和缩放
|
|
202
|
+
*/
|
|
203
|
+
getViewTransform() {
|
|
204
|
+
const nodesBounds = getNodesBounds(this.nodes);
|
|
205
|
+
const viewRect = {
|
|
206
|
+
x: -this.transform.positionX / this.transform.scale,
|
|
207
|
+
y: -this.transform.positionY / this.transform.scale,
|
|
208
|
+
width: this.container.width / this.transform.scale,
|
|
209
|
+
height: this.container.height / this.transform.scale
|
|
210
|
+
};
|
|
211
|
+
const boundingRect = this.nodes.length > 0 ? getBoundsOfRects(nodesBounds, viewRect) : viewRect;
|
|
212
|
+
const { width: elementWidth, height: elementHeight } = this.options;
|
|
213
|
+
const scaledWidth = boundingRect.width / elementWidth;
|
|
214
|
+
const scaledHeight = boundingRect.height / elementHeight;
|
|
215
|
+
const viewScale = Math.max(scaledWidth, scaledHeight, 0.1);
|
|
216
|
+
const viewWidth = viewScale * elementWidth;
|
|
217
|
+
const viewHeight = viewScale * elementHeight;
|
|
218
|
+
const offset = this.options.padding * viewScale;
|
|
219
|
+
const x = boundingRect.x - (viewWidth - boundingRect.width) / 2 - offset;
|
|
220
|
+
const y = boundingRect.y - (viewHeight - boundingRect.height) / 2 - offset;
|
|
221
|
+
const width = viewWidth + offset * 2;
|
|
222
|
+
const height = viewHeight + offset * 2;
|
|
223
|
+
return {
|
|
224
|
+
viewRect,
|
|
225
|
+
boundingRect,
|
|
226
|
+
offset,
|
|
227
|
+
viewBox: `${x} ${y} ${width} ${height}`,
|
|
228
|
+
viewScale,
|
|
229
|
+
x,
|
|
230
|
+
y,
|
|
231
|
+
width,
|
|
232
|
+
height
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 计算节点颜色
|
|
237
|
+
*/
|
|
238
|
+
getNodeColor(node) {
|
|
239
|
+
const { nodeColor } = this.options;
|
|
240
|
+
return typeof nodeColor === "function" ? nodeColor(node) : nodeColor;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 计算节点边框颜色
|
|
244
|
+
*/
|
|
245
|
+
getNodeStrokeColor(node) {
|
|
246
|
+
const { nodeStrokeColor } = this.options;
|
|
247
|
+
return typeof nodeStrokeColor === "function" ? nodeStrokeColor(node) : nodeStrokeColor;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 从SVG坐标转换为流程图坐标
|
|
251
|
+
*/
|
|
252
|
+
getSvgToGraphCoordinates(svgPoint, svgRect) {
|
|
253
|
+
const transform = this.getViewTransform();
|
|
254
|
+
const relativeX = svgPoint.x / svgRect.width;
|
|
255
|
+
const relativeY = svgPoint.y / svgRect.height;
|
|
256
|
+
const pointX = transform.x + relativeX * transform.width;
|
|
257
|
+
const pointY = transform.y + relativeY * transform.height;
|
|
258
|
+
return { pointX, pointY };
|
|
259
|
+
}
|
|
260
|
+
init() {
|
|
261
|
+
this.setupDragStream();
|
|
262
|
+
this.setupInteractable();
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* 设置拖拽流
|
|
266
|
+
*/
|
|
267
|
+
setupDragStream() {
|
|
268
|
+
this.subscription = this.dragStart$.pipe(
|
|
269
|
+
// 对每次拖拽开始事件,创建一个新的拖拽流程
|
|
270
|
+
switchMap((startEvent) => {
|
|
271
|
+
const { startPositionX, startPositionY } = startEvent;
|
|
272
|
+
const viewTransform = this.getViewTransform();
|
|
273
|
+
const moveFactorX = this.transform.scale / viewTransform.viewScale;
|
|
274
|
+
const moveFactorY = this.transform.scale / viewTransform.viewScale;
|
|
275
|
+
let newPositionX = startPositionX;
|
|
276
|
+
let newPositionY = startPositionY;
|
|
277
|
+
return this.dragMove$.pipe(
|
|
278
|
+
// 计算新的位置
|
|
279
|
+
map((moveEvent) => {
|
|
280
|
+
const deltaX = moveEvent.dx / moveFactorX;
|
|
281
|
+
const deltaY = moveEvent.dy / moveFactorY;
|
|
282
|
+
newPositionX -= deltaX;
|
|
283
|
+
newPositionY -= deltaY;
|
|
284
|
+
return { newPositionX, newPositionY };
|
|
285
|
+
}),
|
|
286
|
+
// 实时更新位置
|
|
287
|
+
tap(({ newPositionX: newPositionX2, newPositionY: newPositionY2 }) => {
|
|
288
|
+
if (!this.canvasRef)
|
|
289
|
+
return;
|
|
290
|
+
this.canvasRef.setTransform(newPositionX2, newPositionY2, this.transform.scale, 0);
|
|
291
|
+
}),
|
|
292
|
+
// 直到拖拽结束
|
|
293
|
+
takeUntil(this.dragEnd$)
|
|
294
|
+
);
|
|
295
|
+
})
|
|
296
|
+
).subscribe();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* 初始化 interact.js 的拖拽功能
|
|
300
|
+
*/
|
|
301
|
+
setupInteractable() {
|
|
302
|
+
if (this.currentInteractable)
|
|
303
|
+
return;
|
|
304
|
+
this.currentInteractable = interact(`.${this.classNames.viewBox}[data-plugin-id="${this.pluginId}"]`).draggable({
|
|
305
|
+
listeners: {
|
|
306
|
+
// 开始拖拽时,记录初始状态
|
|
307
|
+
start: (event) => {
|
|
308
|
+
if (!this.canvasRef)
|
|
309
|
+
return;
|
|
310
|
+
this.dragStart$.next({
|
|
311
|
+
x: event.clientX,
|
|
312
|
+
y: event.clientY,
|
|
313
|
+
startPositionX: this.transform.positionX,
|
|
314
|
+
startPositionY: this.transform.positionY
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
// 拖拽过程中,发送位移信息
|
|
318
|
+
move: (event) => {
|
|
319
|
+
this.dragMove$.next({
|
|
320
|
+
dx: event.dx,
|
|
321
|
+
dy: event.dy
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
// 拖拽结束
|
|
325
|
+
end: () => {
|
|
326
|
+
this.dragEnd$.next();
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
cursorChecker: () => "move"
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
destroy() {
|
|
333
|
+
var _a2, _b;
|
|
334
|
+
(_a2 = this.subscription) == null ? void 0 : _a2.unsubscribe();
|
|
335
|
+
(_b = this.currentInteractable) == null ? void 0 : _b.unset();
|
|
336
|
+
this.dragStart$.complete();
|
|
337
|
+
this.dragMove$.complete();
|
|
338
|
+
this.dragEnd$.complete();
|
|
339
|
+
}
|
|
340
|
+
render() {
|
|
341
|
+
const { wrapper, svg, mask, control, zoomIn, zoomOut, reset, viewBox } = this.classNames;
|
|
342
|
+
const { width, height, viewBoxColor, maskColor, showControls, nodeBorderRadius, nodeStrokeWidth } = this.options;
|
|
343
|
+
const container = use(() => this.container);
|
|
344
|
+
const transform = use(() => this.transform);
|
|
345
|
+
const nodes = use(() => this.nodes);
|
|
346
|
+
if (!container || !transform)
|
|
347
|
+
return null;
|
|
348
|
+
const viewTransform = this.getViewTransform();
|
|
349
|
+
const { viewBox: viewBoxAttr, viewRect } = viewTransform;
|
|
350
|
+
return /* @__PURE__ */ jsxs(
|
|
351
|
+
"div",
|
|
352
|
+
{
|
|
353
|
+
className: wrapper,
|
|
354
|
+
style: {
|
|
355
|
+
width,
|
|
356
|
+
height: height + (showControls ? 30 : 0),
|
|
357
|
+
background: "white",
|
|
358
|
+
borderRadius: "4px",
|
|
359
|
+
boxShadow: "0 2px 5px rgba(0, 0, 0, 0.1)",
|
|
360
|
+
display: "flex",
|
|
361
|
+
flexDirection: "column",
|
|
362
|
+
overflow: "hidden",
|
|
363
|
+
userSelect: "none"
|
|
364
|
+
},
|
|
365
|
+
children: [
|
|
366
|
+
/* @__PURE__ */ jsxs(
|
|
367
|
+
"svg",
|
|
368
|
+
{
|
|
369
|
+
className: svg,
|
|
370
|
+
width,
|
|
371
|
+
height,
|
|
372
|
+
viewBox: viewBoxAttr,
|
|
373
|
+
onClick: this.handleMinimapClick,
|
|
374
|
+
style: {
|
|
375
|
+
cursor: this.options.pannable ? "pointer" : "default",
|
|
376
|
+
userSelect: "none",
|
|
377
|
+
flexShrink: 0
|
|
378
|
+
},
|
|
379
|
+
children: [
|
|
380
|
+
nodes.map((node) => {
|
|
381
|
+
if (!node.measured)
|
|
382
|
+
return null;
|
|
383
|
+
const { x, y } = node.position;
|
|
384
|
+
const width2 = node.measured.width || 0;
|
|
385
|
+
const height2 = node.measured.height || 0;
|
|
386
|
+
return /* @__PURE__ */ jsx(
|
|
387
|
+
"rect",
|
|
388
|
+
{
|
|
389
|
+
className: this.classNames.node,
|
|
390
|
+
x,
|
|
391
|
+
y,
|
|
392
|
+
width: width2,
|
|
393
|
+
height: height2,
|
|
394
|
+
fill: this.getNodeColor(node),
|
|
395
|
+
stroke: this.getNodeStrokeColor(node),
|
|
396
|
+
strokeWidth: nodeStrokeWidth,
|
|
397
|
+
rx: nodeBorderRadius,
|
|
398
|
+
ry: nodeBorderRadius
|
|
399
|
+
},
|
|
400
|
+
node.id
|
|
401
|
+
);
|
|
402
|
+
}),
|
|
403
|
+
/* @__PURE__ */ jsx(
|
|
404
|
+
"path",
|
|
405
|
+
{
|
|
406
|
+
className: mask,
|
|
407
|
+
d: `M${viewTransform.x - viewTransform.offset},${viewTransform.y - viewTransform.offset}
|
|
408
|
+
h${viewTransform.width + viewTransform.offset * 2}
|
|
409
|
+
v${viewTransform.height + viewTransform.offset * 2}
|
|
410
|
+
h${-viewTransform.width - viewTransform.offset * 2}z
|
|
411
|
+
M${viewRect.x},${viewRect.y}
|
|
412
|
+
h${viewRect.width}
|
|
413
|
+
v${viewRect.height}
|
|
414
|
+
h${-viewRect.width}z`,
|
|
415
|
+
fill: maskColor,
|
|
416
|
+
fillRule: "evenodd",
|
|
417
|
+
pointerEvents: "none"
|
|
418
|
+
}
|
|
419
|
+
),
|
|
420
|
+
/* @__PURE__ */ jsx(
|
|
421
|
+
"rect",
|
|
422
|
+
{
|
|
423
|
+
className: viewBox,
|
|
424
|
+
"data-plugin-id": this.pluginId,
|
|
425
|
+
x: viewRect.x,
|
|
426
|
+
y: viewRect.y,
|
|
427
|
+
width: viewRect.width,
|
|
428
|
+
height: viewRect.height,
|
|
429
|
+
fill: "transparent",
|
|
430
|
+
stroke: viewBoxColor,
|
|
431
|
+
strokeWidth: 2,
|
|
432
|
+
style: {
|
|
433
|
+
cursor: "move",
|
|
434
|
+
pointerEvents: "all"
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
)
|
|
438
|
+
]
|
|
439
|
+
}
|
|
440
|
+
),
|
|
441
|
+
showControls && /* @__PURE__ */ jsxs(
|
|
442
|
+
"div",
|
|
443
|
+
{
|
|
444
|
+
className: control,
|
|
445
|
+
style: {
|
|
446
|
+
display: "flex",
|
|
447
|
+
justifyContent: "center",
|
|
448
|
+
alignItems: "center",
|
|
449
|
+
padding: "4px 0",
|
|
450
|
+
gap: "12px"
|
|
451
|
+
},
|
|
452
|
+
children: [
|
|
453
|
+
/* @__PURE__ */ jsx(
|
|
454
|
+
"button",
|
|
455
|
+
{
|
|
456
|
+
className: zoomIn,
|
|
457
|
+
onClick: () => this.handleZoom(true),
|
|
458
|
+
disabled: !this.options.zoomable,
|
|
459
|
+
style: {
|
|
460
|
+
border: "none",
|
|
461
|
+
background: "none",
|
|
462
|
+
cursor: this.options.zoomable ? "pointer" : "default",
|
|
463
|
+
fontSize: "16px",
|
|
464
|
+
color: "#555",
|
|
465
|
+
padding: "2px 6px"
|
|
466
|
+
},
|
|
467
|
+
children: "+"
|
|
468
|
+
}
|
|
469
|
+
),
|
|
470
|
+
/* @__PURE__ */ jsx(
|
|
471
|
+
"button",
|
|
472
|
+
{
|
|
473
|
+
className: zoomOut,
|
|
474
|
+
onClick: () => this.handleZoom(false),
|
|
475
|
+
disabled: !this.options.zoomable,
|
|
476
|
+
style: {
|
|
477
|
+
border: "none",
|
|
478
|
+
background: "none",
|
|
479
|
+
cursor: this.options.zoomable ? "pointer" : "default",
|
|
480
|
+
fontSize: "16px",
|
|
481
|
+
color: "#555",
|
|
482
|
+
padding: "2px 6px"
|
|
483
|
+
},
|
|
484
|
+
children: "-"
|
|
485
|
+
}
|
|
486
|
+
),
|
|
487
|
+
/* @__PURE__ */ jsx(
|
|
488
|
+
"button",
|
|
489
|
+
{
|
|
490
|
+
className: reset,
|
|
491
|
+
onClick: this.handleReset,
|
|
492
|
+
style: {
|
|
493
|
+
border: "none",
|
|
494
|
+
background: "none",
|
|
495
|
+
cursor: "pointer",
|
|
496
|
+
fontSize: "14px",
|
|
497
|
+
color: "#555",
|
|
498
|
+
padding: "2px 6px"
|
|
499
|
+
},
|
|
500
|
+
children: "reset"
|
|
501
|
+
}
|
|
502
|
+
)
|
|
503
|
+
]
|
|
504
|
+
}
|
|
505
|
+
)
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
_init = __decoratorStart(_a);
|
|
512
|
+
__decorateElement(_init, 1, "init", _init_dec, Minimap);
|
|
513
|
+
__decorateElement(_init, 1, "destroy", _destroy_dec, Minimap);
|
|
514
|
+
__decorateElement(_init, 1, "render", _render_dec, Minimap);
|
|
515
|
+
__decorateElement(_init, 5, "container", _container_dec, Minimap);
|
|
516
|
+
__decorateElement(_init, 5, "transform", _transform_dec, Minimap);
|
|
517
|
+
__decorateElement(_init, 5, "canvasRef", _canvasRef_dec, Minimap);
|
|
518
|
+
__decorateElement(_init, 5, "nodes", _nodes_dec, Minimap);
|
|
519
|
+
__decoratorMetadata(_init, Minimap);
|
|
520
|
+
|
|
521
|
+
export { Minimap };
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knotx/plugins-minimap",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "Minimap Plugin for Knotx",
|
|
6
|
+
"author": "boenfu",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/boenfu/knotx#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/boenfu/knotx.git",
|
|
12
|
+
"directory": "packages/plugins-minimap"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"interactjs": "^1.10.27"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@interactjs/actions": "^1.10.27",
|
|
36
|
+
"@interactjs/core": "^1.10.27",
|
|
37
|
+
"@interactjs/modifiers": "^1.10.27",
|
|
38
|
+
"@interactjs/types": "^1.10.27",
|
|
39
|
+
"rxjs": "^7.8.1",
|
|
40
|
+
"@knotx/core": "0.0.0",
|
|
41
|
+
"@knotx/decorators": "0.0.0",
|
|
42
|
+
"@knotx/plugins-canvas": "0.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"interactjs": "^1.10.27",
|
|
46
|
+
"@knotx/build-config": "0.0.0",
|
|
47
|
+
"@knotx/eslint-config": "0.0.0",
|
|
48
|
+
"@knotx/jsx": "0.0.0",
|
|
49
|
+
"@knotx/typescript-config": "0.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "unbuild --failOnWarn=false",
|
|
53
|
+
"dev": "unbuild --stub",
|
|
54
|
+
"lint": "eslint .",
|
|
55
|
+
"typecheck": "tsc --noEmit"
|
|
56
|
+
}
|
|
57
|
+
}
|