@ccpc/core 0.1.23 → 0.1.25
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/index.js
CHANGED
|
@@ -99,13 +99,13 @@ class H {
|
|
|
99
99
|
}
|
|
100
100
|
class F {
|
|
101
101
|
constructor() {
|
|
102
|
-
this.
|
|
102
|
+
this._allElements = /* @__PURE__ */ new Map(), this._ctorToElements = /* @__PURE__ */ new Map(), this._eleClsMgr = new H();
|
|
103
103
|
}
|
|
104
104
|
static instance() {
|
|
105
105
|
return this._instance || (this._instance = new F()), this._instance;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* 注册对象
|
|
109
109
|
*/
|
|
110
110
|
registerElement(t, e) {
|
|
111
111
|
this._eleClsMgr.registerCls(t, e);
|
|
@@ -116,23 +116,45 @@ class F {
|
|
|
116
116
|
getElementClsByCtor(t) {
|
|
117
117
|
return this._eleClsMgr.getCls(t);
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* 根据id获取element
|
|
121
|
+
*/
|
|
119
122
|
getElementById(t) {
|
|
120
|
-
return this.
|
|
123
|
+
return this._allElements.get(t);
|
|
121
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* 获取所有element
|
|
127
|
+
*/
|
|
122
128
|
getAllElements() {
|
|
123
|
-
return [...this.
|
|
129
|
+
return [...this._allElements.values()];
|
|
124
130
|
}
|
|
125
131
|
getAllElementIds() {
|
|
126
|
-
return [...this.
|
|
132
|
+
return [...this._allElements.keys()];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 根据序列化id获取element数组
|
|
136
|
+
*/
|
|
137
|
+
getElementsByCtor(t) {
|
|
138
|
+
const e = this._ctorToElements.get(t);
|
|
139
|
+
return e ? [...e] : [];
|
|
127
140
|
}
|
|
128
141
|
add(t, e = !0) {
|
|
129
|
-
|
|
142
|
+
if (!e && this._allElements.has(t.id.asInt()))
|
|
143
|
+
return !1;
|
|
144
|
+
this._allElements.set(t.id.asInt(), t);
|
|
145
|
+
const s = this._ctorToElements.get(t.getSerialId());
|
|
146
|
+
return s ? s.add(t) : this._ctorToElements.set(t.getSerialId(), /* @__PURE__ */ new Set([t])), !0;
|
|
130
147
|
}
|
|
131
148
|
delete(t) {
|
|
132
|
-
|
|
149
|
+
const e = this._allElements.get(t);
|
|
150
|
+
if (e) {
|
|
151
|
+
this._allElements.delete(t);
|
|
152
|
+
const s = this._ctorToElements.get(e.getSerialId());
|
|
153
|
+
s && s.delete(e);
|
|
154
|
+
}
|
|
133
155
|
}
|
|
134
156
|
clear() {
|
|
135
|
-
this.
|
|
157
|
+
this._allElements.clear(), this._ctorToElements.clear();
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
160
|
const Z = F.instance(), u = class u {
|
|
@@ -685,7 +707,7 @@ class L {
|
|
|
685
707
|
return this._instance || (this._instance = new L()), this._instance;
|
|
686
708
|
}
|
|
687
709
|
}
|
|
688
|
-
class
|
|
710
|
+
class C {
|
|
689
711
|
constructor() {
|
|
690
712
|
this.style = {}, this.type = I.UNKOWN;
|
|
691
713
|
}
|
|
@@ -702,7 +724,7 @@ class x {
|
|
|
702
724
|
return e.parent = this.parent, e.gnode = this.gnode, e.globalMatrix = this.globalMatrix?.clone(), e;
|
|
703
725
|
}
|
|
704
726
|
}
|
|
705
|
-
class z extends
|
|
727
|
+
class z extends C {
|
|
706
728
|
constructor() {
|
|
707
729
|
super(...arguments), this.children = [], this.type = I.GROUP;
|
|
708
730
|
}
|
|
@@ -716,19 +738,19 @@ class z extends x {
|
|
|
716
738
|
}), t;
|
|
717
739
|
}
|
|
718
740
|
}
|
|
719
|
-
class gt extends
|
|
741
|
+
class gt extends C {
|
|
720
742
|
constructor() {
|
|
721
743
|
super(...arguments), this.type = I.POINT;
|
|
722
744
|
}
|
|
723
745
|
// TODO clone方法
|
|
724
746
|
}
|
|
725
|
-
class tt extends
|
|
747
|
+
class tt extends C {
|
|
726
748
|
constructor() {
|
|
727
749
|
super(...arguments), this.type = I.EDGE;
|
|
728
750
|
}
|
|
729
751
|
// TODO clone方法
|
|
730
752
|
}
|
|
731
|
-
class mt extends
|
|
753
|
+
class mt extends C {
|
|
732
754
|
constructor() {
|
|
733
755
|
super(...arguments), this.text = "", this.opacity = 1, this.position = P.O();
|
|
734
756
|
}
|
|
@@ -737,7 +759,7 @@ class mt extends x {
|
|
|
737
759
|
return t.text = this.text, t.opacity = this.opacity, t.position = new P(this.position), t;
|
|
738
760
|
}
|
|
739
761
|
}
|
|
740
|
-
class yt extends
|
|
762
|
+
class yt extends C {
|
|
741
763
|
/**
|
|
742
764
|
* 点集,一个点由一个索引组成
|
|
743
765
|
* 离散后的所有顶点, 此数据不渲染,只做存储使用
|
|
@@ -1472,12 +1494,15 @@ const A = class A {
|
|
|
1472
1494
|
i && e.push(i);
|
|
1473
1495
|
}), e;
|
|
1474
1496
|
}
|
|
1475
|
-
// public getElementClsByCtor(ctor:string) {
|
|
1476
|
-
// return this
|
|
1477
|
-
// }
|
|
1478
1497
|
filterElements(t) {
|
|
1479
1498
|
return t ? this.elementMgr.getAllElements().filter(t) : this.elementMgr.getAllElements();
|
|
1480
1499
|
}
|
|
1500
|
+
getAllElementsByCtor(t) {
|
|
1501
|
+
if (!t)
|
|
1502
|
+
return this.filterElements();
|
|
1503
|
+
const e = t.serializedId.ctor;
|
|
1504
|
+
return this.elementMgr.getElementsByCtor(e);
|
|
1505
|
+
}
|
|
1481
1506
|
checkIfCanModifyDoc() {
|
|
1482
1507
|
c.assert(this.transactionMgr.getCurrentTransaction(), "事务外不可修改文档", "wg", "2025-11-18");
|
|
1483
1508
|
}
|
|
@@ -1499,7 +1524,7 @@ const A = class A {
|
|
|
1499
1524
|
};
|
|
1500
1525
|
A.canCreate = !1;
|
|
1501
1526
|
let E = A;
|
|
1502
|
-
class
|
|
1527
|
+
class Ct {
|
|
1503
1528
|
constructor() {
|
|
1504
1529
|
this._db = {}, this._cache = {};
|
|
1505
1530
|
}
|
|
@@ -1685,7 +1710,7 @@ class xt {
|
|
|
1685
1710
|
return e === "string" || e === "number" || e === "boolean";
|
|
1686
1711
|
}
|
|
1687
1712
|
}
|
|
1688
|
-
class
|
|
1713
|
+
class xt extends Ct {
|
|
1689
1714
|
constructor() {
|
|
1690
1715
|
super(), this.id = m.INVALID, this.name = "", this.visible = !0, this.C_GRep = g.empty, c.assert(E.canCreate, "创建Element必须通过Document.create方法", "wg", "2025-11-18");
|
|
1691
1716
|
}
|
|
@@ -1796,7 +1821,7 @@ var Nt = Object.getOwnPropertyDescriptor, Dt = (n, t, e, s) => {
|
|
|
1796
1821
|
(o = n[r]) && (i = o(i) || i);
|
|
1797
1822
|
return i;
|
|
1798
1823
|
};
|
|
1799
|
-
let U = class extends
|
|
1824
|
+
let U = class extends xt {
|
|
1800
1825
|
init() {
|
|
1801
1826
|
return this;
|
|
1802
1827
|
}
|
|
@@ -1837,7 +1862,7 @@ class Bt {
|
|
|
1837
1862
|
this.clearTmp(), this._doc.deleteElementsById(this._tmpElementId);
|
|
1838
1863
|
}
|
|
1839
1864
|
}
|
|
1840
|
-
class
|
|
1865
|
+
class x extends N {
|
|
1841
1866
|
constructor(t, e) {
|
|
1842
1867
|
super(), this.plane = t.clone(), this.geo = e;
|
|
1843
1868
|
}
|
|
@@ -1845,7 +1870,7 @@ class C extends N {
|
|
|
1845
1870
|
return super._copyFrom(t), this;
|
|
1846
1871
|
}
|
|
1847
1872
|
}
|
|
1848
|
-
class nt extends
|
|
1873
|
+
class nt extends x {
|
|
1849
1874
|
constructor(t, e) {
|
|
1850
1875
|
super(t, e);
|
|
1851
1876
|
}
|
|
@@ -1871,7 +1896,7 @@ class nt extends C {
|
|
|
1871
1896
|
return new nt(this.plane, t ? this.geo.clone() : this.geo)._copyFrom(this);
|
|
1872
1897
|
}
|
|
1873
1898
|
}
|
|
1874
|
-
class ot extends
|
|
1899
|
+
class ot extends x {
|
|
1875
1900
|
constructor(t, e) {
|
|
1876
1901
|
super(t, e);
|
|
1877
1902
|
}
|
|
@@ -1889,7 +1914,7 @@ class ot extends C {
|
|
|
1889
1914
|
return new ot(this.plane, t ? this.geo.clone() : this.geo)._copyFrom(this);
|
|
1890
1915
|
}
|
|
1891
1916
|
}
|
|
1892
|
-
class at extends
|
|
1917
|
+
class at extends x {
|
|
1893
1918
|
constructor(t, e) {
|
|
1894
1919
|
super(t, e);
|
|
1895
1920
|
}
|
|
@@ -1911,7 +1936,7 @@ class at extends C {
|
|
|
1911
1936
|
return new at(this.plane, t ? this.geo.clone() : this.geo)._copyFrom(this);
|
|
1912
1937
|
}
|
|
1913
1938
|
}
|
|
1914
|
-
class ct extends
|
|
1939
|
+
class ct extends x {
|
|
1915
1940
|
constructor(t, e) {
|
|
1916
1941
|
super(t, e);
|
|
1917
1942
|
}
|
|
@@ -1944,7 +1969,7 @@ class ct extends C {
|
|
|
1944
1969
|
return new ct(this.plane.clone(), t ? this.geo.clone() : this.geo)._copyFrom(this);
|
|
1945
1970
|
}
|
|
1946
1971
|
}
|
|
1947
|
-
class dt extends
|
|
1972
|
+
class dt extends x {
|
|
1948
1973
|
constructor(t, e, s) {
|
|
1949
1974
|
super(e, $.rO()), this.text = t, this.position = $.O(), s && (this.position = s);
|
|
1950
1975
|
}
|
|
@@ -2102,7 +2127,7 @@ class $t {
|
|
|
2102
2127
|
}
|
|
2103
2128
|
}
|
|
2104
2129
|
export {
|
|
2105
|
-
|
|
2130
|
+
xt as CElement,
|
|
2106
2131
|
H as ClassManager,
|
|
2107
2132
|
Ft as DBGenerator,
|
|
2108
2133
|
c as DebugUtil,
|
|
@@ -2114,14 +2139,14 @@ export {
|
|
|
2114
2139
|
B as EN_CoreRequestIds,
|
|
2115
2140
|
h as EN_ModelViewChanged,
|
|
2116
2141
|
I as EN_RNODE_TYPE,
|
|
2117
|
-
|
|
2142
|
+
xt as Element,
|
|
2118
2143
|
m as ElementId,
|
|
2119
2144
|
F as ElementMgr,
|
|
2120
2145
|
nt as GCurve2d,
|
|
2121
2146
|
D as GGroup,
|
|
2122
2147
|
w as GNODE_TYPE,
|
|
2123
2148
|
N as GNode,
|
|
2124
|
-
|
|
2149
|
+
x as GNode2d,
|
|
2125
2150
|
at as GPoint2d,
|
|
2126
2151
|
ot as GPolycurve,
|
|
2127
2152
|
ct as GPolygon,
|
|
@@ -2136,7 +2161,7 @@ export {
|
|
|
2136
2161
|
tt as RenderEdge,
|
|
2137
2162
|
z as RenderGroup,
|
|
2138
2163
|
yt as RenderMesh,
|
|
2139
|
-
|
|
2164
|
+
C as RenderNode,
|
|
2140
2165
|
zt as RenderNodeUtil,
|
|
2141
2166
|
gt as RenderPoint,
|
|
2142
2167
|
mt as RenderText,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ccpc/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "Core data model layer for editor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./types/index.d.ts",
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"@ccpc/math": "^0.1.
|
|
10
|
+
"@ccpc/math": "^0.1.25"
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IElement } from '../element/i_element';
|
|
1
|
+
import type { IElement, IElementCtor } from '../element/i_element';
|
|
2
2
|
import type { IDocFile, IDocument } from './i_document';
|
|
3
3
|
import { IDPool } from './id_pool';
|
|
4
4
|
import { ElementId } from '../element/element_id';
|
|
@@ -28,6 +28,7 @@ export declare class Document implements IDocument {
|
|
|
28
28
|
getElementByIdEnsure<T extends IElement>(eleId: ElementId | number): T;
|
|
29
29
|
getElementsByIds(eleIds: Array<ElementId | number>): IElement[];
|
|
30
30
|
filterElements(filter?: (ele: IElement) => boolean): IElement[];
|
|
31
|
+
getAllElementsByCtor<T extends IElement>(eleCtor?: IElementCtor<T>): T[];
|
|
31
32
|
checkIfCanModifyDoc(): void;
|
|
32
33
|
cacheForViewElementChanged(evtType: EN_ModelViewChanged, elements: Array<IElement>): void;
|
|
33
34
|
updateView(rebuild?: boolean): boolean;
|
|
@@ -4,25 +4,39 @@ export declare class ElementMgr {
|
|
|
4
4
|
/**
|
|
5
5
|
* 当前文档中的所有对象
|
|
6
6
|
*/
|
|
7
|
-
private readonly
|
|
7
|
+
private readonly _allElements;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* 序列化id到实例对象的映射
|
|
10
|
+
*/
|
|
11
|
+
private readonly _ctorToElements;
|
|
12
|
+
/**
|
|
13
|
+
* 类管理器
|
|
10
14
|
*/
|
|
11
15
|
private readonly _eleClsMgr;
|
|
12
16
|
static instance(): ElementMgr;
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
18
|
+
* 注册对象
|
|
15
19
|
*/
|
|
16
20
|
registerElement(ctor: string, eleCtor: IElementCtor): void;
|
|
17
21
|
/**
|
|
18
22
|
* 根据序列化id获取Element构造函数
|
|
19
23
|
*/
|
|
20
24
|
getElementClsByCtor(ctor: string): IElementCtor | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* 根据id获取element
|
|
27
|
+
*/
|
|
21
28
|
getElementById<T extends IElement>(id: number): T;
|
|
29
|
+
/**
|
|
30
|
+
* 获取所有element
|
|
31
|
+
*/
|
|
22
32
|
getAllElements(): IElement[];
|
|
23
33
|
getAllElementIds(): number[];
|
|
34
|
+
/**
|
|
35
|
+
* 根据序列化id获取element数组
|
|
36
|
+
*/
|
|
37
|
+
getElementsByCtor(ctor: string): IElement[];
|
|
24
38
|
add(element: IElement, force?: boolean): boolean;
|
|
25
|
-
delete(id: number):
|
|
39
|
+
delete(id: number): void;
|
|
26
40
|
clear(): void;
|
|
27
41
|
}
|
|
28
42
|
export declare const elementMgr: ElementMgr;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ElementId } from '../element/element_id';
|
|
2
|
-
import type { IElement } from '../element/i_element';
|
|
2
|
+
import type { IElement, IElementCtor } from '../element/i_element';
|
|
3
3
|
import { ModelView } from '../model_view/model_view';
|
|
4
4
|
import { RequestMgr } from '../request/request_mgr';
|
|
5
5
|
import { TransactionMgr } from '../transaction/transaction_mgr';
|
|
@@ -36,14 +36,16 @@ export interface IDocument {
|
|
|
36
36
|
/**根据id获取对象*/
|
|
37
37
|
getElementByIdEnsure<T extends IElement>(eleId: ElementId | number): T;
|
|
38
38
|
getElementsByIds(eleIds: Array<ElementId | number>): IElement[];
|
|
39
|
-
/**
|
|
40
|
-
* 根据序列化id获取Element的类
|
|
41
|
-
*/
|
|
42
39
|
/**
|
|
43
40
|
* 返回文档中满足filter条件的Element
|
|
44
41
|
* filter为空返回所有Element
|
|
45
42
|
*/
|
|
46
43
|
filterElements(filter?: (ele: IElement) => boolean): IElement[];
|
|
44
|
+
/**
|
|
45
|
+
* 获取Class下的所有实例Element
|
|
46
|
+
* 不能获取基类的所有子类
|
|
47
|
+
*/
|
|
48
|
+
getAllElementsByCtor<T extends IElement>(eleCtor?: IElementCtor<T>): T[];
|
|
47
49
|
/**
|
|
48
50
|
* 检测是否允许修改文档
|
|
49
51
|
* 包括增加、删除和修改
|
package/types/grep/i_style.d.ts
CHANGED