@ccpc/platform 0.1.3

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/index.js +793 -0
  3. package/package.json +14 -0
  4. package/types/app/app.d.ts +27 -0
  5. package/types/app/app.d.ts.map +1 -0
  6. package/types/cmd/action.d.ts +8 -0
  7. package/types/cmd/action.d.ts.map +1 -0
  8. package/types/cmd/action_result.d.ts +10 -0
  9. package/types/cmd/action_result.d.ts.map +1 -0
  10. package/types/cmd/build_in_action/default_action.d.ts +14 -0
  11. package/types/cmd/build_in_action/default_action.d.ts.map +1 -0
  12. package/types/cmd/build_in_action/i_picked_result.d.ts +30 -0
  13. package/types/cmd/build_in_action/i_picked_result.d.ts.map +1 -0
  14. package/types/cmd/build_in_action/pick_filter.d.ts +38 -0
  15. package/types/cmd/build_in_action/pick_filter.d.ts.map +1 -0
  16. package/types/cmd/build_in_action/pick_point_action.d.ts +53 -0
  17. package/types/cmd/build_in_action/pick_point_action.d.ts.map +1 -0
  18. package/types/cmd/build_in_action/pick_util.d.ts +13 -0
  19. package/types/cmd/build_in_action/pick_util.d.ts.map +1 -0
  20. package/types/cmd/build_in_action/run_snap_util.d.ts +19 -0
  21. package/types/cmd/build_in_action/run_snap_util.d.ts.map +1 -0
  22. package/types/cmd/build_in_action/snap_helper_curve.d.ts +21 -0
  23. package/types/cmd/build_in_action/snap_helper_curve.d.ts.map +1 -0
  24. package/types/cmd/cmd.d.ts +8 -0
  25. package/types/cmd/cmd.d.ts.map +1 -0
  26. package/types/cmd/cmd_action_controller.d.ts +89 -0
  27. package/types/cmd/cmd_action_controller.d.ts.map +1 -0
  28. package/types/cmd/cmd_decorator.d.ts +7 -0
  29. package/types/cmd/cmd_decorator.d.ts.map +1 -0
  30. package/types/cmd/cmd_mgr.d.ts +26 -0
  31. package/types/cmd/cmd_mgr.d.ts.map +1 -0
  32. package/types/cmd/editor_mgr.d.ts +15 -0
  33. package/types/cmd/editor_mgr.d.ts.map +1 -0
  34. package/types/index.d.ts +16 -0
  35. package/types/index.d.ts.map +1 -0
  36. package/types/model/snap_helper_manager.d.ts +30 -0
  37. package/types/model/snap_helper_manager.d.ts.map +1 -0
  38. package/types/selection/high_light.d.ts +33 -0
  39. package/types/selection/high_light.d.ts.map +1 -0
  40. package/types/selection/selection.d.ts +48 -0
  41. package/types/selection/selection.d.ts.map +1 -0
  42. package/types/types/type_define.d.ts +8 -0
  43. package/types/types/type_define.d.ts.map +1 -0
