@likec4/core 1.10.1 → 1.11.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.D78YmZ_A.cjs');
4
4
 
5
5
  const { min: min$4, max: max$4 } = Math;
6
6
 
@@ -3656,14 +3656,256 @@ 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
  }
@@ -3861,16 +4103,16 @@ class LikeC4ViewModel {
3861
4103
  this.model = model;
3862
4104
  for (const node of view.nodes) {
3863
4105
  const el = new LikeC4ViewModel.Element(node, this);
3864
- this.#elements.set(node.id, el);
4106
+ this._elements.set(node.id, el);
3865
4107
  if (types_index.e(node.parent)) {
3866
- this.#rootElements.add(el);
4108
+ this._rootElements.add(el);
3867
4109
  }
3868
4110
  }
3869
- this.#connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
4111
+ this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
3870
4112
  }
3871
- #rootElements = /* @__PURE__ */ new Set();
3872
- #elements = /* @__PURE__ */ new Map();
3873
- #connections;
4113
+ _rootElements = /* @__PURE__ */ new Set();
4114
+ _elements = /* @__PURE__ */ new Map();
4115
+ _connections;
3874
4116
  get id() {
3875
4117
  return this.view.id;
3876
4118
  }
@@ -3887,41 +4129,41 @@ class LikeC4ViewModel {
3887
4129
  return this.view.tags ?? [];
3888
4130
  }
