@likec4/core 1.47.0 → 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.
Files changed (181) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_chunks/Builder.view-element.mjs +3284 -0
  3. package/dist/_chunks/LikeC4Model.d.mts +1287 -0
  4. package/dist/_chunks/LikeC4Styles.mjs +691 -0
  5. package/dist/_chunks/RichText.d.mts +84 -0
  6. package/dist/_chunks/RichText.mjs +148 -0
  7. package/dist/_chunks/_aux.d.mts +289 -0
  8. package/dist/_chunks/_aux.mjs +18 -0
  9. package/dist/_chunks/_types.d.mts +781 -0
  10. package/dist/_chunks/_types2.d.mts +38 -0
  11. package/dist/_chunks/assignTagColors.mjs +24 -0
  12. package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
  13. package/dist/_chunks/connection.mjs +0 -0
  14. package/dist/_chunks/const.d.mts +43 -0
  15. package/dist/_chunks/const.mjs +33 -0
  16. package/dist/_chunks/expression-model.d.mts +192 -0
  17. package/dist/_chunks/expression-model.mjs +103 -0
  18. package/dist/_chunks/expression.d.mts +347 -0
  19. package/dist/_chunks/expression.mjs +107 -0
  20. package/dist/_chunks/find.d.mts +82 -0
  21. package/dist/_chunks/find.mjs +646 -0
  22. package/dist/_chunks/find2.d.mts +78 -0
  23. package/dist/_chunks/find2.mjs +287 -0
  24. package/dist/_chunks/fqnRef.d.mts +58 -0
  25. package/dist/_chunks/fqnRef.mjs +41 -0
  26. package/dist/_chunks/geometry.mjs +335 -0
  27. package/dist/_chunks/index.d.mts +169 -0
  28. package/dist/_chunks/index2.d.mts +937 -0
  29. package/dist/_chunks/index3.d.mts +146 -0
  30. package/dist/_chunks/index4.d.mts +62 -0
  31. package/dist/_chunks/index5.d.mts +42 -0
  32. package/dist/_chunks/index6.d.mts +43 -0
  33. package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
  34. package/dist/_chunks/index8.d.mts +144 -0
  35. package/dist/_chunks/invariant.mjs +18 -0
  36. package/dist/_chunks/iterable.mjs +146 -0
  37. package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
  38. package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
  39. package/dist/_chunks/libs/bail.mjs +14 -0
  40. package/dist/_chunks/libs/ccount.mjs +25 -0
  41. package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
  42. package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
  43. package/dist/_chunks/libs/character-entities.mjs +2136 -0
  44. package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
  45. package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
  46. package/dist/_chunks/libs/defu.mjs +42 -0
  47. package/dist/_chunks/libs/devlop.mjs +5 -0
  48. package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
  49. package/dist/_chunks/libs/extend.mjs +77 -0
  50. package/dist/_chunks/libs/graphology-dag.mjs +703 -0
  51. package/dist/_chunks/libs/graphology-types.d.mts +601 -0
  52. package/dist/_chunks/libs/graphology.d.mts +6 -0
  53. package/dist/_chunks/libs/graphology.mjs +4565 -0
  54. package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
  55. package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
  56. package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
  57. package/dist/_chunks/libs/longest-streak.mjs +30 -0
  58. package/dist/_chunks/libs/markdown-table.mjs +290 -0
  59. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
  60. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
  61. package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
  62. package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
  63. package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
  64. package/dist/_chunks/libs/mnemonist.d.mts +254 -0
  65. package/dist/_chunks/libs/mnemonist.mjs +1978 -0
  66. package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
  67. package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
  68. package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
  69. package/dist/_chunks/libs/remark-gfm.mjs +36 -0
  70. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
  71. package/dist/_chunks/libs/remark-parse.mjs +39 -0
  72. package/dist/_chunks/libs/remark-rehype.mjs +171 -0
  73. package/dist/_chunks/libs/remeda.mjs +702 -0
  74. package/dist/_chunks/libs/trough.mjs +158 -0
  75. package/dist/_chunks/libs/unified.mjs +2212 -0
  76. package/dist/_chunks/mnemonist.d.mts +1 -0
  77. package/dist/_chunks/mnemonist.mjs +0 -0
  78. package/dist/_chunks/model.mjs +1898 -0
  79. package/dist/_chunks/model2.mjs +0 -0
  80. package/dist/_chunks/relationships-view.mjs +132 -0
  81. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  82. package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
  83. package/dist/_chunks/scalar.mjs +84 -0
  84. package/dist/_chunks/utils.mjs +483 -0
  85. package/dist/builder/index.d.mts +11 -775
  86. package/dist/builder/index.mjs +631 -1022
  87. package/dist/compute-view/index.d.mts +85 -56
  88. package/dist/compute-view/index.mjs +247 -214
  89. package/dist/compute-view/relationships-view/index.d.mts +16 -51
  90. package/dist/compute-view/relationships-view/index.mjs +6 -184
  91. package/dist/geometry/index.d.mts +2 -109
  92. package/dist/geometry/index.mjs +2 -327
  93. package/dist/index.d.mts +18 -20
  94. package/dist/index.mjs +27 -18
  95. package/dist/model/connection/deployment/index.d.mts +12 -15
  96. package/dist/model/connection/deployment/index.mjs +9 -2
  97. package/dist/model/connection/index.d.mts +14 -75
  98. package/dist/model/connection/index.mjs +10 -3
  99. package/dist/model/connection/model/index.d.mts +12 -15
  100. package/dist/model/connection/model/index.mjs +8 -2
  101. package/dist/model/index.d.mts +15 -57
  102. package/dist/model/index.mjs +11 -4
  103. package/dist/styles/index.d.mts +9 -117
  104. package/dist/styles/index.mjs +26 -59
  105. package/dist/types/RichText.d.mts +3 -0
  106. package/dist/types/RichText.mjs +7 -0
  107. package/dist/types/_aux.d.mts +3 -4
  108. package/dist/types/_aux.mjs +2 -7
  109. package/dist/types/expression-model.d.mts +6 -190
  110. package/dist/types/expression-model.mjs +6 -108
  111. package/dist/types/expression.d.mts +5 -6
  112. package/dist/types/expression.mjs +6 -112
  113. package/dist/types/fqnRef.d.mts +4 -60
  114. package/dist/types/fqnRef.mjs +6 -44
  115. package/dist/types/index.d.mts +9 -47
  116. package/dist/types/index.mjs +14 -16
  117. package/dist/types/scalar.d.mts +2 -2
  118. package/dist/types/scalar.mjs +7 -4
  119. package/dist/utils/graphology/index.d.mts +2 -1864
  120. package/dist/utils/graphology/index.mjs +3 -1
  121. package/dist/utils/index.d.mts +11 -124
  122. package/dist/utils/index.mjs +16 -43
  123. package/dist/utils/iterable/index.d.mts +9 -132
  124. package/dist/utils/iterable/index.mjs +2 -61
  125. package/dist/utils/mnemonist.d.mts +2 -0
  126. package/dist/utils/mnemonist.mjs +12 -0
  127. package/package.json +17 -22
  128. package/compute-view/relationships/package.json +0 -4
  129. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  130. package/dist/shared/core.78IWAHAE.mjs +0 -332
  131. package/dist/shared/core.B85MJLTf.mjs +0 -5
  132. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  133. package/dist/shared/core.BKlholso.mjs +0 -3
  134. package/dist/shared/core.BNN-3vPH.mjs +0 -1255
  135. package/dist/shared/core.BPGOjone.d.mts +0 -46
  136. package/dist/shared/core.BP_QHEXs.mjs +0 -785
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
  139. package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
  140. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  141. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  142. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  143. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  144. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  145. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  146. package/dist/shared/core.CAgYpDtM.d.mts +0 -98
  147. package/dist/shared/core.CHf8VEa3.mjs +0 -1206
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  150. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  151. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  152. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  153. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  154. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  155. package/dist/shared/core.CywrQs86.d.mts +0 -31
  156. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  157. package/dist/shared/core.D0WZutNd.mjs +0 -94
  158. package/dist/shared/core.D4npX2q8.mjs +0 -18
  159. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  160. package/dist/shared/core.DC5IAaDT.d.mts +0 -334
  161. package/dist/shared/core.DE9qzhn8.d.mts +0 -83
  162. package/dist/shared/core.DGcIbsj4.mjs +0 -3946
  163. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  164. package/dist/shared/core.DKhRkHRN.d.mts +0 -41
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DU5SRqNF.mjs +0 -2209
  167. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  168. package/dist/shared/core.DbfO90vF.mjs +0 -434
  169. package/dist/shared/core.DcS-0zys.mjs +0 -10
  170. package/dist/shared/core.Dh119QSP.mjs +0 -4995
  171. package/dist/shared/core.DjcWextK.mjs +0 -1371
  172. package/dist/shared/core.Dojz4bvg.d.mts +0 -504
  173. package/dist/shared/core.FZ305VYd.mjs +0 -21
  174. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  175. package/dist/shared/core.btEq3i3f.mjs +0 -300
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.osFs8tU7.d.mts +0 -466
  179. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  180. package/dist/shared/core.tpvDGvdC.d.mts +0 -87
  181. package/dist/shared/core.uFk_o9X6.mjs +0 -13
