@likec4/core 1.44.0 → 1.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/builder/index.d.mts +15 -13
  2. package/dist/builder/index.mjs +33 -17
  3. package/dist/compute-view/index.d.mts +8 -7
  4. package/dist/compute-view/index.mjs +7 -6
  5. package/dist/compute-view/relationships-view/index.d.mts +8 -7
  6. package/dist/compute-view/relationships-view/index.mjs +2 -2
  7. package/dist/geometry/index.d.mts +109 -0
  8. package/dist/geometry/index.mjs +328 -0
  9. package/dist/index.d.mts +29 -7
  10. package/dist/index.mjs +10 -8
  11. package/dist/model/connection/deployment/index.d.mts +10 -9
  12. package/dist/model/connection/deployment/index.mjs +2 -2
  13. package/dist/model/connection/index.d.mts +11 -10
  14. package/dist/model/connection/index.mjs +3 -3
  15. package/dist/model/connection/model/index.d.mts +10 -9
  16. package/dist/model/connection/model/index.mjs +2 -2
  17. package/dist/model/index.d.mts +13 -26
  18. package/dist/model/index.mjs +4 -4
  19. package/dist/shared/{core.Bv3cd-jC.mjs → core.3ZhnKAlZ.mjs} +9 -5
  20. package/dist/shared/{core.CKNmSm2W.d.mts → core.5gPDaaG5.d.mts} +9 -15
  21. package/dist/shared/{core.BnOetIAR.d.mts → core.9U0HL3oG.d.mts} +3 -3
  22. package/dist/shared/{core.M9ayqQZa.mjs → core.BK-tI3Q3.mjs} +2 -3
  23. package/dist/shared/{core.DjAM-S6a.d.mts → core.BLG-ADpi.d.mts} +16 -14
  24. package/dist/shared/core.BPGOjone.d.mts +46 -0
  25. package/dist/shared/{core.DIE3F6sw.mjs → core.BYdtmqY5.mjs} +1 -2
  26. package/dist/shared/core.BhNcrwzK.mjs +7 -0
  27. package/dist/shared/{core.CDOKQTW6.d.mts → core.BkSYCfRg.d.mts} +2 -2
  28. package/dist/shared/core.BkVA6gjl.mjs +5 -0
  29. package/dist/shared/{core.5ZQ-r3Oa.d.mts → core.BqtAzeAh.d.mts} +1 -1
  30. package/dist/shared/{core.DEieYfbG.mjs → core.BspBF3SJ.mjs} +22 -70
  31. package/dist/shared/{core.BnDbAOR2.d.mts → core.Byj60hH6.d.mts} +3 -3
  32. package/dist/shared/{core.CR3PmPzr.mjs → core.CBLX4mT8.mjs} +3811 -15032
  33. package/dist/shared/{core.DX-WYEPA.d.mts → core.CDdf8izT.d.mts} +4 -2
  34. package/dist/shared/core.CLSZtnFh.mjs +69 -0
  35. package/dist/shared/{core.bKIs4oDO.mjs → core.CQPEY2wQ.mjs} +5 -4
  36. package/dist/shared/{core.WwMWeiFL.d.mts → core.CQYL_Z-_.d.mts} +3 -3
  37. package/dist/shared/{core.6VsRBhGY.mjs → core.CdNCAwq7.mjs} +1 -1
  38. package/dist/shared/{core.DrUt0Lbi.mjs → core.CmGY9blO.mjs} +198 -291
  39. package/dist/shared/core.Coi_LOUZ.mjs +7 -0
  40. package/dist/shared/{core.C_Ni6yHl.mjs → core.D0WZutNd.mjs} +3 -1
  41. package/dist/shared/{core.DTJYgLXI.d.mts → core.D4Y4U8Lp.d.mts} +3 -3
  42. package/dist/shared/{core.BMtVqKl7.d.mts → core.DE-g9oFF.d.mts} +22 -46
  43. package/dist/shared/{core.23WeDKcI.mjs → core.DJpiszim.mjs} +265 -233
  44. package/dist/shared/{core.h4TqqSC0.mjs → core.DU8pv3Q6.mjs} +71 -1174
  45. package/dist/shared/{core.CHwVhuc9.mjs → core.DbQpDoJS.mjs} +12 -15
  46. package/dist/shared/{core.CbsSAn1j.mjs → core.DbfO90vF.mjs} +1 -12
  47. package/dist/shared/{core.C0Ye2OCr.mjs → core.DqlrMlsf.mjs} +1 -1
  48. package/dist/shared/core.Qv7vZIwZ.mjs +1282 -0
  49. package/dist/shared/core.oSV6SRfk.mjs +13 -0
  50. package/dist/shared/{core.BuQZczj6.mjs → core.om36dXXW.mjs} +5 -2
  51. package/dist/shared/{core.8mmHFn9g.d.mts → core.or6-EHsb.d.mts} +2 -2
  52. package/dist/shared/{core.DFCHU59b.mjs → core.xeuDd__E.mjs} +3 -4
  53. package/dist/styles/index.d.mts +7 -6
  54. package/dist/styles/index.mjs +4 -4
  55. package/dist/types/_aux.d.mts +2 -2
  56. package/dist/types/expression-model.d.mts +3 -3
  57. package/dist/types/expression.d.mts +3 -3
  58. package/dist/types/fqnRef.d.mts +2 -2
  59. package/dist/types/fqnRef.mjs +1 -1
  60. package/dist/types/index.d.mts +11 -9
  61. package/dist/types/index.mjs +6 -166
  62. package/dist/types/scalar.d.mts +1 -1
  63. package/dist/types/scalar.mjs +1 -1
  64. package/dist/utils/graphology/index.mjs +1 -1
  65. package/dist/utils/index.d.mts +3 -3
  66. package/dist/utils/index.mjs +9 -8
  67. package/dist/utils/iterable/index.d.mts +17 -1
  68. package/dist/utils/iterable/index.mjs +17 -1
  69. package/geometry/package.json +4 -0
  70. package/package.json +20 -12
  71. package/dist/shared/core.B9BjmjuH.mjs +0 -9
  72. package/dist/shared/core.BR4zXDH-.mjs +0 -13
  73. package/dist/shared/core.BdPcbSkN.mjs +0 -118
  74. package/dist/shared/core.OHD4KXm9.mjs +0 -5
@@ -1,49 +1,36 @@
1
- import { n as n$6, t as t$b, e as e$4, a as DeploymentNodeModel, b as DeployedInstanceModel, c as DeploymentRelationModel, N as NestedElementOfDeployedInstanceModel } from './core.CHwVhuc9.mjs';
2
- import { e as e$3 } from './core.BKlholso.mjs';
3
- import { c as splitGlobalFqn, g as extractStep, e as isStepEdgeId, i as isGroupElementKind, b as isGlobalFqn, a as GlobalFqn } from './core.C_Ni6yHl.mjs';
4
- import { m as hierarchyLevel, n as nameFromFqn, i as isAncestor, g as commonAncestor, s as sortNaturalByFqn, f as sortParentsFirst, p as parentFqn, a as ancestorsFqn } from './core.6VsRBhGY.mjs';
5
- import { m as memoizeProp } from './core.BR4zXDH-.mjs';
6
- import { R as RichText, e as exact } from './core.M9ayqQZa.mjs';
1
+ import { t as t$3, e as e$3, a as DeploymentNodeModel, b as DeployedInstanceModel, c as DeploymentRelationModel, N as NestedElementOfDeployedInstanceModel } from './core.DbQpDoJS.mjs';
2
+ import { e as e$2 } from './core.BKlholso.mjs';
3
+ import { n as n$1 } from './core.BhNcrwzK.mjs';
4
+ import { c as splitGlobalFqn, h as extractStep, g as isStepEdgeId, i as isGroupElementKind, b as isGlobalFqn, a as GlobalFqn } from './core.D0WZutNd.mjs';
5
+ import { m as hierarchyLevel, n as nameFromFqn, i as isAncestor, g as commonAncestor, s as sortNaturalByFqn, f as sortParentsFirst, p as parentFqn, a as ancestorsFqn } from './core.CdNCAwq7.mjs';
6
+ import { m as memoizeProp } from './core.CLSZtnFh.mjs';
7
+ import { R as RichText, e as exact } from './core.BK-tI3Q3.mjs';
7
8
  import { preferSummary, preferDescription } from '../types/_aux.mjs';
8
9
  import { i as ihead } from './core.uFk_o9X6.mjs';
