rendx-minimap-plugin 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present wei.liang (https://github.com/weiliang0121)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/main.cjs ADDED
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
27
+
28
+ // src/main.ts
29
+ var main_exports = {};
30
+ __export(main_exports, {
31
+ minimapPlugin: () => minimapPlugin
32
+ });
33
+ module.exports = __toCommonJS(main_exports);
34
+
35
+ // src/minimap.ts
36
+ var DEFAULTS = {
37
+ width: 150,
38
+ height: 110,
39
+ position: "bottom-right",
40
+ margin: 10,
41
+ background: "rgba(255,255,255,0.9)",
42
+ borderColor: "#ccc",
43
+ viewportColor: "rgba(24,144,255,0.8)",
44
+ nodeFill: "#999"
45
+ };
46
+ var _app, _wrapper, _canvas, _ctx, _options, _ratio, _MinimapPlugin_instances, createElements_fn;
47
+ var MinimapPlugin = class {
48
+ constructor(options = {}) {
49
+ __privateAdd(this, _MinimapPlugin_instances);
50
+ this.name = "minimap";
51
+ __privateAdd(this, _app, null);
52
+ __privateAdd(this, _wrapper, null);
53
+ __privateAdd(this, _canvas, null);
54
+ __privateAdd(this, _ctx, null);
55
+ __privateAdd(this, _options);
56
+ __privateAdd(this, _ratio, 1);
57
+ __privateSet(this, _options, { ...DEFAULTS, ...options });
58
+ }
59
+ install(app) {
60
+ __privateSet(this, _app, app);
61
+ const container = app.container;
62
+ if (!container) {
63
+ throw new Error(
64
+ "[rendx-minimap-plugin] App must be mounted before calling use(). Call app.mount(el) first, then app.use(minimapPlugin(...))."
65
+ );
66
+ }
67
+ __privateSet(this, _ratio, window.devicePixelRatio || 1);
68
+ __privateMethod(this, _MinimapPlugin_instances, createElements_fn).call(this, container);
69
+ this.draw();
70
+ }
71
+ /**
72
+ * 绘制小地图:
73
+ * 1. 计算场景总包围盒
74
+ * 2. 缩放到小地图尺寸
75
+ * 3. 为每个节点绘制简化矩形
76
+ * 4. 绘制视口指示器
77
+ */
78
+ draw() {
79
+ const ctx = __privateGet(this, _ctx);
80
+ const app = __privateGet(this, _app);
81
+ if (!ctx || !app) return;
82
+ const { width, height, nodeFill, viewportColor } = __privateGet(this, _options);
83
+ ctx.clearRect(0, 0, width, height);
84
+ const entries = [];
85
+ let sceneMinX = Infinity, sceneMinY = Infinity;
86
+ let sceneMaxX = -Infinity, sceneMaxY = -Infinity;
87
+ for (const layer of app.scene.layers) {
88
+ if (layer.isEventLayer) continue;
89
+ const queue = layer.getQueue();
90
+ for (const node of queue) {
91
+ const bb = node.getWorldBBox();
92
+ if (!bb) continue;
93
+ const minX = bb.x, minY = bb.y, maxX = bb.right, maxY = bb.bottom;
94
+ entries.push({ node, minX, minY, maxX, maxY });
95
+ if (minX < sceneMinX) sceneMinX = minX;
96
+ if (minY < sceneMinY) sceneMinY = minY;
97
+ if (maxX > sceneMaxX) sceneMaxX = maxX;
98
+ if (maxY > sceneMaxY) sceneMaxY = maxY;
99
+ }
100
+ }
101
+ const appW = app.cfg.width ?? 800;
102
+ const appH = app.cfg.height ?? 600;
103
+ if (sceneMinX > sceneMaxX) {
104
+ sceneMinX = 0;
105
+ sceneMinY = 0;
106
+ sceneMaxX = appW;
107
+ sceneMaxY = appH;
108
+ }
109
+ sceneMinX = Math.min(sceneMinX, 0);
110
+ sceneMinY = Math.min(sceneMinY, 0);
111
+ sceneMaxX = Math.max(sceneMaxX, appW);
112
+ sceneMaxY = Math.max(sceneMaxY, appH);
113
+ const sceneW = sceneMaxX - sceneMinX || 1;
114
+ const sceneH = sceneMaxY - sceneMinY || 1;
115
+ const pad = 4;
116
+ const drawW = width - pad * 2;
117
+ const drawH = height - pad * 2;
118
+ const scale = Math.min(drawW / sceneW, drawH / sceneH);
119
+ const offsetX = pad + (drawW - sceneW * scale) / 2;
120
+ const offsetY = pad + (drawH - sceneH * scale) / 2;
121
+ const tx = (x) => offsetX + (x - sceneMinX) * scale;
122
+ const ty = (y) => offsetY + (y - sceneMinY) * scale;
123
+ for (const { node, minX, minY, maxX, maxY } of entries) {
124
+ const fill = node.attrs.values.fill || nodeFill;
125
+ ctx.fillStyle = fill;
126
+ ctx.globalAlpha = 0.6;
127
+ ctx.fillRect(tx(minX), ty(minY), (maxX - minX) * scale, (maxY - minY) * scale);
128
+ }
129
+ ctx.globalAlpha = 1;
130
+ ctx.strokeStyle = viewportColor;
131
+ ctx.lineWidth = 1.5;
132
+ ctx.strokeRect(tx(0), ty(0), appW * scale, appH * scale);
133
+ }
134
+ resize() {
135
+ this.draw();
136
+ }
137
+ /** 更新配置并重绘 */
138
+ update(options) {
139
+ const needReposition = options.position !== void 0 || options.margin !== void 0;
140
+ Object.assign(__privateGet(this, _options), options);
141
+ if (__privateGet(this, _wrapper)) {
142
+ if (options.background) __privateGet(this, _wrapper).style.background = options.background;
143
+ if (options.borderColor) __privateGet(this, _wrapper).style.border = `1px solid ${options.borderColor}`;
144
+ if (options.width !== void 0 || options.height !== void 0) {
145
+ const { width, height } = __privateGet(this, _options);
146
+ __privateGet(this, _wrapper).style.width = `${width}px`;
147
+ __privateGet(this, _wrapper).style.height = `${height}px`;
148
+ if (__privateGet(this, _canvas)) {
149
+ __privateGet(this, _canvas).width = width * __privateGet(this, _ratio);
150
+ __privateGet(this, _canvas).height = height * __privateGet(this, _ratio);
151
+ __privateGet(this, _canvas).style.width = `${width}px`;
152
+ __privateGet(this, _canvas).style.height = `${height}px`;
153
+ if (__privateGet(this, _ctx)) __privateGet(this, _ctx).scale(__privateGet(this, _ratio), __privateGet(this, _ratio));
154
+ }
155
+ }
156
+ if (needReposition) {
157
+ const { position, margin } = __privateGet(this, _options);
158
+ __privateGet(this, _wrapper).style.top = "";
159
+ __privateGet(this, _wrapper).style.right = "";
160
+ __privateGet(this, _wrapper).style.bottom = "";
161
+ __privateGet(this, _wrapper).style.left = "";
162
+ switch (position) {
163
+ case "top-left":
164
+ __privateGet(this, _wrapper).style.top = `${margin}px`;
165
+ __privateGet(this, _wrapper).style.left = `${margin}px`;
166
+ break;
167
+ case "top-right":
168
+ __privateGet(this, _wrapper).style.top = `${margin}px`;
169
+ __privateGet(this, _wrapper).style.right = `${margin}px`;
170
+ break;
171
+ case "bottom-left":
172
+ __privateGet(this, _wrapper).style.bottom = `${margin}px`;
173
+ __privateGet(this, _wrapper).style.left = `${margin}px`;
174
+ break;
175
+ case "bottom-right":
176
+ default:
177
+ __privateGet(this, _wrapper).style.bottom = `${margin}px`;
178
+ __privateGet(this, _wrapper).style.right = `${margin}px`;
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ this.draw();
184
+ }
185
+ dispose() {
186
+ if (__privateGet(this, _wrapper)) {
187
+ __privateGet(this, _wrapper).remove();
188
+ __privateSet(this, _wrapper, null);
189
+ __privateSet(this, _canvas, null);
190
+ __privateSet(this, _ctx, null);
191
+ }
192
+ __privateSet(this, _app, null);
193
+ }
194
+ };
195
+ _app = new WeakMap();
196
+ _wrapper = new WeakMap();
197
+ _canvas = new WeakMap();
198
+ _ctx = new WeakMap();
199
+ _options = new WeakMap();
200
+ _ratio = new WeakMap();
201
+ _MinimapPlugin_instances = new WeakSet();
202
+ createElements_fn = function(container) {
203
+ const { width, height, position, margin, background, borderColor } = __privateGet(this, _options);
204
+ const wrapper = document.createElement("div");
205
+ wrapper.style.position = "absolute";
206
+ wrapper.style.width = `${width}px`;
207
+ wrapper.style.height = `${height}px`;
208
+ wrapper.style.zIndex = "99998";
209
+ wrapper.style.pointerEvents = "none";
210
+ wrapper.style.background = background;
211
+ wrapper.style.border = `1px solid ${borderColor}`;
212
+ wrapper.style.borderRadius = "4px";
213
+ wrapper.style.overflow = "hidden";
214
+ wrapper.style.boxSizing = "border-box";
215
+ switch (position) {
216
+ case "top-left":
217
+ wrapper.style.top = `${margin}px`;
218
+ wrapper.style.left = `${margin}px`;
219
+ break;
220
+ case "top-right":
221
+ wrapper.style.top = `${margin}px`;
222
+ wrapper.style.right = `${margin}px`;
223
+ break;
224
+ case "bottom-left":
225
+ wrapper.style.bottom = `${margin}px`;
226
+ wrapper.style.left = `${margin}px`;
227
+ break;
228
+ case "bottom-right":
229
+ default:
230
+ wrapper.style.bottom = `${margin}px`;
231
+ wrapper.style.right = `${margin}px`;
232
+ break;
233
+ }
234
+ const canvas = document.createElement("canvas");
235
+ canvas.width = width * __privateGet(this, _ratio);
236
+ canvas.height = height * __privateGet(this, _ratio);
237
+ canvas.style.width = `${width}px`;
238
+ canvas.style.height = `${height}px`;
239
+ wrapper.appendChild(canvas);
240
+ const ctx = canvas.getContext("2d");
241
+ if (!ctx) throw new Error("[rendx-minimap-plugin] Could not get 2d context");
242
+ ctx.scale(__privateGet(this, _ratio), __privateGet(this, _ratio));
243
+ container.appendChild(wrapper);
244
+ __privateSet(this, _wrapper, wrapper);
245
+ __privateSet(this, _canvas, canvas);
246
+ __privateSet(this, _ctx, ctx);
247
+ };
248
+ function minimapPlugin(options) {
249
+ return new MinimapPlugin(options);
250
+ }
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ minimapPlugin
254
+ });
@@ -0,0 +1,57 @@
1
+ import { Plugin, App } from 'rendx-engine';
2
+
3
+ interface MinimapPluginOptions {
4
+ /** 小地图宽度(px),默认 150 */
5
+ width?: number;
6
+ /** 小地图高度(px),默认 110 */
7
+ height?: number;
8
+ /** 位置,默认 'bottom-right' */
9
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
10
+ /** 距容器边缘的间距(px),默认 10 */
11
+ margin?: number;
12
+ /** 背景色,默认 'rgba(255,255,255,0.9)' */
13
+ background?: string;
14
+ /** 边框色,默认 '#ccc' */
15
+ borderColor?: string;
16
+ /** 视口指示器边框色,默认 'rgba(24,144,255,0.8)' */
17
+ viewportColor?: string;
18
+ /** 节点默认填充色(当节点无 fill 时),默认 '#999' */
19
+ nodeFill?: string;
20
+ }
21
+ declare class MinimapPlugin implements Plugin {
22
+ #private;
23
+ name: string;
24
+ constructor(options?: MinimapPluginOptions);
25
+ install(app: App): void;
26
+ /**
27
+ * 绘制小地图:
28
+ * 1. 计算场景总包围盒
29
+ * 2. 缩放到小地图尺寸
30
+ * 3. 为每个节点绘制简化矩形
31
+ * 4. 绘制视口指示器
32
+ */
33
+ draw(): void;
34
+ resize(): void;
35
+ /** 更新配置并重绘 */
36
+ update(options: Partial<MinimapPluginOptions>): void;
37
+ dispose(): void;
38
+ }
39
+ /**
40
+ * 创建小地图插件
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import {minimapPlugin} from 'rendx-minimap-plugin';
45
+ *
46
+ * const app = new App({width: 800, height: 600});
47
+ * app.mount(container);
48
+ * app.use(minimapPlugin({position: 'bottom-right'}));
49
+ *
50
+ * // 场景变化后手动刷新小地图
51
+ * app.render();
52
+ * (app.getPlugin('minimap') as any).draw();
53
+ * ```
54
+ */
55
+ declare function minimapPlugin(options?: MinimapPluginOptions): MinimapPlugin;
56
+
57
+ export { type MinimapPluginOptions, minimapPlugin };
package/dist/main.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ import { Plugin, App } from 'rendx-engine';
2
+
3
+ interface MinimapPluginOptions {
4
+ /** 小地图宽度(px),默认 150 */
5
+ width?: number;
6
+ /** 小地图高度(px),默认 110 */
7
+ height?: number;
8
+ /** 位置,默认 'bottom-right' */
9
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
10
+ /** 距容器边缘的间距(px),默认 10 */
11
+ margin?: number;
12
+ /** 背景色,默认 'rgba(255,255,255,0.9)' */
13
+ background?: string;
14
+ /** 边框色,默认 '#ccc' */
15
+ borderColor?: string;
16
+ /** 视口指示器边框色,默认 'rgba(24,144,255,0.8)' */
17
+ viewportColor?: string;
18
+ /** 节点默认填充色(当节点无 fill 时),默认 '#999' */
19
+ nodeFill?: string;
20
+ }
21
+ declare class MinimapPlugin implements Plugin {
22
+ #private;
23
+ name: string;
24
+ constructor(options?: MinimapPluginOptions);
25
+ install(app: App): void;
26
+ /**
27
+ * 绘制小地图:
28
+ * 1. 计算场景总包围盒
29
+ * 2. 缩放到小地图尺寸
30
+ * 3. 为每个节点绘制简化矩形
31
+ * 4. 绘制视口指示器
32
+ */
33
+ draw(): void;
34
+ resize(): void;
35
+ /** 更新配置并重绘 */
36
+ update(options: Partial<MinimapPluginOptions>): void;
37
+ dispose(): void;
38
+ }
39
+ /**
40
+ * 创建小地图插件
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import {minimapPlugin} from 'rendx-minimap-plugin';
45
+ *
46
+ * const app = new App({width: 800, height: 600});
47
+ * app.mount(container);
48
+ * app.use(minimapPlugin({position: 'bottom-right'}));
49
+ *
50
+ * // 场景变化后手动刷新小地图
51
+ * app.render();
52
+ * (app.getPlugin('minimap') as any).draw();
53
+ * ```
54
+ */
55
+ declare function minimapPlugin(options?: MinimapPluginOptions): MinimapPlugin;
56
+
57
+ export { type MinimapPluginOptions, minimapPlugin };
package/dist/main.js ADDED
@@ -0,0 +1,228 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+
10
+ // src/minimap.ts
11
+ var DEFAULTS = {
12
+ width: 150,
13
+ height: 110,
14
+ position: "bottom-right",
15
+ margin: 10,
16
+ background: "rgba(255,255,255,0.9)",
17
+ borderColor: "#ccc",
18
+ viewportColor: "rgba(24,144,255,0.8)",
19
+ nodeFill: "#999"
20
+ };
21
+ var _app, _wrapper, _canvas, _ctx, _options, _ratio, _MinimapPlugin_instances, createElements_fn;
22
+ var MinimapPlugin = class {
23
+ constructor(options = {}) {
24
+ __privateAdd(this, _MinimapPlugin_instances);
25
+ this.name = "minimap";
26
+ __privateAdd(this, _app, null);
27
+ __privateAdd(this, _wrapper, null);
28
+ __privateAdd(this, _canvas, null);
29
+ __privateAdd(this, _ctx, null);
30
+ __privateAdd(this, _options);
31
+ __privateAdd(this, _ratio, 1);
32
+ __privateSet(this, _options, { ...DEFAULTS, ...options });
33
+ }
34
+ install(app) {
35
+ __privateSet(this, _app, app);
36
+ const container = app.container;
37
+ if (!container) {
38
+ throw new Error(
39
+ "[rendx-minimap-plugin] App must be mounted before calling use(). Call app.mount(el) first, then app.use(minimapPlugin(...))."
40
+ );
41
+ }
42
+ __privateSet(this, _ratio, window.devicePixelRatio || 1);
43
+ __privateMethod(this, _MinimapPlugin_instances, createElements_fn).call(this, container);
44
+ this.draw();
45
+ }
46
+ /**
47
+ * 绘制小地图:
48
+ * 1. 计算场景总包围盒
49
+ * 2. 缩放到小地图尺寸
50
+ * 3. 为每个节点绘制简化矩形
51
+ * 4. 绘制视口指示器
52
+ */
53
+ draw() {
54
+ const ctx = __privateGet(this, _ctx);
55
+ const app = __privateGet(this, _app);
56
+ if (!ctx || !app) return;
57
+ const { width, height, nodeFill, viewportColor } = __privateGet(this, _options);
58
+ ctx.clearRect(0, 0, width, height);
59
+ const entries = [];
60
+ let sceneMinX = Infinity, sceneMinY = Infinity;
61
+ let sceneMaxX = -Infinity, sceneMaxY = -Infinity;
62
+ for (const layer of app.scene.layers) {
63
+ if (layer.isEventLayer) continue;
64
+ const queue = layer.getQueue();
65
+ for (const node of queue) {
66
+ const bb = node.getWorldBBox();
67
+ if (!bb) continue;
68
+ const minX = bb.x, minY = bb.y, maxX = bb.right, maxY = bb.bottom;
69
+ entries.push({ node, minX, minY, maxX, maxY });
70
+ if (minX < sceneMinX) sceneMinX = minX;
71
+ if (minY < sceneMinY) sceneMinY = minY;
72
+ if (maxX > sceneMaxX) sceneMaxX = maxX;
73
+ if (maxY > sceneMaxY) sceneMaxY = maxY;
74
+ }
75
+ }
76
+ const appW = app.cfg.width ?? 800;
77
+ const appH = app.cfg.height ?? 600;
78
+ if (sceneMinX > sceneMaxX) {
79
+ sceneMinX = 0;
80
+ sceneMinY = 0;
81
+ sceneMaxX = appW;
82
+ sceneMaxY = appH;
83
+ }
84
+ sceneMinX = Math.min(sceneMinX, 0);
85
+ sceneMinY = Math.min(sceneMinY, 0);
86
+ sceneMaxX = Math.max(sceneMaxX, appW);
87
+ sceneMaxY = Math.max(sceneMaxY, appH);
88
+ const sceneW = sceneMaxX - sceneMinX || 1;
89
+ const sceneH = sceneMaxY - sceneMinY || 1;
90
+ const pad = 4;
91
+ const drawW = width - pad * 2;
92
+ const drawH = height - pad * 2;
93
+ const scale = Math.min(drawW / sceneW, drawH / sceneH);
94
+ const offsetX = pad + (drawW - sceneW * scale) / 2;
95
+ const offsetY = pad + (drawH - sceneH * scale) / 2;
96
+ const tx = (x) => offsetX + (x - sceneMinX) * scale;
97
+ const ty = (y) => offsetY + (y - sceneMinY) * scale;
98
+ for (const { node, minX, minY, maxX, maxY } of entries) {
99
+ const fill = node.attrs.values.fill || nodeFill;
100
+ ctx.fillStyle = fill;
101
+ ctx.globalAlpha = 0.6;
102
+ ctx.fillRect(tx(minX), ty(minY), (maxX - minX) * scale, (maxY - minY) * scale);
103
+ }
104
+ ctx.globalAlpha = 1;
105
+ ctx.strokeStyle = viewportColor;
106
+ ctx.lineWidth = 1.5;
107
+ ctx.strokeRect(tx(0), ty(0), appW * scale, appH * scale);
108
+ }
109
+ resize() {
110
+ this.draw();
111
+ }
112
+ /** 更新配置并重绘 */
113
+ update(options) {
114
+ const needReposition = options.position !== void 0 || options.margin !== void 0;
115
+ Object.assign(__privateGet(this, _options), options);
116
+ if (__privateGet(this, _wrapper)) {
117
+ if (options.background) __privateGet(this, _wrapper).style.background = options.background;
118
+ if (options.borderColor) __privateGet(this, _wrapper).style.border = `1px solid ${options.borderColor}`;
119
+ if (options.width !== void 0 || options.height !== void 0) {
120
+ const { width, height } = __privateGet(this, _options);
121
+ __privateGet(this, _wrapper).style.width = `${width}px`;
122
+ __privateGet(this, _wrapper).style.height = `${height}px`;
123
+ if (__privateGet(this, _canvas)) {
124
+ __privateGet(this, _canvas).width = width * __privateGet(this, _ratio);
125
+ __privateGet(this, _canvas).height = height * __privateGet(this, _ratio);
126
+ __privateGet(this, _canvas).style.width = `${width}px`;
127
+ __privateGet(this, _canvas).style.height = `${height}px`;
128
+ if (__privateGet(this, _ctx)) __privateGet(this, _ctx).scale(__privateGet(this, _ratio), __privateGet(this, _ratio));
129
+ }
130
+ }
131
+ if (needReposition) {
132
+ const { position, margin } = __privateGet(this, _options);
133
+ __privateGet(this, _wrapper).style.top = "";
134
+ __privateGet(this, _wrapper).style.right = "";
135
+ __privateGet(this, _wrapper).style.bottom = "";
136
+ __privateGet(this, _wrapper).style.left = "";
137
+ switch (position) {
138
+ case "top-left":
139
+ __privateGet(this, _wrapper).style.top = `${margin}px`;
140
+ __privateGet(this, _wrapper).style.left = `${margin}px`;
141
+ break;
142
+ case "top-right":
143
+ __privateGet(this, _wrapper).style.top = `${margin}px`;
144
+ __privateGet(this, _wrapper).style.right = `${margin}px`;
145
+ break;
146
+ case "bottom-left":
147
+ __privateGet(this, _wrapper).style.bottom = `${margin}px`;
148
+ __privateGet(this, _wrapper).style.left = `${margin}px`;
149
+ break;
150
+ case "bottom-right":
151
+ default:
152
+ __privateGet(this, _wrapper).style.bottom = `${margin}px`;
153
+ __privateGet(this, _wrapper).style.right = `${margin}px`;
154
+ break;
155
+ }
156
+ }
157
+ }
158
+ this.draw();
159
+ }
160
+ dispose() {
161
+ if (__privateGet(this, _wrapper)) {
162
+ __privateGet(this, _wrapper).remove();
163
+ __privateSet(this, _wrapper, null);
164
+ __privateSet(this, _canvas, null);
165
+ __privateSet(this, _ctx, null);
166
+ }
167
+ __privateSet(this, _app, null);
168
+ }
169
+ };
170
+ _app = new WeakMap();
171
+ _wrapper = new WeakMap();
172
+ _canvas = new WeakMap();
173
+ _ctx = new WeakMap();
174
+ _options = new WeakMap();
175
+ _ratio = new WeakMap();
176
+ _MinimapPlugin_instances = new WeakSet();
177
+ createElements_fn = function(container) {
178
+ const { width, height, position, margin, background, borderColor } = __privateGet(this, _options);
179
+ const wrapper = document.createElement("div");
180
+ wrapper.style.position = "absolute";
181
+ wrapper.style.width = `${width}px`;
182
+ wrapper.style.height = `${height}px`;
183
+ wrapper.style.zIndex = "99998";
184
+ wrapper.style.pointerEvents = "none";
185
+ wrapper.style.background = background;
186
+ wrapper.style.border = `1px solid ${borderColor}`;
187
+ wrapper.style.borderRadius = "4px";
188
+ wrapper.style.overflow = "hidden";
189
+ wrapper.style.boxSizing = "border-box";
190
+ switch (position) {
191
+ case "top-left":
192
+ wrapper.style.top = `${margin}px`;
193
+ wrapper.style.left = `${margin}px`;
194
+ break;
195
+ case "top-right":
196
+ wrapper.style.top = `${margin}px`;
197
+ wrapper.style.right = `${margin}px`;
198
+ break;
199
+ case "bottom-left":
200
+ wrapper.style.bottom = `${margin}px`;
201
+ wrapper.style.left = `${margin}px`;
202
+ break;
203
+ case "bottom-right":
204
+ default:
205
+ wrapper.style.bottom = `${margin}px`;
206
+ wrapper.style.right = `${margin}px`;
207
+ break;
208
+ }
209
+ const canvas = document.createElement("canvas");
210
+ canvas.width = width * __privateGet(this, _ratio);
211
+ canvas.height = height * __privateGet(this, _ratio);
212
+ canvas.style.width = `${width}px`;
213
+ canvas.style.height = `${height}px`;
214
+ wrapper.appendChild(canvas);
215
+ const ctx = canvas.getContext("2d");
216
+ if (!ctx) throw new Error("[rendx-minimap-plugin] Could not get 2d context");
217
+ ctx.scale(__privateGet(this, _ratio), __privateGet(this, _ratio));
218
+ container.appendChild(wrapper);
219
+ __privateSet(this, _wrapper, wrapper);
220
+ __privateSet(this, _canvas, canvas);
221
+ __privateSet(this, _ctx, ctx);
222
+ };
223
+ function minimapPlugin(options) {
224
+ return new MinimapPlugin(options);
225
+ }
226
+ export {
227
+ minimapPlugin
228
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "rendx-minimap-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Minimap navigation plugin for Rendx engine",
5
+ "license": "MIT",
6
+ "author": "wei.liang (https://github.com/weiliang0121)",
7
+ "type": "module",
8
+ "keywords": [
9
+ "rendx",
10
+ "2d",
11
+ "canvas",
12
+ "rendering",
13
+ "visualization",
14
+ "scene-graph"
15
+ ],
16
+ "homepage": "https://weiliang0121.github.io/rendx/",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/weiliang0121/rendx.git",
20
+ "directory": "packages/minimap-plugin"
21
+ },
22
+ "main": "dist/main.cjs",
23
+ "module": "dist/main.js",
24
+ "types": "dist/main.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/main.d.ts",
28
+ "import": "./dist/main.js",
29
+ "require": "./dist/main.cjs"
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "rendx-engine": "^0.2.0"
34
+ },
35
+ "sideEffects": false,
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch"
45
+ }
46
+ }