@likec4/core 1.46.4 → 1.48.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 (181) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_chunks/Builder.view-element.mjs +3284 -0
  3. package/dist/_chunks/LikeC4Model.d.mts +1287 -0
  4. package/dist/_chunks/LikeC4Styles.mjs +691 -0
  5. package/dist/_chunks/RichText.d.mts +84 -0
  6. package/dist/_chunks/RichText.mjs +148 -0
  7. package/dist/_chunks/_aux.d.mts +289 -0
  8. package/dist/_chunks/_aux.mjs +18 -0
  9. package/dist/_chunks/_types.d.mts +781 -0
  10. package/dist/_chunks/_types2.d.mts +38 -0
  11. package/dist/_chunks/assignTagColors.mjs +24 -0
  12. package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
  13. package/dist/_chunks/connection.mjs +0 -0
  14. package/dist/_chunks/const.d.mts +43 -0
  15. package/dist/_chunks/const.mjs +33 -0
  16. package/dist/_chunks/expression-model.d.mts +192 -0
  17. package/dist/_chunks/expression-model.mjs +103 -0
  18. package/dist/_chunks/expression.d.mts +347 -0
  19. package/dist/_chunks/expression.mjs +107 -0
  20. package/dist/_chunks/find.d.mts +82 -0
  21. package/dist/_chunks/find.mjs +646 -0
  22. package/dist/_chunks/find2.d.mts +78 -0
  23. package/dist/_chunks/find2.mjs +287 -0
  24. package/dist/_chunks/fqnRef.d.mts +58 -0
  25. package/dist/_chunks/fqnRef.mjs +41 -0
  26. package/dist/_chunks/geometry.mjs +335 -0
  27. package/dist/_chunks/index.d.mts +169 -0
  28. package/dist/_chunks/index2.d.mts +937 -0
  29. package/dist/_chunks/index3.d.mts +146 -0
  30. package/dist/_chunks/index4.d.mts +62 -0
  31. package/dist/_chunks/index5.d.mts +42 -0
  32. package/dist/_chunks/index6.d.mts +43 -0
  33. package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
  34. package/dist/_chunks/index8.d.mts +144 -0
  35. package/dist/_chunks/invariant.mjs +18 -0
  36. package/dist/_chunks/iterable.mjs +146 -0
  37. package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
  38. package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
  39. package/dist/_chunks/libs/bail.mjs +14 -0
  40. package/dist/_chunks/libs/ccount.mjs +25 -0
  41. package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
  42. package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
  43. package/dist/_chunks/libs/character-entities.mjs +2136 -0
  44. package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
  45. package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
  46. package/dist/_chunks/libs/defu.mjs +42 -0
  47. package/dist/_chunks/libs/devlop.mjs +5 -0
  48. package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
  49. package/dist/_chunks/libs/extend.mjs +77 -0
  50. package/dist/_chunks/libs/graphology-dag.mjs +703 -0
  51. package/dist/_chunks/libs/graphology-types.d.mts +601 -0
  52. package/dist/_chunks/libs/graphology.d.mts +6 -0
  53. package/dist/_chunks/libs/graphology.mjs +4565 -0
  54. package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
  55. package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
  56. package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
  57. package/dist/_chunks/libs/longest-streak.mjs +30 -0
  58. package/dist/_chunks/libs/markdown-table.mjs +290 -0
  59. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
  60. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
  61. package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
  62. package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
  63. package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
  64. package/dist/_chunks/libs/mnemonist.d.mts +254 -0
  65. package/dist/_chunks/libs/mnemonist.mjs +1978 -0
  66. package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
  67. package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
  68. package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
  69. package/dist/_chunks/libs/remark-gfm.mjs +36 -0
  70. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
  71. package/dist/_chunks/libs/remark-parse.mjs +39 -0
  72. package/dist/_chunks/libs/remark-rehype.mjs +171 -0
  73. package/dist/_chunks/libs/remeda.mjs +702 -0
  74. package/dist/_chunks/libs/trough.mjs +158 -0
  75. package/dist/_chunks/libs/unified.mjs +2212 -0
  76. package/dist/_chunks/mnemonist.d.mts +1 -0
  77. package/dist/_chunks/mnemonist.mjs +0 -0
  78. package/dist/_chunks/model.mjs +1898 -0
  79. package/dist/_chunks/model2.mjs +0 -0
  80. package/dist/_chunks/relationships-view.mjs +132 -0
  81. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  82. package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
  83. package/dist/_chunks/scalar.mjs +84 -0
  84. package/dist/_chunks/utils.mjs +483 -0
  85. package/dist/builder/index.d.mts +11 -773
  86. package/dist/builder/index.mjs +631 -978
  87. package/dist/compute-view/index.d.mts +90 -27
  88. package/dist/compute-view/index.mjs +253 -83
  89. package/dist/compute-view/relationships-view/index.d.mts +16 -51
  90. package/dist/compute-view/relationships-view/index.mjs +6 -184
  91. package/dist/geometry/index.d.mts +2 -109
  92. package/dist/geometry/index.mjs +2 -327
  93. package/dist/index.d.mts +18 -20
  94. package/dist/index.mjs +27 -18
  95. package/dist/model/connection/deployment/index.d.mts +12 -15
  96. package/dist/model/connection/deployment/index.mjs +9 -2
  97. package/dist/model/connection/index.d.mts +14 -75
  98. package/dist/model/connection/index.mjs +10 -3
  99. package/dist/model/connection/model/index.d.mts +12 -15
  100. package/dist/model/connection/model/index.mjs +8 -2
  101. package/dist/model/index.d.mts +15 -57
  102. package/dist/model/index.mjs +11 -4
  103. package/dist/styles/index.d.mts +9 -117
  104. package/dist/styles/index.mjs +26 -59
  105. package/dist/types/RichText.d.mts +3 -0
  106. package/dist/types/RichText.mjs +7 -0
  107. package/dist/types/_aux.d.mts +3 -4
  108. package/dist/types/_aux.mjs +2 -7
  109. package/dist/types/expression-model.d.mts +6 -190
  110. package/dist/types/expression-model.mjs +6 -108
  111. package/dist/types/expression.d.mts +5 -6
  112. package/dist/types/expression.mjs +6 -112
  113. package/dist/types/fqnRef.d.mts +4 -60
  114. package/dist/types/fqnRef.mjs +6 -44
  115. package/dist/types/index.d.mts +9 -47
  116. package/dist/types/index.mjs +14 -16
  117. package/dist/types/scalar.d.mts +2 -2
  118. package/dist/types/scalar.mjs +7 -4
  119. package/dist/utils/graphology/index.d.mts +2 -1864
  120. package/dist/utils/graphology/index.mjs +3 -1
  121. package/dist/utils/index.d.mts +11 -124
  122. package/dist/utils/index.mjs +16 -43
  123. package/dist/utils/iterable/index.d.mts +9 -132
  124. package/dist/utils/iterable/index.mjs +2 -61
  125. package/dist/utils/mnemonist.d.mts +2 -0
  126. package/dist/utils/mnemonist.mjs +12 -0
  127. package/package.json +18 -22
  128. package/compute-view/relationships/package.json +0 -4
  129. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  130. package/dist/shared/core.78IWAHAE.mjs +0 -332
  131. package/dist/shared/core.B85MJLTf.mjs +0 -5
  132. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  133. package/dist/shared/core.BKlholso.mjs +0 -3
  134. package/dist/shared/core.BPGOjone.d.mts +0 -46
  135. package/dist/shared/core.BYdtmqY5.mjs +0 -1255
  136. package/dist/shared/core.BZCgljZd.d.mts +0 -83
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  139. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  140. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  141. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  142. package/dist/shared/core.BspBF3SJ.mjs +0 -3944
  143. package/dist/shared/core.BvPm_-u3.d.mts +0 -334
  144. package/dist/shared/core.C-Jdx7xo.d.mts +0 -1263
  145. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  146. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  147. package/dist/shared/core.CBLX4mT8.mjs +0 -28411
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CRhT4Iio.mjs +0 -785
  150. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  151. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  152. package/dist/shared/core.ClTP6-TN.d.mts +0 -87
  153. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  154. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  155. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  156. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  157. package/dist/shared/core.Ctj2S3bD.d.mts +0 -466
  158. package/dist/shared/core.CywrQs86.d.mts +0 -31
  159. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  160. package/dist/shared/core.D0WZutNd.mjs +0 -94
  161. package/dist/shared/core.D4npX2q8.mjs +0 -18
  162. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  163. package/dist/shared/core.DEK-BO3_.mjs +0 -1206
  164. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DSalPD6v.mjs +0 -1352
  167. package/dist/shared/core.DVfPJPJj.mjs +0 -2200
  168. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  169. package/dist/shared/core.DbfO90vF.mjs +0 -434
  170. package/dist/shared/core.DcS-0zys.mjs +0 -10
  171. package/dist/shared/core.DeDCYTDR.d.mts +0 -98
  172. package/dist/shared/core.DpKY_3NF.d.mts +0 -504
  173. package/dist/shared/core.Dt0v3djy.d.mts +0 -41
  174. package/dist/shared/core.FZ305VYd.mjs +0 -21
  175. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  179. package/dist/shared/core.uFk_o9X6.mjs +0 -13
  180. package/dist/shared/core.xeuDd__E.mjs +0 -300
  181. package/dist/shared/core.xgoPk2RG.mjs +0 -4989
