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