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