@@ -1,51 +1,16 @@
1
- import { A as Any, U as Unknown, a as ElementId, V as ViewId } from '../../shared/core.D00YbOhQ.mjs';
2
- import { E as ElementModel, R as RelationshipModel, f as LikeC4Model } from '../../shared/core.BfCKSW-g.mjs';
3
- import 'type-fest';
4
- import '../../shared/core.DB0Ue5Wx.mjs';
5
- import '../../shared/core.C_3y3eqV.mjs';
6
- import '../../shared/core.CAgYpDtM.mjs';
7
- import '../../shared/core.DC5IAaDT.mjs';
8
- import '../../types/fqnRef.mjs';
9
- import '../../shared/core.Dojz4bvg.mjs';
10
- import '../../types/expression-model.mjs';
11
- import '../../shared/core.BPGOjone.mjs';
12
- import '../../shared/core.CywrQs86.mjs';
13
- import '../../shared/core.osFs8tU7.mjs';
14
-
15
- type RelationshipsViewData<M extends Any = Unknown> = {
16
- incomers: ReadonlySet<ElementModel<M>>;
17
- incoming: ReadonlySet<RelationshipModel<M>>;
18
- subjects: ReadonlySet<ElementModel<M>>;
19
- outgoing: ReadonlySet<RelationshipModel<M>>;
20
- outgoers: ReadonlySet<ElementModel<M>>;
21
- };
22
-
23
- declare function computeRelationshipsView<M extends Any>(subjectId: ElementId<M>, likec4model: LikeC4Model<M>, scopeViewId: ViewId<M> | null, scope?: 'global' | 'view'): RelationshipsViewData<M>;
24
-
25
- declare function treeFromElements<M extends Any>(elements: Iterable<ElementModel<M>>): {
26
- sorted: readonly ElementModel<M>[];
27
- byId: (id: ElementId<M>) => ElementModel<M>;
28
- root: ReadonlySet<ElementModel<M>>;
29
- parent: (el: ElementModel<M>) => ElementModel<M> | null;
30
- children: (el: ElementModel<M>) => ReadonlyArray<ElementModel<M>>;
31
- /**
32
- * Flattens the tree structure by removing redundant hierarchy levels.
33
- * @example
34
- * A
35
- * └── B
36
- * ├── C
37
- * │ └── D
38
- * │ └── E
39
- * └── F
40
- * └── G
41
- * becomes
42
- * A
43
- * ├── C
44
- * │ └── E
45
- * └── F
46
- * └── G
47
- */
48
- flatten: () => Set<ElementModel<M>>;
49
- };
50
-
51
- export { type RelationshipsViewData, computeRelationshipsView, treeFromElements };
1
+ import "../../_chunks/_aux.mjs";
2
+ import "../../_chunks/scalar.mjs";
3
+ import "../../_chunks/expression.mjs";
4
+ import "../../_chunks/fqnRef.mjs";
5
+ import "../../_chunks/expression-model.mjs";
6
+ import "../../_chunks/index2.mjs";
7
+ import "../../_chunks/RichText.mjs";
8
+ import "../../_chunks/index3.mjs";
9
+ import "../../_chunks/LikeC4Model.mjs";
10
+ import "../../_chunks/const.mjs";
11
+ import "../../_chunks/find.mjs";
12
+ import "../../_chunks/find2.mjs";
13
+ import "../../_chunks/index4.mjs";
14
+ import "../../_chunks/index5.mjs";
15
+ import { n as computeRelationshipsView, r as RelationshipsViewData, t as treeFromElements } from "../../_chunks/index6.mjs";
16
+ export { RelationshipsViewData, computeRelationshipsView, treeFromElements };
@@ -1,185 +1,7 @@
1
- import { t } from '../../shared/core.3ZhnKAlZ.mjs';
2
- import { f as sortParentsFirst, b as isDescendantOf, i as isAncestor } from '../../shared/core.CdNCAwq7.mjs';
3
- import { D as DefaultMap } from '../../shared/core.BbE4y-yl.mjs';
4
- import { a as nonNullable, i as invariant } from '../../shared/core.D4npX2q8.mjs';
5
- import { t as toSet, a as toArray, i as imap } from '../../shared/core.C3JowhaZ.mjs';
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
- function treeFromElements(elements) {
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
- export { B as BBox, P as Point, R as RectBox, X as XYPoint } from '../shared/core.BPGOjone.mjs';
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 };
@@ -1,328 +1,3 @@
1
- import { a as t } from '../shared/core.BsSXS-_R.mjs';
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
- var BBox;
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 };