@@ -1,1352 +0,0 @@
1
- import { a as t$8, t as t$9 } from './core.3ZhnKAlZ.mjs';
2
- import { t as t$7, a as t$c } from './core.BsSXS-_R.mjs';
3
- import { a as t$d } from './core.BspBF3SJ.mjs';
4
- import { b as _layout, t as isDynamicView, u as e$3 } from './core.DH7TXqXf.mjs';
5
- import { e as e$4 } from './core.BKlholso.mjs';
6
- import { e as e$2, t as t$a } from './core.Coi_LOUZ.mjs';
7
- import { t as t$b } from './core.CbT8JVYL.mjs';
8
- import { n as n$6 } from './core.BhNcrwzK.mjs';
9
- import { i as invariant } from './core.D4npX2q8.mjs';
10
- import { s as symmetricDifference } from './core.DbfO90vF.mjs';
11
- import { i as ihead } from './core.uFk_o9X6.mjs';
12
- import { i as ifilter } from './core.DRJma0Ol.mjs';
13
-
14
- const e$1={asc:(e,t)=>e>t,desc:(e,t)=>e<t};function t$6(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$1,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$1&&i.length===0}const a=e=>typeof e==`function`&&e.length===1;
15
-
16
- function n$5(...t){return t$7(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$8;
17
-
18
- function t$5(...t){return t$7(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}};
19
-
20
- function t$4(...t){return t$7(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};
21
-
22
- function e(e){return typeof e==`number`&&!Number.isNaN(e)}
23
-
24
- function t$3(...t){return t$7(n$2,t)}function n$2(e,t){let n={};for(let[r,i]of Object.entries(e))n[r]=t(i,r,e);return n}
25
-
26
- function t$2(...t){return t$7(n$1,t)}function n$1(e,t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}
27
-
28
- function t$1(...t){return n=>t$9(n,...t)}
29
-
30
- function t(...t){return t$6(n,t)}const n=(e,t)=>[...e].sort(t);
31
-
32
- // src/utils/env.ts
33
- var NOTHING = Symbol.for("immer-nothing");
34
- var DRAFTABLE = Symbol.for("immer-draftable");
35
- var DRAFT_STATE = Symbol.for("immer-state");
36
-
37
- // src/utils/errors.ts
38
- var errors = process.env.NODE_ENV !== "production" ? [
39
- // All error codes, starting by 0:
40
- function(plugin) {
41
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
42
- },
43
- function(thing) {
44
- 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}'`;
45
- },
46
- "This object has been frozen and should not be mutated",
47
- function(data) {
48
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
49
- },
50
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
51
- "Immer forbids circular references",
52
- "The first or second argument to `produce` must be a function",
53
- "The third argument to `produce` must be a function or undefined",
54
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
55
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
56
- function(thing) {
57
- return `'current' expects a draft, got: ${thing}`;
58
- },
59
- "Object.defineProperty() cannot be used on an Immer draft",
60
- "Object.setPrototypeOf() cannot be used on an Immer draft",
61
- "Immer only supports deleting array indices",
62
- "Immer only supports setting array indices and the 'length' property",
63
- function(thing) {
64
- return `'original' expects a draft, got: ${thing}`;
65
- }
66
- // Note: if more errors are added, the errorOffset in Patches.ts should be increased
67
- // See Patches.ts for additional errors
68
- ] : [];
69
- function die(error, ...args) {
70
- if (process.env.NODE_ENV !== "production") {
71
- const e = errors[error];
72
- const msg = isFunction(e) ? e.apply(null, args) : e;
73
- throw new Error(`[Immer] ${msg}`);
74
- }
75
- throw new Error(
76
- `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
77
- );
78
- }
79
-
80
- // src/utils/common.ts
81
- var O = Object;
82
- var getPrototypeOf = O.getPrototypeOf;
83
- var CONSTRUCTOR = "constructor";
84
- var PROTOTYPE = "prototype";
85
- var CONFIGURABLE = "configurable";
86
- var ENUMERABLE = "enumerable";
87
- var WRITABLE = "writable";
88
- var VALUE = "value";
89
- var isDraft = (value) => !!value && !!value[DRAFT_STATE];
90
- function isDraftable(value) {
91
- if (!value)
92
- return false;
93
- return isPlainObject(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);
94
- }
95
- var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();
96
- var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
97
- function isPlainObject(value) {
98
- if (!value || !isObjectish(value))
99
- return false;
100
- const proto = getPrototypeOf(value);
101
- if (proto === null || proto === O[PROTOTYPE])
102
- return true;
103
- const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];
104
- if (Ctor === Object)
105
- return true;
106
- if (!isFunction(Ctor))
107
- return false;
108
- let ctorString = cachedCtorStrings.get(Ctor);
109
- if (ctorString === void 0) {
110
- ctorString = Function.toString.call(Ctor);
111
- cachedCtorStrings.set(Ctor, ctorString);
112
- }
113
- return ctorString === objectCtorString;
114
- }
115
- function each(obj, iter, strict = true) {
116
- if (getArchtype(obj) === 0 /* Object */) {
117
- const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj);
118
- keys.forEach((key) => {
119
- iter(key, obj[key], obj);
120
- });
121
- } else {
122
- obj.forEach((entry, index) => iter(index, entry, obj));
123
- }
124
- }
125
- function getArchtype(thing) {
126
- const state = thing[DRAFT_STATE];
127
- return state ? state.type_ : isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
128
- }
129
- var has = (thing, prop, type = getArchtype(thing)) => type === 2 /* Map */ ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);
130
- var get = (thing, prop, type = getArchtype(thing)) => (
131
- // @ts-ignore
132
- type === 2 /* Map */ ? thing.get(prop) : thing[prop]
133
- );
134
- var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {
135
- if (type === 2 /* Map */)
136
- thing.set(propOrOldValue, value);
137
- else if (type === 3 /* Set */) {
138
- thing.add(value);
139
- } else
140
- thing[propOrOldValue] = value;
141
- };
142
- function is(x, y) {
143
- if (x === y) {
144
- return x !== 0 || 1 / x === 1 / y;
145
- } else {
146
- return x !== x && y !== y;
147
- }
148
- }
149
- var isArray = Array.isArray;
150
- var isMap = (target) => target instanceof Map;
151
- var isSet = (target) => target instanceof Set;
152
- var isObjectish = (target) => typeof target === "object";
153
- var isFunction = (target) => typeof target === "function";
154
- var isBoolean = (target) => typeof target === "boolean";
155
- var latest = (state) => state.copy_ || state.base_;
156
- var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
157
- function shallowCopy(base, strict) {
158
- if (isMap(base)) {
159
- return new Map(base);
160
- }
161
- if (isSet(base)) {
162
- return new Set(base);
163
- }
164
- if (isArray(base))
165
- return Array[PROTOTYPE].slice.call(base);
166
- const isPlain = isPlainObject(base);
167
- if (strict === true || strict === "class_only" && !isPlain) {
168
- const descriptors = O.getOwnPropertyDescriptors(base);
169
- delete descriptors[DRAFT_STATE];
170
- let keys = Reflect.ownKeys(descriptors);
171
- for (let i = 0; i < keys.length; i++) {
172
- const key = keys[i];
173
- const desc = descriptors[key];
174
- if (desc[WRITABLE] === false) {
175
- desc[WRITABLE] = true;
176
- desc[CONFIGURABLE] = true;
177
- }
178
- if (desc.get || desc.set)
179
- descriptors[key] = {
180
- [CONFIGURABLE]: true,
181
- [WRITABLE]: true,
182
- // could live with !!desc.set as well here...
183
- [ENUMERABLE]: desc[ENUMERABLE],
184
- [VALUE]: base[key]
185
- };
186
- }
187
- return O.create(getPrototypeOf(base), descriptors);
188
- } else {
189
- const proto = getPrototypeOf(base);
190
- if (proto !== null && isPlain) {
191
- return { ...base };
192
- }
193
- const obj = O.create(proto);
194
- return O.assign(obj, base);
195
- }
196
- }
197
- function freeze(obj, deep = false) {
198
- if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
199
- return obj;
200
- if (getArchtype(obj) > 1) {
201
- O.defineProperties(obj, {
202
- set: dontMutateMethodOverride,
203
- add: dontMutateMethodOverride,
204
- clear: dontMutateMethodOverride,
205
- delete: dontMutateMethodOverride
206
- });
207
- }
208
- O.freeze(obj);
209
- if (deep)
210
- each(
211
- obj,
212
- (_key, value) => {
213
- freeze(value, true);
214
- },
215
- false
216
- );
217
- return obj;
218
- }
219
- function dontMutateFrozenCollections() {
220
- die(2);
221
- }
222
- var dontMutateMethodOverride = {
223
- [VALUE]: dontMutateFrozenCollections
224
- };
225
- function isFrozen(obj) {
226
- if (obj === null || !isObjectish(obj))
227
- return true;
228
- return O.isFrozen(obj);
229
- }
230
-
231
- // src/utils/plugins.ts
232
- var PluginMapSet = "MapSet";
233
- var PluginPatches = "Patches";
234
- var plugins = {};
235
- function getPlugin(pluginKey) {
236
- const plugin = plugins[pluginKey];
237
- if (!plugin) {
238
- die(0, pluginKey);
239
- }
240
- return plugin;
241
- }
242
- var isPluginLoaded = (pluginKey) => !!plugins[pluginKey];
243
-
244
- // src/core/scope.ts
245
- var currentScope;
246
- var getCurrentScope = () => currentScope;
247
- var createScope = (parent_, immer_) => ({
248
- drafts_: [],
249
- parent_,
250
- immer_,
251
- // Whenever the modified draft contains a draft from another scope, we
252
- // need to prevent auto-freezing so the unowned draft can be finalized.
253
- canAutoFreeze_: true,
254
- unfinalizedDrafts_: 0,
255
- handledSet_: /* @__PURE__ */ new Set(),
256
- processedForPatches_: /* @__PURE__ */ new Set(),
257
- mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0
258
- });
259
- function usePatchesInScope(scope, patchListener) {
260
- if (patchListener) {
261
- scope.patchPlugin_ = getPlugin(PluginPatches);
262
- scope.patches_ = [];
263
- scope.inversePatches_ = [];
264
- scope.patchListener_ = patchListener;
265
- }
266
- }
267
- function revokeScope(scope) {
268
- leaveScope(scope);
269
- scope.drafts_.forEach(revokeDraft);
270
- scope.drafts_ = null;
271
- }
272
- function leaveScope(scope) {
273
- if (scope === currentScope) {
274
- currentScope = scope.parent_;
275
- }
276
- }
277
- var enterScope = (immer2) => currentScope = createScope(currentScope, immer2);
278
- function revokeDraft(draft) {
279
- const state = draft[DRAFT_STATE];
280
- if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
281
- state.revoke_();
282
- else
283
- state.revoked_ = true;
284
- }
285
-
286
- // src/core/finalize.ts
287
- function processResult(result, scope) {
288
- scope.unfinalizedDrafts_ = scope.drafts_.length;
289
- const baseDraft = scope.drafts_[0];
290
- const isReplaced = result !== void 0 && result !== baseDraft;
291
- if (isReplaced) {
292
- if (baseDraft[DRAFT_STATE].modified_) {
293
- revokeScope(scope);
294
- die(4);
295
- }
296
- if (isDraftable(result)) {
297
- result = finalize(scope, result);
298
- }
299
- const { patchPlugin_ } = scope;
300
- if (patchPlugin_) {
301
- patchPlugin_.generateReplacementPatches_(
302
- baseDraft[DRAFT_STATE].base_,
303
- result,
304
- scope
305
- );
306
- }
307
- } else {
308
- result = finalize(scope, baseDraft);
309
- }
310
- maybeFreeze(scope, result, true);
311
- revokeScope(scope);
312
- if (scope.patches_) {
313
- scope.patchListener_(scope.patches_, scope.inversePatches_);
314
- }
315
- return result !== NOTHING ? result : void 0;
316
- }
317
- function finalize(rootScope, value) {
318
- if (isFrozen(value))
319
- return value;
320
- const state = value[DRAFT_STATE];
321
- if (!state) {
322
- const finalValue = handleValue(value, rootScope.handledSet_, rootScope);
323
- return finalValue;
324
- }
325
- if (!isSameScope(state, rootScope)) {
326
- return value;
327
- }
328
- if (!state.modified_) {
329
- return state.base_;
330
- }
331
- if (!state.finalized_) {
332
- const { callbacks_ } = state;
333
- if (callbacks_) {
334
- while (callbacks_.length > 0) {
335
- const callback = callbacks_.pop();
336
- callback(rootScope);
337
- }
338
- }
339
- generatePatchesAndFinalize(state, rootScope);
340
- }
341
- return state.copy_;
342
- }
343
- function maybeFreeze(scope, value, deep = false) {
344
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
345
- freeze(value, deep);
346
- }
347
- }
348
- function markStateFinalized(state) {
349
- state.finalized_ = true;
350
- state.scope_.unfinalizedDrafts_--;
351
- }
352
- var isSameScope = (state, rootScope) => state.scope_ === rootScope;
353
- var EMPTY_LOCATIONS_RESULT = [];
354
- function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {
355
- const parentCopy = latest(parent);
356
- const parentType = parent.type_;
357
- if (originalKey !== void 0) {
358
- const currentValue = get(parentCopy, originalKey, parentType);
359
- if (currentValue === draftValue) {
360
- set(parentCopy, originalKey, finalizedValue, parentType);
361
- return;
362
- }
363
- }
364
- if (!parent.draftLocations_) {
365
- const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();
366
- each(parentCopy, (key, value) => {
367
- if (isDraft(value)) {
368
- const keys = draftLocations.get(value) || [];
369
- keys.push(key);
370
- draftLocations.set(value, keys);
371
- }
372
- });
373
- }
374
- const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;
375
- for (const location of locations) {
376
- set(parentCopy, location, finalizedValue, parentType);
377
- }
378
- }
379
- function registerChildFinalizationCallback(parent, child, key) {
380
- parent.callbacks_.push(function childCleanup(rootScope) {
381
- const state = child;
382
- if (!state || !isSameScope(state, rootScope)) {
383
- return;
384
- }
385
- rootScope.mapSetPlugin_?.fixSetContents(state);
386
- const finalizedValue = getFinalValue(state);
387
- updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);
388
- generatePatchesAndFinalize(state, rootScope);
389
- });
390
- }
391
- function generatePatchesAndFinalize(state, rootScope) {
392
- const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || (state.assigned_?.size ?? 0) > 0);
393
- if (shouldFinalize) {
394
- const { patchPlugin_ } = rootScope;
395
- if (patchPlugin_) {
396
- const basePath = patchPlugin_.getPath(state);
397
- if (basePath) {
398
- patchPlugin_.generatePatches_(state, basePath, rootScope);
399
- }
400
- }
401
- markStateFinalized(state);
402
- }
403
- }
404
- function handleCrossReference(target, key, value) {
405
- const { scope_ } = target;
406
- if (isDraft(value)) {
407
- const state = value[DRAFT_STATE];
408
- if (isSameScope(state, scope_)) {
409
- state.callbacks_.push(function crossReferenceCleanup() {
410
- prepareCopy(target);
411
- const finalizedValue = getFinalValue(state);
412
- updateDraftInParent(target, value, finalizedValue, key);
413
- });
414
- }
415
- } else if (isDraftable(value)) {
416
- target.callbacks_.push(function nestedDraftCleanup() {
417
- const targetCopy = latest(target);
418
- if (get(targetCopy, key, target.type_) === value) {
419
- if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {
420
- handleValue(
421
- get(target.copy_, key, target.type_),
422
- scope_.handledSet_,
423
- scope_
424
- );
425
- }
426
- }
427
- });
428
- }
429
- }
430
- function handleValue(target, handledSet, rootScope) {
431
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
432
- return target;
433
- }
434
- if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) {
435
- return target;
436
- }
437
- handledSet.add(target);
438
- each(target, (key, value) => {
439
- if (isDraft(value)) {
440
- const state = value[DRAFT_STATE];
441
- if (isSameScope(state, rootScope)) {
442
- const updatedValue = getFinalValue(state);
443
- set(target, key, updatedValue, target.type_);
444
- markStateFinalized(state);
445
- }
446
- } else if (isDraftable(value)) {
447
- handleValue(value, handledSet, rootScope);
448
- }
449
- });
450
- return target;
451
- }
452
-
453
- // src/core/proxy.ts
454
- function createProxyProxy(base, parent) {
455
- const baseIsArray = isArray(base);
456
- const state = {
457
- type_: baseIsArray ? 1 /* Array */ : 0 /* Object */,
458
- // Track which produce call this is associated with.
459
- scope_: parent ? parent.scope_ : getCurrentScope(),
460
- // True for both shallow and deep changes.
461
- modified_: false,
462
- // Used during finalization.
463
- finalized_: false,
464
- // Track which properties have been assigned (true) or deleted (false).
465
- // actually instantiated in `prepareCopy()`
466
- assigned_: void 0,
467
- // The parent draft state.
468
- parent_: parent,
469
- // The base state.
470
- base_: base,
471
- // The base proxy.
472
- draft_: null,
473
- // set below
474
- // The base copy with any updated values.
475
- copy_: null,
476
- // Called by the `produce` function.
477
- revoke_: null,
478
- isManual_: false,
479
- // `callbacks` actually gets assigned in `createProxy`
480
- callbacks_: void 0
481
- };
482
- let target = state;
483
- let traps = objectTraps;
484
- if (baseIsArray) {
485
- target = [state];
486
- traps = arrayTraps;
487
- }
488
- const { revoke, proxy } = Proxy.revocable(target, traps);
489
- state.draft_ = proxy;
490
- state.revoke_ = revoke;
491
- return [proxy, state];
492
- }
493
- var objectTraps = {
494
- get(state, prop) {
495
- if (prop === DRAFT_STATE)
496
- return state;
497
- const source = latest(state);
498
- if (!has(source, prop, state.type_)) {
499
- return readPropFromProto(state, source, prop);
500
- }
501
- const value = source[prop];
502
- if (state.finalized_ || !isDraftable(value)) {
503
- return value;
504
- }
505
- if (value === peek(state.base_, prop)) {
506
- prepareCopy(state);
507
- const childKey = state.type_ === 1 /* Array */ ? +prop : prop;
508
- const childDraft = createProxy(state.scope_, value, state, childKey);
509
- return state.copy_[childKey] = childDraft;
510
- }
511
- return value;
512
- },
513
- has(state, prop) {
514
- return prop in latest(state);
515
- },
516
- ownKeys(state) {
517
- return Reflect.ownKeys(latest(state));
518
- },
519
- set(state, prop, value) {
520
- const desc = getDescriptorFromProto(latest(state), prop);
521
- if (desc?.set) {
522
- desc.set.call(state.draft_, value);
523
- return true;
524
- }
525
- if (!state.modified_) {
526
- const current2 = peek(latest(state), prop);
527
- const currentState = current2?.[DRAFT_STATE];
528
- if (currentState && currentState.base_ === value) {
529
- state.copy_[prop] = value;
530
- state.assigned_.set(prop, false);
531
- return true;
532
- }
533
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_)))
534
- return true;
535
- prepareCopy(state);
536
- markChanged(state);
537
- }
538
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
539
- (value !== void 0 || prop in state.copy_) || // special case: NaN
540
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
541
- return true;
542
- state.copy_[prop] = value;
543
- state.assigned_.set(prop, true);
544
- handleCrossReference(state, prop, value);
545
- return true;
546
- },
547
- deleteProperty(state, prop) {
548
- prepareCopy(state);
549
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
550
- state.assigned_.set(prop, false);
551
- markChanged(state);
552
- } else {
553
- state.assigned_.delete(prop);
554
- }
555
- if (state.copy_) {
556
- delete state.copy_[prop];
557
- }
558
- return true;
559
- },
560
- // Note: We never coerce `desc.value` into an Immer draft, because we can't make
561
- // the same guarantee in ES5 mode.
562
- getOwnPropertyDescriptor(state, prop) {
563
- const owner = latest(state);
564
- const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
565
- if (!desc)
566
- return desc;
567
- return {
568
- [WRITABLE]: true,
569
- [CONFIGURABLE]: state.type_ !== 1 /* Array */ || prop !== "length",
570
- [ENUMERABLE]: desc[ENUMERABLE],
571
- [VALUE]: owner[prop]
572
- };
573
- },
574
- defineProperty() {
575
- die(11);
576
- },
577
- getPrototypeOf(state) {
578
- return getPrototypeOf(state.base_);
579
- },
580
- setPrototypeOf() {
581
- die(12);
582
- }
583
- };
584
- var arrayTraps = {};
585
- each(objectTraps, (key, fn) => {
586
- arrayTraps[key] = function() {
587
- const args = arguments;
588
- args[0] = args[0][0];
589
- return fn.apply(this, args);
590
- };
591
- });
592
- arrayTraps.deleteProperty = function(state, prop) {
593
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
594
- die(13);
595
- return arrayTraps.set.call(this, state, prop, void 0);
596
- };
597
- arrayTraps.set = function(state, prop, value) {
598
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
599
- die(14);
600
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
601
- };
602
- function peek(draft, prop) {
603
- const state = draft[DRAFT_STATE];
604
- const source = state ? latest(state) : draft;
605
- return source[prop];
606
- }
607
- function readPropFromProto(state, source, prop) {
608
- const desc = getDescriptorFromProto(source, prop);
609
- return desc ? VALUE in desc ? desc[VALUE] : (
610
- // This is a very special case, if the prop is a getter defined by the
611
- // prototype, we should invoke it with the draft as context!
612
- desc.get?.call(state.draft_)
613
- ) : void 0;
614
- }
615
- function getDescriptorFromProto(source, prop) {
616
- if (!(prop in source))
617
- return void 0;
618
- let proto = getPrototypeOf(source);
619
- while (proto) {
620
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
621
- if (desc)
622
- return desc;
623
- proto = getPrototypeOf(proto);
624
- }
625
- return void 0;
626
- }
627
- function markChanged(state) {
628
- if (!state.modified_) {
629
- state.modified_ = true;
630
- if (state.parent_) {
631
- markChanged(state.parent_);
632
- }
633
- }
634
- }
635
- function prepareCopy(state) {
636
- if (!state.copy_) {
637
- state.assigned_ = /* @__PURE__ */ new Map();
638
- state.copy_ = shallowCopy(
639
- state.base_,
640
- state.scope_.immer_.useStrictShallowCopy_
641
- );
642
- }
643
- }
644
-
645
- // src/core/immerClass.ts
646
- var Immer2 = class {
647
- constructor(config) {
648
- this.autoFreeze_ = true;
649
- this.useStrictShallowCopy_ = false;
650
- this.useStrictIteration_ = false;
651
- /**
652
- * The `produce` function takes a value and a "recipe function" (whose
653
- * return value often depends on the base state). The recipe function is
654
- * free to mutate its first argument however it wants. All mutations are
655
- * only ever applied to a __copy__ of the base state.
656
- *
657
- * Pass only a function to create a "curried producer" which relieves you
658
- * from passing the recipe function every time.
659
- *
660
- * Only plain objects and arrays are made mutable. All other objects are
661
- * considered uncopyable.
662
- *
663
- * Note: This function is __bound__ to its `Immer` instance.
664
- *
665
- * @param {any} base - the initial state
666
- * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
667
- * @param {Function} patchListener - optional function that will be called with all the patches produced here
668
- * @returns {any} a new state, or the initial state if nothing was modified
669
- */
670
- this.produce = (base, recipe, patchListener) => {
671
- if (isFunction(base) && !isFunction(recipe)) {
672
- const defaultBase = recipe;
673
- recipe = base;
674
- const self = this;
675
- return function curriedProduce(base2 = defaultBase, ...args) {
676
- return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
677
- };
678
- }
679
- if (!isFunction(recipe))
680
- die(6);
681
- if (patchListener !== void 0 && !isFunction(patchListener))
682
- die(7);
683
- let result;
684
- if (isDraftable(base)) {
685
- const scope = enterScope(this);
686
- const proxy = createProxy(scope, base, void 0);
687
- let hasError = true;
688
- try {
689
- result = recipe(proxy);
690
- hasError = false;
691
- } finally {
692
- if (hasError)
693
- revokeScope(scope);
694
- else
695
- leaveScope(scope);
696
- }
697
- usePatchesInScope(scope, patchListener);
698
- return processResult(result, scope);
699
- } else if (!base || !isObjectish(base)) {
700
- result = recipe(base);
701
- if (result === void 0)
702
- result = base;
703
- if (result === NOTHING)
704
- result = void 0;
705
- if (this.autoFreeze_)
706
- freeze(result, true);
707
- if (patchListener) {
708
- const p = [];
709
- const ip = [];
710
- getPlugin(PluginPatches).generateReplacementPatches_(base, result, {
711
- patches_: p,
712
- inversePatches_: ip
713
- });
714
- patchListener(p, ip);
715
- }
716
- return result;
717
- } else
718
- die(1, base);
719
- };
720
- this.produceWithPatches = (base, recipe) => {
721
- if (isFunction(base)) {
722
- return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
723
- }
724
- let patches, inversePatches;
725
- const result = this.produce(base, recipe, (p, ip) => {
726
- patches = p;
727
- inversePatches = ip;
728
- });
729
- return [result, patches, inversePatches];
730
- };
731
- if (isBoolean(config?.autoFreeze))
732
- this.setAutoFreeze(config.autoFreeze);
733
- if (isBoolean(config?.useStrictShallowCopy))
734
- this.setUseStrictShallowCopy(config.useStrictShallowCopy);
735
- if (isBoolean(config?.useStrictIteration))
736
- this.setUseStrictIteration(config.useStrictIteration);
737
- }
738
- createDraft(base) {
739
- if (!isDraftable(base))
740
- die(8);
741
- if (isDraft(base))
742
- base = current(base);
743
- const scope = enterScope(this);
744
- const proxy = createProxy(scope, base, void 0);
745
- proxy[DRAFT_STATE].isManual_ = true;
746
- leaveScope(scope);
747
- return proxy;
748
- }
749
- finishDraft(draft, patchListener) {
750
- const state = draft && draft[DRAFT_STATE];
751
- if (!state || !state.isManual_)
752
- die(9);
753
- const { scope_: scope } = state;
754
- usePatchesInScope(scope, patchListener);
755
- return processResult(void 0, scope);
756
- }
757
- /**
758
- * Pass true to automatically freeze all copies created by Immer.
759
- *
760
- * By default, auto-freezing is enabled.
761
- */
762
- setAutoFreeze(value) {
763
- this.autoFreeze_ = value;
764
- }
765
- /**
766
- * Pass true to enable strict shallow copy.
767
- *
768
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
769
- */
770
- setUseStrictShallowCopy(value) {
771
- this.useStrictShallowCopy_ = value;
772
- }
773
- /**
774
- * Pass false to use faster iteration that skips non-enumerable properties
775
- * but still handles symbols for compatibility.
776
- *
777
- * By default, strict iteration is enabled (includes all own properties).
778
- */
779
- setUseStrictIteration(value) {
780
- this.useStrictIteration_ = value;
781
- }
782
- shouldUseStrictIteration() {
783
- return this.useStrictIteration_;
784
- }
785
- applyPatches(base, patches) {
786
- let i;
787
- for (i = patches.length - 1; i >= 0; i--) {
788
- const patch = patches[i];
789
- if (patch.path.length === 0 && patch.op === "replace") {
790
- base = patch.value;
791
- break;
792
- }
793
- }
794
- if (i > -1) {
795
- patches = patches.slice(i + 1);
796
- }
797
- const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;
798
- if (isDraft(base)) {
799
- return applyPatchesImpl(base, patches);
800
- }
801
- return this.produce(
802
- base,
803
- (draft) => applyPatchesImpl(draft, patches)
804
- );
805
- }
806
- };
807
- function createProxy(rootScope, value, parent, key) {
808
- const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);
809
- const scope = parent?.scope_ ?? getCurrentScope();
810
- scope.drafts_.push(draft);
811
- state.callbacks_ = parent?.callbacks_ ?? [];
812
- state.key_ = key;
813
- if (parent && key !== void 0) {
814
- registerChildFinalizationCallback(parent, state, key);
815
- } else {
816
- state.callbacks_.push(function rootDraftCleanup(rootScope2) {
817
- rootScope2.mapSetPlugin_?.fixSetContents(state);
818
- const { patchPlugin_ } = rootScope2;
819
- if (state.modified_ && patchPlugin_) {
820
- patchPlugin_.generatePatches_(state, [], rootScope2);
821
- }
822
- });
823
- }
824
- return draft;
825
- }
826
-
827
- // src/core/current.ts
828
- function current(value) {
829
- if (!isDraft(value))
830
- die(10, value);
831
- return currentImpl(value);
832
- }
833
- function currentImpl(value) {
834
- if (!isDraftable(value) || isFrozen(value))
835
- return value;
836
- const state = value[DRAFT_STATE];
837
- let copy;
838
- let strict = true;
839
- if (state) {
840
- if (!state.modified_)
841
- return state.base_;
842
- state.finalized_ = true;
843
- copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
844
- strict = state.scope_.immer_.shouldUseStrictIteration();
845
- } else {
846
- copy = shallowCopy(value, true);
847
- }
848
- each(
849
- copy,
850
- (key, childValue) => {
851
- set(copy, key, currentImpl(childValue));
852
- },
853
- strict
854
- );
855
- if (state) {
856
- state.finalized_ = false;
857
- }
858
- return copy;
859
- }
860
-
861
- // src/immer.ts
862
- var immer = new Immer2();
863
- var produce = immer.produce;
864
- var castDraft = (value) => value;
865
-
866
- function buildElementNotations(nodes) {
867
- return t$9(
868
- nodes,
869
- n$5((n) => !!n.notation),
870
- t$4(e$2("notation")),
871
- t$3(
872
- t$1(
873
- t$4(e$2("shape")),
874
- t$3(
875
- t$1(
876
- t$4(e$2("color")),
877
- t$3(
878
- t$1(
879
- t$b(e$2("kind")),
880
- n$6()
881
- )
882
- ),
883
- t$a(),
884
- t$b(([color, kinds]) => ({
885
- kinds,
886
- color
887
- }))
888
- )
889
- ),
890
- t$a(),
891
- t$5(
892
- ([shape, colors]) => colors.map(({ color, kinds }) => ({
893
- shape,
894
- color,
895
- kinds
896
- }))
897
- )
898
- )
899
- ),
900
- t$a(),
901
- t$5(
902
- ([title, shapes]) => shapes.map(({ shape, color, kinds }) => ({
903
- title,
904
- shape,
905
- color,
906
- kinds
907
- }))
908
- ),
909
- t(
910
- e$2("shape"),
911
- e$2("title"),
912
- [
913
- (n) => n.kinds.length,
914
- "desc"
915
- ]
916
- )
917
- );
918
- }
919
-
920
- const changed = (a, b) => {
921
- if (a === b || e$3(a) && e$3(b)) {
922
- return false;
923
- }
924
- return !t$d(a, b);
925
- };
926
- const MAX_ALLOWED_DRIFT = 5;
927
- function autoApplyMetaAndStyles(draft, next) {
928
- draft.color = next.color;
929
- draft.kind = next.kind;
930
- draft.navigateTo = next.navigateTo ?? null;
931
- draft.links = next.links ? [...next.links] : null;
932
- draft.tags = [...next.tags];
933
- if (e$3(next.style.border)) {
934
- delete draft.style.border;
935
- } else {
936
- draft.style.border = next.style.border;
937
- }
938
- if (e(next.style.opacity)) {
939
- draft.style.opacity = next.style.opacity;
940
- } else {
941
- delete draft.style.opacity;
942
- }
943
- if (e$3(next.style.multiple)) {
944
- delete draft.style.multiple;
945
- } else {
946
- draft.style.multiple = next.style.multiple;
947
- }
948
- }
949
- function autoApplyIcon(draft, next, sizeNotChanged) {
950
- if (changed(next.icon ?? "none", draft.icon ?? "none")) {
951
- const iconWasSet = e$4(draft.icon) && draft.icon !== "none";
952
- switch (true) {
953
- // Icon was set before and changed, auto-apply
954
- case (iconWasSet && e$4(next.icon) && next.icon !== "none"): {
955
- draft.icon = next.icon;
956
- return true;
957
- }
958
- // Icon was set before and now removed, auto-apply
959
- case (iconWasSet && (e$3(next.icon) || next.icon === "none")): {
960
- draft.icon = "none";
961
- return true;
962
- }
963
- // Icon was added
964
- case (!iconWasSet && e$4(next.icon) && next.icon !== "none"): {
965
- if (sizeNotChanged) {
966
- draft.icon = next.icon;
967
- return true;
968
- } else {
969
- return false;
970
- }
971
- }
972
- }
973
- }
974
- return true;
975
- }
976
- function patchMarkdownOrString(draft, next) {
977
- if (!draft) {
978
- return next;
979
- }
980
- if ("md" in next) {
981
- draft.md = next.md;
982
- delete draft.txt;
983
- return draft;
984
- }
985
- if ("txt" in next) {
986
- draft.txt = next.txt;
987
- delete draft.md;
988
- }
989
- return draft;
990
- }
991
- function autoApplyLabelsToLeaf(draft, next, sizeNotChanged) {
992
- let applied = true;
993
- if (changed(draft.title, next.title)) {
994
- if (sizeNotChanged) {
995
- draft.title = next.title;
996
- } else {
997
- applied = false;
998
- }
999
- }
1000
- if (changed(draft.description, next.description)) {
1001
- if (e$3(next.description)) {
1002
- delete draft.description;
1003
- } else if (sizeNotChanged) {
1004
- draft.description = patchMarkdownOrString(
1005
- draft.description,
1006
- next.description
1007
- );
1008
- } else {
1009
- applied = false;
1010
- }
1011
- }
1012
- if (changed(draft.technology, next.technology)) {
1013
- if (e$3(next.technology)) {
1014
- delete draft.technology;
1015
- } else if (sizeNotChanged) {
1016
- draft.technology = next.technology;
1017
- } else {
1018
- applied = false;
1019
- }
1020
- }
1021
- return applied;
1022
- }
1023
- function autoApplyLabelsToCompound(draft, next, _sizeNotChanged) {
1024
- draft.title = next.title;
1025
- if (e$3(next.description)) {
1026
- delete draft.description;
1027
- } else {
1028
- draft.description = patchMarkdownOrString(
1029
- draft.description,
1030
- next.description
1031
- );
1032
- }
1033
- if (e$3(next.technology)) {
1034
- delete draft.technology;
1035
- } else {
1036
- draft.technology = next.technology;
1037
- }
1038
- return true;
1039
- }
1040
- function applyManualLayout(autoLayouted, snapshot) {
1041
- invariant(autoLayouted.id === snapshot.id, "applyManualLayout: view ids do not match");
1042
- invariant(autoLayouted._stage === "layouted", "applyManualLayout: expected layouted view");
1043
- invariant(snapshot._stage === "layouted", "applyManualLayout: expected layouted snapshot");
1044
- invariant(autoLayouted._layout !== "manual", "applyManualLayout: expected auto-layouted view");
1045
- const viewDrifts = /* @__PURE__ */ new Set();
1046
- if (autoLayouted._type !== snapshot._type) {
1047
- viewDrifts.add("type-changed");
1048
- }
1049
- const nextNodes = new Map(autoLayouted.nodes.map((n) => [n.id, n]));
1050
- const nextEdges = new Map(autoLayouted.edges.map((e) => [e.id, e]));
1051
- const nodes = applyNodesManualLayout(snapshot.nodes, nextNodes, viewDrifts);
1052
- const edges = applyEdgesManualLayout(snapshot.edges, nextEdges, viewDrifts);
1053
- const nodeNotations = buildElementNotations(nodes);
1054
- const result = Object.assign(
1055
- { ...snapshot },
1056
- {
1057
- // Auto-layouted properties
1058
- title: autoLayouted.title ?? snapshot.title,
1059
- description: autoLayouted.description ?? snapshot.description,
1060
- tags: autoLayouted.tags ? [...autoLayouted.tags] : null,
1061
- links: autoLayouted.links ? [...autoLayouted.links] : null,
1062
- [_layout]: "manual",
1063
- ...nodeNotations && nodeNotations.length > 0 ? { notation: { nodes: nodeNotations } } : {},
1064
- nodes,
1065
- edges
1066
- }
1067
- );
1068
- if (isDynamicView(autoLayouted) && result._type === "dynamic") {
1069
- result.variant = autoLayouted.variant;
1070
- }
1071
- const drifts = [...viewDrifts];
1072
- if (t$c(drifts, 1)) {
1073
- result.drifts = drifts;
1074
- } else {
1075
- if ("drifts" in result) {
1076
- delete result.drifts;
1077
- }
1078
- }
1079
- return result;
1080
- }
1081
- function applyNodesManualLayout(snapshotNodes, nextNodes, viewDrifts) {
1082
- const nodes = snapshotNodes.map((node) => {
1083
- const next = nextNodes.get(node.id);
1084
- if (next) {
1085
- nextNodes.delete(next.id);
1086
- }
1087
- return produce(node, (draft) => {
1088
- if (!next) {
1089
- draft.drifts = ["removed"];
1090
- viewDrifts.add("nodes-removed");
1091
- return;
1092
- }
1093
- autoApplyMetaAndStyles(draft, next);
1094
- const nodeDrifts = /* @__PURE__ */ new Set();
1095
- const wasCompound = node.children.length > 0;
1096
- const willBeCompound = next.children.length > 0;
1097
- if (changed(draft.modelRef, next.modelRef) || changed(draft.deploymentRef, next.deploymentRef)) {
1098
- nodeDrifts.add("modelRef-changed");
1099
- }
1100
- if (willBeCompound && !wasCompound) {
1101
- nodeDrifts.add("became-compound");
1102
- }
1103
- if (!willBeCompound && wasCompound) {
1104
- nodeDrifts.add("became-leaf");
1105
- }
1106
- if (changed(draft.parent, next.parent)) {
1107
- nodeDrifts.add("parent-changed");
1108
- }
1109
- const sizeNotChanged = draft.width + MAX_ALLOWED_DRIFT >= next.width && draft.height + MAX_ALLOWED_DRIFT >= next.height;
1110
- if (changed(draft.shape, next.shape)) {
1111
- if (sizeNotChanged) {
1112
- draft.shape = next.shape;
1113
- } else {
1114
- nodeDrifts.add("shape-changed");
1115
- }
1116
- }
1117
- if (!autoApplyIcon(draft, next, sizeNotChanged && willBeCompound === wasCompound)) {
1118
- nodeDrifts.add("label-changed");
1119
- }
1120
- const autoApplyLabels = wasCompound ? autoApplyLabelsToCompound : autoApplyLabelsToLeaf;
1121
- if (!autoApplyLabels(draft, next, sizeNotChanged)) {
1122
- nodeDrifts.add("label-changed");
1123
- }
1124
- if (changed(node.notation, next.notation)) {
1125
- draft.notation = next.notation ?? null;
1126
- }
1127
- if (wasCompound && willBeCompound && symmetricDifference(new Set(node.children), new Set(next.children)).size > 0) {
1128
- nodeDrifts.add("children-changed");
1129
- }
1130
- const _drifts = [...nodeDrifts];
1131
- if (t$c(_drifts, 1)) {
1132
- viewDrifts.add("nodes-drift");
1133
- draft.drifts = _drifts;
1134
- } else {
1135
- delete draft.drifts;
1136
- }
1137
- });
1138
- });
1139
- if (nextNodes.size > 0) {
1140
- viewDrifts.add("nodes-added");
1141
- }
1142
- return nodes;
1143
- }
1144
- function applyEdgesManualLayout(snapshotEdges, nextEdges, viewDrifts) {
1145
- const edges = snapshotEdges.map((edge) => {
1146
- let next = nextEdges.get(edge.id) ?? t$9(
1147
- nextEdges.values(),
1148
- ifilter((e) => e.source === edge.source && e.target === edge.target),
1149
- ihead()
1150
- );
1151
- if (next) {
1152
- nextEdges.delete(next.id);
1153
- }
1154
- return produce(edge, (draft) => {
1155
- if (!next) {
1156
- draft.drifts = ["removed"];
1157
- viewDrifts.add("edges-removed");
1158
- return;
1159
- }
1160
- const edgeDrifts = /* @__PURE__ */ new Set();
1161
- const isSameId = edge.id === next.id;
1162
- switch (true) {
1163
- // IDs match, but source/target may have changed
1164
- case (isSameId && edge.source == next.source && edge.target == next.target): {
1165
- if (changed(draft.dir ?? "forward", next.dir ?? "forward")) {
1166
- edgeDrifts.add("direction-changed");
1167
- }
1168
- break;
1169
- }
1170
- case (isSameId && edge.source == next.target && edge.target == next.source): {
1171
- if (edge.source !== edge.target) {
1172
- edgeDrifts.add("direction-changed");
1173
- }
1174
- break;
1175
- }
1176
- case isSameId: {
1177
- if (edge.source != next.source) {
1178
- edgeDrifts.add("source-changed");
1179
- }
1180
- if (edge.target != next.target) {
1181
- edgeDrifts.add("target-changed");
1182
- }
1183
- break;
1184
- }
1185
- default: {
1186
- invariant(edge.id != next.id, "Unexpected case in edge drift detection, ids should not match");
1187
- invariant(edge.source == next.source, "Unexpected case in edge drift detection, sources should match");
1188
- invariant(edge.target == next.target, "Unexpected case in edge drift detection, targets should match");
1189
- if (changed(draft.dir ?? "forward", next.dir ?? "forward")) {
1190
- edgeDrifts.add("direction-changed");
1191
- }
1192
- break;
1193
- }
1194
- }
1195
- draft.color = next.color;
1196
- draft.line = next.line;
1197
- draft.navigateTo = next.navigateTo ?? null;
1198
- draft.tags = next.tags ? [...next.tags] : null;
1199
- if (changed(edge.notes, next.notes)) {
1200
- if (e$3(edge.notes) !== e$3(next.notes)) {
1201
- edgeDrifts.add("notes-changed");
1202
- }
1203
- draft.notes = next.notes ?? edge.notes;
1204
- }
1205
- if (next.astPath) {
1206
- draft.astPath = next.astPath;
1207
- } else {
1208
- delete draft.astPath;
1209
- }
1210
- const labelsBefore = t$2(edge, ["label", "description", "technology", "labelBBox"]);
1211
- const labelsAfter = t$2(next, ["label", "description", "technology", "labelBBox"]);
1212
- if (changed(labelsBefore, labelsAfter)) {
1213
- switch (true) {
1214
- case (next.labelBBox && !edge.labelBBox): {
1215
- edgeDrifts.add("label-added");
1216
- break;
1217
- }
1218
- case (edge.labelBBox && !next.labelBBox): {
1219
- edgeDrifts.add("label-removed");
1220
- break;
1221
- }
1222
- case (!!edge.labelBBox && !!next.labelBBox): {
1223
- const sizeChanged = next.labelBBox.width * next.labelBBox.height > (edge.labelBBox.width + MAX_ALLOWED_DRIFT) * (edge.labelBBox.height + MAX_ALLOWED_DRIFT);
1224
- if (sizeChanged) {
1225
- draft.labelBBox.width = Math.round(next.labelBBox.width);
1226
- draft.labelBBox.height = Math.round(next.labelBBox.height);
1227
- }
1228
- if (changed(edge.label, next.label)) {
1229
- if (e$3(next.label) !== e$3(edge.label)) {
1230
- edgeDrifts.add("label-changed");
1231
- }
1232
- draft.label = next.label ?? edge.label;
1233
- }
1234
- if (changed(edge.description, next.description)) {
1235
- if (e$3(next.description) !== e$3(edge.description)) {
1236
- edgeDrifts.add("label-changed");
1237
- }
1238
- if (next.description) {
1239
- draft.description = patchMarkdownOrString(
1240
- edge.description,
1241
- next.description
1242
- );
1243
- }
1244
- }
1245
- if (changed(edge.technology, next.technology)) {
1246
- if (e$3(next.technology) !== e$3(edge.technology)) {
1247
- edgeDrifts.add("label-changed");
1248
- }
1249
- draft.technology = next.technology ?? edge.technology ?? null;
1250
- }
1251
- break;
1252
- }
1253
- default:
1254
- invariant(!edge.labelBBox, "Unexpected case in edge labelBBox drift detection");
1255
- invariant(!next.labelBBox, "Unexpected case in next labelBBox drift detection");
1256
- break;
1257
- }
1258
- }
1259
- const _drifts = [...edgeDrifts];
1260
- if (t$c(_drifts, 1)) {
1261
- viewDrifts.add("edges-drift");
1262
- draft.drifts = _drifts;
1263
- } else {
1264
- delete draft.drifts;
1265
- }
1266
- });
1267
- });
1268
- if (nextEdges.size > 0) {
1269
- viewDrifts.add("edges-added");
1270
- }
1271
- return edges;
1272
- }
1273
-
1274
- function calcDriftsFromSnapshot(autoLayouted, snapshot) {
1275
- const {
1276
- drifts,
1277
- ...manual
1278
- } = applyManualLayout(autoLayouted, snapshot);
1279
- if (drifts) {
1280
- const viewDrifts = /* @__PURE__ */ new Set();
1281
- if (drifts.includes("type-changed")) {
1282
- viewDrifts.add("type-changed");
1283
- }
1284
- const manualNodes = new Map(manual.nodes.map((n) => [n.id, n]));
1285
- const manualEdges = new Map(manual.edges.map((e) => [e.id, e]));
1286
- const nodes = autoLayouted.nodes.map((node) => {
1287
- const snapshotNode = manualNodes.get(node.id);
1288
- if (snapshotNode) {
1289
- manualNodes.delete(snapshotNode.id);
1290
- }
1291
- return produce(node, (draft) => {
1292
- if (!snapshotNode) {
1293
- viewDrifts.add("nodes-added");
1294
- draft.drifts = ["added"];
1295
- return;
1296
- }
1297
- if (snapshotNode.drifts) {
1298
- viewDrifts.add("nodes-drift");
1299
- draft.drifts = [...snapshotNode.drifts];
1300
- } else {
1301
- delete draft.drifts;
1302
- }
1303
- });
1304
- });
1305
- if (manualNodes.size > 0) {
1306
- viewDrifts.add("nodes-removed");
1307
- }
1308
- const edges = autoLayouted.edges.map((edge) => {
1309
- const snapshotEdge = manualEdges.get(edge.id) ?? t$9(
1310
- manualEdges.values(),
1311
- ifilter((e) => e.source === edge.source && e.target === edge.target),
1312
- ihead()
1313
- );
1314
- if (snapshotEdge) {
1315
- manualEdges.delete(snapshotEdge.id);
1316
- }
1317
- return produce(edge, (draft) => {
1318
- if (!snapshotEdge) {
1319
- viewDrifts.add("edges-added");
1320
- draft.drifts = ["added"];
1321
- return;
1322
- }
1323
- if (snapshotEdge.drifts) {
1324
- viewDrifts.add("edges-drift");
1325
- draft.drifts = [...snapshotEdge.drifts];
1326
- } else {
1327
- delete draft.drifts;
1328
- }
1329
- });
1330
- });
1331
- if (manualEdges.size > 0) {
1332
- viewDrifts.add("edges-removed");
1333
- }
1334
- const _viewDrifts = [...viewDrifts];
1335
- return produce(autoLayouted, (draft) => {
1336
- if (t$c(_viewDrifts, 1)) {
1337
- draft.drifts = _viewDrifts;
1338
- } else {
1339
- delete draft.drifts;
1340
- }
1341
- draft.nodes = castDraft(nodes);
1342
- draft.edges = castDraft(edges);
1343
- draft[_layout] = "auto";
1344
- });
1345
- }
1346
- return produce(autoLayouted, (draft) => {
1347
- delete draft.drifts;
1348
- draft[_layout] = "auto";
1349
- });
1350
- }
1351
-
1352
- export { applyManualLayout as a, t$2 as b, calcDriftsFromSnapshot as c, t$1 as d, t$4 as e, t$5 as f, buildElementNotations as g, t as h, n$5 as n, t$3 as t };