build-dxf 0.0.19-6 → 0.0.19-8

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/src/index.js CHANGED
@@ -1,8 +1,10 @@
1
- import { D, M, i, c } from "./build.js";
2
1
  import "three";
2
+ import { D, M, i, c, g, d } from "./build.js";
3
3
  export {
4
4
  D as DxfSystem,
5
5
  M as ModelDataPlugin,
6
6
  i as components,
7
- c as createEditor
7
+ c as createEditor,
8
+ g as getFileAll,
9
+ d as getGlobalDxfSystem
8
10
  };
package/src/index2.js CHANGED
@@ -622,16 +622,72 @@ class DomEventRegister extends Component {
622
622
  static name = "DomEventRegister";
623
623
  cancelDefaultBehaviorList = [];
624
624
  pointer = new Vector2();
625
+ _isMouseEnter = false;
626
+ set isMouseEnter(isMouseEnter) {
627
+ if (this._isMouseEnter === isMouseEnter) return;
628
+ this._isMouseEnter = isMouseEnter;
629
+ }
630
+ get isMouseEnter() {
631
+ return this._isMouseEnter;
632
+ }
625
633
  /**
626
- *
627
- * @param parent
634
+ * 组件被添加到父组件上时调用
628
635
  */
629
- onAddFromParent(parent) {
630
- const domContainer = parent.findComponentByType(DomContainer);
631
- const variable = parent.findComponentByType(Variable);
632
- const domElement = domContainer.domElement;
636
+ onAddFromParent() {
637
+ this.initMouseMoveEventProxy();
638
+ this.initKeyEvent();
639
+ this.initWheelEvent();
640
+ this.autoBodyCursor();
641
+ }
642
+ /**
643
+ * 初始化鼠标事件代理(判断鼠标是否在domElement上)
644
+ */
645
+ initMouseMoveEventProxy() {
646
+ const domContainer = this.parent?.findComponentByType(DomContainer), domElement = domContainer.domElement, variable = this.parent?.findComponentByType(Variable), globalMousemoveFun = (e) => {
647
+ const rect = domElement.getBoundingClientRect(), offsetX = e.clientX - rect.left, offsetY = e.clientY - rect.top;
648
+ if (offsetX >= 0 && offsetY >= 0 && offsetX <= rect.width && offsetY <= rect.height) {
649
+ this.pointer.set(offsetX, offsetY);
650
+ this.dispatchEvent({
651
+ type: "mousemove",
652
+ x: offsetX,
653
+ y: offsetY,
654
+ moveX: e.movementX,
655
+ moveY: e.movementY
656
+ });
657
+ this.isMouseEnter = true;
658
+ } else {
659
+ this.isMouseEnter = false;
660
+ }
661
+ }, globalMousedownFun = (e) => {
662
+ if (!this.isMouseEnter) return;
663
+ const rect = domElement.getBoundingClientRect();
664
+ variable.set("currentMouseDown", "mouse_" + e.button);
665
+ this.dispatchEvent({
666
+ type: "mousedown",
667
+ x: e.clientX - rect.left,
668
+ y: e.clientY - rect.top
669
+ });
670
+ }, globalMouseupFun = (e) => {
671
+ if (!this.isMouseEnter) return;
672
+ variable.set("currentMouseUp", "mouse_" + e.button);
673
+ };
674
+ document.addEventListener("mousemove", globalMousemoveFun);
675
+ document.addEventListener("mousedown", globalMousedownFun);
676
+ document.addEventListener("mouseup", globalMouseupFun);
677
+ this.addEventRecord("destory", () => {
678
+ document.removeEventListener("mousemove", globalMousemoveFun);
679
+ document.removeEventListener("mousedown", globalMousedownFun);
680
+ document.removeEventListener("mouseup", globalMouseupFun);
681
+ });
682
+ }
683
+ /**
684
+ * 初始化键盘事件
685
+ */
686
+ initKeyEvent() {
687
+ const variable = this.parent?.findComponentByType(Variable);
633
688
  document.body.tabIndex = 1;
634
689
  const onKeyup = (e) => {
690
+ if (!this.isMouseEnter) return;
635
691
  const key = e.key.toLocaleLowerCase();
636
692
  variable.set("currentKeyUp", key);
637
693
  for (let i = 0; i < this.cancelDefaultBehaviorList.length; i++) {
@@ -641,6 +697,7 @@ class DomEventRegister extends Component {
641
697
  };
642
698
  document.body.addEventListener("keyup", onKeyup);
643
699
  const onKeydown = (e) => {
700
+ if (!this.isMouseEnter) return;
644
701
  const key = e.key.toLocaleLowerCase();
645
702
  variable.set("currentKeyDown", key);
646
703
  for (let i = 0; i < this.cancelDefaultBehaviorList.length; i++) {
@@ -649,43 +706,46 @@ class DomEventRegister extends Component {
649
706
  }
650
707
  };
651
708
  document.body.addEventListener("keydown", onKeydown);
709
+ const onFocus = () => variable.set("focus", true);
710
+ document.body.addEventListener("focus", onFocus);
711
+ const onBlur = () => variable.set("focus", false);
712
+ document.body.addEventListener("blur", onBlur);
652
713
  this.addEventRecord("destory", () => {
653
714
  document.body.removeEventListener("keyup", onKeyup);
654
715
  document.body.removeEventListener("keydown", onKeydown);
716
+ document.body.removeEventListener("focus", onFocus);
717
+ document.body.removeEventListener("blur", onBlur);
655
718
  });
656
- domElement.addEventListener("mousedown", (e) => {
657
- variable.set("currentMouseDown", "mouse_" + e.button);
658
- });
659
- domElement.addEventListener("mouseup", (e) => {
660
- variable.set("currentMouseUp", "mouse_" + e.button);
661
- });
662
- domElement.addEventListener("wheel", (e) => {
663
- variable.set("currentWheel", e.wheelDelta);
664
- });
665
- domElement.addEventListener("focus", () => {
666
- variable.set("focus", true);
667
- });
668
- domElement.addEventListener("blur", () => {
669
- variable.set("focus", false);
670
- });
671
- this.dragMoveHelper(domElement, (_0, x, y) => variable.set("pointerMove", { x, y }), { x: 0, y: 0 });
672
- domElement.addEventListener("mousemove", (e) => {
673
- this.pointer.set(e.offsetX, e.offsetY);
674
- this.dispatchEvent({
675
- type: "mousemove",
676
- x: e.offsetX,
677
- y: e.offsetY,
678
- moveX: e.movementX,
679
- moveY: e.movementY
680
- });
719
+ }
720
+ /**
721
+ * 初始化滚轮事件
722
+ */
723
+ initWheelEvent() {
724
+ const variable = this.parent?.findComponentByType(Variable);
725
+ const onWheel = (e) => variable.set("currentWheel", e.wheelDelta);
726
+ document.body.addEventListener("wheel", onWheel);
727
+ this.addEventRecord("destory", () => {
728
+ document.body.removeEventListener("wheel", onWheel);
681
729
  });
682
- domElement.addEventListener("mousedown", (e) => {
683
- this.pointer.set(e.offsetX, e.offsetY);
684
- this.dispatchEvent({
685
- type: "mousedown",
686
- x: e.offsetX,
687
- y: e.offsetY
688
- });
730
+ }
731
+ /**
732
+ * 根据domElement的cursor自动设置body的cursor
733
+ */
734
+ autoBodyCursor() {
735
+ const domContainer = this.parent?.findComponentByType(DomContainer), domElement = domContainer.domElement;
736
+ let bodyCursor = null;
737
+ this.addEventListener("update", () => {
738
+ if (this.isMouseEnter) {
739
+ if (bodyCursor === null) {
740
+ bodyCursor = document.body.style.cursor;
741
+ }
742
+ document.body.style.cursor = domElement.style.cursor;
743
+ } else {
744
+ if (bodyCursor !== null) {
745
+ document.body.style.cursor = bodyCursor;
746
+ bodyCursor = null;
747
+ }
748
+ }
689
749
  });
690
750
  }
691
751
  /**
@@ -762,6 +822,8 @@ class EventInput extends Component {
762
822
  this.mouseList.clear();
763
823
  });
764
824
  this.addEventListener("codeChange", this._computedkeyCombination.bind(this));
825
+ this.addKeyCombination("save", ["control", "s"]);
826
+ this.addCancelDefaultBehavior((input) => input.isOnlyKeyDowns(["control", "s"]));
765
827
  }
766
828
  /** 添加取消浏览器默认行为规则
767
829
  * @param callBack
package/src/index3.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as THREE from "three";
2
2
  import { i as isString, n as noop, r as resolveUnref, t as tryOnScopeDispose, b as isClient, c as tryOnMounted, d as identity, e as buildProps, f as definePropType, _ as _export_sfc, u as useNamespace, g as isNumber, h as addUnit, w as withInstall, j as useEmptyValuesProps, k as useSizeProp, p as provideGlobalConfig, l as iconPropType, m as useGlobalComponentSettings, T as TypeComponentsMap, o as ElIcon, q as TypeComponents, s as useTimeoutFn, v as isString$1, x as isFunction, y as isBoolean, z as isElement, A as withInstallFunction, L as Lines, E as ElButton, a as ElCheckbox, S as SelectLocalFile } from "./selectLocalFile.js";
3
- import { C as Component, L as LineSegment, P as Point, B as Box2, E as EventDispatcher, b as PointVirtualGrid, Q as Quadtree } from "./build.js";
3
+ import { C as Component, L as LineSegment, P as Point, B as Box2, E as EventDispatcher, g as getFileAll, b as PointVirtualGrid, Q as Quadtree } from "./build.js";
4
4
  import { watch, ref, defineComponent, computed, createElementBlock, openBlock, normalizeClass, unref, renderSlot, createVNode, Transition, withCtx, withDirectives, createElementVNode, normalizeStyle, createTextVNode, toDisplayString, vShow, shallowReactive, onMounted, createBlock, createCommentVNode, resolveDynamicComponent, Fragment, withModifiers, nextTick, isVNode, render, toRaw, createStaticVNode, createApp } from "vue";
5
5
  import "clipper-lib";
6
6
  import "dxf-writer";
@@ -1097,11 +1097,11 @@ class Default extends Component {
1097
1097
  const rectangle = line.expandToRectangle(0.02, "bothSides");
1098
1098
  object3D.geometry = editor.renderManager.createGeometry({ position: rectangle.createGeometry() }, 6);
1099
1099
  this.container.add(object3D);
1100
- dom.parentElement.style.cursor = "pointer";
1100
+ dom.style.cursor = "pointer";
1101
1101
  currentSelectLine = line;
1102
1102
  } else {
1103
1103
  object3D.removeFromParent();
1104
- dom.parentElement.style.cursor = "default";
1104
+ dom.style.cursor = "default";
1105
1105
  currentSelectLine = null;
1106
1106
  }
1107
1107
  }),
@@ -1259,7 +1259,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1259
1259
  },
1260
1260
  setup(__props) {
1261
1261
  const props = __props;
1262
- const originalLineVisible = ref(true), dxfVisible = ref(true), whiteModelVisible = ref(true), isLook = ref(false), dxfSystem = toRaw(props.dxfSystem);
1262
+ const originalLineVisible = ref(true), dxfVisible = ref(true), whiteModelVisible = ref(true), isLook = ref(false), dxfSystem = toRaw(props.dxfSystem), log = console.log;
1263
1263
  function setLines(lines) {
1264
1264
  if (lines) {
1265
1265
  localStorage.setItem("lines", JSON.stringify(lines));
@@ -1293,33 +1293,44 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1293
1293
  type: "success",
1294
1294
  onClick: selectLocalFile
1295
1295
  }, {
1296
- default: withCtx(() => _cache[2] || (_cache[2] = [
1296
+ default: withCtx(() => _cache[3] || (_cache[3] = [
1297
1297
  createTextVNode(" 选择文件 ", -1)
1298
1298
  ])),
1299
1299
  _: 1,
1300
- __: [2]
1300
+ __: [3]
1301
1301
  }),
1302
1302
  createVNode(unref(ElButton), {
1303
1303
  size: "small",
1304
1304
  type: "primary",
1305
1305
  onClick: _cache[0] || (_cache[0] = ($event) => unref(dxfSystem).Dxf.download("test.dxf"))
1306
1306
  }, {
1307
- default: withCtx(() => _cache[3] || (_cache[3] = [
1307
+ default: withCtx(() => _cache[4] || (_cache[4] = [
1308
1308
  createTextVNode(" 下载 DXF ", -1)
1309
1309
  ])),
1310
1310
  _: 1,
1311
- __: [3]
1311
+ __: [4]
1312
+ }),
1313
+ createVNode(unref(ElButton), {
1314
+ size: "small",
1315
+ type: "primary",
1316
+ onClick: _cache[1] || (_cache[1] = ($event) => unref(log)(unref(getFileAll)()))
1317
+ }, {
1318
+ default: withCtx(() => _cache[5] || (_cache[5] = [
1319
+ createTextVNode(" 打印 ", -1)
1320
+ ])),
1321
+ _: 1,
1322
+ __: [5]
1312
1323
  })
1313
1324
  ]),
1314
1325
  createElementVNode("div", _hoisted_3, [
1315
1326
  createElementVNode("div", _hoisted_4, [
1316
1327
  createVNode(unref(ElCheckbox), {
1317
1328
  modelValue: dxfVisible.value,
1318
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dxfVisible.value = $event),
1329
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => dxfVisible.value = $event),
1319
1330
  label: "dxf"
1320
1331
  }, null, 8, ["modelValue"])
1321
1332
  ]),
1322
- _cache[4] || (_cache[4] = createStaticVNode('<div class="mt-[5px] text-[#c9c9c9] text-[10px]"><p class="text-right"> 绘制连续线段:<span class="w-[110px] inline-block">Ctrl + L</span></p><p class="text-right"> 绘制线段确认:<span class="w-[110px] inline-block">Enter</span></p><p class="text-right"> 绘制门线:<span class="w-[110px] inline-block">Ctrl + M</span></p><p class="text-right"> 绘制窗户线:<span class="w-[110px] inline-block">Ctrl + Q</span></p><p class="text-right"> 移动线段点:<span class="w-[110px] inline-block">Ctrl + P</span></p><p class="text-right"> 删除线段:<span class="w-[110px] inline-block">选中 + Delete</span></p><p class="text-right"> 删除窗户线:<span class="w-[110px] inline-block">选中 + Q + Delete</span></p><p class="text-right"> 选中:<span class="w-[110px] inline-block">鼠标左键</span></p><p class="text-right"> 多选:<span class="w-[110px] inline-block">鼠标左键 + Ctrl</span></p><p class="text-right"> 取消选中:<span class="w-[110px] inline-block">鼠标左键 + Alt</span></p><p class="text-right"> 框选:<span class="w-[110px] inline-block">鼠标左键 + 移动</span></p><p class="text-right"> 线段同方向合并:<span class="w-[110px] inline-block">Ctrl + G</span></p><p class="text-right"> 线段连接:<span class="w-[110px] inline-block">选中 + Shift + L</span></p><p class="text-right"> 线段交点连接:<span class="w-[110px] inline-block">选中 + Ctrl + Shift + L</span></p><p class="text-right"> 取消命令:<span class="w-[110px] inline-block">Esc</span></p></div>', 1))
1333
+ _cache[6] || (_cache[6] = createStaticVNode('<div class="mt-[5px] text-[#c9c9c9] text-[10px]"><p class="text-right"> 绘制连续线段:<span class="w-[110px] inline-block">Ctrl + L</span></p><p class="text-right"> 绘制线段确认:<span class="w-[110px] inline-block">Enter</span></p><p class="text-right"> 绘制门线:<span class="w-[110px] inline-block">Ctrl + M</span></p><p class="text-right"> 绘制窗户线:<span class="w-[110px] inline-block">Ctrl + Q</span></p><p class="text-right"> 移动线段点:<span class="w-[110px] inline-block">Ctrl + P</span></p><p class="text-right"> 删除线段:<span class="w-[110px] inline-block">选中 + Delete</span></p><p class="text-right"> 删除窗户线:<span class="w-[110px] inline-block">选中 + Q + Delete</span></p><p class="text-right"> 选中:<span class="w-[110px] inline-block">鼠标左键</span></p><p class="text-right"> 多选:<span class="w-[110px] inline-block">鼠标左键 + Ctrl</span></p><p class="text-right"> 取消选中:<span class="w-[110px] inline-block">鼠标左键 + Alt</span></p><p class="text-right"> 框选:<span class="w-[110px] inline-block">鼠标左键 + 移动</span></p><p class="text-right"> 线段同方向合并:<span class="w-[110px] inline-block">Ctrl + G</span></p><p class="text-right"> 线段连接:<span class="w-[110px] inline-block">选中 + Shift + L</span></p><p class="text-right"> 线段交点连接:<span class="w-[110px] inline-block">选中 + Ctrl + Shift + L</span></p><p class="text-right"> 取消命令:<span class="w-[110px] inline-block">Esc</span></p></div>', 1))
1323
1334
  ])
1324
1335
  ]);
1325
1336
  };
@@ -1390,7 +1401,6 @@ let Editor$1 = class Editor extends Component {
1390
1401
  const x = domEventRegister.pointer.x / size.x * 2 - 1;
1391
1402
  const y = -(domEventRegister.pointer.y / size.y * 2 - 1);
1392
1403
  coords.set(x, y);
1393
- console.log("pointer-", "x:", x, "y:", y);
1394
1404
  raycaster.setFromCamera(coords, renderer.camera);
1395
1405
  const intersections = raycaster.intersectObject(this.plane);
1396
1406
  if (intersections.length) {
@@ -1437,7 +1447,6 @@ class RenderManager extends Component {
1437
1447
  actionHistory = /* @__PURE__ */ new Set();
1438
1448
  onAddFromParent() {
1439
1449
  const dxfLineModel = this.dxfLineModel;
1440
- this.reset();
1441
1450
  this.editor.container.add(this.container);
1442
1451
  this.editor.container.add(dxfLineModel.dxfModelGroup);
1443
1452
  dxfLineModel.dxfLineModel.material = new THREE.LineBasicMaterial({
@@ -1451,6 +1460,7 @@ class RenderManager extends Component {
1451
1460
  });
1452
1461
  this.variable.addEventListener("dxfVisible", (e) => dxfLineModel.dxfModelGroup.visible = e.value);
1453
1462
  this.dxf.addEventListener("createGroup", () => this.reset());
1463
+ this.reset();
1454
1464
  }
1455
1465
  updatedMode = null;
1456
1466
  /** 重新设置数据
@@ -1464,6 +1474,7 @@ class RenderManager extends Component {
1464
1474
  }
1465
1475
  this.pointVirtualGrid = new PointVirtualGrid();
1466
1476
  const box = this.dxf.box.clone().expansion(Math.max(this.dxf.box.width, this.dxf.box.height) * 2);
1477
+ if (box.width === 0 || box.height === 0) box.set(-200, -200, 200, 200);
1467
1478
  this.quadtree = new Quadtree(box);
1468
1479
  this.lines.length = 0;
1469
1480
  this.dxf.lineSegments.forEach((line) => {
@@ -32,7 +32,7 @@ export declare class ComponentManager<TEventMap extends {} = {}> extends EventDi
32
32
  * 查找所有符合条件的组件
33
33
  * @param callBack
34
34
  */
35
- findComponents(predicate: (component: Component, index: number) => boolean): Component<{}> | undefined;
35
+ findComponents(predicate: (component: Component, index: number) => boolean): Component<{}>[];
36
36
  /**
37
37
  *
38
38
  * @param type
@@ -1,5 +1,5 @@
1
1
  import { Vector2 } from 'three';
2
- import { Component, ComponentManager } from '../../../../ComponentManager';
2
+ import { Component } from '../../../../ComponentManager';
3
3
  export declare class DomEventRegister extends Component<{
4
4
  mousemove: {
5
5
  x: number;
@@ -15,11 +15,29 @@ export declare class DomEventRegister extends Component<{
15
15
  static name: string;
16
16
  cancelDefaultBehaviorList: ((e: KeyboardEvent) => boolean)[];
17
17
  pointer: Vector2;
18
+ private _isMouseEnter;
19
+ set isMouseEnter(isMouseEnter: boolean);
20
+ get isMouseEnter(): boolean;
18
21
  /**
19
- *
20
- * @param parent
22
+ * 组件被添加到父组件上时调用
23
+ */
24
+ onAddFromParent(): void;
25
+ /**
26
+ * 初始化鼠标事件代理(判断鼠标是否在domElement上)
27
+ */
28
+ initMouseMoveEventProxy(): void;
29
+ /**
30
+ * 初始化键盘事件
31
+ */
32
+ initKeyEvent(): void;
33
+ /**
34
+ * 初始化滚轮事件
35
+ */
36
+ initWheelEvent(): void;
37
+ /**
38
+ * 根据domElement的cursor自动设置body的cursor
21
39
  */
22
- onAddFromParent(parent: ComponentManager): void;
40
+ autoBodyCursor(): void;
23
41
  /**
24
42
  *
25
43
  * @param callBack
@@ -17,7 +17,7 @@ export interface RendererDescription {
17
17
  };
18
18
  resizeObserver?: HTMLElement | null;
19
19
  scene?: THREE.Scene;
20
- camera?: THREE.PerspectiveCamera | THREE.OrthographicCamera;
20
+ camera?: THREE.PerspectiveCamera | THREE.OrthographicCamera | THREE.Camera;
21
21
  }
22
22
  export declare class Renderer extends Component<{
23
23
  resize: {
@@ -7,7 +7,7 @@ type Option = {
7
7
  modelData?: boolean;
8
8
  detailsPoint?: boolean;
9
9
  orbitControls?: boolean;
10
- camera?: THREE.OrthographicCamera;
10
+ camera?: THREE.Camera;
11
11
  };
12
12
  declare function RenderPlugin_(dxfSystem: DxfSystem, option?: Option): void;
13
13
  declare const RenderPlugin: typeof RenderPlugin_ & {