9
- import { a as t$9, t as t$a } from './core.OHD4KXm9.mjs';
10
- import { t as t$8, a as t$c } from './core.BsSXS-_R.mjs';
11
- import { e as e$5, t as t$d, a as t$g } from './core.B9BjmjuH.mjs';
12
- import { t as t$e } from './core.CbT8JVYL.mjs';
13
- import { a as t$f, L as LikeC4Styles } from './core.DEieYfbG.mjs';
10
+ import { t as t$6, b as compareNaturalHierarchically, c as compareNatural } from './core.3ZhnKAlZ.mjs';
11
+ import { t as t$2, a as t$4 } from './core.BsSXS-_R.mjs';
12
+ import { t as t$5, e as e$4 } from './core.Coi_LOUZ.mjs';
13
+ import { t as t$8 } from './core.CbT8JVYL.mjs';
14
+ import { t as t$7 } from './core.BkVA6gjl.mjs';
15
+ import { c as calcDriftsFromSnapshot, a as applyManualLayout, h as t$9 } from './core.Qv7vZIwZ.mjs';
16
+ import { L as LikeC4Styles } from './core.BspBF3SJ.mjs';
14
17
  import { g as getOrCreate } from './core.DcS-0zys.mjs';
15
18
  import { D as DefaultMap } from './core.BbE4y-yl.mjs';
16
19
  import { i as invariant, a as nonNullable } from './core.D4npX2q8.mjs';
17
20
  import { FqnRef } from '../types/fqnRef.mjs';
18
- import { c as isDeploymentNode, b as _layout, u as e$6, t as isDynamicView, a as _type, _ as _stage, i as isOnStage, w as whereOperatorAsPredicate } from './core.DH7TXqXf.mjs';
19
- import { s as symmetricDifference } from './core.CbsSAn1j.mjs';
21
+ import { c as isDeploymentNode, a as _type, _ as _stage, i as isOnStage, w as whereOperatorAsPredicate } from './core.DH7TXqXf.mjs';
20
22
  import { i as ifind } from './core.CmPXpJ8l.mjs';
21
23
  import { i as ifilter } from './core.DRJma0Ol.mjs';
22
- import { a as compareNaturalHierarchically, c as compareNatural } from './core.Bv3cd-jC.mjs';
23
- import './core.C0Ye2OCr.mjs';
24
- import './core.bKIs4oDO.mjs';
24
+ import './core.DqlrMlsf.mjs';
25
+ import './core.CQPEY2wQ.mjs';
25
26
 
26
- const e$2={asc:(e,t)=>e>t,desc:(e,t)=>e<t};function t$7(e,t){let[n,...a]=t;if(!i$1(n)){let t=r$2(...a);return e(n,t)}let o=r$2(n,...a);return t=>e(t,o)}function r$2(t,n,...i){let a=typeof t==`function`?t:t[0],o=typeof t==`function`?`asc`:t[1],{[o]:s}=e$2,c=n===void 0?void 0:r$2(n,...i);return (e,t)=>{let n=a(e),r=a(t);return s(n,r)?1:s(r,n)?-1:c?.(e,t)??0}}function i$1(t){if(a(t))return true;if(typeof t!=`object`||!Array.isArray(t))return false;let[n,r,...i]=t;return a(n)&&typeof r==`string`&&r in e$2&&i.length===0}const a=e=>typeof e==`function`&&e.length===1;
27
+ function e$1(e){if(e==null||e===``)return true;if(typeof e!=`object`)return false;if(`length`in e&&typeof e.length==`number`)return e.length===0;if(`size`in e&&typeof e.size==`number`)return e.size===0;for(let t in e)return false;return Object.getOwnPropertySymbols(e).length===0}
27
28
 
28
- function n$5(...t){return t$8(r$1,t,i)}const r$1=(e,t)=>e.filter(t),i=e=>(n,r,i)=>e(n,r,i)?{done:false,hasNext:true,next:n}:t$9;
29
-
30
- function t$6(...t){return t$8(n$4,t,r)}const n$4=(e,t)=>e.flatMap(t),r=e=>(t,n,r)=>{let i=e(t,n,r);return Array.isArray(i)?{done:false,hasNext:true,hasMany:true,next:i}:{done:false,hasNext:true,next:i}};
31
-
32
- function t$5(...t){return t$8(n$3,t)}const n$3=(e,t)=>{let n=Object.create(null);for(let r=0;r<e.length;r++){let i=e[r],a=t(i,r,e);if(a!==void 0){let e=n[a];e===void 0?n[a]=[i]:e.push(i);}}return Object.setPrototypeOf(n,Object.prototype),n};
33
-
34
- function e$1(e){return typeof e==`number`&&!Number.isNaN(e)}
35
-
36
- function t$4(...t){return t$8(n$2,t)}const n$2=e=>e.at(-1);
37
-
38
- function t$3(...t){return t$8(n$1,t)}function n$1(e,t){let n={};for(let[r,i]of Object.entries(e))n[r]=t(i,r,e);return n}
39
-
40
- function t$2(...t){return n=>t$a(n,...t)}
41
-
42
- function t$1(...t){return t$7(n,t)}const n=(e,t)=>[...e].sort(t);
29
+ function t$1(...t){return t$2(n,t)}const n=e=>e.at(-1);
43
30
 
44
31
  function e(e,t,n){return typeof t==`number`||t===void 0?n=>n.split(e,t):e.split(t,n)}
45
32
 
46
- function t(...t){return t$8(Object.values,t)}
33
+ function t(...t){return t$2(Object.values,t)}
47
34
 