3889
4131
  roots() {
3890
- return [...this.#rootElements];
4132
+ return [...this._rootElements];
3891
4133
  }
3892
4134
  elements() {
3893
- return [...this.#elements.values()];
4135
+ return [...this._elements.values()];
3894
4136
  }
3895
4137
  element(id) {
3896
- return types_index.nonNullable(this.#elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.view.id} not found`);
4138
+ return types_index.nonNullable(this._elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.id} not found`);
3897
4139
  }
3898
4140
  hasElement(id) {
3899
- return this.#elements.has(id);
4141
+ return this._elements.has(id);
3900
4142
  }
3901
4143
  connections() {
3902
- return [...this.#connections.values()];
4144
+ return [...this._connections.values()];
3903
4145
  }
3904
4146
  connection(id) {
3905
- return types_index.nonNullable(this.#connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
4147
+ return types_index.nonNullable(this._connections.get(id), `Connection ${id} in view ${this.id} not found`);
3906
4148
  }
3907
4149
  findConnections(source, target, direction = "direct") {
3908
- const sourceId = t(source) ? source : source.id;
3909
- const targetId = t(target) ? target : target.id;
4150
+ const sourceId = getId(source);
4151
+ const targetId = getId(target);
3910
4152
  return this.connections().filter(
3911
4153
  (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
3912
4154
  );
3913
4155
  }
3914
4156
  parent(element) {
3915
- const el = this.element(t(element) ? element : element.id);
4157
+ const el = this.element(getId(element));
3916
4158
  return el.node.parent ? this.element(el.node.parent) : null;
3917
4159
  }
3918
4160
  children(element) {
3919
- const el = this.element(t(element) ? element : element.id);
4161
+ const el = this.element(getId(element));
3920
4162
  return el.node.children.map((c) => this.element(c));
3921
4163
  }
3922
4164
  // Get all sibling (i.e. same parent)
3923
4165
  siblings(element) {
3924
- const id = t(element) ? element : element.id;
4166
+ const id = getId(element);
3925
4167
  const parent = this.parent(id);
3926
4168
  const siblings = parent ? this.children(parent) : this.roots();
3927
4169
  return siblings.filter((e) => e.id !== id);
@@ -3931,7 +4173,7 @@ class LikeC4ViewModel {
3931
4173
  * (from closest to root)
3932
4174
  */
3933
4175
  ancestors(element) {
3934
- let id = t(element) ? element : element.id;
4176
+ let id = getId(element);
3935
4177
  const result = [];
3936
4178
  let parent;
3937
4179
  while (parent = this.parent(id)) {
@@ -3945,8 +4187,8 @@ class LikeC4ViewModel {
3945
4187
  return children.flatMap((c) => [c, ...this.descendants(c.id)]);
3946
4188
  }
3947
4189
  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`));
4190
+ const el = this.element(getId(element));
4191
+ const edges = el.node.inEdges.map((e) => types_index.nonNullable(this._connections.get(e), `Edge ${e} not found`));
3950
4192
  if (filter === "all" || edges.length === 0) {
3951
4193
  return edges;
3952
4194
  }
@@ -3964,8 +4206,8 @@ class LikeC4ViewModel {
3964
4206
  * Outgoing relationships from the element and its descendants
3965
4207
  */
3966
4208
  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`));
4209
+ const el = this.element(getId(element));
4210
+ const edges = el.node.outEdges.map((e) => types_index.nonNullable(this._connections.get(e), `Edge ${e} not found`));
3969
4211
  if (filter === "all" || edges.length === 0) {
3970
4212
  return edges;
3971
4213
  }
@@ -4078,103 +4320,126 @@ class LikeC4ViewModel {
4078
4320
  LikeC4ViewModel2.Connection = Connection;
4079
4321
  })(LikeC4ViewModel || (LikeC4ViewModel = {}));
4080
4322
 
4081
- const RelationsSet = Set;
4082
- const MapRelations = Map;
4083
4323
  class LikeC4Model {
4084
- constructor(computed) {
4085
- this.computed = computed;
4086
- for (const el of r$1(computed.elements)) {
4324
+ constructor(type, sourcemodel, elements, relations) {
4325
+ this.type = type;
4326
+ this.sourcemodel = sourcemodel;
4327
+ for (const el of elements) {
4087
4328
  this.addElement(el);
4088
4329
  }
4089
- for (const rel of r$1(computed.relations)) {
4330
+ for (const rel of relations) {
4090
4331
  this.addRelation(rel);
4091
4332
  }
4092
- this.#views = new Map(
4093
- r$1(computed.views).map((v) => [v.id, new LikeC4ViewModel(v, this)])
4094
- );
4095
4333
  }
4096
- #elements = /* @__PURE__ */ new Map();
4334
+ _elements = /* @__PURE__ */ new Map();
4097
4335
  // Parent element for given FQN
4098
- #parents = /* @__PURE__ */ new Map();
4336
+ _parents = /* @__PURE__ */ new Map();
4099
4337
  // Children elements for given FQN
4100
- #children = /* @__PURE__ */ new Map();
4101
- #rootElements = /* @__PURE__ */ new Set();
4102
- #relations = /* @__PURE__ */ new Map();
4338
+ _children = /* @__PURE__ */ new Map();
4339
+ _rootElements = /* @__PURE__ */ new Set();
4340
+ _relations = /* @__PURE__ */ new Map();
4103
4341
  // Incoming to an element or its descendants
4104
- #incoming = new MapRelations();
4342
+ _incoming = /* @__PURE__ */ new Map();
4105
4343
  // Outgoing from an element or its descendants
4106
- #outgoing = new MapRelations();
4344
+ _outgoing = /* @__PURE__ */ new Map();
4107
4345
  // 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);
4346
+ _internal = /* @__PURE__ */ new Map();
4347
+ _cacheAscendingSiblings = /* @__PURE__ */ new Map();
4348
+ _views = /* @__PURE__ */ new Map();
4349
+ static create(source) {
4350
+ if (source.__ === "layouted") {
4351
+ return LikeC4Model.layouted(source);
4352
+ }
4353
+ return LikeC4Model.computed(source);
4354
+ }
4355
+ static computed(source) {
4356
+ const instance = new LikeC4Model(
4357
+ "computed",
4358
+ source,
4359
+ r$1(source.elements),
4360
+ r$1(source.relations)
4361
+ );
4362
+ for (const view of r$1(source.views)) {
4363
+ instance._views.set(view.id, new LikeC4ViewModel(view, instance));
4364
+ }
4365
+ return instance;
4366
+ }
4367
+ static layouted(source) {
4368
+ const instance = new LikeC4Model(
4369
+ "layouted",
4370
+ source,
4371
+ r$1(source.elements),
4372
+ r$1(source.relations)
4373
+ );
4374
+ for (const view of r$1(source.views)) {
4375
+ instance._views.set(view.id, new LikeC4DiagramModel(view, instance));
4376
+ }
4377
+ return instance;
4113
4378
  }
4114
4379
  /**
4115
4380
  * Returns the root elements of the model.
4116
4381
  */
4117
4382
  roots() {
4118
- return [...this.#rootElements];
4383
+ return [...this._rootElements];
4119
4384
  }
4120
4385
  /**
4121
4386
  * Returns all elements in the model.
4122
4387
  */
4123
4388
  elements() {
4124
- return [...this.#elements.values()];
4389
+ return [...this._elements.values()];
4125
4390
  }
4126
4391
  /**
4127
4392
  * Returns a specific element by its FQN.
4128
4393
  */
4129
4394
  element(id) {
4130
- return types_index.nonNullable(this.#elements.get(id), `Element ${id} not found`);
4395
+ return types_index.nonNullable(this._elements.get(id), `Element ${id} not found`);
4131
4396
  }
4132
4397
  /**
4133
4398
  * Returns all relationships in the model.
4134
4399
  */
4135
4400
  relationships() {
4136
- return [...this.#relations.values()];
4401
+ return [...this._relations.values()];
4137
4402
  }
4138
4403
  /**
4139
4404
  * Returns a specific relationship by its ID.
4140
4405
  */
4141
4406
  relationship(id) {
4142
- return types_index.nonNullable(this.#relations.get(id), `Relation ${id} not found`);
4407
+ return types_index.nonNullable(this._relations.get(id), `Relation ${id} not found`);
4143
4408
  }
4144
4409
  /**
4145
4410
  * Returns all views in the model.
4146
4411
  */
4147
4412
  views() {
4148
- return [...this.#views.values()];
4413
+ return [...this._views.values()];
4149
4414
  }
4150
4415
  /**
4151
4416
  * Returns a specific view by its ID.
4152
4417
  */
4153
4418
  view(viewId) {
4154
- return types_index.nonNullable(this.#views.get(viewId), `View ${viewId} not found`);
4419
+ return types_index.nonNullable(this._views.get(viewId), `View ${viewId} not found`);
4155
4420
  }
4156
4421
  /**
4157
4422
  * Returns the parent element of given element.
4158
4423
  * @see ancestors
4159
4424
  */
4160
4425
  parent(element) {
4161
- const id = t(element) ? element : element.id;
4162
- return this.#parents.get(id) || null;
4426
+ const id = getId(element);
4427
+ return this._parents.get(id) || null;
4163
4428
  }
4164
4429
  /**
4165
4430
  * Get all children of the element (only direct children),
4166
4431
  * @see descendants
4167
4432
  */
4168
4433
  children(element) {
4169
- const id = t(element) ? element : element.id;
4434
+ const id = getId(element);
4170
4435
  return this._childrenOf(id);
4171
4436
  }
4172
4437
  /**
4173
4438
  * Get all sibling (i.e. same parent)
4174
4439
  */
4175
4440
  siblings(element) {
4176
- const id = t(element) ? element : element.id;
4177
- const parent = this.#parents.get(id);
4441
+ const id = getId(element);
4442
+ const parent = this._parents.get(id);
4178
4443
  const siblings = parent ? this._childrenOf(parent.id) : this.roots();
4179
4444
  return siblings.filter((e) => e.id !== id);
4180
4445
  }
@@ -4186,7 +4451,7 @@ class LikeC4Model {
4186
4451
  let id = t(element) ? element : element.id;
4187
4452
  const result = [];
4188
4453
  let parent;
4189
- while (parent = this.#parents.get(id)) {
4454
+ while (parent = this._parents.get(id)) {
4190
4455
  result.push(parent);
4191
4456
  id = parent.id;
4192
4457
  }
@@ -4196,7 +4461,7 @@ class LikeC4Model {
4196
4461
  * Get all descendant elements (i.e. children, children’s children, etc.)
4197
4462
  */
4198
4463
  descendants(element) {
4199
- const id = t(element) ? element : element.id;
4464
+ const id = getId(element);
4200
4465
  const children = this._childrenOf(id);
4201
4466
  return children.flatMap((c) => [c, ...this.descendants(c.id)]);
4202
4467
  }
@@ -4205,7 +4470,7 @@ class LikeC4Model {
4205
4470
  * @see incomers
4206
4471
  */
4207
4472
  incoming(element, filter = "all") {
4208
- const id = t(element) ? element : element.id;
4473
+ const id = getId(element);
4209
4474
  const incoming = Array.from(this._incomingTo(id));
4210
4475
  if (filter === "all" || incoming.length === 0) {
4211
4476
  return incoming;
@@ -4228,7 +4493,7 @@ class LikeC4Model {
4228
4493
  * @see outgoers
4229
4494
  */
4230
4495
  outgoing(element, filter = "all") {
4231
- const id = t(element) ? element : element.id;
4496
+ const id = getId(element);
4232
4497
  const outgoing = Array.from(this._outgoingFrom(id));
4233
4498
  if (filter === "all" || outgoing.length === 0) {
4234
4499
  return outgoing;
@@ -4250,7 +4515,7 @@ class LikeC4Model {
4250
4515
  * Relationships inside the element, among descendants
4251
4516
  */
4252
4517
  internal(element) {
4253
- const id = t(element) ? element : element.id;
4518
+ const id = getId(element);
4254
4519
  return Array.from(this._internalOf(id));
4255
4520
  }
4256
4521
  /**
@@ -4258,14 +4523,14 @@ class LikeC4Model {
4258
4523
  * (from closest to root)
4259
4524
  */
4260
4525
  ascendingSiblings(element) {
4261
- const id = t(element) ? element : element.id;
4262
- let siblings = this.#cacheAscendingSiblings.get(id);
4526
+ const id = getId(element);
4527
+ let siblings = this._cacheAscendingSiblings.get(id);
4263
4528
  if (!siblings) {
4264
4529
  siblings = [
4265
4530
  ...this.siblings(id),
4266
4531
  ...this.ancestors(id).flatMap((a) => this.siblings(a.id))
4267
4532
  ];
4268
- this.#cacheAscendingSiblings.set(id, siblings);
4533
+ this._cacheAscendingSiblings.set(id, siblings);
4269
4534
  }
4270
4535
  return siblings.slice();
4271
4536
  }
@@ -4273,29 +4538,29 @@ class LikeC4Model {
4273
4538
  * Resolve all views that contain the element
4274
4539
  */
4275
4540
  viewsWithElement(element) {
4276
- const id = t(element) ? element : element.id;
4277
- return [...this.#views.values()].filter((v) => v.hasElement(id));
4541
+ const id = getId(element);
4542
+ return [...this._views.values()].filter((v) => v.hasElement(id));
4278
4543
  }
4279
4544
  addElement(parsed) {
4280
- if (this.#elements.has(parsed.id)) {
4545
+ if (this._elements.has(parsed.id)) {
4281
4546
  throw new Error(`Element ${parsed.id} already exists`);
4282
4547
  }
4283
- const el = new LikeC4Model.Element(parsed, this);
4284
- this.#elements.set(el.id, el);
4548
+ const el = new LikeC4Model.ElementModel(parsed, this);
4549
+ this._elements.set(el.id, el);
4285
4550
  const parentId = parentFqn(el.id);
4286
4551
  if (parentId) {
4287
- this.#parents.set(el.id, this.element(parentId));
4552
+ this._parents.set(el.id, this.element(parentId));
4288
4553
  this._childrenOf(parentId).push(el);
4289
4554
  } else {
4290
- this.#rootElements.add(el);
4555
+ this._rootElements.add(el);
4291
4556
  }
4292
4557
  }
4293
4558
  addRelation(relation) {
4294
- if (this.#relations.has(relation.id)) {
4559
+ if (this._relations.has(relation.id)) {
4295
4560
  throw new Error(`Relation ${relation.id} already exists`);
4296
4561
  }
4297
4562
  const rel = new LikeC4Model.Relationship(relation, this);
4298
- this.#relations.set(rel.id, rel);
4563
+ this._relations.set(rel.id, rel);
4299
4564
  this._incomingTo(relation.target).add(rel);
4300
4565
  this._outgoingFrom(relation.source).add(rel);
4301
4566
  const relParent = commonAncestor(relation.source, relation.target);
@@ -4318,40 +4583,85 @@ class LikeC4Model {
4318
4583
  }
4319
4584
  }
4320
4585
  _childrenOf(id) {
4321
- let children = this.#children.get(id);
4586
+ let children = this._children.get(id);
4322
4587
  if (!children) {
4323
4588
  children = [];
4324
- this.#children.set(id, children);
4589
+ this._children.set(id, children);
4325
4590
  }
4326
4591
  return children;
4327
4592
  }
4328
4593
  _incomingTo(id) {
4329
- let incoming = this.#incoming.get(id);
4594
+ let incoming = this._incoming.get(id);
4330
4595
  if (!incoming) {
4331
- incoming = new RelationsSet();
4332
- this.#incoming.set(id, incoming);
4596
+ incoming = /* @__PURE__ */ new Set();
4597
+ this._incoming.set(id, incoming);
4333
4598
  }
4334
4599
  return incoming;
4335
4600
  }
4336
4601
  _outgoingFrom(id) {
4337
- let outgoing = this.#outgoing.get(id);
4602
+ let outgoing = this._outgoing.get(id);
4338
4603
  if (!outgoing) {
4339
- outgoing = new RelationsSet();
4340
- this.#outgoing.set(id, outgoing);
4604
+ outgoing = /* @__PURE__ */ new Set();
4605
+ this._outgoing.set(id, outgoing);
4341
4606
  }
4342
4607
  return outgoing;
4343
4608
  }
4344
4609
  _internalOf(id) {
4345
- let internal = this.#internal.get(id);
4610
+ let internal = this._internal.get(id);
4346
4611
  if (!internal) {
4347
- internal = new RelationsSet();
4348
- this.#internal.set(id, internal);
4612
+ internal = /* @__PURE__ */ new Set();
4613
+ this._internal.set(id, internal);
4349
4614
  }
4350
4615
  return internal;
4351
4616
  }
4352
4617
  }
4353
4618
  ((LikeC4Model2) => {
4354
- class Element {
4619
+ function isModel(model) {
4620
+ return model instanceof LikeC4Model2;
4621
+ }
4622
+ LikeC4Model2.isModel = isModel;
4623
+ ((ViewModel2) => {
4624
+ function isLayouted2(model) {
4625
+ return model instanceof LikeC4DiagramModel;
4626
+ }
4627
+ ViewModel2.isLayouted = isLayouted2;
4628
+ })(LikeC4Model2.ViewModel || (LikeC4Model2.ViewModel = {}));
4629
+ function isLayouted(model) {
4630
+ return model.type === "layouted";
4631
+ }
4632
+ LikeC4Model2.isLayouted = isLayouted;
4633
+ class Relationship {
4634
+ constructor(relationship, model) {
4635
+ this.relationship = relationship;
4636
+ this.model = model;
4637
+ }
4638
+ get id() {
4639
+ return this.relationship.id;
4640
+ }
4641
+ get title() {
4642
+ return this.relationship.title;
4643
+ }
4644
+ get kind() {
4645
+ return this.relationship.kind ?? null;
4646
+ }
4647
+ get tags() {
4648
+ return this.relationship.tags ?? [];
4649
+ }
4650
+ get source() {
4651
+ return this.model.element(this.relationship.source);
4652
+ }
4653
+ get target() {
4654
+ return this.model.element(this.relationship.target);
4655
+ }
4656
+ metadata(key, defaultValue) {
4657
+ return this.relationship.metadata?.[key] ?? defaultValue;
4658
+ }
4659
+ hasMetadata(key) {
4660
+ return n(this.relationship.metadata?.[key]);
4661
+ }
4662
+ }
4663
+ LikeC4Model2.Relationship = Relationship;
4664
+ class ElementModel {
4355
4665
  constructor(element, model) {
4356
4666
  this.element = element;
4357
4667
  this.model = model;
@@ -4426,46 +4736,21 @@ class LikeC4Model {
4426
4736
  // return
4427
4737
  // }
4428
4738
  }
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;
4739
+ LikeC4Model2.ElementModel = ElementModel;
4461
4740
  })(LikeC4Model || (LikeC4Model = {}));
4462
4741
 
4463
4742
  const DELAY = "LIKEC4_DELAY";
4464
- function delay(ms = 100) {
4743
+ function delay(...args) {
4744
+ let ms = 100;
4745
+ if (args.length === 2) {
4746
+ ms = o(args[0], args[1]);
4747
+ } else if (args.length === 1) {
4748
+ ms = args[0];
4749
+ }
4465
4750
  return new Promise((resolve) => {
4466
4751
  setTimeout(() => {
4467
4752
  resolve(DELAY);
4468
- }, ms);
4753
+ }, ms ?? 100);
4469
4754
  });
4470
4755
  }
4471
4756
 
@@ -4542,6 +4827,7 @@ exports.nonNullable = types_index.nonNullable;
4542
4827
  exports.nonexhaustive = types_index.nonexhaustive;
4543
4828
  exports.whereOperatorAsPredicate = types_index.whereOperatorAsPredicate;
4544
4829
  exports.ElementColors = ElementColors;
4830
+ exports.LikeC4DiagramModel = LikeC4DiagramModel;
4545
4831
  exports.LikeC4Model = LikeC4Model;
4546
4832
  exports.LikeC4ViewModel = LikeC4ViewModel;
4547
4833
  exports.RelationshipColors = RelationshipColors;