package/index.js ADDED
@@ -0,0 +1,793 @@
1
+ import { DefaultController as V, CCanvas as b } from "@ccpc/canvas";
2
+ import { ClassManager as O, DebugUtil as E, TmpElementPainter as M, GPoint2d as R, GCurve2d as S, GPolycurve as B, GPolygon as F, GText2d as K, ElementId as X, GNODE_TYPE as D, GRep as U } from "@ccpc/core";
3
+ import { Ln2 as P, Vec2 as m, CONST as w, alg as j, Arc2 as z, Plane as W, Vec3 as q } from "@ccpc/math";
4
+ import { SnapSetting as y, EN_SNAP_TYPE as a, EN_SNAP_HELP_OBJ as v, SnapEngine as Y, SnapCandidates as J, PtSnap as x, SnapContext as $ } from "@ccpc/snap";
5
+ class k {
6
+ constructor() {
7
+ this._busy = !1, this._clsMgr = new O();
8
+ }
9
+ static instance() {
10
+ return this._instance || (this._instance = new k()), this._instance;
11
+ }
12
+ /**
13
+ * 注册cmd
14
+ */
15
+ registerCmd(e, t) {
16
+ const s = this._clsMgr.getCls(e);
17
+ return E.assert(s === void 0, `${e}已注册`, "wg", "2026-03-09"), this._clsMgr.registerCls(e, t), !0;
18
+ }
19
+ /**
20
+ * 发起一个命令
21
+ */
22
+ async sendCmd(e, ...t) {
23
+ for (this._clsMgr.getClsNameEnsure(e); this._busy; )
24
+ return this.resetAllActions(), new Promise((c) => setTimeout(c, 50));
25
+ const s = new e();
26
+ this._currentCmd = s, this._busy = !0;
27
+ const i = s.initStatus(), r = s.execute(...t);
28
+ return s.executeImmediately && i.resolve(), await Promise.all([i.promise, r]).catch((c) => {
29
+ console.error(c);
30
+ }), s.onDestroy(), delete this._currentCmd, delete this._busy, !0;
31
+ }
32
+ getCurrentAction() {
33
+ let e = this.getCurrentCmd();
34
+ for (; e?.action; )
35
+ e = e.action;
36
+ return e;
37
+ }
38
+ getCurrentCmd() {
39
+ return this._currentCmd;
40
+ }
41
+ resetAllActions() {
42
+ const e = this.getCurrentCmd();
43
+ if (!e) return;
44
+ const t = [e];
45
+ for (; ; ) {
46
+ const s = t[t.length - 1]?.action;
47
+ if (!s) break;
48
+ t.push(s);
49
+ }
50
+ t.reverse().forEach((s) => s.cancel());
51
+ }
52
+ processMouseEvent(e) {
53
+ return !!this.getCurrentAction()?.processMouseEvent(e);
54
+ }
55
+ processKeyboardEvent(e) {
56
+ return !!this.getCurrentAction()?.processKeyboardEvent(e);
57
+ }
58
+ }
59
+ const Q = k.instance();
60
+ class N extends V {
61
+ constructor() {
62
+ super(...arguments), this._status = {
63
+ promise: new Promise(() => {
64
+ }),
65
+ resolve: () => {
66
+ }
67
+ }, this._tmpElementPainters = [];
68
+ }
69
+ /**
70
+ * !!仅由CmdMgr调用
71
+ */
72
+ initStatus() {
73
+ this._status.promise = new Promise((t) => this._status.resolve = t), delete this._status.finish;
74
+ const e = new M(this.getDoc());
75
+ return this._tmpElementPainters.push(e), this._status;
76
+ }
77
+ /**
78
+ * 获取画布
79
+ */
80
+ getCanvas() {
81
+ return p.getCanvas();
82
+ }
83
+ /**
84
+ * 获取文档
85
+ */
86
+ getDoc() {
87
+ return p.doc;
88
+ }
89
+ /**
90
+ * 执行动作
91
+ */
92
+ async runAction(e) {
93
+ this.action = e;
94
+ const t = e.initStatus().promise;
95
+ return await Promise.all([t, e.execute()]), delete this.action, t;
96
+ }
97
+ /**
98
+ * 命令执行
99
+ */
100
+ async execute(...e) {
101
+ }
102
+ /**
103
+ * 命令取消
104
+ */
105
+ cancel() {
106
+ this._resolve();
107
+ }
108
+ /**
109
+ * cmd被销毁
110
+ */
111
+ onDestroy() {
112
+ }
113
+ /**
114
+ * 获取所有临时元素绘制器
115
+ */
116
+ getTmpElementPainters() {
117
+ return this._tmpElementPainters;
118
+ }
119
+ /**
120
+ * 获取默认临时元素绘制器
121
+ */
122
+ getBuildInTmpElementPainter() {
123
+ return this._tmpElementPainters[0];
124
+ }
125
+ /**
126
+ * 获取指定的临时元素绘制器
127
+ */
128
+ getTmpElementPainterByIndex(e) {
129
+ if (e < 0 || e >= this._tmpElementPainters.length) {
130
+ E.assert(!1, "index无效", "wg", "2026-03-15");
131
+ return;
132
+ }
133
+ return this._tmpElementPainters[e];
134
+ }
135
+ /**
136
+ * 用户创建临时元素绘制器
137
+ */
138
+ applyNewTmpElementPainter() {
139
+ const e = new M(this.getDoc());
140
+ return this._tmpElementPainters.push(e), e;
141
+ }
142
+ /**
143
+ * 销毁用户创建的临时元素绘制器
144
+ */
145
+ clearUsersTmpElementPainters() {
146
+ for (let e = 1; e < this._tmpElementPainters.length; e += 1)
147
+ this._tmpElementPainters[e].destroy();
148
+ this._tmpElementPainters.splice(1);
149
+ }
150
+ /**
151
+ * 在指定临时元素绘制器上绘制临时元素
152
+ */
153
+ drawTmpGRep(e, t = 0) {
154
+ if (t < 0 || t >= this._tmpElementPainters.length) {
155
+ E.assert(!1, "index无效", "wg", "2026-03-15");
156
+ return;
157
+ }
158
+ this._tmpElementPainters[t].drawTmpGRep(e);
159
+ }
160
+ /**
161
+ * 清除所有绘制的临时元素
162
+ */
163
+ clearTmp() {
164
+ for (const e of this._tmpElementPainters)
165
+ e && e.clearTmp();
166
+ }
167
+ /**
168
+ * 刷新视图
169
+ */
170
+ _updateView() {
171
+ this.getDoc().updateView();
172
+ }
173
+ /**
174
+ * 结束cmd
175
+ */
176
+ _resolve(e) {
177
+ this._status.finish || (this._status.finish = !0, this._status.resolve(e), this.onDestroy());
178
+ }
179
+ onKeyDown(e) {
180
+ return e.domEvent.key === "Escape" ? (this.cancel(), !0) : !1;
181
+ }
182
+ onMouseEnter(e) {
183
+ return window?.focus(), !1;
184
+ }
185
+ }
186
+ class T {
187
+ /**
188
+ * 返回pick结果,是否从场景中拾取[gnode]
189
+ */
190
+ // TODO 考虑容差
191
+ static pickGNode(e, t, s, i) {
192
+ return this.pickGNodes(e, t, s, i)[0];
193
+ }
194
+ static pickGNodes(e, t, s, i) {
195
+ const r = e.pick(t.x, t.y);
196
+ if (!r.length) return [];
197
+ let c = r;
198
+ if (i ? c = c.filter((o) => o.canSnap) : c = c.filter((o) => o.canPick), !c.length) return [];
199
+ if (s && (c = c.filter((o) => s.isEnable(o, t))), !c.length) return [];
200
+ const l = /* @__PURE__ */ new Map();
201
+ return c.forEach((o) => {
202
+ l.set(o, this._getPickPriority(o));
203
+ }), c.sort((o, g) => (l.get(o) || 100) - (l.get(g) || 100)), c;
204
+ }
205
+ static _getPickPriority(e) {
206
+ return e instanceof R ? 0 : e instanceof S || e instanceof B ? 1 : e instanceof F ? 2 : e instanceof K ? 3 : 100;
207
+ }
208
+ }
209
+ class Z extends N {
210
+ onMouseMove(e) {
211
+ const t = T.pickGNode(this.getCanvas(), e.pos);
212
+ return t ? (p.highLight.reset([t]), this._updateView(), !1) : (p.highLight.clear(), this._updateView(), !1);
213
+ }
214
+ onClick(e) {
215
+ const t = T.pickGNode(this.getCanvas(), e.pos);
216
+ return p.highLight.clear(), !t && !e.fnKey.ctrlKey ? (p.selection.clear(), this._updateView(), !1) : (t && (e.fnKey.ctrlKey ? p.selection.add([t]) : p.selection.reset([t]), this._updateView()), !1);
217
+ }
218
+ onRButtonDown(e) {
219
+ return p.highLight.clear(), p.selection.clear(), this._updateView(), !1;
220
+ }
221
+ onKeyDown(e) {
222
+ return e.domEvent.key !== "Escape" ? !1 : (p.highLight.clear(), p.selection.clear(), this._updateView(), !0);
223
+ }
224
+ }
225
+ class A {
226
+ constructor() {
227
+ this.defaultController = new Z();
228
+ }
229
+ static instance() {
230
+ return this._instance || (this._instance = new A()), this._instance;
231
+ }
232
+ processMouseEvent(e) {
233
+ return !!this.defaultController?.processMouseEvent(e);
234
+ }
235
+ processKeyboardEvent(e) {
236
+ return !!this.defaultController?.processKeyboardEvent(e);
237
+ }
238
+ }
239
+ const ee = A.instance();
240
+ class f {
241
+ constructor() {
242
+ this._selectedIds = [], this._selectedGNodes = [];
243
+ }
244
+ static instance() {
245
+ return f._instance || (f._instance = new f()), f._instance;
246
+ }
247
+ setDoc(e) {
248
+ this._doc = e;
249
+ }
250
+ getDoc() {
251
+ return this._doc;
252
+ }
253
+ /**
254
+ * 获取选中的GNodes
255
+ */
256
+ getSelectedGNodes() {
257
+ return this._selectedGNodes;
258
+ }
259
+ /**
260
+ * 获取所有选中的ElementId
261
+ */
262
+ getAllSelectedEIds() {
263
+ const e = this._selectedIds, t = new Set(e);
264
+ return this._selectedGNodes.forEach((s) => {
265
+ s.elementId.isValid() && t.add(s.elementId.asInt());
266
+ }), [...t];
267
+ }
268
+ /**
269
+ * 获取所有选中的Element
270
+ */
271
+ getAllSelectedElements() {
272
+ const e = this.getAllSelectedEIds();
273
+ return this._doc.getElementsByIds(e);
274
+ }
275
+ /**
276
+ * 获取不包括GNode的ElementId
277
+ */
278
+ getSelectedEIds() {
279
+ return this._selectedIds.length ? this._selectedIds.map((e) => new X(e)) : [];
280
+ }
281
+ /**
282
+ * 获取不包括GNode的Element
283
+ */
284
+ getSelectedElements() {
285
+ return this._doc.getElementsByIds(this.getSelectedEIds());
286
+ }
287
+ /**
288
+ * 清空高亮集合
289
+ */
290
+ clear() {
291
+ !this._selectedGNodes.length && !this._selectedIds.length || (this._selectedGNodes.splice(0), this._selectedIds.splice(0), this._doc.modelView.cacheForView.cacheSelection(this));
292
+ }
293
+ /**
294
+ * 将GNode或者ElementId假如选择集
295
+ */
296
+ add(e) {
297
+ if (!e.length) return;
298
+ let t = [], s = [];
299
+ typeof e[0] == "number" ? s = e.filter((r) => !this._selectedIds.find((c) => c === r)) : t = e.filter((r) => !this._selectedGNodes.find((c) => c === r)), !(!s.length && !t.length) && (this._selectedIds.push(...s), this._selectedGNodes.push(...t), this._doc.modelView.cacheForView.cacheSelection(this));
300
+ }
301
+ /**
302
+ * 将对象从选择集去除
303
+ */
304
+ delete(e) {
305
+ if (!e.length) return;
306
+ let t = !1;
307
+ if (typeof e[0] == "number") {
308
+ const s = e;
309
+ for (let i = 0; i < s.length; i += 1) {
310
+ const r = this._selectedIds.findIndex((c) => c === s[i]);
311
+ r > -1 && (t = !0, this._selectedIds.splice(r, 1));
312
+ }
313
+ } else {
314
+ const s = e;
315
+ for (let i = 0; i < s.length; i += 1) {
316
+ const r = this._selectedGNodes.findIndex((c) => c === s[i]);
317
+ r > -1 && (t = !0, this._selectedGNodes.splice(r, 1));
318
+ }
319
+ }
320
+ t && this._doc.modelView.cacheForView.cacheSelection(this);
321
+ }
322
+ reset(e) {
323
+ this._selectedIds.splice(0), this._selectedGNodes.splice(0), this._doc.modelView.cacheForView.cacheSelection(this), e.length && (typeof e[0] == "number" ? this._selectedIds.push(...new Set(e)) : this._selectedGNodes.push(...new Set(e)));
324
+ }
325
+ }
326
+ class u {
327
+ constructor() {
328
+ this._selectedIds = /* @__PURE__ */ new Set();
329
+ }
330
+ static instance() {
331
+ return u._instance || (u._instance = new u()), u._instance;
332
+ }
333
+ setDoc(e) {
334
+ this._doc = e;
335
+ }
336
+ getDoc() {
337
+ return this._doc;
338
+ }
339
+ /**
340
+ * 获取高亮的GNode
341
+ */
342
+ getActiveGNodes() {
343
+ const e = [];
344
+ return this._selectedIds.forEach((t) => {
345
+ typeof t != "number" && e.push(t);
346
+ }), e;
347
+ }
348
+ /**
349
+ * 获取高亮的ElementId
350
+ */
351
+ getActiveElementIds() {
352
+ const e = [];
353
+ return this._selectedIds.forEach((t) => {
354
+ typeof t == "number" && e.push(t);
355
+ }), e;
356
+ }
357
+ /**
358
+ * 获取高亮的Element
359
+ */
360
+ getActiveElements() {
361
+ const e = this.getActiveElementIds();
362
+ return this._doc.getElementsByIds(e);
363
+ }
364
+ /**
365
+ * 清空高亮集合
366
+ */
367
+ clear() {
368
+ this._selectedIds.size && (this._selectedIds.clear(), this._doc.modelView.cacheForView.cacheHighLight(this));
369
+ }
370
+ /**
371
+ * 重置当前高亮集合,并在内容变化时触发视图刷新。
372
+ */
373
+ reset(e) {
374
+ const t = new Set(e);
375
+ t.size === this._selectedIds.size && [...this._selectedIds].every((s) => t.has(s)) || (this._selectedIds.clear(), e.forEach((s) => this._selectedIds.add(s)), this._doc.modelView.cacheForView.cacheHighLight(this));
376
+ }
377
+ }
378
+ class G {
379
+ constructor() {
380
+ this._cmdMgr = Q, this.selection = f.instance(), this.highLight = u.instance();
381
+ }
382
+ static instance() {
383
+ return this._instance || (this._instance = new G()), this._instance;
384
+ }
385
+ get doc() {
386
+ return E.assert(this._curDoc, "请先调用start方法给doc赋值", "wg", "2026-03-11"), this._curDoc;
387
+ }
388
+ start(e) {
389
+ this._curDoc = e, e.isMainDoc = !0, this.selection.setDoc(e), this.highLight.setDoc(e);
390
+ }
391
+ stop() {
392
+ this.highLight.clear(), this.selection.clear(), this._curCanvas?.destroy(), this._curDoc?.destroy(), delete this._curCanvas, delete this._curDoc;
393
+ }
394
+ /**
395
+ * 获取画布
396
+ */
397
+ getCanvas() {
398
+ return this._curCanvas;
399
+ }
400
+ /**
401
+ * 创建画布
402
+ */
403
+ createCanvas(e) {
404
+ const t = [this._cmdMgr, ee], s = new b(e, t);
405
+ return this._curCanvas = s, this._curDoc && this._curCanvas.resetModelView(this._curDoc.modelView), this._curCanvas.startListening(), s;
406
+ }
407
+ }
408
+ const p = G.instance();
409
+ var C = /* @__PURE__ */ ((n) => (n[n.OK = 0] = "OK", n[n.CANCEL = 1] = "CANCEL", n))(C || {});
410
+ class L {
411
+ constructor(e, t) {
412
+ this._status = e, this._data = t;
413
+ }
414
+ get data() {
415
+ return this._data;
416
+ }
417
+ get isSuccess() {
418
+ return this._status === C.OK;
419
+ }
420
+ get isCanceled() {
421
+ return this._status === C.CANCEL;
422
+ }
423
+ }
424
+ class te extends N {
425
+ _markSuccess(e) {
426
+ super._resolve(new L(C.OK, e));
427
+ }
428
+ _markCanceled() {
429
+ super._resolve(new L(C.CANCEL));
430
+ }
431
+ cancel() {
432
+ this._markCanceled();
433
+ }
434
+ }
435
+ class pe extends N {
436
+ constructor() {
437
+ super(...arguments), this.executeImmediately = !0;
438
+ }
439
+ }
440
+ var _ = /* @__PURE__ */ ((n) => (n[n.UNKENOW = -1] = "UNKENOW", n[n.BRIEF = 0] = "BRIEF", n[n.PERMANENT = 2] = "PERMANENT", n))(_ || {});
441
+ class h {
442
+ static instance() {
443
+ return h._instance || (h._instance = new h()), h._instance;
444
+ }
445
+ constructor() {
446
+ this._snapHelperCvs = /* @__PURE__ */ new Map(), this._snapHelperDirs = /* @__PURE__ */ new Map(), this._snapHelperPts = /* @__PURE__ */ new Map(), this._keyToSnapHelperCvs = /* @__PURE__ */ new Map(), this._keyToSnapHelperDirs = /* @__PURE__ */ new Map(), this._keyToSnapHelperPts = /* @__PURE__ */ new Map();
447
+ }
448
+ addSnapHelperCurves(e, t) {
449
+ !t.length || this._keyToSnapHelperCvs.get(t[0].toString()) || (this._snapHelperCvs.get(e) ? (this._snapHelperCvs.get(e).length > 1 && this._snapHelperCvs.get(e).splice(0, this._snapHelperCvs.get(e).length - 1), this._snapHelperCvs.get(e).push(t[0].toString())) : this._snapHelperCvs.set(e, [t[0].toString()]), this._keyToSnapHelperCvs.set(t[0].toString(), t));
450
+ }
451
+ addSnapHelperDirs(e, t) {
452
+ const s = t.toString();
453
+ this._keyToSnapHelperDirs.get(s) || (this._snapHelperDirs.get(e) ? (this._snapHelperDirs.get(e).length > 1 && this._snapHelperDirs.get(e).splice(0, this._snapHelperDirs.get(e).length - 1), this._snapHelperDirs.get(e).push(s)) : this._snapHelperDirs.set(e, [s]), this._keyToSnapHelperDirs.set(s, t));
454
+ }
455
+ addSnapHelperPoints(e, t) {
456
+ const s = t.toString();
457
+ this._keyToSnapHelperPts.get(s) || (this._snapHelperPts.get(e) ? this._snapHelperPts.get(e).push(s) : this._snapHelperPts.set(e, [s]), this._keyToSnapHelperPts.set(s, t));
458
+ }
459
+ deleteSnapHelperPoints(e, t) {
460
+ const s = this._snapHelperPts.get(e);
461
+ s && t.forEach((i) => {
462
+ const r = i.toString(), c = s.findIndex((l) => r === l);
463
+ c > -1 && s.splice(c, 1), this._keyToSnapHelperPts.delete(r);
464
+ });
465
+ }
466
+ clearSnapHelperObjects(e) {
467
+ this._snapHelperCvs.get(e)?.splice(0).forEach((t) => this._keyToSnapHelperCvs.delete(t)), this._snapHelperDirs.get(e)?.splice(0).forEach((t) => this._keyToSnapHelperDirs.delete(t)), this._snapHelperPts.get(e)?.splice(0).forEach((t) => this._keyToSnapHelperPts.delete(t)), this._snapHelperCvs.delete(e), this._snapHelperDirs.delete(e), this._snapHelperPts.delete(e);
468
+ }
469
+ deleteAllSnapHelperCurves() {
470
+ this._snapHelperCvs = /* @__PURE__ */ new Map(), this._keyToSnapHelperCvs = /* @__PURE__ */ new Map();
471
+ }
472
+ deleteAllSnapHelperDirs() {
473
+ this._snapHelperDirs = /* @__PURE__ */ new Map(), this._keyToSnapHelperDirs = /* @__PURE__ */ new Map();
474
+ }
475
+ deleteAllSnapHelperPoints() {
476
+ this._snapHelperPts = /* @__PURE__ */ new Map(), this._keyToSnapHelperPts = /* @__PURE__ */ new Map();
477
+ }
478
+ getAllSnapHelperCurves() {
479
+ const e = [];
480
+ for (const t of this._snapHelperCvs.values())
481
+ t.forEach((s) => {
482
+ const i = this._keyToSnapHelperCvs.get(s);
483
+ i && e.push(i);
484
+ });
485
+ return e;
486
+ }
487
+ getAllSnapHelperDirs() {
488
+ const e = [];
489
+ for (const t of this._snapHelperDirs.values())
490
+ t.forEach((s) => {
491
+ const i = this._keyToSnapHelperDirs.get(s);
492
+ i && e.push(i);
493
+ });
494
+ return e;
495
+ }
496
+ getAllSnapHelperPoints() {
497
+ const e = [];
498
+ for (const t of this._snapHelperPts.values())
499
+ t.forEach((s) => {
500
+ const i = this._keyToSnapHelperPts.get(s);
501
+ i && e.push(i);
502
+ });
503
+ return e;
504
+ }
505
+ getSnapHelperPoints(e) {
506
+ const t = [];
507
+ for (const s of this._snapHelperPts.get(e) || []) {
508
+ const i = this._keyToSnapHelperPts.get(s);
509
+ i && t.push(i);
510
+ }
511
+ return t;
512
+ }
513
+ }
514
+ var d = /* @__PURE__ */ ((n) => (n[n.POINT_ON_FACE = 1842204] = "POINT_ON_FACE", n[n.END_POINT = 4063173] = "END_POINT", n[n.POINT_ON_CURVE = 1842204] = "POINT_ON_CURVE", n[n.MIDDLE_POINT = 4063173] = "MIDDLE_POINT", n[n.PARALLEL_TO_AXIS = 4063173] = "PARALLEL_TO_AXIS", n[n.INTERSECT_POINT = 4063173] = "INTERSECT_POINT", n[n.VERTICAL_PARALLEL = 4063173] = "VERTICAL_PARALLEL", n))(d || {});
515
+ const H = 200;
516
+ function se(n, e) {
517
+ if (!y.instance().canSnapHelperObject || !n?.pickedGNodes?.length)
518
+ return;
519
+ const t = (/* @__PURE__ */ new Date()).getTime();
520
+ if (n && (n.snapType === a.MiddlePoint || n.snapType === a.EndPoint) && t - e > H && n.pickedPlane) {
521
+ const s = n.pickedPlane.getUVAt(n.point), i = new P(s, m.X(), [-w.MODEL_MAX_LENGTH, w.MODEL_MAX_LENGTH]);
522
+ i.userData = { snapType: a.ReferCurve, lastPickedPt: s.clone() };
523
+ const r = new P(s, m.Y(), [-w.MODEL_MAX_LENGTH, w.MODEL_MAX_LENGTH]);
524
+ r.userData = { snapType: a.ReferCurve, lastPickedPt: s.clone() }, h.instance().addSnapHelperCurves(_.BRIEF, [i, r]);
525
+ }
526
+ }
527
+ function ne(n, e, t) {
528
+ if (!y.instance().canSnapHelperDir)
529
+ return;
530
+ const s = (/* @__PURE__ */ new Date()).getTime();
531
+ if (!(n && s - e > H && n.pickedGNodes?.length === 1))
532
+ return;
533
+ const i = n.pickedGNodes[0];
534
+ let r;
535
+ if (i.getType() === D.GCurve2d && i.geo instanceof P)
536
+ r = i.geo;
537
+ else if (i.getType() === D.GPolycurve) {
538
+ const g = i.geo.getAllCurves();
539
+ g.length === 1 && g[0] instanceof P && (r = g[0]);
540
+ }
541
+ if (!r)
542
+ return;
543
+ const c = r.getDirection().clone();
544
+ if (c.userData = { refCurve: r }, h.instance().addSnapHelperDirs(_.BRIEF, c), !t)
545
+ return;
546
+ const l = new m();
547
+ if (j.D.ptToCurve2d(t, r, l), l.equals(t))
548
+ return;
549
+ const o = l.subtracted(t).normalize();
550
+ o.isPerpendicular(r.getDirection()) && (o.userData = { refCurve: r, snapType: a.VerticalToCurve }, h.instance().addSnapHelperDirs(_.BRIEF, o));
551
+ }
552
+ function ie(n, e) {
553
+ const t = (/* @__PURE__ */ new Date()).getTime();
554
+ if (!(n && t - e > H && n.pickedGNodes?.length === 1))
555
+ return e;
556
+ const s = n.pickedGNodes[0];
557
+ if (s.getType() === D.GPolygon) {
558
+ const i = s.geo.getCentroidPoint();
559
+ return i.userData = { snapType: a.Center }, h.instance().addSnapHelperPoints(_.BRIEF, i), t;
560
+ }
561
+ if (s.getType() === D.GCurve2d && s.geo instanceof z) {
562
+ const i = s.geo;
563
+ return re(i).forEach((c) => {
564
+ c.userData = { snapType: a.Pole }, h.instance().addSnapHelperPoints(_.BRIEF, c);
565
+ }), t;
566
+ }
567
+ return e;
568
+ }
569
+ function re(n) {
570
+ const e = n.getCenter(), t = n.getCoord(), s = [
571
+ e.added(t.getDx().multiplied(n.getA())),
572
+ e.added(t.getDx().multiplied(-n.getA())),
573
+ e.added(t.getDy().multiplied(n.getB())),
574
+ e.added(t.getDy().multiplied(-n.getB()))
575
+ ], i = [];
576
+ return s.forEach((r) => {
577
+ const c = n.getParamAt(r);
578
+ n.getPtAt(c).equals(r) && i.findIndex((o) => o.equals(r)) < 0 && i.push(r);
579
+ }), i;
580
+ }
581
+ function I(n, e) {
582
+ if (!n.getSnappedObjects().length)
583
+ return;
584
+ const t = W.XOY();
585
+ for (const s of n.getSnappedObjects())
586
+ if (s instanceof P && s.userData?.snapType === a.ReferCurve && s.userData?.lastPickedPt) {
587
+ const i = s.userData.lastPickedPt, r = new P(i, n.snappedPt);
588
+ let c = d.PARALLEL_TO_AXIS;
589
+ const l = r.getDirection();
590
+ l.isParallel(m.X()) ? c = 16711680 : l.isParallel(m.Y()) && (c = 65280);
591
+ const o = new S(t, r);
592
+ o.setStyle({
593
+ line: {
594
+ color: c,
595
+ width: 2
596
+ }
597
+ }), e.addNode(o);
598
+ const g = new R(t, i.clone());
599
+ g.setStyle({
600
+ point: {
601
+ color: d.PARALLEL_TO_AXIS,
602
+ size: 6
603
+ }
604
+ }), e.addNode(g);
605
+ } else if (s.isVector2?.() && s.userData?.refCurve) {
606
+ const i = s.userData.refCurve, r = new S(t, i);
607
+ r.setStyle({
608
+ line: {
609
+ color: d.VERTICAL_PARALLEL
610
+ }
611
+ }), e.addNode(r);
612
+ }
613
+ }
614
+ class ce {
615
+ /**
616
+ * 计算当前鼠标位置的吸附结果
617
+ * @param ccanvas 画布
618
+ * @param screenPos 鼠标屏幕坐标
619
+ * @param pickFilter 拾取过滤器
620
+ */
621
+ static snapPoint(e, t, s, i) {
622
+ t.snappableGNodes = T.pickGNodes(s, e, i.getPickFilter(), !0), t.cursorWorld = s.screenToWorkPlaneLocal(e), t.setSnapHelpers(v.POINT, h.instance().getAllSnapHelperPoints()), t.setSnapHelpers(v.CURVE, h.instance().getAllSnapHelperCurves()), t.setSnapHelpers(v.DIR, h.instance().getAllSnapHelperDirs()), y.instance().setPixelsPerUnit(s.pixelsPerUnit());
623
+ let r = Y.snap(t);
624
+ r.snapResults.length || (r = new J(), r.addSnapResult(new x(a.PointOnSnapPlane, t.cursorWorld.clone(), 0)));
625
+ const c = r.snapResults[0];
626
+ this._drawSnapPrompt(r), i.highlightPickedGNodes && u.instance().reset([...c.getSnappedGNodes()]);
627
+ const l = s.getWorkPlane().plane;
628
+ return {
629
+ point: l.getPtAt(c.snappedPt),
630
+ screenPt: e.clone(),
631
+ pickedPlane: l,
632
+ pickedGNodes: c.getSnappedGNodes(),
633
+ pickedRefObject: c.getSnappedObjects(),
634
+ snapType: c.getSnapType()
635
+ };
636
+ }
637
+ static _drawSnapPrompt(e) {
638
+ const t = e.snapResults[0];
639
+ if (!(t instanceof x))
640
+ return;
641
+ const s = new U();
642
+ let i = d.POINT_ON_FACE;
643
+ switch (t.getSnapType()) {
644
+ case a.Pole:
645
+ case a.EndPoint:
646
+ i = d.END_POINT;
647
+ break;
648
+ case a.MiddlePoint:
649
+ case a.Center:
650
+ i = d.MIDDLE_POINT;
651
+ break;
652
+ case a.ExtensionPoint:
653
+ case a.ParallelToX:
654
+ case a.ParallelToY:
655
+ i = d.PARALLEL_TO_AXIS;
656
+ break;
657
+ case a.PointOnCurve:
658
+ i = d.POINT_ON_CURVE;
659
+ break;
660
+ case a.ClosedLineParallelToX:
661
+ case a.ClosedLineParallelToY:
662
+ i = d.PARALLEL_TO_AXIS;
663
+ break;
664
+ case a.XPt:
665
+ i = d.INTERSECT_POINT;
666
+ break;
667
+ case a.ReferCurve:
668
+ I(t, s), i = d.POINT_ON_CURVE;
669
+ break;
670
+ case a.PerpendicularPoint:
671
+ case a.ParallelToCurve:
672
+ case a.VerticalToCurve:
673
+ I(t, s), i = d.VERTICAL_PARALLEL;
674
+ break;
675
+ }
676
+ if (t.anotherSnapType)
677
+ switch (t.anotherSnapType) {
678
+ case a.ReferCurve:
679
+ case a.ParallelToCurve:
680
+ case a.VerticalToCurve:
681
+ I(t, s);
682
+ break;
683
+ }
684
+ s.addNode(t.getSnapPrompt()), s.setStyle({ point: { size: 8, color: i } });
685
+ const r = k.instance().getCurrentAction();
686
+ r?.drawTmpGRep(s), r?.getDoc().updateView();
687
+ }
688
+ }
689
+ class ue extends te {
690
+ constructor(e = new ae()) {
691
+ super(), this._currentMousePos = m.O(), this._hoverSnappedPtTime = Date.now(), this._hoverPickedGNodeTime = Date.now(), this._context = e, e.snapContext && e.snapContext.addSnapHelpers(
692
+ v.POINT,
693
+ h.instance().getAllSnapHelperPoints()
694
+ );
695
+ }
696
+ getSnapContext() {
697
+ return this._context.snapContext;
698
+ }
699
+ setSnapContext(e) {
700
+ this._context.snapContext = e;
701
+ }
702
+ getCurrentResult() {
703
+ return this._currentPickResult;
704
+ }
705
+ getCurrentMousePos() {
706
+ return this._currentMousePos;
707
+ }
708
+ getPickContext() {
709
+ return this._context;
710
+ }
711
+ onDestroy() {
712
+ super.onDestroy(), h.instance().clearSnapHelperObjects(_.BRIEF), u.instance().clear(), this.getBuildInTmpElementPainter()?.clearTmp();
713
+ }
714
+ onClick(e) {
715
+ if (this._currentMousePos = e.pos, this._context.getClickCallback() && this._currentPickResult && this._context.getClickCallback()?.(this._currentPickResult, e.fnKey), this._currentPickResult)
716
+ this._markSuccess(this._currentPickResult);
717
+ else {
718
+ const t = this._getPickPointResult(this._currentMousePos);
719
+ this._markSuccess(t);
720
+ }
721
+ return !0;
722
+ }
723
+ onMouseMove(e) {
724
+ this._currentMousePos = e.pos, this.getBuildInTmpElementPainter() && (u.instance().clear(), this.getBuildInTmpElementPainter()?.clearTmp());
725
+ const t = this._getPickPointResult(e.pos);
726
+ return this._context.movePoint(t, e.fnKey), this._currentPickResult = t, !0;
727
+ }
728
+ _getPickPointResult(e) {
729
+ se(this._lastPickedResult, this._hoverSnappedPtTime), ne(
730
+ this._lastPickedResult,
731
+ this._hoverSnappedPtTime,
732
+ this._context.snapContext?.previousPoint
733
+ ), ie(this._lastPickedResult, this._hoverPickedGNodeTime);
734
+ const t = this.getCanvas();
735
+ this._context.snapContext || (this._context.snapContext = new $());
736
+ const s = ce.snapPoint(e, this._context.snapContext, t, this._context);
737
+ return this._hoverSnappedPtTime = Date.now(), !this._lastPickedResult?.pickedGNodes?.length || !s.pickedGNodes?.length || this._lastPickedResult.pickedGNodes.length !== s.pickedGNodes.length ? this._hoverPickedGNodeTime = Date.now() : s.pickedGNodes.some((i, r) => i !== this._lastPickedResult.pickedGNodes[r]) && (this._hoverPickedGNodeTime = Date.now()), this._lastPickedResult = {
738
+ ...s,
739
+ point: s.point.clone()
740
+ }, s;
741
+ }
742
+ }
743
+ class ae {
744
+ constructor(e) {
745
+ this._movingCallBack = e?.movingCallBack, this._clickCallBack = e?.clickCallBack, this._pickFilter = e?.pickFilter, this.snapContext = e?.snapContext, this._currentPos = q.O();
746
+ }
747
+ movePoint(e, t) {
748
+ this._movingCallBack && this._movingCallBack(e, t), this._currentPos = e.point;
749
+ }
750
+ setClickCallBack(e) {
751
+ this._clickCallBack = e;
752
+ }
753
+ getClickCallback() {
754
+ return this._clickCallBack;
755
+ }
756
+ getPickFilter() {
757
+ return this._pickFilter;
758
+ }
759
+ setPickFilter(e) {
760
+ return this._pickFilter = e, this;
761
+ }
762
+ get highlightPickedGNodes() {
763
+ return this._highlightPickedGNodes;
764
+ }
765
+ set highlightPickedGNodes(e) {
766
+ this._highlightPickedGNodes = e;
767
+ }
768
+ }
769
+ function ge(n) {
770
+ return (e) => {
771
+ k.instance().registerCmd(n, e);
772
+ };
773
+ }
774
+ export {
775
+ te as Action,
776
+ G as App,
777
+ pe as Cmd,
778
+ N as CmdActionController,
779
+ k as CmdMgr,
780
+ _ as EN_SNAP_HELPER_TYPE,
781
+ u as HighLight,
782
+ ue as PickPointAction,
783
+ ae as PickPointContext,
784
+ ce as RunSnapUtil,
785
+ f as Selection,
786
+ h as SnapHelpMgr,
787
+ p as app,
788
+ Q as cmdMgr,
789
+ se as createReferenceCurves,
790
+ ne as createReferenceDirs,
791
+ ie as createReferencePoint,
792
+ ge as registerCmd
793
+ };