@likec4/core 1.47.0 → 1.49.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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/dist/THIRD-PARTY-LICENSES.md +1012 -0
  3. package/dist/_chunks/Builder.view-element.mjs +2 -0
  4. package/dist/_chunks/LikeC4Model.d.mts +1283 -0
  5. package/dist/_chunks/RichText.mjs +1 -0
  6. package/dist/_chunks/_types.d.mts +777 -0
  7. package/dist/_chunks/_types2.d.mts +36 -0
  8. package/dist/_chunks/assignTagColors.mjs +1 -0
  9. package/dist/_chunks/calcDriftsFromSnapshot.mjs +1 -0
  10. package/dist/_chunks/guards.d.mts +2026 -0
  11. package/dist/_chunks/guards.mjs +4 -0
  12. package/dist/_chunks/index.d.mts +288 -0
  13. package/dist/_chunks/libs/@mantine/colors-generator.mjs +15 -0
  14. package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -0
  15. package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -0
  16. package/dist/_chunks/libs/bail.mjs +1 -0
  17. package/dist/_chunks/libs/ccount.mjs +1 -0
  18. package/dist/_chunks/libs/character-entities-html4.mjs +1 -0
  19. package/dist/_chunks/libs/character-entities-legacy.mjs +1 -0
  20. package/dist/_chunks/libs/character-entities.mjs +2 -0
  21. package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -0
  22. package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -0
  23. package/dist/_chunks/libs/defu.mjs +1 -0
  24. package/dist/_chunks/libs/devlop.mjs +1 -0
  25. package/dist/_chunks/libs/escape-string-regexp.mjs +1 -0
  26. package/dist/_chunks/libs/extend.mjs +1 -0
  27. package/dist/_chunks/libs/graphology-dag.mjs +1 -0
  28. package/dist/_chunks/libs/graphology.mjs +1 -0
  29. package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -0
  30. package/dist/_chunks/libs/hast-util-to-html.mjs +9 -0
  31. package/dist/_chunks/libs/is-plain-obj.mjs +1 -0
  32. package/dist/_chunks/libs/longest-streak.mjs +1 -0
  33. package/dist/_chunks/libs/markdown-table.mjs +2 -0
  34. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -0
  35. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +3 -0
  36. package/dist/_chunks/libs/mdast-util-gfm.mjs +15 -0
  37. package/dist/_chunks/libs/mdast-util-to-hast.mjs +11 -0
  38. package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -0
  39. package/dist/_chunks/libs/mnemonist.d.mts +164 -0
  40. package/dist/_chunks/libs/mnemonist.mjs +1 -0
  41. package/dist/_chunks/libs/natural-compare-lite.mjs +9 -0
  42. package/dist/_chunks/libs/ohash.mjs +1 -0
  43. package/dist/_chunks/libs/rehype-sanitize.mjs +1 -0
  44. package/dist/_chunks/libs/rehype-stringify.mjs +1 -0
  45. package/dist/_chunks/libs/remark-gfm.mjs +1 -0
  46. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +3 -0
  47. package/dist/_chunks/libs/remark-parse.mjs +1 -0
  48. package/dist/_chunks/libs/remark-rehype.mjs +1 -0
  49. package/dist/_chunks/libs/remeda.mjs +1 -0
  50. package/dist/_chunks/libs/trough.mjs +1 -0
  51. package/dist/_chunks/libs/unified.mjs +1 -0
  52. package/dist/_chunks/rolldown-runtime.mjs +1 -0
  53. package/dist/_chunks/theme.d.mts +148 -0
  54. package/dist/_chunks/to-text.d.mts +404 -0
  55. package/dist/_chunks/to-text.mjs +1 -0
  56. package/dist/_chunks/vector.d.mts +198 -0
  57. package/dist/_chunks/vector.mjs +1 -0
  58. package/dist/builder/index.d.mts +5 -775
  59. package/dist/builder/index.mjs +1 -1053
  60. package/dist/compute-view/index.d.mts +156 -56
  61. package/dist/compute-view/index.mjs +2 -229
  62. package/dist/geometry/index.d.mts +2 -109
  63. package/dist/geometry/index.mjs +1 -328
  64. package/dist/index.d.mts +14 -20
  65. package/dist/index.mjs +1 -18
  66. package/dist/model/index.d.mts +5 -57
  67. package/dist/model/index.mjs +1 -4
  68. package/dist/styles/index.d.mts +3 -117
  69. package/dist/styles/index.mjs +1 -63
  70. package/dist/types/index.d.mts +3 -47
  71. package/dist/types/index.mjs +1 -17
  72. package/dist/utils/graphology/index.d.mts +2 -1864
  73. package/dist/utils/graphology/index.mjs +1 -1
  74. package/dist/utils/index.d.mts +4 -124
  75. package/dist/utils/index.mjs +1 -44
  76. package/package.json +20 -24
  77. package/compute-view/relationships/package.json +0 -4
  78. package/dist/compute-view/relationships-view/index.d.mts +0 -51
  79. package/dist/compute-view/relationships-view/index.mjs +0 -185
  80. package/dist/model/connection/deployment/index.d.mts +0 -15
  81. package/dist/model/connection/deployment/index.mjs +0 -2
  82. package/dist/model/connection/index.d.mts +0 -75
  83. package/dist/model/connection/index.mjs +0 -3
  84. package/dist/model/connection/model/index.d.mts +0 -15
  85. package/dist/model/connection/model/index.mjs +0 -2
  86. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  87. package/dist/shared/core.78IWAHAE.mjs +0 -332
  88. package/dist/shared/core.B85MJLTf.mjs +0 -5
  89. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  90. package/dist/shared/core.BKlholso.mjs +0 -3
  91. package/dist/shared/core.BNN-3vPH.mjs +0 -1255
  92. package/dist/shared/core.BPGOjone.d.mts +0 -46
  93. package/dist/shared/core.BP_QHEXs.mjs +0 -785
  94. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  95. package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
  96. package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
  97. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  98. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  99. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  100. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  101. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  102. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  103. package/dist/shared/core.CAgYpDtM.d.mts +0 -98
  104. package/dist/shared/core.CHf8VEa3.mjs +0 -1206
  105. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  106. package/dist/shared/core.C_3y3eqV.d.mts +0 -139
  107. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  108. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  109. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  110. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  111. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  112. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  113. package/dist/shared/core.CywrQs86.d.mts +0 -31
  114. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  115. package/dist/shared/core.D0WZutNd.mjs +0 -94
  116. package/dist/shared/core.D4npX2q8.mjs +0 -18
  117. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  118. package/dist/shared/core.DC5IAaDT.d.mts +0 -334
  119. package/dist/shared/core.DE9qzhn8.d.mts +0 -83
  120. package/dist/shared/core.DGcIbsj4.mjs +0 -3946
  121. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  122. package/dist/shared/core.DKhRkHRN.d.mts +0 -41
  123. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  124. package/dist/shared/core.DU5SRqNF.mjs +0 -2209
  125. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  126. package/dist/shared/core.DbfO90vF.mjs +0 -434
  127. package/dist/shared/core.DcS-0zys.mjs +0 -10
  128. package/dist/shared/core.Dh119QSP.mjs +0 -4995
  129. package/dist/shared/core.DjcWextK.mjs +0 -1371
  130. package/dist/shared/core.Dojz4bvg.d.mts +0 -504
  131. package/dist/shared/core.FZ305VYd.mjs +0 -21
  132. package/dist/shared/core.OtRNdMxy.d.mts +0 -352
  133. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  134. package/dist/shared/core.btEq3i3f.mjs +0 -300
  135. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  136. package/dist/shared/core.om36dXXW.mjs +0 -41
  137. package/dist/shared/core.osFs8tU7.d.mts +0 -466
  138. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  139. package/dist/shared/core.tpvDGvdC.d.mts +0 -87
  140. package/dist/shared/core.uFk_o9X6.mjs +0 -13
  141. package/dist/types/_aux.d.mts +0 -4
  142. package/dist/types/_aux.mjs +0 -8
  143. package/dist/types/expression-model.d.mts +0 -190
  144. package/dist/types/expression-model.mjs +0 -109
  145. package/dist/types/expression.d.mts +0 -6
  146. package/dist/types/expression.mjs +0 -113
  147. package/dist/types/fqnRef.d.mts +0 -60
  148. package/dist/types/fqnRef.mjs +0 -45
  149. package/dist/types/scalar.d.mts +0 -2
  150. package/dist/types/scalar.mjs +0 -4
  151. package/dist/utils/iterable/index.d.mts +0 -132
  152. package/dist/utils/iterable/index.mjs +0 -62
