@knotx/plugins-minimap 0.0.6 → 0.0.7

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 CHANGED
@@ -130,12 +130,11 @@ function getBoundsOfRects(bounds1, bounds2) {
130
130
  };
131
131
  }
132
132
  class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject.container()], _transform_dec = [decorators.inject.canvas.transform()], _canvasRef_dec = [decorators.inject.canvas.ref()], _nodes_dec = [decorators.inject.nodes()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _render_dec = [decorators.panel("right-bottom")], _a) {
133
- constructor(props = {}) {
134
- super();
135
- this.props = props;
133
+ constructor() {
134
+ super(...arguments);
136
135
  __runInitializers(_init, 5, this);
137
136
  __publicField(this, "name", "minimap");
138
- __publicField(this, "options");
137
+ __publicField(this, "config");
139
138
  __publicField(this, "subscription");
140
139
  __publicField(this, "currentInteractable");
141
140
  __publicField(this, "dragStart$", new rxjs.Subject());
@@ -149,7 +148,7 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
149
148
  * 处理小地图上的点击事件,移动视图
150
149
  */
151
150
  __publicField(this, "handleMinimapClick", (event) => {
152
- if (!this.options.pannable || !this.canvasRef)
151
+ if (!this.config.pannable || !this.canvasRef)
153
152
  return;
154
153
  const svg = event.currentTarget;
155
154
  const svgRect = svg.getBoundingClientRect();
@@ -168,9 +167,9 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
168
167
  * 处理缩放按钮点击事件
169
168
  */
170
169
  __publicField(this, "handleZoom", (isZoomIn) => {
171
- if (!this.options.zoomable || !this.canvasRef)
170
+ if (!this.config.zoomable || !this.canvasRef)
172
171
  return;
173
- const step = this.options.zoomStep;
172
+ const step = this.config.zoomStep;
174
173
  if (isZoomIn) {
175
174
  this.canvasRef.zoomIn(step, 300);
176
175
  } else {
@@ -185,10 +184,6 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
185
184
  return;
186
185
  this.canvasRef.resetTransform(300);
187
186
  });
188
- this.options = __spreadProps(__spreadValues(__spreadValues({}, defaultProps), props), {
189
- nodeColor: props.nodeColor || "#AB7BFE",
190
- nodeStrokeColor: props.nodeStrokeColor || "transparent"
191
- });
192
187
  }
193
188
  get classNames() {
194
189
  return {
@@ -215,13 +210,13 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
215
210
  height: this.container.height / this.transform.scale
216
211
  };
217
212
  const boundingRect = this.nodes.length > 0 ? getBoundsOfRects(nodesBounds, viewRect) : viewRect;
218
- const { width: elementWidth, height: elementHeight } = this.options;
213
+ const { width: elementWidth, height: elementHeight } = this.config;
219
214
  const scaledWidth = boundingRect.width / elementWidth;
220
215
  const scaledHeight = boundingRect.height / elementHeight;
221
216
  const viewScale = Math.max(scaledWidth, scaledHeight, 0.1);
222
217
  const viewWidth = viewScale * elementWidth;
223
218
  const viewHeight = viewScale * elementHeight;
224
- const offset = this.options.padding * viewScale;
219
+ const offset = this.config.padding * viewScale;
225
220
  const x = boundingRect.x - (viewWidth - boundingRect.width) / 2 - offset;
226
221
  const y = boundingRect.y - (viewHeight - boundingRect.height) / 2 - offset;
227
222
  const width = viewWidth + offset * 2;
@@ -242,14 +237,14 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
242
237
  * 计算节点颜色
243
238
  */
244
239
  getNodeColor(node) {
245
- const { nodeColor } = this.options;
240
+ const { nodeColor } = this.config;
246
241
  return typeof nodeColor === "function" ? nodeColor(node) : nodeColor;
247
242
  }
248
243
  /**
249
244
  * 计算节点边框颜色
250
245
  */
251
246
  getNodeStrokeColor(node) {
252
- const { nodeStrokeColor } = this.options;
247
+ const { nodeStrokeColor } = this.config;
253
248
  return typeof nodeStrokeColor === "function" ? nodeStrokeColor(node) : nodeStrokeColor;
254
249
  }
255
250
  /**
@@ -263,7 +258,11 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
263
258
  const pointY = transform.y + relativeY * transform.height;
264
259
  return { pointX, pointY };
265
260
  }
266
- init() {
261
+ init(config) {
262
+ this.config = __spreadProps(__spreadValues(__spreadValues({}, defaultProps), config), {
263
+ nodeColor: config.nodeColor || "#AB7BFE",
264
+ nodeStrokeColor: config.nodeStrokeColor || "transparent"
265
+ });
267
266
  this.setupDragStream();
268
267
  this.setupInteractable();
269
268
  }
@@ -345,7 +344,7 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
345
344
  }
346
345
  render() {
347
346
  const { wrapper, svg, mask, control, zoomIn, zoomOut, reset, viewBox } = this.classNames;
348
- const { width, height, viewBoxColor, maskColor, showControls, nodeBorderRadius, nodeStrokeWidth } = this.options;
347
+ const { width, height, viewBoxColor, maskColor, showControls, nodeBorderRadius, nodeStrokeWidth } = this.config;
349
348
  const container = core.use(() => this.container);
350
349
  const transform = core.use(() => this.transform);
351
350
  const nodes = core.use(() => this.nodes);
@@ -378,7 +377,7 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
378
377
  viewBox: viewBoxAttr,
379
378
  onClick: this.handleMinimapClick,
380
379
  style: {
381
- cursor: this.options.pannable ? "pointer" : "default",
380
+ cursor: this.config.pannable ? "pointer" : "default",
382
381
  userSelect: "none",
383
382
  flexShrink: 0
384
383
  },
@@ -461,11 +460,11 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
461
460
  {
462
461
  className: zoomIn,
463
462
  onClick: () => this.handleZoom(true),
464
- disabled: !this.options.zoomable,
463
+ disabled: !this.config.zoomable,
465
464
  style: {
466
465
  border: "none",
467
466
  background: "none",
468
- cursor: this.options.zoomable ? "pointer" : "default",
467
+ cursor: this.config.zoomable ? "pointer" : "default",
469
468
  fontSize: "16px",
470
469
  color: "#555",
471
470
  padding: "2px 6px"
@@ -478,11 +477,11 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
478
477
  {
479
478
  className: zoomOut,
480
479
  onClick: () => this.handleZoom(false),
481
- disabled: !this.options.zoomable,
480
+ disabled: !this.config.zoomable,
482
481
  style: {
483
482
  border: "none",
484
483
  background: "none",
485
- cursor: this.options.zoomable ? "pointer" : "default",
484
+ cursor: this.config.zoomable ? "pointer" : "default",
486
485
  fontSize: "16px",
487
486
  color: "#555",
488
487
  padding: "2px 6px"
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NodeData, BasePlugin, Container } from '@knotx/core';
2
2
  import { CanvasTransformState, CanvasRef } from '@knotx/plugins-canvas';
3
3
 
4
- interface MinimapProps {
4
+ interface MinimapConfig {
5
5
  /**
6
6
  * 小地图宽度
7
7
  * @default 200
@@ -71,16 +71,14 @@ interface MinimapProps {
71
71
  /**
72
72
  * Minimap 插件 - 提供画布内容的缩略图预览和交互
73
73
  */
74
- declare class Minimap extends BasePlugin<'minimap'> {
75
- private props;
74
+ declare class Minimap extends BasePlugin<'minimap', MinimapConfig> {
76
75
  name: "minimap";
77
- private options;
76
+ private config;
78
77
  private subscription?;
79
78
  private currentInteractable?;
80
79
  private dragStart$;
81
80
  private dragMove$;
82
81
  private dragEnd$;
83
- constructor(props?: MinimapProps);
84
82
  container: Container;
85
83
  transform: CanvasTransformState;
86
84
  canvasRef: CanvasRef | null;
@@ -127,7 +125,7 @@ declare class Minimap extends BasePlugin<'minimap'> {
127
125
  /**
128
126
  * 初始化拖拽功能
129
127
  */
130
- init(): void;
128
+ init(config: MinimapConfig): void;
131
129
  /**
132
130
  * 设置拖拽流
133
131
  */
@@ -143,4 +141,4 @@ declare class Minimap extends BasePlugin<'minimap'> {
143
141
  render(): JSX.Element | null;
144
142
  }
145
143
 
146
- export { Minimap, type MinimapProps };
144
+ export { Minimap, type MinimapConfig };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NodeData, BasePlugin, Container } from '@knotx/core';
2
2
  import { CanvasTransformState, CanvasRef } from '@knotx/plugins-canvas';
3
3
 
4
- interface MinimapProps {
4
+ interface MinimapConfig {
5
5
  /**
6
6
  * 小地图宽度
7
7
  * @default 200
@@ -71,16 +71,14 @@ interface MinimapProps {
71
71
  /**
72
72
  * Minimap 插件 - 提供画布内容的缩略图预览和交互
73
73
  */
74
- declare class Minimap extends BasePlugin<'minimap'> {
75
- private props;
74
+ declare class Minimap extends BasePlugin<'minimap', MinimapConfig> {
76
75
  name: "minimap";
77
- private options;
76
+ private config;
78
77
  private subscription?;
79
78
  private currentInteractable?;
80
79
  private dragStart$;
81
80
  private dragMove$;
82
81
  private dragEnd$;
83
- constructor(props?: MinimapProps);
84
82
  container: Container;
85
83
  transform: CanvasTransformState;
86
84
  canvasRef: CanvasRef | null;
@@ -127,7 +125,7 @@ declare class Minimap extends BasePlugin<'minimap'> {
127
125
  /**
128
126
  * 初始化拖拽功能
129
127
  */
130
- init(): void;
128
+ init(config: MinimapConfig): void;
131
129
  /**
132
130
  * 设置拖拽流
133
131
  */
@@ -143,4 +141,4 @@ declare class Minimap extends BasePlugin<'minimap'> {
143
141
  render(): JSX.Element | null;
144
142
  }
145
143
 
146
- export { Minimap, type MinimapProps };
144
+ export { Minimap, type MinimapConfig };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NodeData, BasePlugin, Container } from '@knotx/core';
2
2
  import { CanvasTransformState, CanvasRef } from '@knotx/plugins-canvas';
3
3
 
4
- interface MinimapProps {
4
+ interface MinimapConfig {
5
5
  /**
6
6
  * 小地图宽度
7
7
  * @default 200
@@ -71,16 +71,14 @@ interface MinimapProps {
71
71
  /**
72
72
  * Minimap 插件 - 提供画布内容的缩略图预览和交互
73
73
  */
74
- declare class Minimap extends BasePlugin<'minimap'> {
75
- private props;
74
+ declare class Minimap extends BasePlugin<'minimap', MinimapConfig> {
76
75
  name: "minimap";
77
- private options;
76
+ private config;
78
77
  private subscription?;
79
78
  private currentInteractable?;
80
79
  private dragStart$;
81
80
  private dragMove$;
82
81
  private dragEnd$;
83
- constructor(props?: MinimapProps);
84
82
  container: Container;
85
83
  transform: CanvasTransformState;
86
84
  canvasRef: CanvasRef | null;
@@ -127,7 +125,7 @@ declare class Minimap extends BasePlugin<'minimap'> {
127
125
  /**
128
126
  * 初始化拖拽功能
129
127
  */
130
- init(): void;
128
+ init(config: MinimapConfig): void;
131
129
  /**
132
130
  * 设置拖拽流
133
131
  */
@@ -143,4 +141,4 @@ declare class Minimap extends BasePlugin<'minimap'> {
143
141
  render(): JSX.Element | null;
144
142
  }
145
143
 
146
- export { Minimap, type MinimapProps };
144
+ export { Minimap, type MinimapConfig };
package/dist/index.mjs CHANGED
@@ -124,12 +124,11 @@ function getBoundsOfRects(bounds1, bounds2) {
124
124
  };
125
125
  }
126
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;
127
+ constructor() {
128
+ super(...arguments);
130
129
  __runInitializers(_init, 5, this);
131
130
  __publicField(this, "name", "minimap");
132
- __publicField(this, "options");
131
+ __publicField(this, "config");
133
132
  __publicField(this, "subscription");
134
133
  __publicField(this, "currentInteractable");
135
134
  __publicField(this, "dragStart$", new Subject());
@@ -143,7 +142,7 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
143
142
  * 处理小地图上的点击事件,移动视图
144
143
  */
145
144
  __publicField(this, "handleMinimapClick", (event) => {
146
- if (!this.options.pannable || !this.canvasRef)
145
+ if (!this.config.pannable || !this.canvasRef)
147
146
  return;
148
147
  const svg = event.currentTarget;
149
148
  const svgRect = svg.getBoundingClientRect();
@@ -162,9 +161,9 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
162
161
  * 处理缩放按钮点击事件
163
162
  */
164
163
  __publicField(this, "handleZoom", (isZoomIn) => {
165
- if (!this.options.zoomable || !this.canvasRef)
164
+ if (!this.config.zoomable || !this.canvasRef)
166
165
  return;
167
- const step = this.options.zoomStep;
166
+ const step = this.config.zoomStep;
168
167
  if (isZoomIn) {
169
168
  this.canvasRef.zoomIn(step, 300);
170
169
  } else {
@@ -179,10 +178,6 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
179
178
  return;
180
179
  this.canvasRef.resetTransform(300);
181
180
  });
182
- this.options = __spreadProps(__spreadValues(__spreadValues({}, defaultProps), props), {
183
- nodeColor: props.nodeColor || "#AB7BFE",
184
- nodeStrokeColor: props.nodeStrokeColor || "transparent"
185
- });
186
181
  }
187
182
  get classNames() {
188
183
  return {
@@ -209,13 +204,13 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
209
204
  height: this.container.height / this.transform.scale
210
205
  };
211
206
  const boundingRect = this.nodes.length > 0 ? getBoundsOfRects(nodesBounds, viewRect) : viewRect;
212
- const { width: elementWidth, height: elementHeight } = this.options;
207
+ const { width: elementWidth, height: elementHeight } = this.config;
213
208
  const scaledWidth = boundingRect.width / elementWidth;
214
209
  const scaledHeight = boundingRect.height / elementHeight;
215
210
  const viewScale = Math.max(scaledWidth, scaledHeight, 0.1);
216
211
  const viewWidth = viewScale * elementWidth;
217
212
  const viewHeight = viewScale * elementHeight;
218
- const offset = this.options.padding * viewScale;
213
+ const offset = this.config.padding * viewScale;
219
214
  const x = boundingRect.x - (viewWidth - boundingRect.width) / 2 - offset;
220
215
  const y = boundingRect.y - (viewHeight - boundingRect.height) / 2 - offset;
221
216
  const width = viewWidth + offset * 2;
@@ -236,14 +231,14 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
236
231
  * 计算节点颜色
237
232
  */
238
233
  getNodeColor(node) {
239
- const { nodeColor } = this.options;
234
+ const { nodeColor } = this.config;
240
235
  return typeof nodeColor === "function" ? nodeColor(node) : nodeColor;
241
236
  }
242
237
  /**
243
238
  * 计算节点边框颜色
244
239
  */
245
240
  getNodeStrokeColor(node) {
246
- const { nodeStrokeColor } = this.options;
241
+ const { nodeStrokeColor } = this.config;
247
242
  return typeof nodeStrokeColor === "function" ? nodeStrokeColor(node) : nodeStrokeColor;
248
243
  }
249
244
  /**
@@ -257,7 +252,11 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
257
252
  const pointY = transform.y + relativeY * transform.height;
258
253
  return { pointX, pointY };
259
254
  }
260
- init() {
255
+ init(config) {
256
+ this.config = __spreadProps(__spreadValues(__spreadValues({}, defaultProps), config), {
257
+ nodeColor: config.nodeColor || "#AB7BFE",
258
+ nodeStrokeColor: config.nodeStrokeColor || "transparent"
259
+ });
261
260
  this.setupDragStream();
262
261
  this.setupInteractable();
263
262
  }
@@ -339,7 +338,7 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
339
338
  }
340
339
  render() {
341
340
  const { wrapper, svg, mask, control, zoomIn, zoomOut, reset, viewBox } = this.classNames;
342
- const { width, height, viewBoxColor, maskColor, showControls, nodeBorderRadius, nodeStrokeWidth } = this.options;
341
+ const { width, height, viewBoxColor, maskColor, showControls, nodeBorderRadius, nodeStrokeWidth } = this.config;
343
342
  const container = use(() => this.container);
344
343
  const transform = use(() => this.transform);
345
344
  const nodes = use(() => this.nodes);
@@ -372,7 +371,7 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
372
371
  viewBox: viewBoxAttr,
373
372
  onClick: this.handleMinimapClick,
374
373
  style: {
375
- cursor: this.options.pannable ? "pointer" : "default",
374
+ cursor: this.config.pannable ? "pointer" : "default",
376
375
  userSelect: "none",
377
376
  flexShrink: 0
378
377
  },
@@ -455,11 +454,11 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
455
454
  {
456
455
  className: zoomIn,
457
456
  onClick: () => this.handleZoom(true),
458
- disabled: !this.options.zoomable,
457
+ disabled: !this.config.zoomable,
459
458
  style: {
460
459
  border: "none",
461
460
  background: "none",
462
- cursor: this.options.zoomable ? "pointer" : "default",
461
+ cursor: this.config.zoomable ? "pointer" : "default",
463
462
  fontSize: "16px",
464
463
  color: "#555",
465
464
  padding: "2px 6px"
@@ -472,11 +471,11 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
472
471
  {
473
472
  className: zoomOut,
474
473
  onClick: () => this.handleZoom(false),
475
- disabled: !this.options.zoomable,
474
+ disabled: !this.config.zoomable,
476
475
  style: {
477
476
  border: "none",
478
477
  background: "none",
479
- cursor: this.options.zoomable ? "pointer" : "default",
478
+ cursor: this.config.zoomable ? "pointer" : "default",
480
479
  fontSize: "16px",
481
480
  color: "#555",
482
481
  padding: "2px 6px"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@knotx/plugins-minimap",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "description": "Minimap Plugin for Knotx",
6
6
  "author": "boenfu",
7
7
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "peerDependencies": {
32
32
  "interactjs": "^1.10.27",
33
- "@knotx/plugins-canvas": "0.0.6"
33
+ "@knotx/plugins-canvas": "0.0.7"
34
34
  },
35
35
  "dependencies": {
36
36
  "@interactjs/actions": "^1.10.27",
@@ -38,16 +38,16 @@
38
38
  "@interactjs/modifiers": "^1.10.27",
39
39
  "@interactjs/types": "^1.10.27",
40
40
  "rxjs": "^7.8.1",
41
- "@knotx/core": "0.0.6",
42
- "@knotx/decorators": "0.0.6"
41
+ "@knotx/core": "0.0.7",
42
+ "@knotx/decorators": "0.0.7"
43
43
  },
44
44
  "devDependencies": {
45
45
  "interactjs": "^1.10.27",
46
- "@knotx/build-config": "0.0.6",
47
- "@knotx/eslint-config": "0.0.6",
48
- "@knotx/jsx": "0.0.6",
49
- "@knotx/plugins-canvas": "0.0.6",
50
- "@knotx/typescript-config": "0.0.6"
46
+ "@knotx/build-config": "0.0.7",
47
+ "@knotx/eslint-config": "0.0.7",
48
+ "@knotx/jsx": "0.0.7",
49
+ "@knotx/plugins-canvas": "0.0.7",
50
+ "@knotx/typescript-config": "0.0.7"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "unbuild --failOnWarn=false",