@likec4/core 1.10.1 → 1.12.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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { u, e, n as nonNullable, D as DefaultElementShape, a as DefaultThemeColor } from './shared/core.DeifT5lC.mjs';
2
- export { A as AsFqn, B as BorderStyles, J as DefaultArrowType, I as DefaultLineStyle, K as DefaultRelationshipColor, E as ElementShapes, c as Expr, V as StepEdgeId, X as extractStep, $ as getBBoxCenter, Y as getParallelStepsPrefix, i as invariant, F as isAndOperator, Z as isComputedDynamicView, _ as isComputedElementView, g as isCustomElement, w as isCustomRelationExpr, R as isDynamicView, P as isDynamicViewIncludeRule, Q as isDynamicViewParallelSteps, l as isElement, j as isElementKindExpr, o as isElementPredicateExpr, d as isElementRef, k as isElementTagExpr, S as isElementView, m as isElementWhere, f as isExpandedElementExpr, T as isExtendsElementView, q as isInOut, r as isIncoming, z as isKindEqual, C as isNotOperator, G as isOrOperator, s as isOutgoing, p as isRelation, t as isRelationExpression, x as isRelationPredicateExpr, v as isRelationWhere, U as isScopedElementView, W as isStepEdgeId, y as isTagEqual, L as isThemeColor, O as isViewRuleAutoLayout, M as isViewRulePredicate, N as isViewRuleStyle, h as isWildcard, b as nonexhaustive, H as whereOperatorAsPredicate } from './shared/core.DeifT5lC.mjs';
1
+ import { u, e, n as nonNullable, D as DefaultRelationshipColor, a as DefaultElementShape, b as DefaultThemeColor } from './shared/core.BvFch1jG.mjs';
2
+ export { A as AsFqn, B as BorderStyles, K as DefaultArrowType, J as DefaultLineStyle, E as ElementShapes, c as Expr, W as StepEdgeId, Y as extractStep, a0 as getBBoxCenter, Z as getParallelStepsPrefix, i as invariant, G as isAndOperator, O as isAutoLayoutDirection, _ as isComputedDynamicView, $ as isComputedElementView, h as isCustomElement, x as isCustomRelationExpr, S as isDynamicView, Q as isDynamicViewIncludeRule, R as isDynamicViewParallelSteps, m as isElement, k as isElementKindExpr, p as isElementPredicateExpr, f as isElementRef, l as isElementTagExpr, T as isElementView, o as isElementWhere, g as isExpandedElementExpr, U as isExtendsElementView, r as isInOut, s as isIncoming, C as isKindEqual, F as isNotOperator, H as isOrOperator, t as isOutgoing, q as isRelation, v as isRelationExpression, y as isRelationPredicateExpr, w as isRelationWhere, V as isScopedElementView, X as isStepEdgeId, z as isTagEqual, L as isThemeColor, P as isViewRuleAutoLayout, M as isViewRulePredicate, N as isViewRuleStyle, j as isWildcard, d as nonexhaustive, I as whereOperatorAsPredicate } from './shared/core.BvFch1jG.mjs';
3
3
 
4
4
  const { min: min$4, max: max$4 } = Math;
5
5
 
@@ -3655,76 +3655,325 @@ function computeColorValues(color) {
3655
3655
  }
3656
3656
  }
3657
3657
 
3658
- function r$1(...t){return u(Object.values,t)}
3658
+ function r$1(...n){return u(Object.values,n)}
3659
3659
 
3660
3660
  function i(...e){return u(r,e)}var r=(e,t)=>e.length>=t;
3661
3661
 
3662
+ function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInteger: The range [${r.toString()},${n.toString()}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}
3663
+
3662
3664
  function t(r){return typeof r=="string"}
3663
3665
 
3664
3666
  function n(e){return !!e}
3665
3667
 
