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