@@ -1,69 +0,0 @@
1
- function memoizeProp(obj, tag, fn) {
2
- const tagSymbol = typeof tag === "symbol" ? tag : Symbol.for(tag);
3
- if (!obj.hasOwnProperty(tagSymbol)) {
4
- Object.defineProperty(obj, tagSymbol, {
5
- enumerable: false,
6
- writable: false,
7
- value: fn()
8
- });
9
- }
10
- return obj[tagSymbol];
11
- }
12
-
13
- function isPlainObject(value) {
14
- if (value === null || typeof value !== "object") {
15
- return false;
16
- }
17
- const prototype = Object.getPrototypeOf(value);
18
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
19
- return false;
20
- }
21
- if (Symbol.iterator in value) {
22
- return false;
23
- }
24
- if (Symbol.toStringTag in value) {
25
- return Object.prototype.toString.call(value) === "[object Module]";
26
- }
27
- return true;
28
- }
29
-
30
- function _defu(baseObject, defaults, namespace = ".", merger) {
31
- if (!isPlainObject(defaults)) {
32
- return _defu(baseObject, {}, namespace, merger);
33
- }
34
- const object = Object.assign({}, defaults);
35
- for (const key in baseObject) {
36
- if (key === "__proto__" || key === "constructor") {
37
- continue;
38
- }
39
- const value = baseObject[key];
40
- if (value === null || value === void 0) {
41
- continue;
42
- }
43
- if (merger && merger(object, key, value, namespace)) {
44
- continue;
45
- }
46
- if (Array.isArray(value) && Array.isArray(object[key])) {
47
- object[key] = [...value, ...object[key]];
48
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
49
- object[key] = _defu(
50
- value,
51
- object[key],
52
- (namespace ? `${namespace}.` : "") + key.toString(),
53
- merger
54
- );
55
- } else {
56
- object[key] = value;
57
- }
58
- }
59
- return object;
60
- }
61
- function createDefu(merger) {
62
- return (...arguments_) => (
63
- // eslint-disable-next-line unicorn/no-array-reduce
64
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
65
- );
66
- }
67
- const defu = createDefu();
68
-
69
- export { defu as d, memoizeProp as m };
@@ -1,139 +0,0 @@
1
- import { Tagged } from 'type-fest';
2
-
3
- type ProjectId<T = string> = Tagged<T, 'ProjectID'>;
4
- declare function ProjectId(name: string): ProjectId;
5
- type MarkdownOrString = {
6
- txt: string;
7
- md?: never;
8
- } | {
9
- md: string;
10
- txt?: never;
11
- };
12
- /**
13
- * Converts a MarkdownOrString object or a plain string into a simple string representation.
14
- * This utility function handles different types of text content and normalizes them to a string format.
15
- *
16
- * @param value - The content to be flattened.
17
- * Can be one of:
18
- * - A plain string
19
- * - A MarkdownOrString object with either txt or md property
20
- * - undefined or null
21
- *
22
- * @returns The string content contained within the input value.
23
- * - Returns the input directly if it's already a string
24
- * - Returns the txt property if available in a MarkdownOrString object
25
- * - Falls back to the md property if txt is not available
26
- * - Returns null if:
27
- * - The input is null or undefined
28
- * - The resulting string value is empty, whitespace, or null
29
- *
30
- * @example
31
- * // String input
32
- * flattenMarkdownOrString("Hello world") // Returns: "Hello world"
33
- * flattenMarkdownOrString(" ") // Returns: null
34
- *
35
- * // MarkdownOrString with txt property
36
- * flattenMarkdownOrString({ txt: "Plain text" }) // Returns: "Plain text"
37
- * flattenMarkdownOrString({ txt: " " }) // Returns: null
38
- *
39
- * // MarkdownOrString with md property
40
- * flattenMarkdownOrString({ md: "**Bold markdown**" }) // Returns: "**Bold markdown**"
41
- *
42
- * // Null input
43
- * flattenMarkdownOrString(null) // Returns: null
44
- */
45
- declare function flattenMarkdownOrString(value: MarkdownOrString | string): string;
46
- declare function flattenMarkdownOrString(value: MarkdownOrString | string | undefined | null): string | null;
47
- type BuiltInIcon = 'none' | `${'aws' | 'azure' | 'gcp' | 'tech' | 'bootstrap'}:${string}`;
48
- type Icon = Tagged<string, 'Icon'> | BuiltInIcon;
49
- declare const NoneIcon: Icon;
50
- type IconUrl = Icon;
51
- /**
52
- * Full-qualified-name for model elements
53
- *
54
- * @param This - Fqn of the element (specific element)
55
- * @param All - The type of all known FQNs
56
- *
57
- * @example
58
- * ```ts
59
- * type ElementAFqn = Fqn<'a', 'a' | ' | 'b'>
60
- *
61
- * ```
62
- */
63
- type Fqn<Id = string> = Tagged<Id, 'Fqn'>;
64
- declare function Fqn(name: string, parent?: Fqn | null): Fqn;
65
- type ElementKind<Kinds = string> = Tagged<Kinds, 'ElementKind'>;
66
- declare const GroupElementKind: ElementKind<"@group">;
67
- type GroupElementKind = typeof GroupElementKind;
68
- declare function isGroupElementKind<V extends {
69
- kind?: any;
70
- }>(v: V): v is V & {
71
- kind: GroupElementKind;
72
- };
73
- /**
74
- * Full-qualified-name for deployment elements
75
- */
76
- type DeploymentFqn<T = string> = Tagged<T, 'DeploymentFqn'>;
77
- declare function DeploymentFqn(name: string, parent?: DeploymentFqn | null): DeploymentFqn;
78
- type DeploymentKind<Kinds = string> = Tagged<Kinds, 'DeploymentKind'>;
79
- type ViewId<Id = string> = Tagged<Id, 'ViewId'>;
80
- declare function ViewId(id: string): ViewId;
81
- type AnyFqn<T = string> = DeploymentFqn<T> | Fqn<T>;
82
- /**
83
- * @deprecated Use {@link RelationshipKind} instead
84
- */
85
- type RelationKind<Kinds = string> = RelationshipKind<Kinds>;
86
- type RelationshipKind<Kinds = string> = Tagged<Kinds, 'RelationshipKind'>;
87
- type RelationId<Id = string> = Tagged<Id, 'RelationId'>;
88
- declare function RelationId(id: string): RelationId;
89
- type Tag<T = string> = Tagged<T, 'Tag'>;
90
- type GlobalFqn<Id = string> = Tagged<Fqn<Id>, 'GlobalFqn'>;
91
- declare function GlobalFqn<A>(projectId: A | ProjectId<A>, name: string): GlobalFqn<A>;
92
- declare function isGlobalFqn<A extends string>(fqn: A): fqn is GlobalFqn<A>;
93
- declare function splitGlobalFqn<I extends string>(fqn: Fqn<I> | GlobalFqn<I>): [ProjectId | null, Fqn<I>];
94
- type NodeId = Tagged<string, 'NodeId' | 'Fqn' | 'DeploymentFqn'>;
95
- declare function NodeId(id: string): NodeId;
96
- type EdgeId = Tagged<string, 'EdgeId'>;
97
- declare function EdgeId(id: string): EdgeId;
98
- type StepEdgeIdLiteral = `step-${number}` | `step-${number}.${number}`;
99
- type StepEdgeId = Tagged<StepEdgeIdLiteral, 'EdgeId'>;
100
- declare function stepEdgeId(step: number, parallelStep?: number): StepEdgeId;
101
- declare const StepEdgeKind = "@step";
102
- declare function isStepEdgeId(id: string): id is StepEdgeId;
103
- declare function extractStep(id: EdgeId): number;
104
-
105
- type scalar_AnyFqn<T = string> = AnyFqn<T>;
106
- type scalar_BuiltInIcon = BuiltInIcon;
107
- declare const scalar_DeploymentFqn: typeof DeploymentFqn;
108
- type scalar_DeploymentKind<Kinds = string> = DeploymentKind<Kinds>;
109
- declare const scalar_EdgeId: typeof EdgeId;
110
- type scalar_ElementKind<Kinds = string> = ElementKind<Kinds>;
111
- declare const scalar_Fqn: typeof Fqn;
112
- declare const scalar_GlobalFqn: typeof GlobalFqn;
113
- type scalar_GroupElementKind = GroupElementKind;
114
- type scalar_Icon = Icon;
115
- type scalar_IconUrl = IconUrl;
116
- type scalar_MarkdownOrString = MarkdownOrString;
117
- declare const scalar_NodeId: typeof NodeId;
118
- declare const scalar_NoneIcon: typeof NoneIcon;
119
- declare const scalar_ProjectId: typeof ProjectId;
120
- declare const scalar_RelationId: typeof RelationId;
121
- type scalar_RelationKind<Kinds = string> = RelationKind<Kinds>;
122
- type scalar_RelationshipKind<Kinds = string> = RelationshipKind<Kinds>;
123
- type scalar_StepEdgeId = StepEdgeId;
124
- type scalar_StepEdgeIdLiteral = StepEdgeIdLiteral;
125
- declare const scalar_StepEdgeKind: typeof StepEdgeKind;
126
- type scalar_Tag<T = string> = Tag<T>;
127
- declare const scalar_ViewId: typeof ViewId;
128
- declare const scalar_extractStep: typeof extractStep;
129
- declare const scalar_flattenMarkdownOrString: typeof flattenMarkdownOrString;
130
- declare const scalar_isGlobalFqn: typeof isGlobalFqn;
131
- declare const scalar_isGroupElementKind: typeof isGroupElementKind;
132
- declare const scalar_isStepEdgeId: typeof isStepEdgeId;
133
- declare const scalar_splitGlobalFqn: typeof splitGlobalFqn;
134
- declare const scalar_stepEdgeId: typeof stepEdgeId;
135
- declare namespace scalar {
136
- export { type scalar_AnyFqn as AnyFqn, type scalar_BuiltInIcon as BuiltInIcon, scalar_DeploymentFqn as DeploymentFqn, type scalar_DeploymentKind as DeploymentKind, scalar_EdgeId as EdgeId, type scalar_ElementKind as ElementKind, scalar_Fqn as Fqn, scalar_GlobalFqn as GlobalFqn, type scalar_GroupElementKind as GroupElementKind, type scalar_Icon as Icon, type scalar_IconUrl as IconUrl, type scalar_MarkdownOrString as MarkdownOrString, scalar_NodeId as NodeId, scalar_NoneIcon as NoneIcon, scalar_ProjectId as ProjectId, scalar_RelationId as RelationId, type scalar_RelationKind as RelationKind, type scalar_RelationshipKind as RelationshipKind, type scalar_StepEdgeId as StepEdgeId, type scalar_StepEdgeIdLiteral as StepEdgeIdLiteral, scalar_StepEdgeKind as StepEdgeKind, type scalar_Tag as Tag, scalar_ViewId as ViewId, scalar_extractStep as extractStep, scalar_flattenMarkdownOrString as flattenMarkdownOrString, scalar_isGlobalFqn as isGlobalFqn, scalar_isGroupElementKind as isGroupElementKind, scalar_isStepEdgeId as isStepEdgeId, scalar_splitGlobalFqn as splitGlobalFqn, scalar_stepEdgeId as stepEdgeId };
137
- }
138
-
139
- export { type AnyFqn as A, type BuiltInIcon as B, DeploymentFqn as D, type ElementKind as E, Fqn as F, GroupElementKind as G, type Icon as I, type MarkdownOrString as M, NoneIcon as N, ProjectId as P, type RelationKind as R, type StepEdgeIdLiteral as S, type Tag as T, ViewId as V, type IconUrl as a, type DeploymentKind as b, type RelationshipKind as c, RelationId as d, GlobalFqn as e, flattenMarkdownOrString as f, isGlobalFqn as g, splitGlobalFqn as h, isGroupElementKind as i, NodeId as j, EdgeId as k, type StepEdgeId as l, stepEdgeId as m, StepEdgeKind as n, isStepEdgeId as o, extractStep as p, scalar as s };
@@ -1,5 +0,0 @@
1
- import { t as t$1 } from './core.BsSXS-_R.mjs';
2
-
3
- function t(...t){return t$1(n,t,r)}const n=(e,t)=>e.map(t),r=e=>(t,n,r)=>({done:false,hasNext:true,next:e(t,n,r)});
4
-
5
- export { t };
@@ -1,176 +0,0 @@
1
- import { c as compareNatural } from './core.3ZhnKAlZ.mjs';
2
-
3
- function isString(value) {
4
- return value != null && typeof value === "string";
5
- }
6
- function isNonEmptyArray(arr) {
7
- return !!arr && Array.isArray(arr) && arr.length > 0;
8
- }
9
- function hasProp(value, path) {
10
- return value[path] != null;
11
- }
12
- function isAnyOf(...predicates) {
13
- return (value) => {
14
- return predicates.some((predicate) => predicate(value));
15
- };
16
- }
17
-
18
- function parentFqn(fqn) {
19
- const lastDot = fqn.lastIndexOf(".");
20
- if (lastDot > 0) {
21
- return fqn.slice(0, lastDot);
22
- }
23
- return null;
24
- }
25
- function nameFromFqn(fqn) {
26
- const lastDot = fqn.lastIndexOf(".");
27
- if (lastDot > 0) {
28
- return fqn.slice(lastDot + 1);
29
- } else {
30
- return fqn;
31
- }
32
- }
33
- const asString = (e) => isString(e) ? e : e.id;
34
- function isAncestor(arg1, arg2) {
35
- const arg1Id = asString(arg1);
36
- if (arg2) {
37
- const arg2Id = asString(arg2);
38
- return arg2Id.startsWith(arg1Id + ".");
39
- }
40
- return (ancestor) => {
41
- const ancestorId = asString(ancestor);
42
- return arg1Id.startsWith(ancestorId + ".");
43
- };
44
- }
45
- function isSameHierarchy(one, another) {
46
- if (!another) {
47
- return (b) => isSameHierarchy(one, b);
48
- }
49
- const first = asString(one);
50
- const second = asString(another);
51
- return first === second || second.startsWith(first + ".") || first.startsWith(second + ".");
52
- }
53
- function isDescendantOf(descedant, ancestor) {
54
- if (!ancestor) {
55
- return (d) => isAncestor(descedant, d);
56
- }
57
- return isAncestor(ancestor, descedant);
58
- }
59
- function hierarchyLevel(elementOfFqn) {
60
- const first = isString(elementOfFqn) ? elementOfFqn : elementOfFqn.id;
61
- return first.split(".").length;
62
- }
63
- function hierarchyDistance(one, another) {
64
- const first = isString(one) ? one : one.id;
65
- const second = isString(another) ? another : another.id;
66
- if (first === second) {
67
- return 0;
68
- }
69
- const firstDepth = hierarchyLevel(first);
70
- const secondDepth = hierarchyLevel(second);
71
- if (isSameHierarchy(first, second)) {
72
- return Math.abs(firstDepth - secondDepth);
73
- }
74
- const ancestor = commonAncestor(first, second);
75
- const ancestorDepth = ancestor ? hierarchyLevel(ancestor) : 0;
76
- return firstDepth + secondDepth - (2 * ancestorDepth + 1);
77
- }
78
- function commonAncestor(first, second) {
79
- const a = first.split(".");
80
- if (a.length < 2) {
81
- return null;
82
- }
83
- const b = second.split(".");
84
- if (b.length < 2) {
85
- return null;
86
- }
87
- let ancestor = [];
88
- for (let i = 0; i < Math.min(a.length, b.length) - 1 && a[i] === b[i]; i++) {
89
- ancestor.push(a[i]);
90
- }
91
- if (ancestor.length === 0) {
92
- return null;
93
- }
94
- return ancestor.join(".");
95
- }
96
- function ancestorsFqn(fqn) {
97
- const path = fqn.split(".");
98
- path.pop();
99
- if (path.length === 0) {
100
- return [];
101
- }
102
- return path.reduce((acc, part, idx) => {
103
- if (idx === 0) {
104
- acc.push(part);
105
- return acc;
106
- }
107
- acc.unshift(`${acc[0]}.${part}`);
108
- return acc;
109
- }, []);
110
- }
111
- function compareFqnHierarchically(a, b) {
112
- const depthA = a.split(".").length;
113
- const depthB = b.split(".").length;
114
- switch (true) {
115
- case depthA > depthB: {
116
- return 1;
117
- }
118
- case depthA < depthB: {
119
- return -1;
120
- }
121
- default: {
122
- return 0;
123
- }
124
- }
125
- }
126
- function compareByFqnHierarchically(a, b) {
127
- return compareFqnHierarchically(a.id, b.id);
128
- }
129
- function sortByFqnHierarchically(array) {
130
- return array.map((item) => ({ item, fqn: item.id.split(".") })).sort((a, b) => {
131
- return a.fqn.length - b.fqn.length;
132
- }).map(({ item }) => item);
133
- }
134
- function findTopAncestor(items, item) {
135
- let parent = item;
136
- for (const e of items) {
137
- if (isAncestor(e, parent)) {
138
- parent = e;
139
- }
140
- }
141
- return parent !== item ? parent : null;
142
- }
143
- function sortParentsFirst(array) {
144
- const result = [];
145
- const items = [...array];
146
- let item;
147
- while (item = items.shift()) {
148
- let parent;
149
- while (parent = findTopAncestor(items, item)) {
150
- result.push(items.splice(items.indexOf(parent), 1)[0]);
151
- }
152
- result.push(item);
153
- }
154
- return result;
155
- }
156
- function sortNaturalByFqn(array, sort) {
157
- if (!array || isString(array)) {
158
- const dir2 = array ?? "asc";
159
- return (arr) => sortNaturalByFqn(arr, dir2);
160
- }
161
- const dir = sort === "desc" ? -1 : 1;
162
- return array.map((item) => ({ item, fqn: item.id.split(".") })).sort((a, b) => {
163
- if (a.fqn.length !== b.fqn.length) {
164
- return (a.fqn.length - b.fqn.length) * dir;
165
- }
166
- for (let i = 0; i < a.fqn.length; i++) {
167
- const compare = compareNatural(a.fqn[i], b.fqn[i]);
168
- if (compare !== 0) {
169
- return compare;
170
- }
171
- }
172
- return 0;
173
- }).map(({ item }) => item);
174
- }
175
-
176
- export { ancestorsFqn as a, isDescendantOf as b, isNonEmptyArray as c, isSameHierarchy as d, isString as e, sortParentsFirst as f, commonAncestor as g, hasProp as h, isAncestor as i, compareByFqnHierarchically as j, compareFqnHierarchically as k, hierarchyDistance as l, hierarchyLevel as m, nameFromFqn as n, sortByFqnHierarchically as o, parentFqn as p, isAnyOf as q, sortNaturalByFqn as s };