48
35
  class ElementModel {
49
36
  constructor($model, $element) {
@@ -95,7 +82,7 @@ class ElementModel {
95
82
  */
96
83
  get tags() {
97
84
  return memoizeProp(this, Symbol.for("tags"), () => {
98
- return n$6([
85
+ return n$1([
99
86
  ...this.$element.tags ?? [],
100
87
  ...this.$model.specification.elements[this.$element.kind]?.tags ?? []
101
88
  ]);
@@ -109,7 +96,7 @@ class ElementModel {
109
96
  * (if one is missing - it falls back to another)
110
97
  */
111
98
  get hasSummary() {
112
- return !!this.$element.summary && !!this.$element.description && !t$b(this.$element.summary, this.$element.description);
99
+ return !!this.$element.summary && !!this.$element.description && !t$3(this.$element.summary, this.$element.description);
113
100
  }
114
101
  /**
115
102
  * Short description of the element.
@@ -277,13 +264,13 @@ class ElementModel {
277
264
  * @returns true if the element is deployed
278
265
  */
279
266
  isDeployed() {
280
- return e$3(ihead(this.deployments()));
267
+ return e$2(ihead(this.deployments()));
281
268
  }
282
269
  deployments() {
283
270
  return this.$model.deployment.instancesOf(this);
284
271
  }
285
272
  hasMetadata() {
286
- return !!this.$element.metadata && !e$4(this.$element.metadata);
273
+ return !!this.$element.metadata && !e$3(this.$element.metadata);
287
274
  }
288
275
  getMetadata(field) {
289
276
  if (field) {
@@ -308,7 +295,7 @@ const splitViewTitle = (title) => {
308
295
  invariant(!title.includes("\n"), "View title cannot contain newlines");
309
296
  if (title.includes(VIEW_FOLDERS_SEPARATOR)) {
310
297
  const segments = title.split(VIEW_FOLDERS_SEPARATOR).map((s) => s.trim()).filter((s) => s.length > 0);
311
- if (t$c(segments, 1)) {
298
+ if (t$4(segments, 1)) {
312
299
  return segments;
313
300
  }
314
301
  return [""];
@@ -320,7 +307,7 @@ const normalizeViewPath = (title) => {
320
307
  };
321
308
  const getViewFolderPath = (title) => {
322
309
  const segments = splitViewTitle(title);
323
- if (!t$c(segments, 2)) {
310
+ if (!t$4(segments, 2)) {
324
311
  return null;
325
312
  }
326
313
  return segments.slice(0, -1).join(VIEW_FOLDERS_SEPARATOR);
@@ -662,13 +649,13 @@ class RelationshipModel {
662
649
  return `${this.source.id} -> ${this.target.id}`;
663
650
  }
664
651
  get title() {
665
- if (!e$3(this.$relationship.title)) {
652
+ if (!e$2(this.$relationship.title)) {
666
653
  return null;
667
654
  }
668
655
  return this.$relationship.title;
669
656
  }
670
657
  get technology() {
671
- if (!e$3(this.$relationship.technology)) {
658
+ if (!e$2(this.$relationship.technology)) {
672
659
  return null;
673
660
  }
674
661
  return this.$relationship.technology;
@@ -678,7 +665,7 @@ class RelationshipModel {
678
665
  * (if one is missing - it falls back to another)
679
666
  */
680
667
  get hasSummary() {
681
- return !!this.$relationship.summary && !!this.$relationship.description && !t$b(this.$relationship.summary, this.$relationship.description);
668
+ return !!this.$relationship.summary && !!this.$relationship.description && !t$3(this.$relationship.summary, this.$relationship.description);
682
669
  }
683
670
  /**
684
671
  * Short description of the relationship.
@@ -736,7 +723,7 @@ class RelationshipModel {
736
723
  return true;
737
724
  }
738
725
  hasMetadata() {
739
- return !!this.$relationship.metadata && !e$4(this.$relationship.metadata);
726
+ return !!this.$relationship.metadata && !e$3(this.$relationship.metadata);
740
727
  }
741
728
  getMetadata(field) {
742
729
  if (field) {
@@ -752,1103 +739,6 @@ class RelationshipModel {
752
739
  }
753
740
  }
754
741
 
755
- // src/utils/env.ts
756
- var NOTHING = Symbol.for("immer-nothing");
757
- var DRAFTABLE = Symbol.for("immer-draftable");
758
- var DRAFT_STATE = Symbol.for("immer-state");
759
-
760
- // src/utils/errors.ts
761
- var errors = process.env.NODE_ENV !== "production" ? [
762
- // All error codes, starting by 0:
763
- function(plugin) {
764
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
765
- },
766
- function(thing) {
767
- return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
768
- },
769
- "This object has been frozen and should not be mutated",
770
- function(data) {
771
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
772
- },
773
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
774
- "Immer forbids circular references",
775
- "The first or second argument to `produce` must be a function",
776
- "The third argument to `produce` must be a function or undefined",
777
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
778
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
779
- function(thing) {
780
- return `'current' expects a draft, got: ${thing}`;
781
- },
782
- "Object.defineProperty() cannot be used on an Immer draft",
783
- "Object.setPrototypeOf() cannot be used on an Immer draft",
784
- "Immer only supports deleting array indices",
785
- "Immer only supports setting array indices and the 'length' property",
786
- function(thing) {
787
- return `'original' expects a draft, got: ${thing}`;
788
- }
789
- // Note: if more errors are added, the errorOffset in Patches.ts should be increased
790
- // See Patches.ts for additional errors
791
- ] : [];
792
- function die(error, ...args) {
793
- if (process.env.NODE_ENV !== "production") {
794
- const e = errors[error];
795
- const msg = typeof e === "function" ? e.apply(null, args) : e;
796
- throw new Error(`[Immer] ${msg}`);
797
- }
798
- throw new Error(
799
- `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
800
- );
801
- }
802
-
803
- // src/utils/common.ts
804
- var getPrototypeOf = Object.getPrototypeOf;
805
- function isDraft(value) {
806
- return !!value && !!value[DRAFT_STATE];
807
- }
808
- function isDraftable(value) {
809
- if (!value)
810
- return false;
811
- return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
812
- }
813
- var objectCtorString = Object.prototype.constructor.toString();
814
- var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
815
- function isPlainObject(value) {
816
- if (!value || typeof value !== "object")
817
- return false;
818
- const proto = Object.getPrototypeOf(value);
819
- if (proto === null || proto === Object.prototype)
820
- return true;
821
- const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
822
- if (Ctor === Object)
823
- return true;
824
- if (typeof Ctor !== "function")
825
- return false;
826
- let ctorString = cachedCtorStrings.get(Ctor);
827
- if (ctorString === void 0) {
828
- ctorString = Function.toString.call(Ctor);
829
- cachedCtorStrings.set(Ctor, ctorString);
830
- }
831
- return ctorString === objectCtorString;
832
- }
833
- function each(obj, iter, strict = true) {
834
- if (getArchtype(obj) === 0 /* Object */) {
835
- const keys = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
836
- keys.forEach((key) => {
837
- iter(key, obj[key], obj);
838
- });
839
- } else {
840
- obj.forEach((entry, index) => iter(index, entry, obj));
841
- }
842
- }
843
- function getArchtype(thing) {
844
- const state = thing[DRAFT_STATE];
845
- return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
846
- }
847
- function has(thing, prop) {
848
- return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
849
- }
850
- function set(thing, propOrOldValue, value) {
851
- const t = getArchtype(thing);
852
- if (t === 2 /* Map */)
853
- thing.set(propOrOldValue, value);
854
- else if (t === 3 /* Set */) {
855
- thing.add(value);
856
- } else
857
- thing[propOrOldValue] = value;
858
- }
859
- function is(x, y) {
860
- if (x === y) {
861
- return x !== 0 || 1 / x === 1 / y;
862
- } else {
863
- return x !== x && y !== y;
864
- }
865
- }
866
- function isMap(target) {
867
- return target instanceof Map;
868
- }
869
- function isSet(target) {
870
- return target instanceof Set;
871
- }
872
- function latest(state) {
873
- return state.copy_ || state.base_;
874
- }
875
- function shallowCopy(base, strict) {
876
- if (isMap(base)) {
877
- return new Map(base);
878
- }
879
- if (isSet(base)) {
880
- return new Set(base);
881
- }
882
- if (Array.isArray(base))
883
- return Array.prototype.slice.call(base);
884
- const isPlain = isPlainObject(base);
885
- if (strict === true || strict === "class_only" && !isPlain) {
886
- const descriptors = Object.getOwnPropertyDescriptors(base);
887
- delete descriptors[DRAFT_STATE];
888
- let keys = Reflect.ownKeys(descriptors);
889
- for (let i = 0; i < keys.length; i++) {
890
- const key = keys[i];
891
- const desc = descriptors[key];
892
- if (desc.writable === false) {
893
- desc.writable = true;
894
- desc.configurable = true;
895
- }
896
- if (desc.get || desc.set)
897
- descriptors[key] = {
898
- configurable: true,
899
- writable: true,
900
- // could live with !!desc.set as well here...
901
- enumerable: desc.enumerable,
902
- value: base[key]
903
- };
904
- }
905
- return Object.create(getPrototypeOf(base), descriptors);
906
- } else {
907
- const proto = getPrototypeOf(base);
908
- if (proto !== null && isPlain) {
909
- return { ...base };
910
- }
911
- const obj = Object.create(proto);
912
- return Object.assign(obj, base);
913
- }
914
- }
915
- function freeze(obj, deep = false) {
916
- if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
917
- return obj;
918
- if (getArchtype(obj) > 1) {
919
- Object.defineProperties(obj, {
920
- set: dontMutateMethodOverride,
921
- add: dontMutateMethodOverride,
922
- clear: dontMutateMethodOverride,
923
- delete: dontMutateMethodOverride
924
- });
925
- }
926
- Object.freeze(obj);
927
- if (deep)
928
- Object.values(obj).forEach((value) => freeze(value, true));
929
- return obj;
930
- }
931
- function dontMutateFrozenCollections() {
932
- die(2);
933
- }
934
- var dontMutateMethodOverride = {
935
- value: dontMutateFrozenCollections
936
- };
937
- function isFrozen(obj) {
938
- if (obj === null || typeof obj !== "object")
939
- return true;
940
- return Object.isFrozen(obj);
941
- }
942
-
943
- // src/utils/plugins.ts
944
- var plugins = {};
945
- function getPlugin(pluginKey) {
946
- const plugin = plugins[pluginKey];
947
- if (!plugin) {
948
- die(0, pluginKey);
949
- }
950
- return plugin;
951
- }
952
-
953
- // src/core/scope.ts
954
- var currentScope;
955
- function getCurrentScope() {
956
- return currentScope;
957
- }
958
- function createScope(parent_, immer_) {
959
- return {
960
- drafts_: [],
961
- parent_,
962
- immer_,
963
- // Whenever the modified draft contains a draft from another scope, we
964
- // need to prevent auto-freezing so the unowned draft can be finalized.
965
- canAutoFreeze_: true,
966
- unfinalizedDrafts_: 0
967
- };
968
- }
969
- function usePatchesInScope(scope, patchListener) {
970
- if (patchListener) {
971
- getPlugin("Patches");
972
- scope.patches_ = [];
973
- scope.inversePatches_ = [];
974
- scope.patchListener_ = patchListener;
975
- }
976
- }
977
- function revokeScope(scope) {
978
- leaveScope(scope);
979
- scope.drafts_.forEach(revokeDraft);
980
- scope.drafts_ = null;
981
- }
982
- function leaveScope(scope) {
983
- if (scope === currentScope) {
984
- currentScope = scope.parent_;
985
- }
986
- }
987
- function enterScope(immer2) {
988
- return currentScope = createScope(currentScope, immer2);
989
- }
990
- function revokeDraft(draft) {
991
- const state = draft[DRAFT_STATE];
992
- if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
993
- state.revoke_();
994
- else
995
- state.revoked_ = true;
996
- }
997
-
998
- // src/core/finalize.ts
999
- function processResult(result, scope) {
1000
- scope.unfinalizedDrafts_ = scope.drafts_.length;
1001
- const baseDraft = scope.drafts_[0];
1002
- const isReplaced = result !== void 0 && result !== baseDraft;
1003
- if (isReplaced) {
1004
- if (baseDraft[DRAFT_STATE].modified_) {
1005
- revokeScope(scope);
1006
- die(4);
1007
- }
1008
- if (isDraftable(result)) {
1009
- result = finalize(scope, result);
1010
- if (!scope.parent_)
1011
- maybeFreeze(scope, result);
1012
- }
1013
- if (scope.patches_) {
1014
- getPlugin("Patches").generateReplacementPatches_(
1015
- baseDraft[DRAFT_STATE].base_,
1016
- result,
1017
- scope.patches_,
1018
- scope.inversePatches_
1019
- );
1020
- }
1021
- } else {
1022
- result = finalize(scope, baseDraft, []);
1023
- }
1024
- revokeScope(scope);
1025
- if (scope.patches_) {
1026
- scope.patchListener_(scope.patches_, scope.inversePatches_);
1027
- }
1028
- return result !== NOTHING ? result : void 0;
1029
- }
1030
- function finalize(rootScope, value, path) {
1031
- if (isFrozen(value))
1032
- return value;
1033
- const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
1034
- const state = value[DRAFT_STATE];
1035
- if (!state) {
1036
- each(
1037
- value,
1038
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path),
1039
- useStrictIteration
1040
- );
1041
- return value;
1042
- }
1043
- if (state.scope_ !== rootScope)
1044
- return value;
1045
- if (!state.modified_) {
1046
- maybeFreeze(rootScope, state.base_, true);
1047
- return state.base_;
1048
- }
1049
- if (!state.finalized_) {
1050
- state.finalized_ = true;
1051
- state.scope_.unfinalizedDrafts_--;
1052
- const result = state.copy_;
1053
- let resultEach = result;
1054
- let isSet2 = false;
1055
- if (state.type_ === 3 /* Set */) {
1056
- resultEach = new Set(result);
1057
- result.clear();
1058
- isSet2 = true;
1059
- }
1060
- each(
1061
- resultEach,
1062
- (key, childValue) => finalizeProperty(
1063
- rootScope,
1064
- state,
1065
- result,
1066
- key,
1067
- childValue,
1068
- path,
1069
- isSet2
1070
- ),
1071
- useStrictIteration
1072
- );
1073
- maybeFreeze(rootScope, result, false);
1074
- if (path && rootScope.patches_) {
1075
- getPlugin("Patches").generatePatches_(
1076
- state,
1077
- path,
1078
- rootScope.patches_,
1079
- rootScope.inversePatches_
1080
- );
1081
- }
1082
- }
1083
- return state.copy_;
1084
- }
1085
- function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
1086
- if (childValue == null) {
1087
- return;
1088
- }
1089
- if (typeof childValue !== "object" && !targetIsSet) {
1090
- return;
1091
- }
1092
- const childIsFrozen = isFrozen(childValue);
1093
- if (childIsFrozen && !targetIsSet) {
1094
- return;
1095
- }
1096
- if (process.env.NODE_ENV !== "production" && childValue === targetObject)
1097
- die(5);
1098
- if (isDraft(childValue)) {
1099
- const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.
1100
- !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
1101
- const res = finalize(rootScope, childValue, path);
1102
- set(targetObject, prop, res);
1103
- if (isDraft(res)) {
1104
- rootScope.canAutoFreeze_ = false;
1105
- } else
1106
- return;
1107
- } else if (targetIsSet) {
1108
- targetObject.add(childValue);
1109
- }
1110
- if (isDraftable(childValue) && !childIsFrozen) {
1111
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
1112
- return;
1113
- }
1114
- if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) {
1115
- return;
1116
- }
1117
- finalize(rootScope, childValue);
1118
- if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop)))
1119
- maybeFreeze(rootScope, childValue);
1120
- }
1121
- }
1122
- function maybeFreeze(scope, value, deep = false) {
1123
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
1124
- freeze(value, deep);
1125
- }
1126
- }
1127
-
1128
- // src/core/proxy.ts
1129
- function createProxyProxy(base, parent) {
1130
- const isArray = Array.isArray(base);
1131
- const state = {
1132
- type_: isArray ? 1 /* Array */ : 0 /* Object */,
1133
- // Track which produce call this is associated with.
1134
- scope_: parent ? parent.scope_ : getCurrentScope(),
1135
- // True for both shallow and deep changes.
1136
- modified_: false,
1137
- // Used during finalization.
1138
- finalized_: false,
1139
- // Track which properties have been assigned (true) or deleted (false).
1140
- assigned_: {},
1141
- // The parent draft state.
1142
- parent_: parent,
1143
- // The base state.
1144
- base_: base,
1145
- // The base proxy.
1146
- draft_: null,
1147
- // set below
1148
- // The base copy with any updated values.
1149
- copy_: null,
1150
- // Called by the `produce` function.
1151
- revoke_: null,
1152
- isManual_: false
1153
- };
1154
- let target = state;
1155
- let traps = objectTraps;
1156
- if (isArray) {
1157
- target = [state];
1158
- traps = arrayTraps;
1159
- }
1160
- const { revoke, proxy } = Proxy.revocable(target, traps);
1161
- state.draft_ = proxy;
1162
- state.revoke_ = revoke;
1163
- return proxy;
1164
- }
1165
- var objectTraps = {
1166
- get(state, prop) {
1167
- if (prop === DRAFT_STATE)
1168
- return state;
1169
- const source = latest(state);
1170
- if (!has(source, prop)) {
1171
- return readPropFromProto(state, source, prop);
1172
- }
1173
- const value = source[prop];
1174
- if (state.finalized_ || !isDraftable(value)) {
1175
- return value;
1176
- }
1177
- if (value === peek(state.base_, prop)) {
1178
- prepareCopy(state);
1179
- return state.copy_[prop] = createProxy(value, state);
1180
- }
1181
- return value;
1182
- },
1183
- has(state, prop) {
1184
- return prop in latest(state);
1185
- },
1186
- ownKeys(state) {
1187
- return Reflect.ownKeys(latest(state));
1188
- },
1189
- set(state, prop, value) {
1190
- const desc = getDescriptorFromProto(latest(state), prop);
1191
- if (desc?.set) {
1192
- desc.set.call(state.draft_, value);
1193
- return true;
1194
- }
1195
- if (!state.modified_) {
1196
- const current2 = peek(latest(state), prop);
1197
- const currentState = current2?.[DRAFT_STATE];
1198
- if (currentState && currentState.base_ === value) {
1199
- state.copy_[prop] = value;
1200
- state.assigned_[prop] = false;
1201
- return true;
1202
- }
1203
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
1204
- return true;
1205
- prepareCopy(state);
1206
- markChanged(state);
1207
- }
1208
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
1209
- (value !== void 0 || prop in state.copy_) || // special case: NaN
1210
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
1211
- return true;
1212
- state.copy_[prop] = value;
1213
- state.assigned_[prop] = true;
1214
- return true;
1215
- },
1216
- deleteProperty(state, prop) {
1217
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
1218
- state.assigned_[prop] = false;
1219
- prepareCopy(state);
1220
- markChanged(state);
1221
- } else {
1222
- delete state.assigned_[prop];
1223
- }
1224
- if (state.copy_) {
1225
- delete state.copy_[prop];
1226
- }
1227
- return true;
1228
- },
1229
- // Note: We never coerce `desc.value` into an Immer draft, because we can't make
1230
- // the same guarantee in ES5 mode.
1231
- getOwnPropertyDescriptor(state, prop) {
1232
- const owner = latest(state);
1233
- const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
1234
- if (!desc)
1235
- return desc;
1236
- return {
1237
- writable: true,
1238
- configurable: state.type_ !== 1 /* Array */ || prop !== "length",
1239
- enumerable: desc.enumerable,
1240
- value: owner[prop]
1241
- };
1242
- },
1243
- defineProperty() {
1244
- die(11);
1245
- },
1246
- getPrototypeOf(state) {
1247
- return getPrototypeOf(state.base_);
1248
- },
1249
- setPrototypeOf() {
1250
- die(12);
1251
- }
1252
- };
1253
- var arrayTraps = {};
1254
- each(objectTraps, (key, fn) => {
1255
- arrayTraps[key] = function() {
1256
- arguments[0] = arguments[0][0];
1257
- return fn.apply(this, arguments);
1258
- };
1259
- });
1260
- arrayTraps.deleteProperty = function(state, prop) {
1261
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
1262
- die(13);
1263
- return arrayTraps.set.call(this, state, prop, void 0);
1264
- };
1265
- arrayTraps.set = function(state, prop, value) {
1266
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
1267
- die(14);
1268
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
1269
- };
1270
- function peek(draft, prop) {
1271
- const state = draft[DRAFT_STATE];
1272
- const source = state ? latest(state) : draft;
1273
- return source[prop];
1274
- }
1275
- function readPropFromProto(state, source, prop) {
1276
- const desc = getDescriptorFromProto(source, prop);
1277
- return desc ? `value` in desc ? desc.value : (
1278
- // This is a very special case, if the prop is a getter defined by the
1279
- // prototype, we should invoke it with the draft as context!
1280
- desc.get?.call(state.draft_)
1281
- ) : void 0;
1282
- }
1283
- function getDescriptorFromProto(source, prop) {
1284
- if (!(prop in source))
1285
- return void 0;
1286
- let proto = getPrototypeOf(source);
1287
- while (proto) {
1288
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
1289
- if (desc)
1290
- return desc;
1291
- proto = getPrototypeOf(proto);
1292
- }
1293
- return void 0;
1294
- }
1295
- function markChanged(state) {
1296
- if (!state.modified_) {
1297
- state.modified_ = true;
1298
- if (state.parent_) {
1299
- markChanged(state.parent_);
1300
- }
1301
- }
1302
- }
1303
- function prepareCopy(state) {
1304
- if (!state.copy_) {
1305
- state.copy_ = shallowCopy(
1306
- state.base_,
1307
- state.scope_.immer_.useStrictShallowCopy_
1308
- );
1309
- }
1310
- }
1311
-
1312
- // src/core/immerClass.ts
1313
- var Immer2 = class {
1314
- constructor(config) {
1315
- this.autoFreeze_ = true;
1316
- this.useStrictShallowCopy_ = false;
1317
- this.useStrictIteration_ = true;
1318
- /**
1319
- * The `produce` function takes a value and a "recipe function" (whose
1320
- * return value often depends on the base state). The recipe function is
1321
- * free to mutate its first argument however it wants. All mutations are
1322
- * only ever applied to a __copy__ of the base state.
1323
- *
1324
- * Pass only a function to create a "curried producer" which relieves you
1325
- * from passing the recipe function every time.
1326
- *
1327
- * Only plain objects and arrays are made mutable. All other objects are
1328
- * considered uncopyable.
1329
- *
1330
- * Note: This function is __bound__ to its `Immer` instance.
1331
- *
1332
- * @param {any} base - the initial state
1333
- * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
1334
- * @param {Function} patchListener - optional function that will be called with all the patches produced here
1335
- * @returns {any} a new state, or the initial state if nothing was modified
1336
- */
1337
- this.produce = (base, recipe, patchListener) => {
1338
- if (typeof base === "function" && typeof recipe !== "function") {
1339
- const defaultBase = recipe;
1340
- recipe = base;
1341
- const self = this;
1342
- return function curriedProduce(base2 = defaultBase, ...args) {
1343
- return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
1344
- };
1345
- }
1346
- if (typeof recipe !== "function")
1347
- die(6);
1348
- if (patchListener !== void 0 && typeof patchListener !== "function")
1349
- die(7);
1350
- let result;
1351
- if (isDraftable(base)) {
1352
- const scope = enterScope(this);
1353
- const proxy = createProxy(base, void 0);
1354
- let hasError = true;
1355
- try {
1356
- result = recipe(proxy);
1357
- hasError = false;
1358
- } finally {
1359
- if (hasError)
1360
- revokeScope(scope);
1361
- else
1362
- leaveScope(scope);
1363
- }
1364
- usePatchesInScope(scope, patchListener);
1365
- return processResult(result, scope);
1366
- } else if (!base || typeof base !== "object") {
1367
- result = recipe(base);
1368
- if (result === void 0)
1369
- result = base;
1370
- if (result === NOTHING)
1371
- result = void 0;
1372
- if (this.autoFreeze_)
1373
- freeze(result, true);
1374
- if (patchListener) {
1375
- const p = [];
1376
- const ip = [];
1377
- getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
1378
- patchListener(p, ip);
1379
- }
1380
- return result;
1381
- } else
1382
- die(1, base);
1383
- };
1384
- this.produceWithPatches = (base, recipe) => {
1385
- if (typeof base === "function") {
1386
- return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
1387
- }
1388
- let patches, inversePatches;
1389
- const result = this.produce(base, recipe, (p, ip) => {
1390
- patches = p;
1391
- inversePatches = ip;
1392
- });
1393
- return [result, patches, inversePatches];
1394
- };
1395
- if (typeof config?.autoFreeze === "boolean")
1396
- this.setAutoFreeze(config.autoFreeze);
1397
- if (typeof config?.useStrictShallowCopy === "boolean")
1398
- this.setUseStrictShallowCopy(config.useStrictShallowCopy);
1399
- if (typeof config?.useStrictIteration === "boolean")
1400
- this.setUseStrictIteration(config.useStrictIteration);
1401
- }
1402
- createDraft(base) {
1403
- if (!isDraftable(base))
1404
- die(8);
1405
- if (isDraft(base))
1406
- base = current(base);
1407
- const scope = enterScope(this);
1408
- const proxy = createProxy(base, void 0);
1409
- proxy[DRAFT_STATE].isManual_ = true;
1410
- leaveScope(scope);
1411
- return proxy;
1412
- }
1413
- finishDraft(draft, patchListener) {
1414
- const state = draft && draft[DRAFT_STATE];
1415
- if (!state || !state.isManual_)
1416
- die(9);
1417
- const { scope_: scope } = state;
1418
- usePatchesInScope(scope, patchListener);
1419
- return processResult(void 0, scope);
1420
- }
1421
- /**
1422
- * Pass true to automatically freeze all copies created by Immer.
1423
- *
1424
- * By default, auto-freezing is enabled.
1425
- */
1426
- setAutoFreeze(value) {
1427
- this.autoFreeze_ = value;
1428
- }
1429
- /**
1430
- * Pass true to enable strict shallow copy.
1431
- *
1432
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
1433
- */
1434
- setUseStrictShallowCopy(value) {
1435
- this.useStrictShallowCopy_ = value;
1436
- }
1437
- /**
1438
- * Pass false to use faster iteration that skips non-enumerable properties
1439
- * but still handles symbols for compatibility.
1440
- *
1441
- * By default, strict iteration is enabled (includes all own properties).
1442
- */
1443
- setUseStrictIteration(value) {
1444
- this.useStrictIteration_ = value;
1445
- }
1446
- shouldUseStrictIteration() {
1447
- return this.useStrictIteration_;
1448
- }
1449
- applyPatches(base, patches) {
1450
- let i;
1451
- for (i = patches.length - 1; i >= 0; i--) {
1452
- const patch = patches[i];
1453
- if (patch.path.length === 0 && patch.op === "replace") {
1454
- base = patch.value;
1455
- break;
1456
- }
1457
- }
1458
- if (i > -1) {
1459
- patches = patches.slice(i + 1);
1460
- }
1461
- const applyPatchesImpl = getPlugin("Patches").applyPatches_;
1462
- if (isDraft(base)) {
1463
- return applyPatchesImpl(base, patches);
1464
- }
1465
- return this.produce(
1466
- base,
1467
- (draft) => applyPatchesImpl(draft, patches)
1468
- );
1469
- }
1470
- };
1471
- function createProxy(value, parent) {
1472
- const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
1473
- const scope = parent ? parent.scope_ : getCurrentScope();
1474
- scope.drafts_.push(draft);
1475
- return draft;
1476
- }
1477
-
1478
- // src/core/current.ts
1479
- function current(value) {
1480
- if (!isDraft(value))
1481
- die(10, value);
1482
- return currentImpl(value);
1483
- }
1484
- function currentImpl(value) {
1485
- if (!isDraftable(value) || isFrozen(value))
1486
- return value;
1487
- const state = value[DRAFT_STATE];
1488
- let copy;
1489
- let strict = true;
1490
- if (state) {
1491
- if (!state.modified_)
1492
- return state.base_;
1493
- state.finalized_ = true;
1494
- copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
1495
- strict = state.scope_.immer_.shouldUseStrictIteration();
1496
- } else {
1497
- copy = shallowCopy(value, true);
1498
- }
1499
- each(
1500
- copy,
1501
- (key, childValue) => {
1502
- set(copy, key, currentImpl(childValue));
1503
- },
1504
- strict
1505
- );
1506
- if (state) {
1507
- state.finalized_ = false;
1508
- }
1509
- return copy;
1510
- }
1511
-
1512
- // src/immer.ts
1513
- var immer = new Immer2();
1514
- var produce = immer.produce;
1515
-
1516
- function buildElementNotations(nodes) {
1517
- return t$a(
1518
- nodes,
1519
- n$5((n) => !!n.notation),
1520
- t$5(e$5("notation")),
1521
- t$3(
1522
- t$2(
1523
- t$5(e$5("shape")),
1524
- t$3(
1525
- t$2(
1526
- t$5(e$5("color")),
1527
- t$3(
1528
- t$2(
1529
- t$e(e$5("kind")),
1530
- n$6()
1531
- )
1532
- ),
1533
- t$d(),
1534
- t$e(([color, kinds]) => ({
1535
- kinds,
1536
- color
1537
- }))
1538
- )
1539
- ),
1540
- t$d(),
1541
- t$6(
1542
- ([shape, colors]) => colors.map(({ color, kinds }) => ({
1543
- shape,
1544
- color,
1545
- kinds
1546
- }))
1547
- )
1548
- )
1549
- ),
1550
- t$d(),
1551
- t$6(
1552
- ([title, shapes]) => shapes.map(({ shape, color, kinds }) => ({
1553
- title,
1554
- shape,
1555
- color,
1556
- kinds
1557
- }))
1558
- ),
1559
- t$1(
1560
- e$5("shape"),
1561
- e$5("title"),
1562
- [
1563
- (n) => n.kinds.length,
1564
- "desc"
1565
- ]
1566
- )
1567
- );
1568
- }
1569
-
1570
- const changed = (a, b) => {
1571
- if (a === b || e$6(a) && e$6(b)) {
1572
- return false;
1573
- }
1574
- return !t$f(a, b);
1575
- };
1576
- const MAX_ALLOWED_DRIFT = 5;
1577
- function autoApplyMetaAndStyles(draft, next) {
1578
- draft.color = next.color;
1579
- draft.kind = next.kind;
1580
- draft.navigateTo = next.navigateTo ?? null;
1581
- draft.links = next.links ? [...next.links] : null;
1582
- draft.tags = [...next.tags];
1583
- if (e$6(next.style.border)) {
1584
- delete draft.style.border;
1585
- } else {
1586
- draft.style.border = next.style.border;
1587
- }
1588
- if (e$1(next.style.opacity)) {
1589
- draft.style.opacity = next.style.opacity;
1590
- } else {
1591
- delete draft.style.opacity;
1592
- }
1593
- if (e$6(next.style.multiple)) {
1594
- delete draft.style.multiple;
1595
- } else {
1596
- draft.style.multiple = next.style.multiple;
1597
- }
1598
- }
1599
- function autoApplyIcon(draft, next, sizeNotChanged) {
1600
- if (changed(next.icon ?? "none", draft.icon ?? "none")) {
1601
- const iconWasSet = e$3(draft.icon) && draft.icon !== "none";
1602
- switch (true) {
1603
- // Icon was set before and changed, auto-apply
1604
- case (iconWasSet && e$3(next.icon) && next.icon !== "none"): {
1605
- draft.icon = next.icon;
1606
- return true;
1607
- }
1608
- // Icon was set before and now removed, auto-apply
1609
- case (iconWasSet && (e$6(next.icon) || next.icon === "none")): {
1610
- draft.icon = "none";
1611
- return true;
1612
- }
1613
- // Icon was added
1614
- case (!iconWasSet && e$3(next.icon) && next.icon !== "none"): {
1615
- if (sizeNotChanged) {
1616
- draft.icon = next.icon;
1617
- return true;
1618
- } else {
1619
- return false;
1620
- }
1621
- }
1622
- }
1623
- }
1624
- return true;
1625
- }
1626
- function autoApplyLabelsToLeaf(draft, next, sizeNotChanged) {
1627
- let applied = true;
1628
- if (changed(draft.title, next.title)) {
1629
- if (sizeNotChanged) {
1630
- draft.title = next.title;
1631
- } else {
1632
- applied = false;
1633
- }
1634
- }
1635
- if (changed(draft.description, next.description)) {
1636
- if (e$6(next.description)) {
1637
- delete draft.description;
1638
- } else if (sizeNotChanged) {
1639
- draft.description = next.description;
1640
- } else {
1641
- applied = false;
1642
- }
1643
- }
1644
- if (changed(draft.technology, next.technology)) {
1645
- if (e$6(next.technology)) {
1646
- delete draft.technology;
1647
- } else if (sizeNotChanged) {
1648
- draft.technology = next.technology;
1649
- } else {
1650
- applied = false;
1651
- }
1652
- }
1653
- return applied;
1654
- }
1655
- function autoApplyLabelsToCompound(draft, next, _sizeNotChanged) {
1656
- draft.title = next.title;
1657
- if (e$6(next.description)) {
1658
- delete draft.description;
1659
- } else {
1660
- draft.description = next.description;
1661
- }
1662
- if (e$6(next.technology)) {
1663
- delete draft.technology;
1664
- } else {
1665
- draft.technology = next.technology;
1666
- }
1667
- return true;
1668
- }
1669
- function applyManualLayout(autoLayouted, snapshot) {
1670
- invariant(autoLayouted.id === snapshot.id, "applyManualLayout: view ids do not match");
1671
- invariant(autoLayouted._stage === "layouted", "applyManualLayout: expected layouted view");
1672
- invariant(snapshot._stage === "layouted", "applyManualLayout: expected layouted snapshot");
1673
- invariant(autoLayouted._layout !== "manual", "applyManualLayout: expected auto-layouted view");
1674
- const viewDrifts = /* @__PURE__ */ new Set();
1675
- if (autoLayouted._type !== snapshot._type) {
1676
- viewDrifts.add("type-changed");
1677
- }
1678
- const nextNodes = new Map(autoLayouted.nodes.map((n) => [n.id, n]));
1679
- const nextEdges = new Map(autoLayouted.edges.map((e) => [e.id, e]));
1680
- const nextNodeIds = new Set(nextNodes.keys());
1681
- const nextEdgeIds = new Set(nextEdges.keys());
1682
- const snapshotNodeIds = new Set(snapshot.nodes.map((n) => n.id));
1683
- const snapshotEdgeIds = new Set(snapshot.edges.map((e) => e.id));
1684
- if (symmetricDifference(nextNodeIds, snapshotNodeIds).size > 0) {
1685
- viewDrifts.add("nodes-mismatch");
1686
- }
1687
- if (symmetricDifference(nextEdgeIds, snapshotEdgeIds).size > 0) {
1688
- viewDrifts.add("edges-mismatch");
1689
- }
1690
- const nodes = snapshot.nodes.map((node) => {
1691
- const next = nextNodes.get(node.id);
1692
- return produce(node, (draft) => {
1693
- if (!next) {
1694
- draft.drifts = ["missing"];
1695
- return;
1696
- }
1697
- autoApplyMetaAndStyles(draft, next);
1698
- const nodeDrifts = /* @__PURE__ */ new Set();
1699
- const wasCompound = node.children.length > 0;
1700
- const willBeCompound = next.children.length > 0;
1701
- if (changed(draft.modelRef, next.modelRef) || changed(draft.deploymentRef, next.deploymentRef)) {
1702
- nodeDrifts.add("modelRef-changed");
1703
- }
1704
- if (willBeCompound && !wasCompound) {
1705
- nodeDrifts.add("became-compound");
1706
- }
1707
- if (!willBeCompound && wasCompound) {
1708
- nodeDrifts.add("became-leaf");
1709
- }
1710
- if (changed(draft.parent, next.parent)) {
1711
- nodeDrifts.add("parent-changed");
1712
- }
1713
- const sizeNotChanged = draft.width + MAX_ALLOWED_DRIFT >= next.width && draft.height + MAX_ALLOWED_DRIFT >= next.height;
1714
- if (changed(draft.shape, next.shape)) {
1715
- if (sizeNotChanged) {
1716
- draft.shape = next.shape;
1717
- } else {
1718
- nodeDrifts.add("shape-changed");
1719
- }
1720
- }
1721
- if (!autoApplyIcon(draft, next, sizeNotChanged && willBeCompound === wasCompound)) {
1722
- nodeDrifts.add("label-changed");
1723
- }
1724
- const autoApplyLabels = wasCompound ? autoApplyLabelsToCompound : autoApplyLabelsToLeaf;
1725
- if (!autoApplyLabels(draft, next, sizeNotChanged)) {
1726
- nodeDrifts.add("label-changed");
1727
- }
1728
- if (changed(node.notation, next.notation)) {
1729
- draft.notation = next.notation ?? null;
1730
- }
1731
- if (wasCompound && willBeCompound && symmetricDifference(new Set(node.children), new Set(next.children)).size > 0) {
1732
- nodeDrifts.add("children-changed");
1733
- }
1734
- const _drifts = [...nodeDrifts];
1735
- if (t$c(_drifts, 1)) {
1736
- viewDrifts.add("nodes-mismatch");
1737
- draft.drifts = _drifts;
1738
- }
1739
- });
1740
- });
1741
- const edges = snapshot.edges.map((edge) => {
1742
- const next = nextEdges.get(edge.id);
1743
- return produce(edge, (draft) => {
1744
- if (!next) {
1745
- draft.drifts = ["missing"];
1746
- return;
1747
- }
1748
- const edgeDrifts = /* @__PURE__ */ new Set();
1749
- if (draft.source === next.target && draft.target === next.source) {
1750
- edgeDrifts.add("direction-changed");
1751
- } else {
1752
- if (draft.source !== next.source) {
1753
- edgeDrifts.add("source-changed");
1754
- }
1755
- if (draft.target !== next.target) {
1756
- edgeDrifts.add("target-changed");
1757
- }
1758
- }
1759
- if (edgeDrifts.size === 0 && changed(draft.dir ?? "forward", next.dir ?? "forward")) {
1760
- edgeDrifts.add("direction-changed");
1761
- }
1762
- draft.color = next.color;
1763
- draft.line = next.line;
1764
- draft.navigateTo = next.navigateTo ?? null;
1765
- draft.tags = next.tags ? [...next.tags] : null;
1766
- if (e$6(next.notes)) {
1767
- delete draft.notes;
1768
- } else {
1769
- draft.notes = next.notes;
1770
- }
1771
- if (next.astPath) {
1772
- draft.astPath = next.astPath;
1773
- }
1774
- if (next.labelBBox) {
1775
- if (!draft.labelBBox || !e$3(draft.label) && e$3(next.label)) {
1776
- edgeDrifts.add("label-changed");
1777
- }
1778
- draft.labelBBox = {
1779
- // Preserve x,y if possible
1780
- x: draft.labelBBox?.x ?? next.labelBBox.x,
1781
- y: draft.labelBBox?.y ?? next.labelBBox.y,
1782
- // Take width/height from next
1783
- width: next.labelBBox.width,
1784
- height: next.labelBBox.height
1785
- };
1786
- draft.label = next.label;
1787
- draft.description = next.description ?? null;
1788
- draft.technology = next.technology ?? null;
1789
- } else if (edge.labelBBox) {
1790
- edgeDrifts.add("label-changed");
1791
- }
1792
- const _drifts = [...edgeDrifts];
1793
- if (t$c(_drifts, 1)) {
1794
- viewDrifts.add("edges-mismatch");
1795
- draft.drifts = _drifts;
1796
- }
1797
- });
1798
- });
1799
- const nodeNotations = buildElementNotations(nodes);
1800
- const result = { ...snapshot };
1801
- Object.assign(
1802
- result,
1803
- {
1804
- // Auto-layouted properties
1805
- title: autoLayouted.title ?? snapshot.title,
1806
- description: autoLayouted.description ?? snapshot.description,
1807
- tags: autoLayouted.tags ? [...autoLayouted.tags] : null,
1808
- links: autoLayouted.links ? [...autoLayouted.links] : null,
1809
- [_layout]: "manual",
1810
- ...nodeNotations && nodeNotations.length > 0 ? { notation: { nodes: nodeNotations } } : {},
1811
- nodes,
1812
- edges
1813
- }
1814
- );
1815
- if (isDynamicView(autoLayouted) && result._type === "dynamic") {
1816
- Object.assign(
1817
- result,
1818
- {
1819
- variant: autoLayouted.variant
1820
- }
1821
- );
1822
- }
1823
- const drifts = [...viewDrifts];
1824
- if (t$c(drifts, 1)) {
1825
- result.drifts = drifts;
1826
- } else {
1827
- if ("drifts" in result) {
1828
- delete result.drifts;
1829
- }
1830
- }
1831
- return result;
1832
- }
1833
- function applyLayoutDriftReasons(autoLayouted, snapshot) {
1834
- const { drifts } = applyManualLayout(autoLayouted, snapshot);
1835
- if (drifts) {
1836
- Object.assign(
1837
- autoLayouted,
1838
- {
1839
- [_layout]: "auto",
1840
- drifts
1841
- }
1842
- );
1843
- } else {
1844
- const mutable = autoLayouted;
1845
- if ("drifts" in autoLayouted) {
1846
- delete mutable.drifts;
1847
- }
1848
- }
1849
- return autoLayouted;
1850
- }
1851
-
1852
742
  class EdgeModel {
1853
743
  constructor($viewModel, $edge, source, target) {
1854
744
  this.source = source;
@@ -2079,13 +969,13 @@ class NodeModel {
2079
969
  * Check if this node references to logical model element.
2080
970
  */
2081
971
  hasElement() {
2082
- return e$3(this.$node.modelRef);
972
+ return e$2(this.$node.modelRef);
2083
973
  }
2084
974
  /**
2085
975
  * Check if this node references to deployment element (Node or Instance).
2086
976
  */
2087
977
  hasDeployment() {
2088
- return e$3(this.$node.deploymentRef);
978
+ return e$2(this.$node.deploymentRef);
2089
979
  }
2090
980
  /**
2091
981
  * Check if this node references to deployed instance
@@ -2267,7 +1157,8 @@ class LikeC4ViewModel {
2267
1157
  return [...this.#allTags.keys()];
2268
1158
  }
2269
1159
  /**
2270
- * The original view (auto-layouted).
1160
+ * The original view from the model.
1161
+ * In case of layouted model, this is the latest auto-layouted view without manual changes applied
2271
1162
  * @see {@link $layouted} should be used for rendering in the UI
2272
1163
  */
2273
1164
  get $view() {
@@ -2277,7 +1168,7 @@ class LikeC4ViewModel {
2277
1168
  const snapshot = this.#manualLayoutSnapshot;
2278
1169
  if (snapshot) {
2279
1170
  return memoizeProp(this, "withDriftReasons", () => {
2280
- return applyLayoutDriftReasons(this.#view, snapshot);
1171
+ return calcDriftsFromSnapshot(this.#view, snapshot);
2281
1172
  });
2282
1173
  }
2283
1174
  return this.#view;
@@ -2290,15 +1181,22 @@ class LikeC4ViewModel {
2290
1181
  if (!this.isLayouted()) {
2291
1182
  throw new Error("View is not layouted");
2292
1183
  }
2293
- return this.manualLayouted ?? this.#view;
1184
+ return this.$manual ?? this.#view;
2294
1185
  }
2295
1186
  get hasManualLayout() {
2296
1187
  return this.#manualLayoutSnapshot !== void 0;
2297
1188
  }
1189
+ get hasLayoutDrifts() {
1190
+ if (!this.isLayouted()) {
1191
+ return false;
1192
+ }
1193
+ const manualLayout = this.$manual;
1194
+ return !!manualLayout?.drifts && manualLayout.drifts.length > 0;
1195
+ }
2298
1196
  /**
2299
1197
  * If view has manual layout, returns it with manual layout applied
2300
1198
  */
2301
- get manualLayouted() {
1199
+ get $manual() {
2302
1200
  if (!this.isLayouted()) {
2303
1201
  return null;
2304
1202
  }
@@ -2310,16 +1208,6 @@ class LikeC4ViewModel {
2310
1208
  }
2311
1209
  return null;
2312
1210
  }
2313
- /**
2314
- * Returns the layout drift reasons, if any
2315
- * (Only for layouted views with manual layout)
2316
- */
2317
- get driftReasons() {
2318
- if (!this.isLayouted()) {
2319
- return [];
2320
- }
2321
- return this.$view.drifts ?? [];
2322
- }
2323
1211
  roots() {
2324
1212
  return this.#rootnodes.values();
2325
1213
  }
@@ -2445,7 +1333,7 @@ class LikeC4ViewModel {
2445
1333
  return this.#view[_type] === "element";
2446
1334
  }
2447
1335
  isScopedElementView() {
2448
- return this.#view[_type] === "element" && e$3(this.#view.viewOf);
1336
+ return this.#view[_type] === "element" && e$2(this.#view.viewOf);
2449
1337
  }
2450
1338
  isDeploymentView() {
2451
1339
  return this.#view[_type] === "deployment";
@@ -2487,7 +1375,7 @@ class LikeC4ViewsFolder {
2487
1375
  this.$model = $model;
2488
1376
  this.path = path.join("/");
2489
1377
  this.isRoot = this.path === "";
2490
- this.title = t$4(path);
1378
+ this.title = t$1(path);
2491
1379
  if (this.isRoot) {
2492
1380
  this.parentPath = void 0;
2493
1381
  } else {
@@ -2542,7 +1430,7 @@ class LikeC4ViewsFolder {
2542
1430
  */
2543
1431
  get parent() {
2544
1432
  invariant(!this.isRoot, "Root view folder has no parent");
2545
- if (e$4(this.parentPath)) {
1433
+ if (e$1(this.parentPath)) {
2546
1434
  return null;
2547
1435
  }
2548
1436
  return this.$model.viewFolder(this.parentPath);
@@ -2659,13 +1547,13 @@ class LikeC4Model {
2659
1547
  $data;
2660
1548
  constructor($data) {
2661
1549
  this.$data = $data;
2662
- for (const [, element] of t$d($data.elements)) {
1550
+ for (const [, element] of t$5($data.elements)) {
2663
1551
  const el = this.addElement(element);
2664
1552
  for (const tag of el.tags) {
2665
1553
  this._allTags.get(tag).add(el);
2666
1554
  }
2667
1555
  }
2668
- for (const [projectId, elements] of t$d($data.imports ?? {})) {
1556
+ for (const [projectId, elements] of t$5($data.imports ?? {})) {
2669
1557
  for (const element of sortParentsFirst(elements)) {
2670
1558
  const el = this.addImportedElement(projectId, element);
2671
1559
  for (const tag of el.tags) {
@@ -2682,22 +1570,21 @@ class LikeC4Model {
2682
1570
  this.deployment = new LikeC4DeploymentModel(this);
2683
1571
  if (isOnStage($data, "computed") || isOnStage($data, "layouted")) {
2684
1572
  const compare = compareNaturalHierarchically(VIEW_FOLDERS_SEPARATOR);
2685
- t($data.views);
2686
- const views = t$a(
1573
+ const views = t$6(
2687
1574
  t($data.views),
2688
- t$e((view) => ({
1575
+ t$8((view) => ({
2689
1576
  view,
2690
1577
  path: normalizeViewPath(view.title ?? view.id),
2691
1578
  folderPath: view.title && getViewFolderPath(view.title) || ""
2692
1579
  })),
2693
1580
  // Sort hierarchically by groups, but keep same order within groups
2694
- t$g((a, b) => compare(a.folderPath, b.folderPath))
1581
+ t$7((a, b) => compare(a.folderPath, b.folderPath))
2695
1582
  );
2696
1583
  const getOrCreateFolder = (path) => {
2697
1584
  let folder = this._viewFolders.get(path);
2698
1585
  if (!folder) {
2699
1586
  const segments = e(path, VIEW_FOLDERS_SEPARATOR);
2700
- invariant(t$c(segments, 1), `View group path "${path}" must have at least one element`);
1587
+ invariant(t$4(segments, 1), `View group path "${path}" must have at least one element`);
2701
1588
  let defaultView;
2702
1589
  if (path === "") {
2703
1590
  defaultView = views.find((view) => view.view.id === "index");
@@ -2716,7 +1603,7 @@ class LikeC4Model {
2716
1603
  }
2717
1604
  e(folderPath, VIEW_FOLDERS_SEPARATOR).reduce((segments, segment) => {
2718
1605
  const parent = segments.join(VIEW_FOLDERS_SEPARATOR);
2719
- const path = e$4(parent) ? segment : parent + VIEW_FOLDERS_SEPARATOR + segment;
1606
+ const path = e$3(parent) ? segment : parent + VIEW_FOLDERS_SEPARATOR + segment;
2720
1607
  const folder = getOrCreateFolder(path);
2721
1608
  this._viewFolderItems.get(parent).add(folder);
2722
1609
  segments.push(segment);
@@ -2945,6 +1832,16 @@ class LikeC4Model {
2945
1832
  findView(viewId) {
2946
1833
  return this._views.get(viewId) ?? null;
2947
1834
  }
1835
+ /**
1836
+ * Returns manual layout snapshot for given view ID, if any.
1837
+ */
1838
+ findManualLayout(viewId) {
1839
+ if ("manualLayouts" in this.$data) {
1840
+ const view = this.$data.manualLayouts?.[viewId];
1841
+ return view ?? null;
1842
+ }
1843
+ return null;
1844
+ }
2948
1845
  /**
2949
1846
  * Returns a view folder by its path.
2950
1847
  * Path is extracted from the view title, e.g. "Group 1/Group 2/View" -> "Group 1/Group 2"
@@ -3068,22 +1965,22 @@ class LikeC4Model {
3068
1965
  * Use {@link specification.tags} to get all defined tags
3069
1966
  */
3070
1967
  get tags() {
3071
- return memoizeProp(this, "tags", () => t$g([...this._allTags.keys()], compareNatural));
1968
+ return memoizeProp(this, "tags", () => t$7([...this._allTags.keys()], compareNatural));
3072
1969
  }
3073
1970
  /**
3074
1971
  * Returns all tags used in the model, sorted by usage count (descending).
3075
1972
  */
3076
1973
  get tagsSortedByUsage() {
3077
- return memoizeProp(this, "tagsSortedByUsage", () => t$a(
1974
+ return memoizeProp(this, "tagsSortedByUsage", () => t$6(
3078
1975
  [...this._allTags.entries()],
3079
- t$e(([tag, tagged]) => ({
1976
+ t$8(([tag, tagged]) => ({
3080
1977
  tag,
3081
1978
  count: tagged.size,
3082
1979
  tagged
3083
1980
  })),
3084
- t$g((a, b) => compareNatural(a.tag, b.tag)),
3085
- t$1(
3086
- [e$5("count"), "desc"]
1981
+ t$7((a, b) => compareNatural(a.tag, b.tag)),
1982
+ t$9(
1983
+ [e$4("count"), "desc"]
3087
1984
  )
3088
1985
  ));
3089
1986
  }
@@ -3299,4 +2196,4 @@ function isEdgeModel(edge) {
3299
2196
  return edge instanceof EdgeModel;
3300
2197
  }
3301
2198
 
3302
- export { isEdgeModel as A, ElementModel as E, LikeC4Model as L, NodeModel as N, RelationshipModel as R, VIEW_FOLDERS_SEPARATOR as V, t$3 as a, t$4 as b, t$2 as c, t$5 as d, t$6 as e, isNestedElementOfDeployedInstanceModel as f, isDeployedInstanceModel as g, isDeploymentNodeModel as h, isElementModel as i, isDeploymentElementModel as j, buildElementNotations as k, LikeC4DeploymentModel as l, EdgeModel as m, n$5 as n, LikeC4ViewModel as o, LikeC4ViewsFolder as p, extractViewTitleFromPath as q, getViewFolderPath as r, normalizeViewPath as s, t, applyLayoutDriftReasons as u, applyManualLayout as v, isDeploymentRelationModel as w, isRelationModel as x, isLikeC4ViewModel as y, isNodeModel as z };
2199
+ export { ElementModel as E, LikeC4Model as L, NodeModel as N, RelationshipModel as R, VIEW_FOLDERS_SEPARATOR as V, t$1 as a, isNestedElementOfDeployedInstanceModel as b, isDeployedInstanceModel as c, isDeploymentNodeModel as d, isDeploymentElementModel as e, LikeC4DeploymentModel as f, EdgeModel as g, LikeC4ViewModel as h, isElementModel as i, LikeC4ViewsFolder as j, extractViewTitleFromPath as k, getViewFolderPath as l, isDeploymentRelationModel as m, normalizeViewPath as n, isRelationModel as o, isLikeC4ViewModel as p, isNodeModel as q, isEdgeModel as r, t };