build-dxf 0.1.15 → 0.1.16
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/package.json +1 -1
- package/src/DomEventRegister.js +472 -0
- package/src/build.js +3064 -3359
- package/src/index.css +1 -131
- package/src/index.js +10 -10
- package/src/index2.js +2 -155
- package/src/index3.js +6295 -2640
- package/src/utils/DxfSystem/DxfSystem.d.ts +0 -3
- package/src/utils/DxfSystem/components/CorrectionDxf.d.ts +26 -2
- package/src/utils/DxfSystem/components/Dxf.d.ts +3 -2
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/ClippingLine.d.ts +1 -2
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/CommandFlowComponent.d.ts +7 -2
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DeleteSelectLine.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawDoorLine.d.ts +2 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawLine.d.ts +3 -5
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawWindow.d.ts +2 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/MergeLine.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/PointDrag.d.ts +2 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/SelectAll.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/{IntersectionConnectionLine.d.ts → TwoLineConnectionLine.d.ts} +3 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/{ConnectionLine.d.ts → TwoPointConnection.d.ts} +3 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/{VerticalCorrection.d.ts → VerticalCorr.d.ts} +2 -12
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/{DeleteSelectWindow.d.ts → VerticalCorrContinue.d.ts} +10 -8
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalReferenceLine.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/ViewAngle.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/index.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/RenderPlugin/components/Renderer.d.ts +1 -0
- package/src/utils/DxfSystem/plugin/RenderPlugin/index.d.ts +1 -2
- package/src/utils/DxfSystem/type.d.ts +2 -0
- package/src/utils/DxfSystem/utils/DoorFind.d.ts +36 -0
- package/src/utils/{modelScenario → DxfSystem/utils}/SceneAutoGenerat.d.ts +3 -1
- package/src/utils/DxfSystem/utils/index.d.ts +1 -5
- package/src/utils/LineSegment.d.ts +9 -0
- package/src/utils/Map.d.ts +1 -0
- package/src/utils/MaxiCircles.d.ts +13 -0
- package/src/utils/MiniCircles.d.ts +33 -0
- package/src/utils/Point.d.ts +1 -1
- package/src/utils/{PointVirtualGrid/index.d.ts → PointVirtualGrid.d.ts} +5 -5
- package/src/utils/Polygon.d.ts +11 -0
- package/src/utils/UndirectedGraph.d.ts +4 -0
- package/src/utils/index.d.ts +4 -2
- package/src/bin/Main.js +0 -269
- package/src/bin/mini_cycles.js +0 -15
- package/src/bin/mini_cycles.wasm +0 -0
- package/src/bin/mini_cycles.wasm.map +0 -1
- package/src/bin/wasm_mini_cycles.js +0 -296
- package/src/index4.js +0 -4261
- package/src/utils/DxfSystem/components/DoorsAnalysis.d.ts +0 -115
- package/src/utils/DxfSystem/plugin/RenderPlugin/pages/Dxf.vue.d.ts +0 -21
- package/src/utils/DxfSystem/utils/closedPathArea.d.ts +0 -2
- package/src/utils/DxfSystem/utils/findClosedPolygons.d.ts +0 -14
- package/src/utils/DxfSystem/utils/findLargestCircle.d.ts +0 -14
- package/src/utils/DxfSystem/utils/mergeSmallestCircle.d.ts +0 -14
- package/src/utils/DxfSystem/utils/smallestCircle.d.ts +0 -6
- package/src/utils/deepClone.d.ts +0 -6
- package/src/utils/drawLinePathToPng.d.ts +0 -7
- /package/src/utils/{Lines.d.ts → DxfSystem/utils/Lines.d.ts} +0 -0
- /package/src/utils/{LoadModel.d.ts → DxfSystem/utils/LoadModel.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
import { Vector2 } from "three";
|
|
6
|
+
import { CSS3DObject, CSS3DSprite, CSS3DRenderer } from "three/addons/renderers/CSS3DRenderer.js";
|
|
7
|
+
import { CSS2DObject, CSS2DRenderer } from "three/addons/renderers/CSS2DRenderer.js";
|
|
8
|
+
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
9
|
+
import * as TWEEN from "@tweenjs/tween.js";
|
|
10
|
+
import { C as Component, a as Point, V as Variable } from "./build.js";
|
|
11
|
+
class DomContainer extends Component {
|
|
12
|
+
static name = "DomContainer";
|
|
13
|
+
domElement = document.createElement("div");
|
|
14
|
+
canvas = document.createElement("canvas");
|
|
15
|
+
html2DRenderer = document.createElement("div");
|
|
16
|
+
html3DRenderer = document.createElement("div");
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.domElement.id = "build-dxf-container";
|
|
20
|
+
this.domElement.appendChild(this.canvas);
|
|
21
|
+
this.domElement.appendChild(this.html3DRenderer);
|
|
22
|
+
this.domElement.appendChild(this.html2DRenderer);
|
|
23
|
+
Object.assign(this.domElement.style, {
|
|
24
|
+
width: "100%",
|
|
25
|
+
height: "100%",
|
|
26
|
+
position: "relative",
|
|
27
|
+
userSelect: "none"
|
|
28
|
+
});
|
|
29
|
+
Object.assign(this.html3DRenderer.style, {
|
|
30
|
+
position: "absolute",
|
|
31
|
+
left: 0,
|
|
32
|
+
top: 0,
|
|
33
|
+
// zIndex: 9,
|
|
34
|
+
width: "100%",
|
|
35
|
+
height: "100%"
|
|
36
|
+
});
|
|
37
|
+
Object.assign(this.html2DRenderer.style, {
|
|
38
|
+
position: "absolute",
|
|
39
|
+
left: 0,
|
|
40
|
+
top: 0,
|
|
41
|
+
// zIndex: 10,
|
|
42
|
+
width: "100%",
|
|
43
|
+
height: "100%"
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const circlePng = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wgaExY5fZXYlgAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAASFUlEQVR42u1bS48bR5KOR2ZV8dHsh97WeD2Y82IxEI996YMAw/9jftb8j8ECPVgBgz74QP+AgS0YMNAtW61+kyxWZkbsIbPIYrHYLcmaxQK7BFJksyiy4osvIiPjAfD/j//bD/ySX/aXv/wFW9+LD6zmQxvP9y3461//qv+rAGgJXi96YDVBaAoo96z6OnwpMPALCl4Lxem1Sa9N6zWn1WZBLWQAAN94br6ur0sTtN8DAn4hjVNDMNtYWWvZw/HYQrHDvZ5h8IBgADx4BQ/inPNlWfrJZOIAwAFA1XiuXzdBCb8XCPwdwjfpbJLAeVoFABRjgN7O0VGR93qFZVswY27IZMhoAMEg4NIEFDSogBcJVQihEucWpXPl5eW8nExO5gBQprVIqwYptEzkk8wCP0N4bFDdNDTdS2tweHg4GI6GwyIrBsbagWHuE1GPiQogyhAxIwRGQEp3KqoaVNWpqhORUkTKEPxcJEzdwk1nZTm9PD6eTgCmADADgHkComowogbio0HAzxCeGlSvBe8DwPDo8Gg03B+OcpuPTGZGhs0OMw+JaYCEPSIuECAnjAyAyAAEAFHQAAJeQSsRXajKXCTMQpBp8O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mqN0BgDMeDymoiioLMtYkZqAAEzqhIy7Z7X7fz9rWuxfMTiJHazgjoFJbk2PbhZmNld7aHKtxPU/Pjj5kUBsG6HFlvDQAYJC98jsF58h/lcNT0PH4ei+wek2CLBl6uOLD0//NxKXqwa3BaHgAAAAAElFTkSuQmCC";
|
|
48
|
+
THREE.Object3D.DEFAULT_UP = new THREE.Vector3(0, 0, 1);
|
|
49
|
+
const circleTexture = new THREE.TextureLoader().load(circlePng);
|
|
50
|
+
const _Renderer = class _Renderer extends Component {
|
|
51
|
+
scene;
|
|
52
|
+
camera;
|
|
53
|
+
renderer;
|
|
54
|
+
orbitControls;
|
|
55
|
+
resizeObserver;
|
|
56
|
+
description;
|
|
57
|
+
html2DRenderer;
|
|
58
|
+
html3DRenderer;
|
|
59
|
+
container = new THREE.Group();
|
|
60
|
+
container2 = new THREE.Group();
|
|
61
|
+
onUpdate;
|
|
62
|
+
onResize;
|
|
63
|
+
width = 0;
|
|
64
|
+
height = 0;
|
|
65
|
+
tweenTaskList = [];
|
|
66
|
+
constructor(description) {
|
|
67
|
+
super();
|
|
68
|
+
this.description = description;
|
|
69
|
+
const {
|
|
70
|
+
scene = new THREE.Scene(),
|
|
71
|
+
camera = new THREE.PerspectiveCamera(45, 1, 0.01, 1e3)
|
|
72
|
+
} = description;
|
|
73
|
+
this.camera = camera;
|
|
74
|
+
this.scene = scene;
|
|
75
|
+
scene.add(this.container);
|
|
76
|
+
scene.add(this.container2);
|
|
77
|
+
this.renderer = new THREE.WebGLRenderer({
|
|
78
|
+
canvas: this.description.canvas,
|
|
79
|
+
antialias: true
|
|
80
|
+
});
|
|
81
|
+
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
82
|
+
if (description.htmlRenderer) {
|
|
83
|
+
if (description.htmlRenderer["2d"]) {
|
|
84
|
+
this.html2DRenderer = new CSS2DRenderer();
|
|
85
|
+
Object.assign(this.html2DRenderer.domElement.style, { position: "absolute", left: "0px", top: "0px" });
|
|
86
|
+
description.htmlRenderer["2d"].appendChild(this.html2DRenderer.domElement);
|
|
87
|
+
}
|
|
88
|
+
if (description.htmlRenderer["3d"]) {
|
|
89
|
+
this.html3DRenderer = new CSS3DRenderer();
|
|
90
|
+
Object.assign(this.html3DRenderer.domElement.style, { position: "absolute", left: "0px", top: "0px" });
|
|
91
|
+
description.htmlRenderer["3d"].appendChild(this.html3DRenderer.domElement);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (description.orbitControls) {
|
|
95
|
+
this.orbitControls = new OrbitControls(this.camera, description.orbitControls.domElement);
|
|
96
|
+
Object.assign(this.orbitControls, description.orbitControls);
|
|
97
|
+
}
|
|
98
|
+
if (this.description.resizeObserver) {
|
|
99
|
+
const dom = this.description.resizeObserver;
|
|
100
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
101
|
+
const camera2 = this.camera;
|
|
102
|
+
const { width, height } = dom.getBoundingClientRect();
|
|
103
|
+
this.renderer.setSize(width, height);
|
|
104
|
+
if (this.html2DRenderer) this.html2DRenderer.setSize(width, height);
|
|
105
|
+
if (this.html3DRenderer) this.html3DRenderer.setSize(width, height);
|
|
106
|
+
if (this.orbitControls) {
|
|
107
|
+
if (camera2 instanceof THREE.PerspectiveCamera) {
|
|
108
|
+
camera2.aspect = width / height;
|
|
109
|
+
} else if (camera2 instanceof THREE.OrthographicCamera) {
|
|
110
|
+
camera2.left = -width * 0.5;
|
|
111
|
+
camera2.right = width * 0.5;
|
|
112
|
+
camera2.top = height * 0.5;
|
|
113
|
+
camera2.bottom = -height * 0.5;
|
|
114
|
+
}
|
|
115
|
+
camera2.updateProjectionMatrix();
|
|
116
|
+
}
|
|
117
|
+
this.width = width;
|
|
118
|
+
this.height = height;
|
|
119
|
+
this.onResize && this.onResize(width, height);
|
|
120
|
+
this.dispatchEvent({ type: "resize", width, height });
|
|
121
|
+
});
|
|
122
|
+
this.resizeObserver.observe(dom);
|
|
123
|
+
}
|
|
124
|
+
this.renderer.setAnimationLoop(() => {
|
|
125
|
+
if (this.html2DRenderer) this.html2DRenderer.render(this.scene, this.camera);
|
|
126
|
+
if (this.html3DRenderer) this.html3DRenderer.render(this.scene, this.camera);
|
|
127
|
+
this.render();
|
|
128
|
+
if (this.orbitControls && this.orbitControls.enabled) this.orbitControls.update();
|
|
129
|
+
this.tweenTaskList.forEach((tween) => tween.update());
|
|
130
|
+
this.onUpdate && this.onUpdate();
|
|
131
|
+
this.parent?.components.forEach((c) => c.dispatchEvent({ type: "update" }));
|
|
132
|
+
});
|
|
133
|
+
this.scene.add(new THREE.AmbientLight(16777215, 0.5));
|
|
134
|
+
this.scene.background = new THREE.Color(3355443);
|
|
135
|
+
const directLight = new THREE.DirectionalLight(16777215, 4);
|
|
136
|
+
directLight.position.set(100, -100, 100);
|
|
137
|
+
this.scene.add(directLight);
|
|
138
|
+
}
|
|
139
|
+
render() {
|
|
140
|
+
this.renderer.render(this.scene, this.camera);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 世界坐标转屏幕坐标
|
|
144
|
+
* @param worldPosition
|
|
145
|
+
* @param camera
|
|
146
|
+
* @param renderer
|
|
147
|
+
* @returns
|
|
148
|
+
*/
|
|
149
|
+
worldToScreenPosition(worldPosition) {
|
|
150
|
+
const vector = new THREE.Vector3();
|
|
151
|
+
vector.copy(worldPosition);
|
|
152
|
+
vector.project(this.camera);
|
|
153
|
+
const x = (vector.x * 0.5 + 0.5) * this.renderer.domElement.clientWidth;
|
|
154
|
+
const z = (-vector.z * 0.5 + 0.5) * this.renderer.domElement.clientHeight;
|
|
155
|
+
return new THREE.Vector2(x, z);
|
|
156
|
+
}
|
|
157
|
+
cameraPositionRecord = [];
|
|
158
|
+
/**
|
|
159
|
+
* 相机
|
|
160
|
+
* @param position
|
|
161
|
+
* @param lookAt
|
|
162
|
+
* @param onEnd
|
|
163
|
+
*/
|
|
164
|
+
cameraTo(position, lookAt, onEnd) {
|
|
165
|
+
this.cameraPositionRecord.push([
|
|
166
|
+
this.camera.position.clone(),
|
|
167
|
+
this.camera.quaternion.clone()
|
|
168
|
+
]);
|
|
169
|
+
const tween = new TWEEN.Tween(this.camera.position);
|
|
170
|
+
tween.to(position, 600);
|
|
171
|
+
tween.start();
|
|
172
|
+
tween.onUpdate(() => {
|
|
173
|
+
this.camera.lookAt(lookAt);
|
|
174
|
+
});
|
|
175
|
+
tween.onComplete(() => {
|
|
176
|
+
const i = this.tweenTaskList.indexOf(tween);
|
|
177
|
+
this.tweenTaskList.splice(i, 1);
|
|
178
|
+
onEnd && onEnd();
|
|
179
|
+
});
|
|
180
|
+
this.tweenTaskList.push(tween);
|
|
181
|
+
}
|
|
182
|
+
cameraBack() {
|
|
183
|
+
if (this.cameraPositionRecord.length) {
|
|
184
|
+
const [pos, quat] = this.cameraPositionRecord.pop();
|
|
185
|
+
this.camera.position.copy(pos);
|
|
186
|
+
this.camera.quaternion.copy(quat);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 创建点
|
|
191
|
+
* @param pos
|
|
192
|
+
*/
|
|
193
|
+
createPointMesh(pos, size = 0.02, parameters, parent = this.container) {
|
|
194
|
+
const box = new THREE.Mesh(
|
|
195
|
+
new THREE.SphereGeometry(size),
|
|
196
|
+
new THREE.MeshBasicMaterial(parameters)
|
|
197
|
+
);
|
|
198
|
+
if (pos instanceof Point) box.position.set(pos.x, pos.y, 0);
|
|
199
|
+
else if (pos instanceof THREE.Vector3) box.position.copy(pos);
|
|
200
|
+
parent.add(box);
|
|
201
|
+
return box;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 创建文本
|
|
205
|
+
* @param text
|
|
206
|
+
* @param pos
|
|
207
|
+
* @param style
|
|
208
|
+
*/
|
|
209
|
+
createText(text, pos, style, parent = this.container) {
|
|
210
|
+
const div = document.createElement("div");
|
|
211
|
+
div.innerHTML = text;
|
|
212
|
+
div.style.pointerEvents = "none";
|
|
213
|
+
Object.assign(div.style, { fontSize: "10px", color: "#ffffff", ...style });
|
|
214
|
+
const css2DObject = new _Renderer.CSS2DObject(div);
|
|
215
|
+
if (pos instanceof Point) css2DObject.position.set(pos.x, pos.y, 0);
|
|
216
|
+
else if (pos instanceof THREE.Vector3) css2DObject.position.copy(pos);
|
|
217
|
+
parent.add(css2DObject);
|
|
218
|
+
return css2DObject;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 创建几何缓冲区
|
|
222
|
+
* @param map
|
|
223
|
+
* @param count
|
|
224
|
+
*/
|
|
225
|
+
createLineSegments(map, count, parameters, parent = this.container) {
|
|
226
|
+
if (Array.isArray(map)) {
|
|
227
|
+
const position = map.flatMap((line) => line?.points?.flatMap((p) => [p.x, p.y, 0]));
|
|
228
|
+
return this.createLineSegments({ position }, map.length * 2, parameters, parent);
|
|
229
|
+
}
|
|
230
|
+
const geometry = new THREE.BufferGeometry();
|
|
231
|
+
Object.keys(map).forEach((key) => {
|
|
232
|
+
const value = map[key];
|
|
233
|
+
geometry.setAttribute(key, new THREE.BufferAttribute(new Float32Array(value), value.length / count));
|
|
234
|
+
});
|
|
235
|
+
const lineSegmentList = new THREE.LineSegments(geometry, new THREE.LineBasicMaterial({ ...parameters }));
|
|
236
|
+
parent.add(lineSegmentList);
|
|
237
|
+
return lineSegmentList;
|
|
238
|
+
}
|
|
239
|
+
/** 创建点
|
|
240
|
+
* @param point
|
|
241
|
+
* @param parameters
|
|
242
|
+
* @param parent
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
createCircle(point, parameters, parent) {
|
|
246
|
+
const vertices = [];
|
|
247
|
+
if (Array.isArray(point)) point.forEach((p) => vertices.push(p.x, p.y, 0));
|
|
248
|
+
else vertices.push(point.x, point.y, 0);
|
|
249
|
+
const geometry = new THREE.BufferGeometry();
|
|
250
|
+
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
|
|
251
|
+
const material = new THREE.PointsMaterial({
|
|
252
|
+
color: 16777215,
|
|
253
|
+
sizeAttenuation: false,
|
|
254
|
+
size: 12,
|
|
255
|
+
map: circleTexture,
|
|
256
|
+
transparent: true,
|
|
257
|
+
...parameters
|
|
258
|
+
});
|
|
259
|
+
const points = new THREE.Points(geometry, material);
|
|
260
|
+
parent && parent.add(points);
|
|
261
|
+
return points;
|
|
262
|
+
}
|
|
263
|
+
destroy() {
|
|
264
|
+
if (this.resizeObserver) {
|
|
265
|
+
this.renderer.dispose();
|
|
266
|
+
this.resizeObserver.disconnect();
|
|
267
|
+
this.resizeObserver = void 0;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
__publicField(_Renderer, "name", "Renderer");
|
|
272
|
+
__publicField(_Renderer, "CSS2DObject", CSS2DObject);
|
|
273
|
+
__publicField(_Renderer, "CSS3DObject", CSS3DObject);
|
|
274
|
+
__publicField(_Renderer, "CSS3DSprite", CSS3DSprite);
|
|
275
|
+
__publicField(_Renderer, "Group", THREE.Group);
|
|
276
|
+
__publicField(_Renderer, "Object3D", THREE.Object3D);
|
|
277
|
+
__publicField(_Renderer, "Mesh", THREE.Mesh);
|
|
278
|
+
__publicField(_Renderer, "Line", THREE.Line);
|
|
279
|
+
__publicField(_Renderer, "LineSegments", THREE.LineSegments);
|
|
280
|
+
__publicField(_Renderer, "Points", THREE.Points);
|
|
281
|
+
let Renderer = _Renderer;
|
|
282
|
+
class DomEventRegister extends Component {
|
|
283
|
+
static name = "DomEventRegister";
|
|
284
|
+
cancelDefaultBehaviorList = [];
|
|
285
|
+
pointer = new Vector2();
|
|
286
|
+
_isMouseEnter = false;
|
|
287
|
+
set isMouseEnter(isMouseEnter) {
|
|
288
|
+
if (this._isMouseEnter === isMouseEnter) return;
|
|
289
|
+
this._isMouseEnter = isMouseEnter;
|
|
290
|
+
}
|
|
291
|
+
get isMouseEnter() {
|
|
292
|
+
return this._isMouseEnter;
|
|
293
|
+
}
|
|
294
|
+
_mouseMoveEventProxylock = false;
|
|
295
|
+
set mouseMoveEventProxylock(lock) {
|
|
296
|
+
this._mouseMoveEventProxylock = lock;
|
|
297
|
+
if (lock) {
|
|
298
|
+
this._isMouseEnter = false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
get mouseMoveEventProxylock() {
|
|
302
|
+
return this._mouseMoveEventProxylock;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* 组件被添加到父组件上时调用
|
|
306
|
+
*/
|
|
307
|
+
onAddFromParent() {
|
|
308
|
+
this.initMouseMoveEventProxy();
|
|
309
|
+
this.initKeyEvent();
|
|
310
|
+
this.initWheelEvent();
|
|
311
|
+
this.autoBodyCursor();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 初始化鼠标事件代理(判断鼠标是否在domElement上)
|
|
315
|
+
*/
|
|
316
|
+
initMouseMoveEventProxy() {
|
|
317
|
+
const domContainer = this.parent?.findComponentByType(DomContainer), domElement = domContainer.domElement, variable = this.parent?.findComponentByType(Variable), globalMousemoveFun = (e) => {
|
|
318
|
+
if (this._mouseMoveEventProxylock) return;
|
|
319
|
+
const rect = domElement.getBoundingClientRect(), offsetX = e.clientX - rect.left, offsetY = e.clientY - rect.top;
|
|
320
|
+
if (offsetX >= 0 && offsetY >= 0 && offsetX <= rect.width && offsetY <= rect.height) {
|
|
321
|
+
this.pointer.set(offsetX, offsetY);
|
|
322
|
+
this.dispatchEvent({
|
|
323
|
+
type: "mousemove",
|
|
324
|
+
x: offsetX,
|
|
325
|
+
y: offsetY,
|
|
326
|
+
moveX: e.movementX,
|
|
327
|
+
moveY: e.movementY
|
|
328
|
+
});
|
|
329
|
+
this.isMouseEnter = true;
|
|
330
|
+
} else {
|
|
331
|
+
this.isMouseEnter = false;
|
|
332
|
+
}
|
|
333
|
+
}, globalMousedownFun = (e) => {
|
|
334
|
+
if (!this.isMouseEnter) return;
|
|
335
|
+
const rect = domElement.getBoundingClientRect(), offsetX = e.clientX - rect.left, offsetY = e.clientY - rect.top;
|
|
336
|
+
this.pointer.set(offsetX, offsetY);
|
|
337
|
+
variable.set("currentMouseDown", "mouse_" + e.button);
|
|
338
|
+
this.dispatchEvent({
|
|
339
|
+
type: "mousedown",
|
|
340
|
+
x: offsetX,
|
|
341
|
+
y: offsetY
|
|
342
|
+
});
|
|
343
|
+
}, globalMouseupFun = (e) => {
|
|
344
|
+
if (!this.isMouseEnter) return;
|
|
345
|
+
variable.set("currentMouseUp", "mouse_" + e.button);
|
|
346
|
+
};
|
|
347
|
+
document.addEventListener("mousemove", globalMousemoveFun);
|
|
348
|
+
document.addEventListener("mousedown", globalMousedownFun);
|
|
349
|
+
document.addEventListener("mouseup", globalMouseupFun);
|
|
350
|
+
this.addEventRecord("destory", () => {
|
|
351
|
+
document.removeEventListener("mousemove", globalMousemoveFun);
|
|
352
|
+
document.removeEventListener("mousedown", globalMousedownFun);
|
|
353
|
+
document.removeEventListener("mouseup", globalMouseupFun);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* 初始化键盘事件
|
|
358
|
+
*/
|
|
359
|
+
initKeyEvent() {
|
|
360
|
+
const variable = this.parent?.findComponentByType(Variable);
|
|
361
|
+
document.body.tabIndex = 1;
|
|
362
|
+
const onKeyup = (e) => {
|
|
363
|
+
if (!this.isMouseEnter) return;
|
|
364
|
+
const key = e.key.toLocaleLowerCase();
|
|
365
|
+
variable.set("currentKeyUp", key);
|
|
366
|
+
for (let i = 0; i < this.cancelDefaultBehaviorList.length; i++) {
|
|
367
|
+
const element = this.cancelDefaultBehaviorList[i];
|
|
368
|
+
if (element(e)) e.preventDefault();
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
document.body.addEventListener("keyup", onKeyup);
|
|
372
|
+
const onKeydown = (e) => {
|
|
373
|
+
if (!this.isMouseEnter) return;
|
|
374
|
+
const key = e.key.toLocaleLowerCase();
|
|
375
|
+
variable.set("currentKeyDown", key);
|
|
376
|
+
for (let i = 0; i < this.cancelDefaultBehaviorList.length; i++) {
|
|
377
|
+
const element = this.cancelDefaultBehaviorList[i];
|
|
378
|
+
if (element(e)) e.preventDefault();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
document.body.addEventListener("keydown", onKeydown);
|
|
382
|
+
const onFocus = () => variable.set("focus", true);
|
|
383
|
+
document.body.addEventListener("focus", onFocus);
|
|
384
|
+
const onBlur = () => variable.set("focus", false);
|
|
385
|
+
document.body.addEventListener("blur", onBlur);
|
|
386
|
+
this.addEventRecord("destory", () => {
|
|
387
|
+
document.body.removeEventListener("keyup", onKeyup);
|
|
388
|
+
document.body.removeEventListener("keydown", onKeydown);
|
|
389
|
+
document.body.removeEventListener("focus", onFocus);
|
|
390
|
+
document.body.removeEventListener("blur", onBlur);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* 初始化滚轮事件
|
|
395
|
+
*/
|
|
396
|
+
initWheelEvent() {
|
|
397
|
+
const variable = this.parent?.findComponentByType(Variable);
|
|
398
|
+
const onWheel = (e) => variable.set("currentWheel", e.wheelDelta);
|
|
399
|
+
document.body.addEventListener("wheel", onWheel);
|
|
400
|
+
this.addEventRecord("destory", () => {
|
|
401
|
+
document.body.removeEventListener("wheel", onWheel);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* 根据domElement的cursor自动设置body的cursor
|
|
406
|
+
*/
|
|
407
|
+
autoBodyCursor() {
|
|
408
|
+
const domContainer = this.parent?.findComponentByType(DomContainer), domElement = domContainer.domElement;
|
|
409
|
+
let bodyCursor = null;
|
|
410
|
+
this.addEventListener("update", () => {
|
|
411
|
+
if (this._mouseMoveEventProxylock) return;
|
|
412
|
+
if (this.isMouseEnter) {
|
|
413
|
+
if (bodyCursor === null) {
|
|
414
|
+
bodyCursor = document.body.style.cursor;
|
|
415
|
+
}
|
|
416
|
+
document.body.style.cursor = domElement.style.cursor;
|
|
417
|
+
} else {
|
|
418
|
+
if (bodyCursor !== null) {
|
|
419
|
+
document.body.style.cursor = bodyCursor;
|
|
420
|
+
bodyCursor = null;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
this.addEventRecord("destory", () => {
|
|
425
|
+
document.body.style.cursor = bodyCursor ?? "";
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
*
|
|
430
|
+
* @param callBack
|
|
431
|
+
*/
|
|
432
|
+
addCancelDefaultBehavior(callBack) {
|
|
433
|
+
this.cancelDefaultBehaviorList.push(callBack);
|
|
434
|
+
return this;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
*
|
|
438
|
+
* @param el
|
|
439
|
+
* @param callBack
|
|
440
|
+
* @param offset
|
|
441
|
+
* @param condition
|
|
442
|
+
*/
|
|
443
|
+
static dragMoveHelper(el, callBack, offset = { x: 0, y: 0 }, condition = () => true) {
|
|
444
|
+
function onMousedown() {
|
|
445
|
+
if (!condition()) return;
|
|
446
|
+
const move = (e) => {
|
|
447
|
+
offset.x += e.movementX;
|
|
448
|
+
offset.y += e.movementY;
|
|
449
|
+
callBack({ ...offset }, e.movementX, e.movementY);
|
|
450
|
+
};
|
|
451
|
+
const end = () => {
|
|
452
|
+
document.removeEventListener("mousemove", move);
|
|
453
|
+
document.removeEventListener("mouseup", end);
|
|
454
|
+
};
|
|
455
|
+
document.addEventListener("mousemove", move);
|
|
456
|
+
document.addEventListener("mouseup", end);
|
|
457
|
+
}
|
|
458
|
+
el.addEventListener("mousedown", onMousedown);
|
|
459
|
+
callBack({ ...offset }, 0, 0);
|
|
460
|
+
return () => {
|
|
461
|
+
el.removeEventListener("mousedown", onMousedown);
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
destroy() {
|
|
465
|
+
this.canceEventRecord("destory");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
export {
|
|
469
|
+
DomEventRegister as D,
|
|
470
|
+
Renderer as R,
|
|
471
|
+
DomContainer as a
|
|
472
|
+
};
|