3668
+ function getId(element) {
3669
+ return t(element) ? element : element.id;
3670
+ }
3671
+
3672
+ class LikeC4DiagramModel {
3673
+ constructor(view, model) {
3674
+ this.view = view;
3675
+ this.model = model;
3676
+ for (const node of view.nodes) {
3677
+ const el = new LikeC4DiagramModel.Element(node, this);
3678
+ this._elements.set(node.id, el);
3679
+ if (e(node.parent)) {
3680
+ this._rootElements.add(el);
3681
+ }
3682
+ }
3683
+ this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4DiagramModel.Connection(e, this)]));
3684
+ }
3685
+ _rootElements = /* @__PURE__ */ new Set();
3686
+ _elements = /* @__PURE__ */ new Map();
3687
+ _connections;
3688
+ get isDynamic() {
3689
+ return this.view.__ === "dynamic";
3690
+ }
3691
+ get id() {
3692
+ return this.view.id;
3693
+ }
3694
+ get title() {
3695
+ return this.view.title;
3696
+ }
3697
+ get viewOf() {
3698
+ if (e(this.view.__) || this.view.__ === "element") {
3699
+ const computedView = this.view;
3700
+ return computedView.viewOf ? this.model.element(computedView.viewOf) : null;
3701
+ }
3702
+ return null;
3703
+ }
3704
+ get tags() {
3705
+ return this.view.tags ?? [];
3706
+ }
3707
+ roots() {
3708
+ return [...this._rootElements];
3709
+ }
3710
+ elements() {
3711
+ return [...this._elements.values()];
3712
+ }
3713
+ element(id) {
3714
+ return nonNullable(this._elements.get(id), `LikeC4DiagramModel.Element ${id} in view ${this.view.id} not found`);
3715
+ }
3716
+ hasElement(id) {
3717
+ return this._elements.has(id);
3718
+ }
3719
+ connections() {
3720
+ return [...this._connections.values()];
3721
+ }
3722
+ connection(id) {
3723
+ return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
3724
+ }
3725
+ findConnections(source, target, direction = "direct") {
3726
+ const sourceId = getId(source);
3727
+ const targetId = getId(target);
3728
+ return this.connections().filter(
3729
+ (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
3730
+ );
3731
+ }
3732
+ parent(element) {
3733
+ const el = this.element(getId(element));
3734
+ return el.node.parent ? this.element(el.node.parent) : null;
3735
+ }
3736
+ children(element) {
3737
+ const el = this.element(getId(element));
3738
+ return el.node.children.map((c) => this.element(c));
3739
+ }
3740
+ // Get all sibling (i.e. same parent)
3741
+ siblings(element) {
3742
+ const id = getId(element);
3743
+ const parent = this.parent(id);
3744
+ const siblings = parent ? this.children(parent) : this.roots();
3745
+ return siblings.filter((e) => e.id !== id);
3746
+ }
3747
+ /**
3748
+ * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
3749
+ * (from closest to root)
3750
+ */
3751
+ ancestors(element) {
3752
+ let id = getId(element);
3753
+ const result = [];
3754
+ let parent;
3755
+ while (parent = this.parent(id)) {
3756
+ result.push(parent);
3757
+ id = parent.id;
3758
+ }
3759
+ return result;
3760
+ }
3761
+ descendants(element) {
3762
+ const children = this.children(element);
3763
+ return children.flatMap((c) => [c, ...this.descendants(c.id)]);
3764
+ }
3765
+ incoming(element, filter = "all") {
3766
+ const el = this.element(getId(element));
3767
+ const edges = el.node.inEdges.map((e) => this.connection(e));
3768
+ if (filter === "all" || edges.length === 0) {
3769
+ return edges;
3770
+ }
3771
+ return edges.filter((rel) => {
3772
+ if (filter === "direct") {
3773
+ return rel.target.id === el.id;
3774
+ }
3775
+ return rel.target.id !== el.id;
3776
+ });
3777
+ }
3778
+ incomers(element, filter = "all") {
3779
+ return this.incoming(element, filter).map((r) => r.source);
3780
+ }
3781
+ /**
3782
+ * Outgoing relationships from the element and its descendants
3783
+ */
3784
+ outgoing(element, filter = "all") {
3785
+ const el = this.element(getId(element));
3786
+ const edges = el.node.outEdges.map((e) => this.connection(e));
3787
+ if (filter === "all" || edges.length === 0) {
3788
+ return edges;
3789
+ }
3790
+ return edges.filter((rel) => {
3791
+ if (filter === "direct") {
3792
+ return rel.source.id === el.id;
3793
+ }
3794
+ return rel.source.id !== el.id;
3795
+ });
3796
+ }
3797
+ outgoers(element, filter = "all") {
3798
+ return this.outgoing(element, filter).map((r) => r.target);
3799
+ }
3800
+ }
3801
+ ((LikeC4DiagramModel2) => {
3802
+ class Element {
3803
+ constructor(node, view) {
3804
+ this.node = node;
3805
+ this.view = view;
3806
+ }
3807
+ get id() {
3808
+ return this.node.id;
3809
+ }
3810
+ get title() {
3811
+ return this.node.title;
3812
+ }
3813
+ get kind() {
3814
+ return this.node.kind;
3815
+ }
3816
+ get isRoot() {
3817
+ return e(this.node.parent);
3818
+ }
3819
+ get hasNested() {
3820
+ return this.node.children.length > 0;
3821
+ }
3822
+ get shape() {
3823
+ return this.node.shape;
3824
+ }
3825
+ get color() {
3826
+ return this.node.color;
3827
+ }
3828
+ get tags() {
3829
+ return this.node.tags ?? [];
3830
+ }
3831
+ get level() {
3832
+ return this.node.level;
3833
+ }
3834
+ get depth() {
3835
+ return this.node.depth ?? 0;
3836
+ }
3837
+ model() {
3838
+ return this.view.model.element(this.id);
3839
+ }
3840
+ parent() {
3841
+ return this.node.parent ? this.view.element(this.node.parent) : null;
3842
+ }
3843
+ metadata(key, defaultValue) {
3844
+ return this.model().metadata(key) ?? defaultValue;
3845
+ }
3846
+ hasMetadata(key) {
3847
+ return this.model().hasMetadata(key);
3848
+ }
3849
+ ancestors() {
3850
+ return this.view.ancestors(this);
3851
+ }
3852
+ siblings() {
3853
+ return this.view.siblings(this);
3854
+ }
3855
+ descendants() {
3856
+ return this.view.descendants(this);
3857
+ }
3858
+ children() {
3859
+ return this.view.children(this);
3860
+ }
3861
+ incoming(filter = "all") {
3862
+ return this.view.incoming(this, filter);
3863
+ }
3864
+ incomers(filter = "all") {
3865
+ return this.view.incomers(this, filter);
3866
+ }
3867
+ outgoing(filter = "all") {
3868
+ return this.view.outgoing(this, filter);
3869
+ }
3870
+ outgoers(filter = "all") {
3871
+ return this.view.outgoers(this, filter);
3872
+ }
3873
+ connectionsTo(target) {
3874
+ return this.view.findConnections(this, target);
3875
+ }
3876
+ }
3877
+ LikeC4DiagramModel2.Element = Element;
3878
+ class Connection {
3879
+ constructor(edge, view) {
3880
+ this.edge = edge;
3881
+ this.view = view;
3882
+ }
3883
+ get id() {
3884
+ return this.edge.id;
3885
+ }
3886
+ get source() {
3887
+ return this.view.element(this.edge.source);
3888
+ }
3889
+ get target() {
3890
+ return this.view.element(this.edge.target);
3891
+ }
3892
+ get tags() {
3893
+ return this.edge.tags ?? [];
3894
+ }
3895
+ get color() {
3896
+ return this.edge.color ?? DefaultRelationshipColor;
3897
+ }
3898
+ /**
3899
+ * Model relationships
3900
+ */
3901
+ relationships() {
3902
+ return this.edge.relations.map((r) => nonNullable(this.view.model.relationship(r)));
3903
+ }
3904
+ }
3905
+ LikeC4DiagramModel2.Connection = Connection;
3906
+ })(LikeC4DiagramModel || (LikeC4DiagramModel = {}));
3907
+
3666
3908
  function getDefaultExportFromCjs (x) {
3667
3909
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3668
3910
  }
