@likec4/core 1.46.4 → 1.48.0
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/LICENSE +1 -1
- package/dist/_chunks/Builder.view-element.mjs +3284 -0
- package/dist/_chunks/LikeC4Model.d.mts +1287 -0
- package/dist/_chunks/LikeC4Styles.mjs +691 -0
- package/dist/_chunks/RichText.d.mts +84 -0
- package/dist/_chunks/RichText.mjs +148 -0
- package/dist/_chunks/_aux.d.mts +289 -0
- package/dist/_chunks/_aux.mjs +18 -0
- package/dist/_chunks/_types.d.mts +781 -0
- package/dist/_chunks/_types2.d.mts +38 -0
- package/dist/_chunks/assignTagColors.mjs +24 -0
- package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
- package/dist/_chunks/connection.mjs +0 -0
- package/dist/_chunks/const.d.mts +43 -0
- package/dist/_chunks/const.mjs +33 -0
- package/dist/_chunks/expression-model.d.mts +192 -0
- package/dist/_chunks/expression-model.mjs +103 -0
- package/dist/_chunks/expression.d.mts +347 -0
- package/dist/_chunks/expression.mjs +107 -0
- package/dist/_chunks/find.d.mts +82 -0
- package/dist/_chunks/find.mjs +646 -0
- package/dist/_chunks/find2.d.mts +78 -0
- package/dist/_chunks/find2.mjs +287 -0
- package/dist/_chunks/fqnRef.d.mts +58 -0
- package/dist/_chunks/fqnRef.mjs +41 -0
- package/dist/_chunks/geometry.mjs +335 -0
- package/dist/_chunks/index.d.mts +169 -0
- package/dist/_chunks/index2.d.mts +937 -0
- package/dist/_chunks/index3.d.mts +146 -0
- package/dist/_chunks/index4.d.mts +62 -0
- package/dist/_chunks/index5.d.mts +42 -0
- package/dist/_chunks/index6.d.mts +43 -0
- package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
- package/dist/_chunks/index8.d.mts +144 -0
- package/dist/_chunks/invariant.mjs +18 -0
- package/dist/_chunks/iterable.mjs +146 -0
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
- package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
- package/dist/_chunks/libs/bail.mjs +14 -0
- package/dist/_chunks/libs/ccount.mjs +25 -0
- package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
- package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
- package/dist/_chunks/libs/character-entities.mjs +2136 -0
- package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
- package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
- package/dist/_chunks/libs/defu.mjs +42 -0
- package/dist/_chunks/libs/devlop.mjs +5 -0
- package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
- package/dist/_chunks/libs/extend.mjs +77 -0
- package/dist/_chunks/libs/graphology-dag.mjs +703 -0
- package/dist/_chunks/libs/graphology-types.d.mts +601 -0
- package/dist/_chunks/libs/graphology.d.mts +6 -0
- package/dist/_chunks/libs/graphology.mjs +4565 -0
- package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
- package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
- package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
- package/dist/_chunks/libs/longest-streak.mjs +30 -0
- package/dist/_chunks/libs/markdown-table.mjs +290 -0
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
- package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
- package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
- package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
- package/dist/_chunks/libs/mnemonist.d.mts +254 -0
- package/dist/_chunks/libs/mnemonist.mjs +1978 -0
- package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
- package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
- package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
- package/dist/_chunks/libs/remark-gfm.mjs +36 -0
- package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
- package/dist/_chunks/libs/remark-parse.mjs +39 -0
- package/dist/_chunks/libs/remark-rehype.mjs +171 -0
- package/dist/_chunks/libs/remeda.mjs +702 -0
- package/dist/_chunks/libs/trough.mjs +158 -0
- package/dist/_chunks/libs/unified.mjs +2212 -0
- package/dist/_chunks/mnemonist.d.mts +1 -0
- package/dist/_chunks/mnemonist.mjs +0 -0
- package/dist/_chunks/model.mjs +1898 -0
- package/dist/_chunks/model2.mjs +0 -0
- package/dist/_chunks/relationships-view.mjs +132 -0
- package/dist/_chunks/rolldown-runtime.mjs +42 -0
- package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
- package/dist/_chunks/scalar.mjs +84 -0
- package/dist/_chunks/utils.mjs +483 -0
- package/dist/builder/index.d.mts +11 -773
- package/dist/builder/index.mjs +631 -978
- package/dist/compute-view/index.d.mts +90 -27
- package/dist/compute-view/index.mjs +253 -83
- package/dist/compute-view/relationships-view/index.d.mts +16 -51
- package/dist/compute-view/relationships-view/index.mjs +6 -184
- package/dist/geometry/index.d.mts +2 -109
- package/dist/geometry/index.mjs +2 -327
- package/dist/index.d.mts +18 -20
- package/dist/index.mjs +27 -18
- package/dist/model/connection/deployment/index.d.mts +12 -15
- package/dist/model/connection/deployment/index.mjs +9 -2
- package/dist/model/connection/index.d.mts +14 -75
- package/dist/model/connection/index.mjs +10 -3
- package/dist/model/connection/model/index.d.mts +12 -15
- package/dist/model/connection/model/index.mjs +8 -2
- package/dist/model/index.d.mts +15 -57
- package/dist/model/index.mjs +11 -4
- package/dist/styles/index.d.mts +9 -117
- package/dist/styles/index.mjs +26 -59
- package/dist/types/RichText.d.mts +3 -0
- package/dist/types/RichText.mjs +7 -0
- package/dist/types/_aux.d.mts +3 -4
- package/dist/types/_aux.mjs +2 -7
- package/dist/types/expression-model.d.mts +6 -190
- package/dist/types/expression-model.mjs +6 -108
- package/dist/types/expression.d.mts +5 -6
- package/dist/types/expression.mjs +6 -112
- package/dist/types/fqnRef.d.mts +4 -60
- package/dist/types/fqnRef.mjs +6 -44
- package/dist/types/index.d.mts +9 -47
- package/dist/types/index.mjs +14 -16
- package/dist/types/scalar.d.mts +2 -2
- package/dist/types/scalar.mjs +7 -4
- package/dist/utils/graphology/index.d.mts +2 -1864
- package/dist/utils/graphology/index.mjs +3 -1
- package/dist/utils/index.d.mts +11 -124
- package/dist/utils/index.mjs +16 -43
- package/dist/utils/iterable/index.d.mts +9 -132
- package/dist/utils/iterable/index.mjs +2 -61
- package/dist/utils/mnemonist.d.mts +2 -0
- package/dist/utils/mnemonist.mjs +12 -0
- package/package.json +18 -22
- package/compute-view/relationships/package.json +0 -4
- package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
- package/dist/shared/core.78IWAHAE.mjs +0 -332
- package/dist/shared/core.B85MJLTf.mjs +0 -5
- package/dist/shared/core.BFd1lU9R.mjs +0 -29
- package/dist/shared/core.BKlholso.mjs +0 -3
- package/dist/shared/core.BPGOjone.d.mts +0 -46
- package/dist/shared/core.BYdtmqY5.mjs +0 -1255
- package/dist/shared/core.BZCgljZd.d.mts +0 -83
- package/dist/shared/core.BbE4y-yl.mjs +0 -177
- package/dist/shared/core.BhNcrwzK.mjs +0 -7
- package/dist/shared/core.BkVA6gjl.mjs +0 -5
- package/dist/shared/core.BoYfZOBm.mjs +0 -3
- package/dist/shared/core.BsSXS-_R.mjs +0 -7
- package/dist/shared/core.BspBF3SJ.mjs +0 -3944
- package/dist/shared/core.BvPm_-u3.d.mts +0 -334
- package/dist/shared/core.C-Jdx7xo.d.mts +0 -1263
- package/dist/shared/core.C3JowhaZ.mjs +0 -32
- package/dist/shared/core.C4x8aaWa.mjs +0 -27
- package/dist/shared/core.CBLX4mT8.mjs +0 -28411
- package/dist/shared/core.CLSZtnFh.mjs +0 -69
- package/dist/shared/core.CRhT4Iio.mjs +0 -785
- package/dist/shared/core.CbT8JVYL.mjs +0 -5
- package/dist/shared/core.CdNCAwq7.mjs +0 -176
- package/dist/shared/core.ClTP6-TN.d.mts +0 -87
- package/dist/shared/core.CmGY9blO.mjs +0 -6717
- package/dist/shared/core.CmPXpJ8l.mjs +0 -21
- package/dist/shared/core.Coi_LOUZ.mjs +0 -7
- package/dist/shared/core.CqAJJpK_.mjs +0 -3
- package/dist/shared/core.Ctj2S3bD.d.mts +0 -466
- package/dist/shared/core.CywrQs86.d.mts +0 -31
- package/dist/shared/core.D00YbOhQ.d.mts +0 -300
- package/dist/shared/core.D0WZutNd.mjs +0 -94
- package/dist/shared/core.D4npX2q8.mjs +0 -18
- package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
- package/dist/shared/core.DEK-BO3_.mjs +0 -1206
- package/dist/shared/core.DH7TXqXf.mjs +0 -136
- package/dist/shared/core.DRJma0Ol.mjs +0 -22
- package/dist/shared/core.DSalPD6v.mjs +0 -1352
- package/dist/shared/core.DVfPJPJj.mjs +0 -2200
- package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
- package/dist/shared/core.DbfO90vF.mjs +0 -434
- package/dist/shared/core.DcS-0zys.mjs +0 -10
- package/dist/shared/core.DeDCYTDR.d.mts +0 -98
- package/dist/shared/core.DpKY_3NF.d.mts +0 -504
- package/dist/shared/core.Dt0v3djy.d.mts +0 -41
- package/dist/shared/core.FZ305VYd.mjs +0 -21
- package/dist/shared/core.RfnaEmgA.mjs +0 -7
- package/dist/shared/core.oSV6SRfk.mjs +0 -13
- package/dist/shared/core.om36dXXW.mjs +0 -41
- package/dist/shared/core.q10OP9oJ.mjs +0 -5
- package/dist/shared/core.uFk_o9X6.mjs +0 -13
- package/dist/shared/core.xeuDd__E.mjs +0 -300
- package/dist/shared/core.xgoPk2RG.mjs +0 -4989
|
@@ -1,185 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { i as ifilter } from '../../shared/core.DRJma0Ol.mjs';
|
|
1
|
+
import "../../_chunks/libs/natural-compare-lite.mjs";
|
|
2
|
+
import "../../_chunks/libs/graphology-dag.mjs";
|
|
3
|
+
import "../../_chunks/libs/defu.mjs";
|
|
4
|
+
import "../../_chunks/libs/extend.mjs";
|
|
5
|
+
import { n as treeFromElements, t as computeRelationshipsView } from "../../_chunks/relationships-view.mjs";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
const sorted = sortParentsFirst([...elements]);
|
|
10
|
-
const root = new Set(sorted);
|
|
11
|
-
const map = new Map(sorted.map((e) => [e._literalId, e]));
|
|
12
|
-
const parents = new DefaultMap(() => null);
|
|
13
|
-
const children = sorted.reduce((acc, parent, index, all) => {
|
|
14
|
-
acc.set(
|
|
15
|
-
parent,
|
|
16
|
-
all.slice(index + 1).filter(isDescendantOf(parent)).map((e) => {
|
|
17
|
-
root.delete(e);
|
|
18
|
-
return e;
|
|
19
|
-
}).reduce((acc2, el) => {
|
|
20
|
-
if (!acc2.some(isAncestor(el))) {
|
|
21
|
-
acc2.push(el);
|
|
22
|
-
parents.set(el, parent);
|
|
23
|
-
}
|
|
24
|
-
return acc2;
|
|
25
|
-
}, [])
|
|
26
|
-
);
|
|
27
|
-
return acc;
|
|
28
|
-
}, new DefaultMap(() => []));
|
|
29
|
-
return {
|
|
30
|
-
sorted,
|
|
31
|
-
byId: (id) => nonNullable(map.get(id), `Element not found by id: ${id}`),
|
|
32
|
-
root,
|
|
33
|
-
parent: (el) => parents.get(el),
|
|
34
|
-
children: (el) => children.get(el),
|
|
35
|
-
/**
|
|
36
|
-
* Flattens the tree structure by removing redundant hierarchy levels.
|
|
37
|
-
* @example
|
|
38
|
-
* A
|
|
39
|
-
* └── B
|
|
40
|
-
* ├── C
|
|
41
|
-
* │ └── D
|
|
42
|
-
* │ └── E
|
|
43
|
-
* └── F
|
|
44
|
-
* └── G
|
|
45
|
-
* becomes
|
|
46
|
-
* A
|
|
47
|
-
* ├── C
|
|
48
|
-
* │ └── E
|
|
49
|
-
* └── F
|
|
50
|
-
* └── G
|
|
51
|
-
*/
|
|
52
|
-
flatten: () => {
|
|
53
|
-
return /* @__PURE__ */ new Set([
|
|
54
|
-
...root,
|
|
55
|
-
...sorted.reduce((acc, el) => {
|
|
56
|
-
const _children = children.get(el);
|
|
57
|
-
if (_children.length === 0) {
|
|
58
|
-
acc.push(el);
|
|
59
|
-
return acc;
|
|
60
|
-
}
|
|
61
|
-
if (_children.length > 1) {
|
|
62
|
-
acc.push(..._children);
|
|
63
|
-
}
|
|
64
|
-
return acc;
|
|
65
|
-
}, [])
|
|
66
|
-
]);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const finalize = (elements, explicits) => {
|
|
72
|
-
if (elements.size > 2 && explicits.size !== elements.size) {
|
|
73
|
-
return new Set(sortParentsFirst([
|
|
74
|
-
...treeFromElements(elements).flatten(),
|
|
75
|
-
...explicits
|
|
76
|
-
]));
|
|
77
|
-
}
|
|
78
|
-
if (elements.size > 1) {
|
|
79
|
-
return new Set(sortParentsFirst([...elements]));
|
|
80
|
-
}
|
|
81
|
-
return elements;
|
|
82
|
-
};
|
|
83
|
-
function computeRelationships(subject, others, relationships) {
|
|
84
|
-
const isOther = (e) => others.has(e);
|
|
85
|
-
let subjects = /* @__PURE__ */ new Set([subject]);
|
|
86
|
-
const explicits = {
|
|
87
|
-
incomers: /* @__PURE__ */ new Set(),
|
|
88
|
-
subjects: /* @__PURE__ */ new Set([subject]),
|
|
89
|
-
outgoers: /* @__PURE__ */ new Set()
|
|
90
|
-
};
|
|
91
|
-
let incomers = new Set(relationships.incoming.flatMap((r) => {
|
|
92
|
-
explicits.subjects.add(r.target);
|
|
93
|
-
explicits.incomers.add(r.source);
|
|
94
|
-
subjects.add(r.target);
|
|
95
|
-
if (r.target !== subject) {
|
|
96
|
-
let target = r.target.parent;
|
|
97
|
-
while (target && target !== subject) {
|
|
98
|
-
subjects.add(target);
|
|
99
|
-
target = target.parent;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
let source = r.source;
|
|
103
|
-
const incomerBranch = [];
|
|
104
|
-
while (true) {
|
|
105
|
-
incomerBranch.push(source);
|
|
106
|
-
if (isOther(source) || !source.parent) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
source = source.parent;
|
|
110
|
-
}
|
|
111
|
-
return incomerBranch;
|
|
112
|
-
}));
|
|
113
|
-
let outgoers = new Set(relationships.outgoing.flatMap((r) => {
|
|
114
|
-
explicits.subjects.add(r.source);
|
|
115
|
-
explicits.outgoers.add(r.target);
|
|
116
|
-
subjects.add(r.source);
|
|
117
|
-
if (r.source !== subject) {
|
|
118
|
-
let source = r.source.parent;
|
|
119
|
-
while (source && source !== subject) {
|
|
120
|
-
subjects.add(source);
|
|
121
|
-
source = source.parent;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
let target = r.target;
|
|
125
|
-
const outgoerBranch = [];
|
|
126
|
-
while (true) {
|
|
127
|
-
outgoerBranch.push(target);
|
|
128
|
-
if (isOther(target) || !target.parent) {
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
target = target.parent;
|
|
132
|
-
}
|
|
133
|
-
return outgoerBranch;
|
|
134
|
-
}));
|
|
135
|
-
return {
|
|
136
|
-
incomers: finalize(incomers, explicits.incomers),
|
|
137
|
-
incoming: new Set(relationships.incoming),
|
|
138
|
-
subjects: finalize(subjects, explicits.subjects),
|
|
139
|
-
outgoing: new Set(relationships.outgoing),
|
|
140
|
-
outgoers: finalize(outgoers, explicits.outgoers)
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function computeRelationshipsView(subjectId, likec4model, scopeViewId, scope = "global") {
|
|
144
|
-
const view = scopeViewId ? likec4model.findView(scopeViewId) : null;
|
|
145
|
-
if (scope === "view") {
|
|
146
|
-
invariant(
|
|
147
|
-
view,
|
|
148
|
-
'Scope view id is required when scope is "view"'
|
|
149
|
-
);
|
|
150
|
-
return computeScopedRelationshipsView(subjectId, view, likec4model);
|
|
151
|
-
}
|
|
152
|
-
const subject = likec4model.element(subjectId);
|
|
153
|
-
const subjectSiblings = toSet(subject.ascendingSiblings());
|
|
154
|
-
return computeRelationships(
|
|
155
|
-
subject,
|
|
156
|
-
subjectSiblings,
|
|
157
|
-
{
|
|
158
|
-
incoming: [...subject.incoming()],
|
|
159
|
-
outgoing: [...subject.outgoing()]
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
function computeScopedRelationshipsView(subjectId, view, likec4model) {
|
|
164
|
-
const subject = likec4model.element(subjectId);
|
|
165
|
-
let relationships = {
|
|
166
|
-
incoming: toArray(ifilter(subject.incoming(), (r) => view.includesRelation(r.id))),
|
|
167
|
-
outgoing: toArray(ifilter(subject.outgoing(), (r) => view.includesRelation(r.id)))
|
|
168
|
-
};
|
|
169
|
-
const isDescendant = isDescendantOf(subject);
|
|
170
|
-
const others = /* @__PURE__ */ new Set([
|
|
171
|
-
...subject.ascendingSiblings(),
|
|
172
|
-
...t(
|
|
173
|
-
view.elements(),
|
|
174
|
-
imap((e) => e.element),
|
|
175
|
-
ifilter((e) => e !== subject && isDescendant(e))
|
|
176
|
-
)
|
|
177
|
-
]);
|
|
178
|
-
return computeRelationships(
|
|
179
|
-
subject,
|
|
180
|
-
others,
|
|
181
|
-
relationships
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export { computeRelationshipsView, treeFromElements };
|
|
7
|
+
export { computeRelationshipsView, treeFromElements };
|
|
@@ -1,109 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
interface VectorValue {
|
|
4
|
-
readonly x: number;
|
|
5
|
-
readonly y: number;
|
|
6
|
-
}
|
|
7
|
-
declare class Vector implements VectorValue {
|
|
8
|
-
readonly x: number;
|
|
9
|
-
readonly y: number;
|
|
10
|
-
constructor(x: number, y: number);
|
|
11
|
-
static create(position: VectorValue): Vector;
|
|
12
|
-
static create(x: number, y: number): Vector;
|
|
13
|
-
/**
|
|
14
|
-
* Adds two vectors.
|
|
15
|
-
* @param a The first vector.
|
|
16
|
-
* @param b The second vector.
|
|
17
|
-
* @returns The sum of the two vectors.
|
|
18
|
-
*/
|
|
19
|
-
static add(a: VectorValue, b: VectorValue): VectorValue;
|
|
20
|
-
/**
|
|
21
|
-
* Subtracts two vectors.
|
|
22
|
-
* @param a The first vector.
|
|
23
|
-
* @param b The second vector.
|
|
24
|
-
* @returns The difference of the two vectors.
|
|
25
|
-
*/
|
|
26
|
-
static subtract(a: VectorValue, b: VectorValue): VectorValue;
|
|
27
|
-
/**
|
|
28
|
-
* Multiplies a vector by a scalar.
|
|
29
|
-
* @param a The vector.
|
|
30
|
-
* @param b The scalar.
|
|
31
|
-
* @returns The scaled vector.
|
|
32
|
-
*/
|
|
33
|
-
static multiply(a: VectorValue, b: number): VectorValue;
|
|
34
|
-
/**
|
|
35
|
-
* Divides a vector by a scalar.
|
|
36
|
-
* @param a The vector.
|
|
37
|
-
* @param b The scalar.
|
|
38
|
-
* @returns The scaled vector.
|
|
39
|
-
*/
|
|
40
|
-
static divide(a: VectorValue, b: number): VectorValue;
|
|
41
|
-
/**
|
|
42
|
-
* Calculates the dot product of the vectors.
|
|
43
|
-
* @param a The first vector.
|
|
44
|
-
* @param b The second vector.
|
|
45
|
-
* @returns The dot product.
|
|
46
|
-
*/
|
|
47
|
-
static dot(a: VectorValue, b: VectorValue): number;
|
|
48
|
-
/**
|
|
49
|
-
* Adds the given vector to this vector.
|
|
50
|
-
* @param b The vector to add.
|
|
51
|
-
* @returns A new vector that is the sum of this vector and the given vector.
|
|
52
|
-
*/
|
|
53
|
-
add(b: VectorValue): Vector;
|
|
54
|
-
/**
|
|
55
|
-
* Subtracts the given vector from this vector.
|
|
56
|
-
* @param b The vector to subtract.
|
|
57
|
-
* @returns A new vector that is the difference of this vector and the given vector.
|
|
58
|
-
*/
|
|
59
|
-
subtract(b: VectorValue): Vector;
|
|
60
|
-
/**
|
|
61
|
-
* Multiplies this vector by a scalar.
|
|
62
|
-
* @param b The scalar to multiply by.
|
|
63
|
-
* @returns A new vector that is the product of this vector and the given scalar.
|
|
64
|
-
*/
|
|
65
|
-
multiply(b: number): Vector;
|
|
66
|
-
/**
|
|
67
|
-
* Divides this vector by a scalar.
|
|
68
|
-
* @param b The scalar to divide by.
|
|
69
|
-
* @returns A new vector that is the quotient of this vector and the given scalar.
|
|
70
|
-
*/
|
|
71
|
-
divide(b: number): Vector;
|
|
72
|
-
/**
|
|
73
|
-
* Calculates the dot product of this vector and another vector.
|
|
74
|
-
* @param b The other vector.
|
|
75
|
-
* @returns The dot product.
|
|
76
|
-
*/
|
|
77
|
-
dot(b: VectorValue): number;
|
|
78
|
-
/**
|
|
79
|
-
* Calculates the cross product of this vector and another vector.
|
|
80
|
-
* The cross product of two 2D vectors is a scalar value: a.x * b.y - a.y * b.x
|
|
81
|
-
* @param b The other vector.
|
|
82
|
-
* @returns The cross product as a scalar.
|
|
83
|
-
*/
|
|
84
|
-
cross(b: VectorValue): number;
|
|
85
|
-
/**
|
|
86
|
-
* Calculates the length (magnitude) of this vector.
|
|
87
|
-
* @returns The length of the vector.
|
|
88
|
-
*/
|
|
89
|
-
length(): number;
|
|
90
|
-
/**
|
|
91
|
-
* Normalizes the vector (makes it unit length, i.e., has a length of 1).
|
|
92
|
-
* @returns A new vector that is the normalized version of this vector.
|
|
93
|
-
*/
|
|
94
|
-
normalize(): Vector;
|
|
95
|
-
/**
|
|
96
|
-
* Rounds the components of the vector to the nearest integers.
|
|
97
|
-
* @returns A new vector with rounded components.
|
|
98
|
-
*/
|
|
99
|
-
round(): Vector;
|
|
100
|
-
/**
|
|
101
|
-
* Converts the vector to a plain object.
|
|
102
|
-
* @returns An object with x and y properties.
|
|
103
|
-
*/
|
|
104
|
-
toObject(): VectorValue;
|
|
105
|
-
}
|
|
106
|
-
declare function vector(source: VectorValue | Vector): Vector;
|
|
107
|
-
declare function vector(x: number, y: number): Vector;
|
|
108
|
-
|
|
109
|
-
export { Vector, type VectorValue, vector };
|
|
1
|
+
import { a as Point, i as BBox, n as VectorValue, o as RectBox, r as vector, s as XYPoint, t as Vector } from "../_chunks/index.mjs";
|
|
2
|
+
export { BBox, Point, RectBox, Vector, VectorValue, XYPoint, vector };
|
package/dist/geometry/index.mjs
CHANGED
|
@@ -1,328 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as invariant } from '../shared/core.D4npX2q8.mjs';
|
|
1
|
+
import { i as RectBox, n as vector, r as BBox, t as Vector } from "../_chunks/geometry.mjs";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
((BBox2) => {
|
|
6
|
-
function center({ x, y, width, height }) {
|
|
7
|
-
return {
|
|
8
|
-
x: x + width / 2,
|
|
9
|
-
y: y + height / 2
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
BBox2.center = center;
|
|
13
|
-
function toPoints({ x, y, width, height }) {
|
|
14
|
-
return [
|
|
15
|
-
{ x, y },
|
|
16
|
-
// Top left
|
|
17
|
-
{ x: x + width, y },
|
|
18
|
-
// Top right
|
|
19
|
-
{ x: x + width, y: y + height },
|
|
20
|
-
// Bottom right
|
|
21
|
-
{ x, y: y + height }
|
|
22
|
-
// Bottom left
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
BBox2.toPoints = toPoints;
|
|
26
|
-
function fromPoints(points) {
|
|
27
|
-
const { x1, y1, x2, y2 } = RectBox.fromPoints(points);
|
|
28
|
-
return {
|
|
29
|
-
x: x1,
|
|
30
|
-
y: y1,
|
|
31
|
-
width: x2 - x1,
|
|
32
|
-
height: y2 - y1
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
BBox2.fromPoints = fromPoints;
|
|
36
|
-
function merge(...boxes) {
|
|
37
|
-
invariant(t(boxes, 1), "No boxes provided");
|
|
38
|
-
if (boxes.length === 1) {
|
|
39
|
-
return boxes[0];
|
|
40
|
-
}
|
|
41
|
-
let minX = boxes[0].x;
|
|
42
|
-
let minY = boxes[0].y;
|
|
43
|
-
let maxX = boxes[0].x + boxes[0].width;
|
|
44
|
-
let maxY = boxes[0].y + boxes[0].height;
|
|
45
|
-
for (let i = 1; i < boxes.length; i++) {
|
|
46
|
-
const box = boxes[i];
|
|
47
|
-
minX = Math.min(minX, box.x);
|
|
48
|
-
minY = Math.min(minY, box.y);
|
|
49
|
-
maxX = Math.max(maxX, box.x + box.width);
|
|
50
|
-
maxY = Math.max(maxY, box.y + box.height);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
x: Math.floor(minX),
|
|
54
|
-
y: Math.floor(minY),
|
|
55
|
-
width: Math.round(maxX - minX),
|
|
56
|
-
height: Math.round(maxY - minY)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
BBox2.merge = merge;
|
|
60
|
-
function fromRectBox(rect) {
|
|
61
|
-
return {
|
|
62
|
-
x: Math.min(rect.x1, rect.x2),
|
|
63
|
-
y: Math.min(rect.y1, rect.y2),
|
|
64
|
-
width: Math.abs(rect.x2 - rect.x1),
|
|
65
|
-
height: Math.abs(rect.y2 - rect.y1)
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
BBox2.fromRectBox = fromRectBox;
|
|
69
|
-
function toRectBox(box) {
|
|
70
|
-
return {
|
|
71
|
-
x1: box.x,
|
|
72
|
-
y1: box.y,
|
|
73
|
-
x2: box.x + box.width,
|
|
74
|
-
y2: box.y + box.height
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
BBox2.toRectBox = toRectBox;
|
|
78
|
-
function expand(box, plus) {
|
|
79
|
-
if (plus === 0) {
|
|
80
|
-
return box;
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
x: box.x - plus,
|
|
84
|
-
y: box.y - plus,
|
|
85
|
-
width: box.width + plus * 2,
|
|
86
|
-
height: box.height + plus * 2
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
BBox2.expand = expand;
|
|
90
|
-
function shrink(box, minus) {
|
|
91
|
-
if (minus === 0) {
|
|
92
|
-
return box;
|
|
93
|
-
}
|
|
94
|
-
return {
|
|
95
|
-
x: box.x + minus,
|
|
96
|
-
y: box.y + minus,
|
|
97
|
-
width: box.width - minus * 2,
|
|
98
|
-
height: box.height - minus * 2
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
BBox2.shrink = shrink;
|
|
102
|
-
function includes(a, b) {
|
|
103
|
-
if (a === b) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
return a.x <= b.x && a.y <= b.y && a.x + a.width >= b.x + b.width && a.y + a.height >= b.y + b.height;
|
|
107
|
-
}
|
|
108
|
-
BBox2.includes = includes;
|
|
109
|
-
})(BBox || (BBox = {}));
|
|
110
|
-
var RectBox;
|
|
111
|
-
((RectBox2) => {
|
|
112
|
-
function center({ x1, y1, x2, y2 }) {
|
|
113
|
-
return {
|
|
114
|
-
x: (x1 + x2) / 2,
|
|
115
|
-
y: (y1 + y2) / 2
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
RectBox2.center = center;
|
|
119
|
-
function fromPoints(points) {
|
|
120
|
-
invariant(points.length > 0, "At least one point is required");
|
|
121
|
-
let minX = Infinity;
|
|
122
|
-
let minY = Infinity;
|
|
123
|
-
let maxX = -Infinity;
|
|
124
|
-
let maxY = -Infinity;
|
|
125
|
-
for (const [x, y] of points) {
|
|
126
|
-
minX = Math.min(minX, x);
|
|
127
|
-
minY = Math.min(minY, y);
|
|
128
|
-
maxX = Math.max(maxX, x);
|
|
129
|
-
maxY = Math.max(maxY, y);
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
x1: minX,
|
|
133
|
-
y1: minY,
|
|
134
|
-
x2: maxX,
|
|
135
|
-
y2: maxY
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
RectBox2.fromPoints = fromPoints;
|
|
139
|
-
function merge(...boxes) {
|
|
140
|
-
invariant(boxes.length > 0, "No boxes provided");
|
|
141
|
-
let minX = Infinity;
|
|
142
|
-
let minY = Infinity;
|
|
143
|
-
let maxX = -Infinity;
|
|
144
|
-
let maxY = -Infinity;
|
|
145
|
-
for (const box of boxes) {
|
|
146
|
-
minX = Math.min(minX, box.x1);
|
|
147
|
-
minY = Math.min(minY, box.y1);
|
|
148
|
-
maxX = Math.max(maxX, box.x2);
|
|
149
|
-
maxY = Math.max(maxY, box.y2);
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
x1: minX,
|
|
153
|
-
y1: minY,
|
|
154
|
-
x2: maxX,
|
|
155
|
-
y2: maxY
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
RectBox2.merge = merge;
|
|
159
|
-
function toBBox(box) {
|
|
160
|
-
return {
|
|
161
|
-
x: box.x1,
|
|
162
|
-
y: box.y1,
|
|
163
|
-
width: box.x2 - box.x1,
|
|
164
|
-
height: box.y2 - box.y1
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
RectBox2.toBBox = toBBox;
|
|
168
|
-
function includes(a, b) {
|
|
169
|
-
if (a === b) {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return a.x1 <= b.x1 && a.y1 <= b.y1 && a.x2 >= b.x2 && a.y2 >= b.y2;
|
|
173
|
-
}
|
|
174
|
-
RectBox2.includes = includes;
|
|
175
|
-
})(RectBox || (RectBox = {}));
|
|
176
|
-
|
|
177
|
-
class Vector {
|
|
178
|
-
constructor(x, y) {
|
|
179
|
-
this.x = x;
|
|
180
|
-
this.y = y;
|
|
181
|
-
}
|
|
182
|
-
static create(...args) {
|
|
183
|
-
if (args.length === 2) {
|
|
184
|
-
return new Vector(args[0], args[1]);
|
|
185
|
-
}
|
|
186
|
-
return new Vector(args[0].x, args[0].y);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Adds two vectors.
|
|
190
|
-
* @param a The first vector.
|
|
191
|
-
* @param b The second vector.
|
|
192
|
-
* @returns The sum of the two vectors.
|
|
193
|
-
*/
|
|
194
|
-
static add(a, b) {
|
|
195
|
-
return { x: a.x + b.x, y: a.y + b.y };
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Subtracts two vectors.
|
|
199
|
-
* @param a The first vector.
|
|
200
|
-
* @param b The second vector.
|
|
201
|
-
* @returns The difference of the two vectors.
|
|
202
|
-
*/
|
|
203
|
-
static subtract(a, b) {
|
|
204
|
-
return { x: a.x - b.x, y: a.y - b.y };
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Multiplies a vector by a scalar.
|
|
208
|
-
* @param a The vector.
|
|
209
|
-
* @param b The scalar.
|
|
210
|
-
* @returns The scaled vector.
|
|
211
|
-
*/
|
|
212
|
-
static multiply(a, b) {
|
|
213
|
-
return { x: a.x * b, y: a.y * b };
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Divides a vector by a scalar.
|
|
217
|
-
* @param a The vector.
|
|
218
|
-
* @param b The scalar.
|
|
219
|
-
* @returns The scaled vector.
|
|
220
|
-
*/
|
|
221
|
-
static divide(a, b) {
|
|
222
|
-
return { x: a.x / b, y: a.y / b };
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Calculates the dot product of the vectors.
|
|
226
|
-
* @param a The first vector.
|
|
227
|
-
* @param b The second vector.
|
|
228
|
-
* @returns The dot product.
|
|
229
|
-
*/
|
|
230
|
-
static dot(a, b) {
|
|
231
|
-
return a.x * b.x + a.y * b.y;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Adds the given vector to this vector.
|
|
235
|
-
* @param b The vector to add.
|
|
236
|
-
* @returns A new vector that is the sum of this vector and the given vector.
|
|
237
|
-
*/
|
|
238
|
-
add(b) {
|
|
239
|
-
return new Vector(this.x + b.x, this.y + b.y);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Subtracts the given vector from this vector.
|
|
243
|
-
* @param b The vector to subtract.
|
|
244
|
-
* @returns A new vector that is the difference of this vector and the given vector.
|
|
245
|
-
*/
|
|
246
|
-
subtract(b) {
|
|
247
|
-
return new Vector(this.x - b.x, this.y - b.y);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Multiplies this vector by a scalar.
|
|
251
|
-
* @param b The scalar to multiply by.
|
|
252
|
-
* @returns A new vector that is the product of this vector and the given scalar.
|
|
253
|
-
*/
|
|
254
|
-
multiply(b) {
|
|
255
|
-
return new Vector(this.x * b, this.y * b);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Divides this vector by a scalar.
|
|
259
|
-
* @param b The scalar to divide by.
|
|
260
|
-
* @returns A new vector that is the quotient of this vector and the given scalar.
|
|
261
|
-
*/
|
|
262
|
-
divide(b) {
|
|
263
|
-
return new Vector(this.x / b, this.y / b);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Calculates the dot product of this vector and another vector.
|
|
267
|
-
* @param b The other vector.
|
|
268
|
-
* @returns The dot product.
|
|
269
|
-
*/
|
|
270
|
-
dot(b) {
|
|
271
|
-
return this.x * b.x + this.y * b.y;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Calculates the cross product of this vector and another vector.
|
|
275
|
-
* The cross product of two 2D vectors is a scalar value: a.x * b.y - a.y * b.x
|
|
276
|
-
* @param b The other vector.
|
|
277
|
-
* @returns The cross product as a scalar.
|
|
278
|
-
*/
|
|
279
|
-
cross(b) {
|
|
280
|
-
return this.x * b.y - this.y * b.x;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Calculates the length (magnitude) of this vector.
|
|
284
|
-
* @returns The length of the vector.
|
|
285
|
-
*/
|
|
286
|
-
length() {
|
|
287
|
-
if (this.x === 0 && this.y === 0) {
|
|
288
|
-
return 0;
|
|
289
|
-
}
|
|
290
|
-
return Math.sqrt(this.x ** 2 + this.y ** 2);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Normalizes the vector (makes it unit length, i.e., has a length of 1).
|
|
294
|
-
* @returns A new vector that is the normalized version of this vector.
|
|
295
|
-
*/
|
|
296
|
-
normalize() {
|
|
297
|
-
const len = this.length();
|
|
298
|
-
if (len === 0) {
|
|
299
|
-
return new Vector(0, 0);
|
|
300
|
-
}
|
|
301
|
-
return new Vector(this.x / len, this.y / len);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Rounds the components of the vector to the nearest integers.
|
|
305
|
-
* @returns A new vector with rounded components.
|
|
306
|
-
*/
|
|
307
|
-
round() {
|
|
308
|
-
return new Vector(Math.round(this.x), Math.round(this.y));
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Converts the vector to a plain object.
|
|
312
|
-
* @returns An object with x and y properties.
|
|
313
|
-
*/
|
|
314
|
-
toObject() {
|
|
315
|
-
return { x: this.x, y: this.y };
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function vector(...args) {
|
|
319
|
-
if (args.length === 1 && args[0] instanceof Vector) {
|
|
320
|
-
return args[0];
|
|
321
|
-
}
|
|
322
|
-
if (args.length === 2) {
|
|
323
|
-
return new Vector(args[0], args[1]);
|
|
324
|
-
}
|
|
325
|
-
return new Vector(args[0].x, args[0].y);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export { BBox, RectBox, Vector, vector };
|
|
3
|
+
export { BBox, RectBox, Vector, vector };
|