build-dxf 0.1.34 → 0.1.36

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.
Files changed (25) hide show
  1. package/package.json +1 -1
  2. package/src/DomEventRegister.js +57 -5
  3. package/src/build.js +87 -36
  4. package/src/components/NumberEditor.vue.d.ts +2 -0
  5. package/src/index.css +187 -28
  6. package/src/index.js +10 -10
  7. package/src/index3.js +1594 -1709
  8. package/src/utils/CommandManager/CommandFlow.d.ts +4 -4
  9. package/src/utils/CommandManager/CommandManager.d.ts +11 -3
  10. package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/CommandFlowComponent.d.ts +94 -9
  11. package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/Default.d.ts +3 -0
  12. package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/PointDrag/index.d.ts +38 -0
  13. package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/PointDrag/modifyDoor.d.ts +40 -0
  14. package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/PointDrag/modifyLine.d.ts +34 -0
  15. package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/PointDrag/modifyWindow.d.ts +25 -0
  16. package/src/utils/DxfSystem/plugin/Editor/components/RenderManager.d.ts +13 -22
  17. package/src/utils/DxfSystem/plugin/Editor/type.d.ts +11 -0
  18. package/src/utils/DxfSystem/plugin/RenderPlugin/components/DomContainer.d.ts +3 -0
  19. package/src/utils/DxfSystem/plugin/RenderPlugin/components/DomEventRegister.d.ts +5 -1
  20. package/src/utils/DxfSystem/utils/Lines.d.ts +1 -0
  21. package/src/utils/DxfSystem/utils/Lines2.d.ts +1 -0
  22. package/src/utils/DxfSystem/utils/tools.d.ts +2 -0
  23. package/src/utils/LineSegment.d.ts +1 -0
  24. package/src/utils/Point.d.ts +6 -4
  25. /package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/{PointDrag.d.ts → PointDrag copy.d.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-dxf",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "线段构建双线墙壁的dxf版本",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -7,21 +7,46 @@ import { CSS3DObject, CSS3DSprite, CSS3DRenderer } from "three/addons/renderers/
7
7
  import { CSS2DObject, CSS2DRenderer } from "three/addons/renderers/CSS2DRenderer.js";
8
8
  import { OrbitControls } from "three/addons/controls/OrbitControls.js";
9
9
  import * as TWEEN from "@tweenjs/tween.js";
10
- import { C as Component, a as Point, j as getDefaultExportFromCjs, A as ArrayMap, V as Variable } from "./build.js";
10
+ import { C as Component, a as Point, k as getDefaultExportFromCjs, A as ArrayMap, V as Variable } from "./build.js";
11
11
  import { ref } from "vue";
12
+ const css = `
13
+ .overlay {
14
+ pointer-events: none;
15
+ }
16
+
17
+ .overlay > * {
18
+ pointer-events: auto;
19
+ }
20
+ `;
12
21
  class DomContainer extends Component {
13
22
  static name = "DomContainer";
23
+ container = document.createElement("div");
14
24
  domElement = document.createElement("div");
15
25
  canvas = document.createElement("canvas");
16
26
  html2DRenderer = document.createElement("div");
17
27
  html3DRenderer = document.createElement("div");
28
+ dialogLayer = document.createElement("div");
29
+ style = document.createElement("style");
18
30
  rect;
19
31
  constructor() {
20
32
  super();
33
+ this.dialogLayer.classList.add("dialog-layer");
21
34
  this.domElement.id = "build-dxf-container";
35
+ this.container.appendChild(this.domElement);
36
+ this.container.appendChild(this.style);
37
+ this.container.appendChild(this.dialogLayer);
22
38
  this.domElement.appendChild(this.canvas);
23
39
  this.domElement.appendChild(this.html3DRenderer);
24
40
  this.domElement.appendChild(this.html2DRenderer);
41
+ this.style.innerHTML = css;
42
+ this.dialogLayer.classList.add("overlay");
43
+ this.html3DRenderer.classList.add("overlay");
44
+ this.html2DRenderer.classList.add("overlay");
45
+ Object.assign(this.container.style, {
46
+ width: "100%",
47
+ height: "100%",
48
+ position: "relative"
49
+ });
25
50
  Object.assign(this.domElement.style, {
26
51
  width: "100%",
27
52
  height: "100%",
@@ -44,6 +69,14 @@ class DomContainer extends Component {
44
69
  width: "100%",
45
70
  height: "100%"
46
71
  });
72
+ Object.assign(this.dialogLayer.style, {
73
+ left: "0px",
74
+ top: "0px",
75
+ width: "100%",
76
+ height: "100%",
77
+ position: "absolute",
78
+ zIndex: "20"
79
+ });
47
80
  this.rect = this.domElement.getBoundingClientRect();
48
81
  new ResizeObserver(() => {
49
82
  this.rect = this.domElement.getBoundingClientRect();
@@ -84,17 +117,20 @@ const _Renderer = class _Renderer extends Component {
84
117
  canvas: this.description.canvas,
85
118
  antialias: true
86
119
  });
120
+ this.renderer.domElement.classList.add("overlay");
87
121
  this.renderer.setPixelRatio(window.devicePixelRatio);
88
122
  if (description.htmlRenderer) {
89
123
  if (description.htmlRenderer["2d"]) {
90
124
  this.html2DRenderer = new CSS2DRenderer();
91
- Object.assign(this.html2DRenderer.domElement.style, { position: "absolute", left: "0px", top: "0px" });
125
+ Object.assign(this.html2DRenderer.domElement.style, { position: "absolute", left: "0px", top: "0px", pointerEvents: "none" });
92
126
  description.htmlRenderer["2d"].appendChild(this.html2DRenderer.domElement);
127
+ this.html2DRenderer.domElement.classList.add("overlay");
93
128
  }
94
129
  if (description.htmlRenderer["3d"]) {
95
130
  this.html3DRenderer = new CSS3DRenderer();
96
- Object.assign(this.html3DRenderer.domElement.style, { position: "absolute", left: "0px", top: "0px" });
131
+ Object.assign(this.html3DRenderer.domElement.style, { position: "absolute", left: "0px", top: "0px", pointerEvents: "none" });
97
132
  description.htmlRenderer["3d"].appendChild(this.html3DRenderer.domElement);
133
+ this.html3DRenderer.domElement.classList.add("overlay");
98
134
  }
99
135
  }
100
136
  if (description.orbitControls) {
@@ -1170,6 +1206,21 @@ class DomEventRegister extends Component {
1170
1206
  offsetY
1171
1207
  };
1172
1208
  }
1209
+ /** 更新鼠标
1210
+ * @param e
1211
+ */
1212
+ updatePointer(e) {
1213
+ const domContainer = this.parent?.findComponentByType(DomContainer);
1214
+ const { offsetX, offsetY } = this.computedPosition(e instanceof TouchEvent ? e.touches[0] : e, domContainer.rect);
1215
+ this.pointer.set(offsetX, offsetY);
1216
+ this.dispatchEvent({
1217
+ type: "pointerdown",
1218
+ x: offsetX,
1219
+ y: offsetY,
1220
+ pointerId: 0,
1221
+ pointerCount: 0
1222
+ });
1223
+ }
1173
1224
  /**
1174
1225
  * 初始化基础事件代理
1175
1226
  */
@@ -1222,7 +1273,6 @@ class DomEventRegister extends Component {
1222
1273
  this.pointer.set(offsetX, offsetY);
1223
1274
  map.append(e.pointerId, new Vector2(offsetX, offsetY));
1224
1275
  const movement = getMovement(e.pointerId);
1225
- console.log(offsetX, offsetY);
1226
1276
  this.dispatchEvent({
1227
1277
  type: "pointermove",
1228
1278
  x: offsetX,
@@ -1356,7 +1406,7 @@ class DomEventRegister extends Component {
1356
1406
  * 根据domElement的cursor自动设置body的cursor
1357
1407
  */
1358
1408
  autoBodyCursor() {
1359
- const domContainer = this.parent?.findComponentByType(DomContainer), domElement = domContainer.domElement;
1409
+ const domContainer = this.parent?.findComponentByType(DomContainer), domElement = domContainer.dialogLayer;
1360
1410
  let bodyCursor = null;
1361
1411
  this.addEventListener("update", () => {
1362
1412
  if (this._mouseMoveEventProxylock) return;
@@ -1365,6 +1415,8 @@ class DomEventRegister extends Component {
1365
1415
  bodyCursor = document.body.style.cursor;
1366
1416
  }
1367
1417
  document.body.style.cursor = domElement.style.cursor;
1418
+ domContainer.container.style.cursor = domElement.style.cursor;
1419
+ domContainer.domElement.style.cursor = domElement.style.cursor;
1368
1420
  } else {
1369
1421
  if (bodyCursor !== null) {
1370
1422
  document.body.style.cursor = bodyCursor;
package/src/build.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as THREE from "three";
2
- import { EventDispatcher as EventDispatcher$1, Group as Group$1, Vector3, Matrix3, MathUtils, Box3, Matrix4, Ray } from "three";
2
+ import { EventDispatcher as EventDispatcher$1, Vector3, Group as Group$1, Matrix3, MathUtils, Box3, Matrix4, Ray } from "three";
3
3
  import ClipperLib from "clipper-lib";
4
4
  import Drawing from "dxf-writer";
5
5
  import { Brush, Evaluator, SUBTRACTION } from "three-bvh-csg";
@@ -2159,6 +2159,24 @@ class LineSegment {
2159
2159
  return true;
2160
2160
  });
2161
2161
  }
2162
+ static constrainLine(line, base) {
2163
+ const center = line.center, width = line.length();
2164
+ if (base.length() < width) {
2165
+ line.start.copy(base.start);
2166
+ line.end.copy(base.end);
2167
+ return line;
2168
+ }
2169
+ const hw = width * 0.5, start = base.start.clone().add(base.end.direction(base.start).multiplyScalar(width * 0.5)), end = base.end.clone().add(base.start.direction(base.end).multiplyScalar(width * 0.5)), dir = base.direction();
2170
+ const pl = new LineSegment(start, end);
2171
+ center.copy(pl.projectPoint(center, false));
2172
+ if (!pl.projectPoint(center, true)) {
2173
+ if (center.distance(start) < center.distance(end)) center.copy(start);
2174
+ else center.copy(end);
2175
+ line.start.copy(center).add(dir.clone().multiplyScalar(-hw));
2176
+ line.end.copy(center).add(dir.clone().multiplyScalar(hw));
2177
+ }
2178
+ return line;
2179
+ }
2162
2180
  static createModifyManager() {
2163
2181
  const modifyMap = new MapEnhance();
2164
2182
  function setPoint(line, point2, value) {
@@ -2243,12 +2261,6 @@ class Point {
2243
2261
  this.y = arr[1];
2244
2262
  return this;
2245
2263
  }
2246
- /**
2247
- *
2248
- */
2249
- toArray() {
2250
- return [this.x, this.y];
2251
- }
2252
2264
  /**
2253
2265
  * multiplyScalar
2254
2266
  * @param scalar
@@ -2484,6 +2496,12 @@ class Point {
2484
2496
  this.y = p2.y ?? 0;
2485
2497
  return this;
2486
2498
  }
2499
+ /**
2500
+ *
2501
+ */
2502
+ toArray() {
2503
+ return [this.x, this.y];
2504
+ }
2487
2505
  toJson(z = 0) {
2488
2506
  return {
2489
2507
  x: this.x,
@@ -2491,6 +2509,9 @@ class Point {
2491
2509
  z
2492
2510
  };
2493
2511
  }
2512
+ toVector3(z = 0) {
2513
+ return new Vector3(this.x, this.y, z);
2514
+ }
2494
2515
  static adsorb(points, tolerance = 15e-5) {
2495
2516
  const grid = new PointVirtualGrid();
2496
2517
  points.forEach((p2) => grid.insert(p2));
@@ -3542,10 +3563,18 @@ function createQuadtree(lines) {
3542
3563
  }
3543
3564
  return quadtree;
3544
3565
  }
3566
+ function mToMm(value) {
3567
+ return Number((value * 1e3).toFixed(0));
3568
+ }
3569
+ function mmTom(value) {
3570
+ return Number((value / 1e3).toFixed(4));
3571
+ }
3545
3572
  const tools = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3546
3573
  __proto__: null,
3547
3574
  createPointVirtualGrid,
3548
- createQuadtree
3575
+ createQuadtree,
3576
+ mToMm,
3577
+ mmTom
3549
3578
  }, Symbol.toStringTag, { value: "Module" }));
3550
3579
  function findDiscretePointLine(lines, grid0, lineSet, deep = true) {
3551
3580
  lineSet = lineSet ?? /* @__PURE__ */ new Set();
@@ -5209,8 +5238,7 @@ function correction$1(targettLine, lines, intersectMap, errAngle = 15) {
5209
5238
  const center = line.center;
5210
5239
  line.start.rotate(center, diff);
5211
5240
  line.end.rotate(center, diff);
5212
- if (line.userData.isDoor) doorLines.push(line);
5213
- else parallelLines.push(line);
5241
+ parallelLines.push(line);
5214
5242
  return line;
5215
5243
  }
5216
5244
  function vertical(line) {
@@ -14928,7 +14956,7 @@ const PRE_PROCESSOR = {
14928
14956
  return doorFind.getLines();
14929
14957
  },
14930
14958
  AxisAlignCorr(lines, option, verticalReferenceLine) {
14931
- verticalReferenceLine = verticalReferenceLine ?? findVerticalReference(lines);
14959
+ verticalReferenceLine = verticalReferenceLine ?? findVerticalReference(lines.filter((line) => !line.userData.isDoor));
14932
14960
  if (verticalReferenceLine) {
14933
14961
  const t2 = performance.now();
14934
14962
  const lineSegments = AxisAlignCorr.correction(lines, verticalReferenceLine, option);
@@ -15669,6 +15697,7 @@ class Lines extends THREE.LineSegments {
15669
15697
  geometry = new THREE.BufferGeometry();
15670
15698
  points = [];
15671
15699
  pointsObject3D;
15700
+ continuous = true;
15672
15701
  constructor(points = [], color = 16777215) {
15673
15702
  super();
15674
15703
  this.geometry = this.geometry;
@@ -15718,13 +15747,20 @@ class Lines extends THREE.LineSegments {
15718
15747
  updateGeometry() {
15719
15748
  if (this._timer) clearTimeout(this._timer);
15720
15749
  this._timer = setTimeout(() => {
15721
- const array = this.points.flatMap((p2, i) => {
15722
- if (i === 0) return [];
15723
- else {
15750
+ const array = [];
15751
+ if (this.continuous) {
15752
+ this.points.forEach((p2, i) => {
15753
+ if (i === 0) return;
15724
15754
  const p0 = this.points[i - 1];
15725
- return [p0.x, p0.y, p0.z, p2.x, p2.y, p2.z];
15755
+ array.push(p0.x, p0.y, p0.z, p2.x, p2.y, p2.z);
15756
+ });
15757
+ } else {
15758
+ for (let i = 0; i < this.points.length; i += 2) {
15759
+ const p0 = this.points[i];
15760
+ const p2 = this.points[i + 1];
15761
+ if (p0 && p2) array.push(p0.x, p0.y, p0.z, p2.x, p2.y, p2.z);
15726
15762
  }
15727
- });
15763
+ }
15728
15764
  const position = new THREE.BufferAttribute(new Float32Array(array), 3);
15729
15765
  this.geometry.setAttribute("position", position);
15730
15766
  this._timer = null;
@@ -15801,7 +15837,7 @@ class CommandFlow extends EventDispatcher {
15801
15837
  rollbacklist = [];
15802
15838
  revokeRollbacklist = [];
15803
15839
  // 是否写入操作记录
15804
- writeOperationList = true;
15840
+ writeOperationRecord = true;
15805
15841
  loop = false;
15806
15842
  currentIndex = 0;
15807
15843
  setLoop(loop) {
@@ -15813,9 +15849,9 @@ class CommandFlow extends EventDispatcher {
15813
15849
  * @param operation
15814
15850
  * @returns
15815
15851
  */
15816
- add(operation, data = {}) {
15852
+ add(operation, data) {
15817
15853
  this.list.push(operation);
15818
- this.dataList.push(data);
15854
+ this.dataList.push(data ?? {});
15819
15855
  return this;
15820
15856
  }
15821
15857
  /** 添加回滚回调列表
@@ -15859,13 +15895,26 @@ class CommandManager extends EventDispatcher {
15859
15895
  constructor() {
15860
15896
  super();
15861
15897
  }
15898
+ /** 写入记录
15899
+ * @param name
15900
+ * @param data
15901
+ */
15902
+ addOperation(name, data) {
15903
+ const commandFlow = this.getCommandFlow(name);
15904
+ if (!commandFlow) throw new Error(`${name} 命令不存在`);
15905
+ if (commandFlow.writeOperationRecord) {
15906
+ this.operationList.push({ name, data });
15907
+ this.rollbackList.length = 0;
15908
+ }
15909
+ }
15862
15910
  /** 添加命令流
15863
15911
  * @param name
15912
+ * @param custom 自定义命令流类
15864
15913
  * @returns
15865
15914
  */
15866
- addCommandFlow(name) {
15915
+ addCommandFlow(name, custom) {
15867
15916
  if (this.commandFlowMap.has(name)) throw new Error(`${name} 命令已经存在`);
15868
- const commandFlow = new CommandFlow();
15917
+ const commandFlow = custom ? custom() : new CommandFlow();
15869
15918
  this.commandFlowMap.set(name, commandFlow);
15870
15919
  return commandFlow;
15871
15920
  }
@@ -15932,7 +15981,7 @@ class CommandManager extends EventDispatcher {
15932
15981
  if (this.abortController && !this.abortController.signal.aborted) {
15933
15982
  commandFlow.dispatchEvent({ type: "completed", data });
15934
15983
  this.dispatchEvent({ type: "completed", name, data });
15935
- if (commandFlow.writeOperationList) {
15984
+ if (commandFlow.writeOperationRecord) {
15936
15985
  this.operationList.push({ name, data });
15937
15986
  this.rollbackList.length = 0;
15938
15987
  }
@@ -19069,7 +19118,7 @@ async function createEditor(dom, camera, orbitControls = false, viewPermission)
19069
19118
  camera
19070
19119
  })).usePlugin(editor.EditorPlugin.create({ viewPermission }));
19071
19120
  const domContainer = dxfSystem.findComponentByType(rp.components.DomContainer);
19072
- domContainer && dom.appendChild(domContainer.domElement);
19121
+ domContainer && dom.appendChild(domContainer.container);
19073
19122
  gloabalDxfSystem = dxfSystem;
19074
19123
  return {
19075
19124
  dxfSystem,
@@ -19203,18 +19252,20 @@ export {
19203
19252
  Lines as e,
19204
19253
  recomputedWindow as f,
19205
19254
  drawText$1 as g,
19206
- PRE_PROCESSOR as h,
19207
- CommandManager as i,
19208
- getDefaultExportFromCjs as j,
19209
- createEditor as k,
19210
- getModels as l,
19211
- buildJson as m,
19212
- getFileAll as n,
19213
- getGlobalDxfSystem as o,
19214
- index$1 as p,
19215
- index as q,
19255
+ mmTom as h,
19256
+ PRE_PROCESSOR as i,
19257
+ CommandManager as j,
19258
+ getDefaultExportFromCjs as k,
19259
+ createEditor as l,
19260
+ mToMm as m,
19261
+ getModels as n,
19262
+ buildJson as o,
19263
+ getFileAll as p,
19264
+ getGlobalDxfSystem as q,
19216
19265
  recomputedWindowCenter as r,
19217
- DxfSystem as s,
19218
- components as t,
19219
- uuid as u
19266
+ index$1 as s,
19267
+ index as t,
19268
+ uuid as u,
19269
+ DxfSystem as v,
19270
+ components as w
19220
19271
  };
@@ -2,6 +2,7 @@ type __VLS_Props = {
2
2
  showCancel?: boolean;
3
3
  showMax?: boolean;
4
4
  showMin?: boolean;
5
+ showConfirm?: boolean;
5
6
  };
6
7
  declare const __VLS_defaults: {
7
8
  modelValue: string;
@@ -25,5 +26,6 @@ declare const _default: import('vue').DefineComponent<__VLS_PublicProps, {}, {},
25
26
  showCancel: boolean;
26
27
  showMax: boolean;
27
28
  showMin: boolean;
29
+ showConfirm: boolean;
28
30
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
29
31
  export default _default;