3669
3911
 
3670
3912
  var naturalCompareLite = {exports: {}};
3671
3913
 
3672
- /*
3673
- * @version 1.4.0
3674
- * @date 2015-10-26
3675
- * @stability 3 - Stable
3676
- * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
3677
- * @license MIT License
3678
- */
3679
-
3680
-
3681
- var naturalCompare = function(a, b) {
3682
- var i, codeA
3683
- , codeB = 1
3684
- , posA = 0
3685
- , posB = 0
3686
- , alphabet = String.alphabet;
3687
-
3688
- function getCode(str, pos, code) {
3689
- if (code) {
3690
- for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
3691
- return +str.slice(pos - 1, i)
3914
+ var hasRequiredNaturalCompareLite;
3915
+
3916
+ function requireNaturalCompareLite () {
3917
+ if (hasRequiredNaturalCompareLite) return naturalCompareLite.exports;
3918
+ hasRequiredNaturalCompareLite = 1;
3919
+ /*
3920
+ * @version 1.4.0
3921
+ * @date 2015-10-26
3922
+ * @stability 3 - Stable
3923
+ * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
3924
+ * @license MIT License
3925
+ */
3926
+
3927
+
3928
+ var naturalCompare = function(a, b) {
3929
+ var i, codeA
3930
+ , codeB = 1
3931
+ , posA = 0
3932
+ , posB = 0
3933
+ , alphabet = String.alphabet;
3934
+
3935
+ function getCode(str, pos, code) {
3936
+ if (code) {
3937
+ for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
3938
+ return +str.slice(pos - 1, i)
3939
+ }
3940
+ code = alphabet && alphabet.indexOf(str.charAt(pos));
3941
+ return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
3942
+ : code < 46 ? 65 // -
3943
+ : code < 48 ? code - 1
3944
+ : code < 58 ? code + 18 // 0-9
3945
+ : code < 65 ? code - 11
3946
+ : code < 91 ? code + 11 // A-Z
3947
+ : code < 97 ? code - 37
3948
+ : code < 123 ? code + 5 // a-z
3949
+ : code - 63
3692
3950
  }
3693
- code = alphabet && alphabet.indexOf(str.charAt(pos));
3694
- return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
3695
- : code < 46 ? 65 // -
3696
- : code < 48 ? code - 1
3697
- : code < 58 ? code + 18 // 0-9
3698
- : code < 65 ? code - 11
3699
- : code < 91 ? code + 11 // A-Z
3700
- : code < 97 ? code - 37
3701
- : code < 123 ? code + 5 // a-z
3702
- : code - 63
3703
- }
3704
3951
 
3705
3952
 
3706
- if ((a+="") != (b+="")) for (;codeB;) {
3707
- codeA = getCode(a, posA++);
3708
- codeB = getCode(b, posB++);
3953
+ if ((a+="") != (b+="")) for (;codeB;) {
3954
+ codeA = getCode(a, posA++);
3955
+ codeB = getCode(b, posB++);
3956
+
3957
+ if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
3958
+ codeA = getCode(a, posA, posA);
3959
+ codeB = getCode(b, posB, posA = i);
3960
+ posB = i;
3961
+ }
3709
3962
 
3710
- if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
3711
- codeA = getCode(a, posA, posA);
3712
- codeB = getCode(b, posB, posA = i);
3713
- posB = i;
3963
+ if (codeA != codeB) return (codeA < codeB) ? -1 : 1
3714
3964
  }
3965
+ return 0
3966
+ };
3715
3967
 
3716
- if (codeA != codeB) return (codeA < codeB) ? -1 : 1
3968
+ try {
3969
+ naturalCompareLite.exports = naturalCompare;
3970
+ } catch (e) {
3971
+ String.naturalCompare = naturalCompare;
3717
3972
  }
3718
- return 0
3719
- };
3720
-
3721
- try {
3722
- naturalCompareLite.exports = naturalCompare;
3723
- } catch (e) {
3724
- String.naturalCompare = naturalCompare;
3973
+ return naturalCompareLite.exports;
3725
3974
  }
3726
3975
 
3727
- var naturalCompareLiteExports = naturalCompareLite.exports;
3976
+ var naturalCompareLiteExports = requireNaturalCompareLite();
3728
3977
  const compare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareLiteExports);
3729
3978
 
3730
3979
  function compareNatural(a, b) {
@@ -3860,16 +4109,16 @@ class LikeC4ViewModel {
3860
4109
  this.model = model;
3861
4110
  for (const node of view.nodes) {
3862
4111
  const el = new LikeC4ViewModel.Element(node, this);
3863
- this.#elements.set(node.id, el);
4112
+ this._elements.set(node.id, el);
3864
4113
  if (e(node.parent)) {
3865
- this.#rootElements.add(el);
4114
+ this._rootElements.add(el);
3866
4115
  }
3867
4116
  }
3868
- this.#connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
4117
+ this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
3869
4118
  }
3870
- #rootElements = /* @__PURE__ */ new Set();
3871
- #elements = /* @__PURE__ */ new Map();
3872
- #connections;
4119
+ _rootElements = /* @__PURE__ */ new Set();
4120
+ _elements = /* @__PURE__ */ new Map();
4121
+ _connections;
3873
4122
  get id() {
3874
4123
  return this.view.id;
3875
4124
  }
@@ -3886,41 +4135,41 @@ class LikeC4ViewModel {
3886
4135
  return this.view.tags ?? [];
3887
4136
  }
3888
4137
  roots() {
3889
- return [...this.#rootElements];
4138
+ return [...this._rootElements];
3890
4139
  }
3891
4140
  elements() {
3892
- return [...this.#elements.values()];
4141
+ return [...this._elements.values()];
3893
4142
  }
3894
4143
  element(id) {
3895
- return nonNullable(this.#elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.view.id} not found`);
4144
+ return nonNullable(this._elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.id} not found`);
3896
4145
  }
3897
4146
  hasElement(id) {
3898
- return this.#elements.has(id);
4147
+ return this._elements.has(id);
3899
4148
  }
3900
4149
  connections() {
3901
- return [...this.#connections.values()];
4150
+ return [...this._connections.values()];
3902
4151
  }
3903
4152
  connection(id) {
3904
- return nonNullable(this.#connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
4153
+ return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.id} not found`);
3905
4154
  }
3906
4155
  findConnections(source, target, direction = "direct") {
3907
- const sourceId = t(source) ? source : source.id;
3908
- const targetId = t(target) ? target : target.id;
4156
+ const sourceId = getId(source);
4157
+ const targetId = getId(target);
3909
4158
  return this.connections().filter(
3910
4159
  (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
3911
4160
  );
3912
4161
  }
3913
4162
  parent(element) {
3914
- const el = this.element(t(element) ? element : element.id);
4163
+ const el = this.element(getId(element));
3915
4164
  return el.node.parent ? this.element(el.node.parent) : null;
3916
4165
  }
3917
4166
  children(element) {
3918
- const el = this.element(t(element) ? element : element.id);
4167
+ const el = this.element(getId(element));
3919
4168
  return el.node.children.map((c) => this.element(c));
3920
4169
  }
3921
4170
  // Get all sibling (i.e. same parent)
3922
4171
  siblings(element) {
3923
- const id = t(element) ? element : element.id;
4172
+ const id = getId(element);
3924
4173
  const parent = this.parent(id);
3925
4174
  const siblings = parent ? this.children(parent) : this.roots();
3926
4175
  return siblings.filter((e) => e.id !== id);
@@ -3930,7 +4179,7 @@ class LikeC4ViewModel {
3930
4179
  * (from closest to root)
3931
4180
  */
3932
4181
  ancestors(element) {
3933
- let id = t(element) ? element : element.id;
4182
+ let id = getId(element);
3934
4183
  const result = [];
3935
4184
  let parent;
3936
4185
  while (parent = this.parent(id)) {
@@ -3944,8 +4193,8 @@ class LikeC4ViewModel {
3944
4193
  return children.flatMap((c) => [c, ...this.descendants(c.id)]);
3945
4194
  }
3946
4195
  incoming(element, filter = "all") {
3947
- const el = this.element(t(element) ? element : element.id);
3948
- const edges = el.node.inEdges.map((e) => nonNullable(this.#connections.get(e), `Edge ${e} not found`));
4196
+ const el = this.element(getId(element));
4197
+ const edges = el.node.inEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
3949
4198
  if (filter === "all" || edges.length === 0) {
3950
4199
  return edges;
3951
4200
  }
@@ -3963,8 +4212,8 @@ class LikeC4ViewModel {
3963
4212
  * Outgoing relationships from the element and its descendants
3964
4213
  */
3965
4214
  outgoing(element, filter = "all") {
3966
- const el = this.element(t(element) ? element : element.id);
3967
- const edges = el.node.outEdges.map((e) => nonNullable(this.#connections.get(e), `Edge ${e} not found`));
4215
+ const el = this.element(getId(element));
4216
+ const edges = el.node.outEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
3968
4217
  if (filter === "all" || edges.length === 0) {
3969
4218
  return edges;
3970
4219
  }
@@ -4077,103 +4326,126 @@ class LikeC4ViewModel {
4077
4326
  LikeC4ViewModel2.Connection = Connection;
4078
4327
  })(LikeC4ViewModel || (LikeC4ViewModel = {}));
4079
4328
 
4080
- const RelationsSet = Set;
4081
- const MapRelations = Map;
4082
4329
  class LikeC4Model {
4083
- constructor(computed) {
4084
- this.computed = computed;
4085
- for (const el of r$1(computed.elements)) {
4330
+ constructor(type, sourcemodel, elements, relations) {
4331
+ this.type = type;
4332
+ this.sourcemodel = sourcemodel;
4333
+ for (const el of elements) {
4086
4334
  this.addElement(el);
4087
4335
  }
4088
- for (const rel of r$1(computed.relations)) {
4336
+ for (const rel of relations) {
4089
4337
  this.addRelation(rel);
4090
4338
  }
4091
- this.#views = new Map(
4092
- r$1(computed.views).map((v) => [v.id, new LikeC4ViewModel(v, this)])
4093
- );
4094
4339
  }
4095
- #elements = /* @__PURE__ */ new Map();
4340
+ _elements = /* @__PURE__ */ new Map();
4096
4341
  // Parent element for given FQN
4097
- #parents = /* @__PURE__ */ new Map();
4342
+ _parents = /* @__PURE__ */ new Map();
4098
4343
  // Children elements for given FQN
4099
- #children = /* @__PURE__ */ new Map();
4100
- #rootElements = /* @__PURE__ */ new Set();
4101
- #relations = /* @__PURE__ */ new Map();
4344
+ _children = /* @__PURE__ */ new Map();
4345
+ _rootElements = /* @__PURE__ */ new Set();
4346
+ _relations = /* @__PURE__ */ new Map();
4102
4347
  // Incoming to an element or its descendants
4103
- #incoming = new MapRelations();
4348
+ _incoming = /* @__PURE__ */ new Map();
4104
4349
  // Outgoing from an element or its descendants
4105
- #outgoing = new MapRelations();
4350
+ _outgoing = /* @__PURE__ */ new Map();
4106
4351
  // Relationships inside the element, among descendants
4107
- #internal = new MapRelations();
4108
- #cacheAscendingSiblings = /* @__PURE__ */ new Map();
4109
- #views;
4110
- static from(computed) {
4111
- return new LikeC4Model(computed);
4352
+ _internal = /* @__PURE__ */ new Map();
4353
+ _cacheAscendingSiblings = /* @__PURE__ */ new Map();
4354
+ _views = /* @__PURE__ */ new Map();
4355
+ static create(source) {
4356
+ if (source.__ === "layouted") {
4357
+ return LikeC4Model.layouted(source);
4358
+ }
4359
+ return LikeC4Model.computed(source);
4360
+ }
4361
+ static computed(source) {
4362
+ const instance = new LikeC4Model(
4363
+ "computed",
4364
+ source,
4365
+ r$1(source.elements),
4366
+ r$1(source.relations)
4367
+ );
4368
+ for (const view of r$1(source.views)) {
4369
+ instance._views.set(view.id, new LikeC4ViewModel(view, instance));
4370
+ }
4371
+ return instance;
4372
+ }
4373
+ static layouted(source) {
4374
+ const instance = new LikeC4Model(
4375
+ "layouted",
4376
+ source,
4377
+ r$1(source.elements),
4378
+ r$1(source.relations)
4379
+ );
4380
+ for (const view of r$1(source.views)) {
4381
+ instance._views.set(view.id, new LikeC4DiagramModel(view, instance));
4382
+ }
4383
+ return instance;
4112
4384
  }
4113
4385
  /**
4114
4386
  * Returns the root elements of the model.
4115
4387
  */
4116
4388
  roots() {
4117
- return [...this.#rootElements];
4389
+ return [...this._rootElements];
4118
4390
  }
4119
4391
  /**
4120
4392
  * Returns all elements in the model.
4121
4393
  */
4122
4394
  elements() {
4123
- return [...this.#elements.values()];
4395
+ return [...this._elements.values()];
4124
4396
  }
4125
4397
  /**
4126
4398
  * Returns a specific element by its FQN.
4127
4399
  */
4128
4400
  element(id) {
4129
- return nonNullable(this.#elements.get(id), `Element ${id} not found`);
4401
+ return nonNullable(this._elements.get(id), `Element ${id} not found`);
4130
4402
  }
4131
4403
  /**
4132
4404
  * Returns all relationships in the model.
4133
4405
  */
4134
4406
  relationships() {
4135
- return [...this.#relations.values()];
4407
+ return [...this._relations.values()];
4136
4408
  }
4137
4409
  /**
4138
4410
  * Returns a specific relationship by its ID.
4139
4411
  */
4140
4412
  relationship(id) {
4141
- return nonNullable(this.#relations.get(id), `Relation ${id} not found`);
4413
+ return nonNullable(this._relations.get(id), `Relation ${id} not found`);
4142
4414
  }
4143
4415
  /**
4144
4416
  * Returns all views in the model.
4145
4417
  */
4146
4418
  views() {
4147
- return [...this.#views.values()];
4419
+ return [...this._views.values()];
4148
4420
  }
4149
4421
  /**
4150
4422
  * Returns a specific view by its ID.
4151
4423
  */
4152
4424
  view(viewId) {
4153
- return nonNullable(this.#views.get(viewId), `View ${viewId} not found`);
4425
+ return nonNullable(this._views.get(viewId), `View ${viewId} not found`);
4154
4426
  }
4155
4427
  /**
4156
4428
  * Returns the parent element of given element.
4157
4429
  * @see ancestors
4158
4430
  */
4159
4431
  parent(element) {
4160
- const id = t(element) ? element : element.id;
4161
- return this.#parents.get(id) || null;
4432
+ const id = getId(element);
4433
+ return this._parents.get(id) || null;
4162
4434
  }
4163
4435
  /**
4164
4436
  * Get all children of the element (only direct children),
4165
4437
  * @see descendants
4166
4438
  */
4167
4439
  children(element) {
4168
- const id = t(element) ? element : element.id;
4440
+ const id = getId(element);
4169
4441
  return this._childrenOf(id);
4170
4442
  }
4171
4443
  /**
4172
4444
  * Get all sibling (i.e. same parent)
4173
4445
  */
4174
4446
  siblings(element) {
4175
- const id = t(element) ? element : element.id;
4176
- const parent = this.#parents.get(id);
4447
+ const id = getId(element);
4448
+ const parent = this._parents.get(id);
4177
4449
  const siblings = parent ? this._childrenOf(parent.id) : this.roots();
4178
4450
  return siblings.filter((e) => e.id !== id);
4179
4451
  }
@@ -4185,7 +4457,7 @@ class LikeC4Model {
4185
4457
  let id = t(element) ? element : element.id;
4186
4458
  const result = [];
4187
4459
  let parent;
4188
- while (parent = this.#parents.get(id)) {
4460
+ while (parent = this._parents.get(id)) {
4189
4461
  result.push(parent);
4190
4462
  id = parent.id;
4191
4463
  }
@@ -4195,7 +4467,7 @@ class LikeC4Model {
4195
4467
  * Get all descendant elements (i.e. children, children’s children, etc.)
4196
4468
  */
4197
4469
  descendants(element) {
4198
- const id = t(element) ? element : element.id;
4470
+ const id = getId(element);
4199
4471
  const children = this._childrenOf(id);
4200
4472
  return children.flatMap((c) => [c, ...this.descendants(c.id)]);
4201
4473
  }
@@ -4204,7 +4476,7 @@ class LikeC4Model {
4204
4476
  * @see incomers
4205
4477
  */
4206
4478
  incoming(element, filter = "all") {
4207
- const id = t(element) ? element : element.id;
4479
+ const id = getId(element);
4208
4480
  const incoming = Array.from(this._incomingTo(id));
4209
4481
  if (filter === "all" || incoming.length === 0) {
4210
4482
  return incoming;
@@ -4227,7 +4499,7 @@ class LikeC4Model {
4227
4499
  * @see outgoers
4228
4500
  */
4229
4501
  outgoing(element, filter = "all") {
4230
- const id = t(element) ? element : element.id;
4502
+ const id = getId(element);
4231
4503
  const outgoing = Array.from(this._outgoingFrom(id));
4232
4504
  if (filter === "all" || outgoing.length === 0) {
4233
4505
  return outgoing;
@@ -4249,7 +4521,7 @@ class LikeC4Model {
4249
4521
  * Relationships inside the element, among descendants
4250
4522
  */
4251
4523
  internal(element) {
4252
- const id = t(element) ? element : element.id;
4524
+ const id = getId(element);
4253
4525
  return Array.from(this._internalOf(id));
4254
4526
  }
4255
4527
  /**
@@ -4257,14 +4529,14 @@ class LikeC4Model {
4257
4529
  * (from closest to root)
4258
4530
  */
4259
4531
  ascendingSiblings(element) {
4260
- const id = t(element) ? element : element.id;
4261
- let siblings = this.#cacheAscendingSiblings.get(id);
4532
+ const id = getId(element);
4533
+ let siblings = this._cacheAscendingSiblings.get(id);
4262
4534
  if (!siblings) {
4263
4535
  siblings = [
4264
4536
  ...this.siblings(id),
4265
4537
  ...this.ancestors(id).flatMap((a) => this.siblings(a.id))
4266
4538
  ];
4267
- this.#cacheAscendingSiblings.set(id, siblings);
4539
+ this._cacheAscendingSiblings.set(id, siblings);
4268
4540
  }
4269
4541
  return siblings.slice();
4270
4542
  }
@@ -4272,29 +4544,29 @@ class LikeC4Model {
4272
4544
  * Resolve all views that contain the element
4273
4545
  */
4274
4546
  viewsWithElement(element) {
4275
- const id = t(element) ? element : element.id;
4276
- return [...this.#views.values()].filter((v) => v.hasElement(id));
4547
+ const id = getId(element);
4548
+ return [...this._views.values()].filter((v) => v.hasElement(id));
4277
4549
  }
4278
4550
  addElement(parsed) {
4279
- if (this.#elements.has(parsed.id)) {
4551
+ if (this._elements.has(parsed.id)) {
4280
4552
  throw new Error(`Element ${parsed.id} already exists`);
4281
4553
  }
4282
- const el = new LikeC4Model.Element(parsed, this);
4283
- this.#elements.set(el.id, el);
4554
+ const el = new LikeC4Model.ElementModel(parsed, this);
4555
+ this._elements.set(el.id, el);
4284
4556
  const parentId = parentFqn(el.id);
4285
4557
  if (parentId) {
4286
- this.#parents.set(el.id, this.element(parentId));
4558
+ this._parents.set(el.id, this.element(parentId));
4287
4559
  this._childrenOf(parentId).push(el);
4288
4560
  } else {
4289
- this.#rootElements.add(el);
4561
+ this._rootElements.add(el);
4290
4562
  }
4291
4563
  }
4292
4564
  addRelation(relation) {
4293
- if (this.#relations.has(relation.id)) {
4565
+ if (this._relations.has(relation.id)) {
4294
4566
  throw new Error(`Relation ${relation.id} already exists`);
4295
4567
  }
4296
4568
  const rel = new LikeC4Model.Relationship(relation, this);
4297
- this.#relations.set(rel.id, rel);
4569
+ this._relations.set(rel.id, rel);
4298
4570
  this._incomingTo(relation.target).add(rel);
4299
4571
  this._outgoingFrom(relation.source).add(rel);
4300
4572
  const relParent = commonAncestor(relation.source, relation.target);
@@ -4317,40 +4589,85 @@ class LikeC4Model {
4317
4589
  }
4318
4590
  }
4319
4591
  _childrenOf(id) {
4320
- let children = this.#children.get(id);
4592
+ let children = this._children.get(id);
4321
4593
  if (!children) {
4322
4594
  children = [];
4323
- this.#children.set(id, children);
4595
+ this._children.set(id, children);
4324
4596
  }
4325
4597
  return children;
4326
4598
  }
4327
4599
  _incomingTo(id) {
4328
- let incoming = this.#incoming.get(id);
4600
+ let incoming = this._incoming.get(id);
4329
4601
  if (!incoming) {
4330
- incoming = new RelationsSet();
4331
- this.#incoming.set(id, incoming);
4602
+ incoming = /* @__PURE__ */ new Set();
4603
+ this._incoming.set(id, incoming);
4332
4604
  }
4333
4605
  return incoming;
4334
4606
  }
4335
4607
  _outgoingFrom(id) {
4336
- let outgoing = this.#outgoing.get(id);
4608
+ let outgoing = this._outgoing.get(id);
4337
4609
  if (!outgoing) {
4338
- outgoing = new RelationsSet();
4339
- this.#outgoing.set(id, outgoing);
4610
+ outgoing = /* @__PURE__ */ new Set();
4611
+ this._outgoing.set(id, outgoing);
4340
4612
  }
4341
4613
  return outgoing;
4342
4614
  }
4343
4615
  _internalOf(id) {
4344
- let internal = this.#internal.get(id);
4616
+ let internal = this._internal.get(id);
4345
4617
  if (!internal) {
4346
- internal = new RelationsSet();
4347
- this.#internal.set(id, internal);
4618
+ internal = /* @__PURE__ */ new Set();
4619
+ this._internal.set(id, internal);
4348
4620
  }
4349
4621
  return internal;
4350
4622
  }
4351
4623
  }
4352
4624
  ((LikeC4Model2) => {
4353
- class Element {
4625
+ function isModel(model) {
4626
+ return model instanceof LikeC4Model2;
4627
+ }
4628
+ LikeC4Model2.isModel = isModel;
4629
+ ((ViewModel2) => {
4630
+ function isLayouted2(model) {
4631
+ return model instanceof LikeC4DiagramModel;
4632
+ }
4633
+ ViewModel2.isLayouted = isLayouted2;
4634
+ })(LikeC4Model2.ViewModel || (LikeC4Model2.ViewModel = {}));
4635
+ function isLayouted(model) {
4636
+ return model.type === "layouted";
4637
+ }
4638
+ LikeC4Model2.isLayouted = isLayouted;
4639
+ class Relationship {
4640
+ constructor(relationship, model) {
4641
+ this.relationship = relationship;
4642
+ this.model = model;
4643
+ }
4644
+ get id() {
4645
+ return this.relationship.id;
4646
+ }
4647
+ get title() {
4648
+ return this.relationship.title;
4649
+ }
4650
+ get kind() {
4651
+ return this.relationship.kind ?? null;
4652
+ }
4653
+ get tags() {
4654
+ return this.relationship.tags ?? [];
4655
+ }
4656
+ get source() {
4657
+ return this.model.element(this.relationship.source);
4658
+ }
4659
+ get target() {
4660
+ return this.model.element(this.relationship.target);
4661
+ }
4662
+ metadata(key, defaultValue) {
4663
+ return this.relationship.metadata?.[key] ?? defaultValue;
4664
+ }
4665
+ hasMetadata(key) {
4666
+ return n(this.relationship.metadata?.[key]);
4667
+ }
4668
+ }
4669
+ LikeC4Model2.Relationship = Relationship;
4670
+ class ElementModel {
4354
4671
  constructor(element, model) {
4355
4672
  this.element = element;
4356
4673
  this.model = model;
@@ -4425,46 +4742,21 @@ class LikeC4Model {
4425
4742
  // return
4426
4743
  // }
4427
4744
  }
4428
- LikeC4Model2.Element = Element;
4429
- class Relationship {
4430
- constructor(relationship, model) {
4431
- this.relationship = relationship;
4432
- this.model = model;
4433
- }
4434
- get id() {
4435
- return this.relationship.id;
4436
- }
4437
- get title() {
4438
- return this.relationship.title;
4439
- }
4440
- get kind() {
4441
- return this.relationship.kind ?? null;
4442
- }
4443
- get tags() {
4444
- return this.relationship.tags ?? [];
4445
- }
4446
- get source() {
4447
- return this.model.element(this.relationship.source);
4448
- }
4449
- get target() {
4450
- return this.model.element(this.relationship.target);
4451
- }
4452
- metadata(key, defaultValue) {
4453
- return this.relationship.metadata?.[key] ?? defaultValue;
4454
- }
4455
- hasMetadata(key) {
4456
- return n(this.relationship.metadata?.[key]);
4457
- }
4458
- }
4459
- LikeC4Model2.Relationship = Relationship;
4745
+ LikeC4Model2.ElementModel = ElementModel;
4460
4746
  })(LikeC4Model || (LikeC4Model = {}));
4461
4747
 
4462
4748
  const DELAY = "LIKEC4_DELAY";
4463
- function delay(ms = 100) {
4749
+ function delay(...args) {
4750
+ let ms = 100;
4751
+ if (args.length === 2) {
4752
+ ms = o(args[0], args[1]);
4753
+ } else if (args.length === 1) {
4754
+ ms = args[0];
4755
+ }
4464
4756
  return new Promise((resolve) => {
4465
4757
  setTimeout(() => {
4466
4758
  resolve(DELAY);
4467
- }, ms);
4759
+ }, ms ?? 100);
4468
4760
  });
4469
4761
  }
4470
4762
 
@@ -4488,4 +4780,4 @@ const compareRelations = (a, b) => {
4488
4780
  return compareFqnHierarchically(a.target, b.target);
4489
4781
  };
4490
4782
 
4491
- export { DefaultElementShape, DefaultThemeColor, ElementColors, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i as hasAtLeast, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };
4783
+ export { DefaultElementShape, DefaultRelationshipColor, DefaultThemeColor, ElementColors, LikeC4DiagramModel, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i as hasAtLeast, isAncestor, isDescendantOf, isNonEmptyArray, isSameHierarchy, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };