@likec4/diagram 1.0.0-next.1 → 1.0.0-next.11

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 (68) hide show
  1. package/dist/cjs/index.cjs +4596 -0
  2. package/dist/esm/index.mjs +4596 -0
  3. package/dist/style.css +1 -1
  4. package/dist/{EmbeddedLikeC4Diagram.css.d.ts → types/EmbeddedLikeC4Diagram.css.d.ts} +0 -1
  5. package/dist/{EmbeddedLikeC4Diagram.d.ts → types/EmbeddedLikeC4Diagram.d.ts} +0 -1
  6. package/dist/{LikeC4Diagram.css.d.ts → types/LikeC4Diagram.css.d.ts} +0 -1
  7. package/dist/{LikeC4Diagram.d.ts → types/LikeC4Diagram.d.ts} +0 -1
  8. package/dist/{LikeC4Diagram.props.d.ts → types/LikeC4Diagram.props.d.ts} +5 -5
  9. package/dist/{StaticLikeC4Diagram.d.ts → types/StaticLikeC4Diagram.d.ts} +0 -1
  10. package/dist/{hooks → types/hooks}/index.d.ts +0 -1
  11. package/dist/{hooks → types/hooks}/use-set-state.d.ts +0 -1
  12. package/dist/types/hooks/use-update-effect.d.ts +3 -0
  13. package/dist/{icons → types/icons}/Clipboard.d.ts +0 -1
  14. package/dist/{icons → types/icons}/Link.d.ts +0 -1
  15. package/dist/{icons → types/icons}/ZoomIn.d.ts +0 -1
  16. package/dist/{icons → types/icons}/index.d.ts +0 -1
  17. package/dist/types/index.css.d.ts +1 -0
  18. package/dist/types/index.d.ts +9 -0
  19. package/dist/{mantine → types/mantine}/EnsureMantine.d.ts +0 -1
  20. package/dist/{mantine → types/mantine}/index.d.ts +0 -1
  21. package/dist/{state → types/state}/DiagramState.d.ts +0 -1
  22. package/dist/types/state/index.d.ts +1 -0
  23. package/dist/{theme.css.d.ts → types/theme.css.d.ts} +0 -1
  24. package/dist/{ui → types/ui}/Camera.d.ts +0 -1
  25. package/dist/types/ui/KeepAspectRatio.css.d.ts +1 -0
  26. package/dist/{ui → types/ui}/KeepAspectRatio.d.ts +0 -1
  27. package/dist/types/ui/OptionsPanel.css.d.ts +1 -0
  28. package/dist/{ui → types/ui}/OptionsPanel.d.ts +0 -1
  29. package/dist/{ui → types/ui}/index.d.ts +0 -1
  30. package/dist/{ui → types/ui}/options/NodeOptions.d.ts +0 -1
  31. package/dist/types/xyflow/FitviewOnDiagramChange.d.ts +4 -0
  32. package/dist/{xyflow → types/xyflow}/UpdateOnDiagramChange.d.ts +0 -1
  33. package/dist/{xyflow → types/xyflow}/XYFlowBackground.d.ts +0 -1
  34. package/dist/{xyflow → types/xyflow}/XYFlowEvents.d.ts +5 -6
  35. package/dist/{xyflow → types/xyflow}/XYFlowWrapper.d.ts +0 -1
  36. package/dist/{xyflow → types/xyflow}/const.d.ts +1 -2
  37. package/dist/{xyflow → types/xyflow}/diagram-to-xyflow.d.ts +0 -1
  38. package/dist/{xyflow → types/xyflow}/edges/RelationshipEdge.d.ts +0 -1
  39. package/dist/{xyflow → types/xyflow}/edges/edges.css.d.ts +0 -1
  40. package/dist/{xyflow → types/xyflow}/edges/utils.d.ts +0 -1
  41. package/dist/{xyflow → types/xyflow}/hooks/index.d.ts +0 -1
  42. package/dist/{xyflow → types/xyflow}/hooks/use-layout-/321/201onstraints.d.ts +0 -1
  43. package/dist/{xyflow → types/xyflow}/nodes/compound/CompoundNode.css.d.ts +0 -1
  44. package/dist/{xyflow → types/xyflow}/nodes/compound/CompoundNode.d.ts +0 -1
  45. package/dist/{xyflow → types/xyflow}/nodes/compound/index.d.ts +0 -1
  46. package/dist/{xyflow → types/xyflow}/nodes/element/ElementIcon.d.ts +0 -1
  47. package/dist/{xyflow → types/xyflow}/nodes/element/ElementLink.css.d.ts +0 -1
  48. package/dist/{xyflow → types/xyflow}/nodes/element/ElementLink.d.ts +0 -1
  49. package/dist/types/xyflow/nodes/element/ElementNode.d.ts +7 -0
  50. package/dist/{xyflow → types/xyflow}/nodes/element/ElementShapeSvg.d.ts +0 -1
  51. package/dist/{xyflow → types/xyflow}/nodes/element/element.css.d.ts +0 -1
  52. package/dist/{xyflow → types/xyflow}/nodes/element/index.d.ts +0 -1
  53. package/dist/{xyflow → types/xyflow}/nodes/shared/NavigateToBtn.d.ts +0 -1
  54. package/dist/{xyflow → types/xyflow}/types.d.ts +0 -1
  55. package/dist/{xyflow → types/xyflow}/utils.d.ts +0 -1
  56. package/package.json +29 -45
  57. package/dist/bundle.d.ts +0 -12
  58. package/dist/bundle.js +0 -30
  59. package/dist/hooks/use-update-effect.d.ts +0 -4
  60. package/dist/index-DClug9zV.js +0 -23964
  61. package/dist/index.css.d.ts +0 -2
  62. package/dist/index.d.ts +0 -7
  63. package/dist/index.js +0 -1
  64. package/dist/state/index.d.ts +0 -2
  65. package/dist/ui/KeepAspectRatio.css.d.ts +0 -2
  66. package/dist/ui/OptionsPanel.css.d.ts +0 -2
  67. package/dist/xyflow/FitviewOnDiagramChange.d.ts +0 -6
  68. package/dist/xyflow/nodes/element/ElementNode.d.ts +0 -7
@@ -0,0 +1,4596 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
8
+ import { invariant, isAncestor, nonNullable, hasAtLeast as hasAtLeast$1, defaultTheme, ElementShapes, compareByFqnHierarchically, nonexhaustive } from "@likec4/core";
9
+ import { createTheme, MantineContext, MantineProvider, Box, Stack, Text, Tooltip, Divider, Flex, ColorSwatch, CheckIcon, rem, Select, Card, ActionIcon, HoverCard, UnstyledButton, Group, Anchor, CopyButton, Button, useMantineColorScheme, Modal, Title, CloseButton } from "@mantine/core";
10
+ import { useRef, useMemo, useEffect, useState, useCallback, useContext, createContext, memo, forwardRef } from "react";
11
+ import { isNode, useReactFlow, useNodesData, useOnSelectionChange, getBezierEdgeCenter, useNodesInitialized, Background, BackgroundVariant, Position, useStore, getBezierPath, EdgeLabelRenderer, Handle, ReactFlow, ReactFlowProvider, Controls } from "@xyflow/react";
12
+ import clsx from "clsx";
13
+ import { createContainer } from "react-tracked";
14
+ import { AnimatePresence, motion } from "framer-motion";
15
+ var scope = "_2t65ix0";
16
+ function useSyncedRef(value) {
17
+ const ref = useRef(value);
18
+ ref.current = value;
19
+ return useMemo(() => Object.freeze({
20
+ get current() {
21
+ return ref.current;
22
+ }
23
+ }), []);
24
+ }
25
+ function useUnmountEffect(effect) {
26
+ const effectRef = useSyncedRef(effect);
27
+ useEffect(() => () => {
28
+ effectRef.current();
29
+ }, []);
30
+ }
31
+ function useDebouncedCallback(callback, deps, delay, maxWait = 0) {
32
+ const timeout = useRef();
33
+ const waitTimeout = useRef();
34
+ const cb = useRef(callback);
35
+ const lastCall = useRef();
36
+ const clear = () => {
37
+ if (timeout.current) {
38
+ clearTimeout(timeout.current);
39
+ timeout.current = void 0;
40
+ }
41
+ if (waitTimeout.current) {
42
+ clearTimeout(waitTimeout.current);
43
+ waitTimeout.current = void 0;
44
+ }
45
+ };
46
+ useUnmountEffect(clear);
47
+ useEffect(() => {
48
+ cb.current = callback;
49
+ }, deps);
50
+ return useMemo(() => {
51
+ const execute = () => {
52
+ clear();
53
+ if (!lastCall.current)
54
+ return;
55
+ const context = lastCall.current;
56
+ lastCall.current = void 0;
57
+ cb.current.apply(context.this, context.args);
58
+ };
59
+ const wrapped = function(...args) {
60
+ if (timeout.current) {
61
+ clearTimeout(timeout.current);
62
+ }
63
+ lastCall.current = { args, this: this };
64
+ timeout.current = setTimeout(execute, delay);
65
+ if (maxWait > 0 && !waitTimeout.current) {
66
+ waitTimeout.current = setTimeout(execute, maxWait);
67
+ }
68
+ };
69
+ Object.defineProperties(wrapped, {
70
+ length: { value: callback.length },
71
+ name: { value: `${callback.name || "anonymous"}__debounced__${delay}` }
72
+ });
73
+ return wrapped;
74
+ }, [delay, maxWait, ...deps]);
75
+ }
76
+ const isBrowser = typeof window !== "undefined" && typeof navigator !== "undefined" && typeof document !== "undefined";
77
+ const basicDepsComparator = (d1, d2) => {
78
+ if (d1 === d2)
79
+ return true;
80
+ if (d1.length !== d2.length)
81
+ return false;
82
+ for (const [i, element] of d1.entries()) {
83
+ if (element !== d2[i]) {
84
+ return false;
85
+ }
86
+ }
87
+ return true;
88
+ };
89
+ function useCustomCompareEffect(callback, deps, comparator = basicDepsComparator, effectHook = useEffect, ...effectHookRestArgs) {
90
+ const dependencies = useRef();
91
+ if (dependencies.current === void 0 || isBrowser && !comparator(dependencies.current, deps)) {
92
+ dependencies.current = deps;
93
+ }
94
+ effectHook(callback, dependencies.current, ...effectHookRestArgs);
95
+ }
96
+ function useDebouncedEffect(callback, deps, delay, maxWait = 0) {
97
+ useEffect(useDebouncedCallback(callback, deps, delay, maxWait), deps);
98
+ }
99
+ function resolveHookState(nextState, previousState) {
100
+ if (typeof nextState === "function")
101
+ return nextState(previousState);
102
+ return nextState;
103
+ }
104
+ const useCustomCompareMemo = (factory, deps, comparator) => {
105
+ const dependencies = useRef();
106
+ if (dependencies.current === void 0 || !comparator(dependencies.current, deps)) {
107
+ dependencies.current = deps;
108
+ }
109
+ return useMemo(factory, dependencies.current);
110
+ };
111
+ function useToggle(initialState = false, ignoreReactEvents = true) {
112
+ const [state, setState] = useState(initialState);
113
+ const ignoreReactEventsRef = useSyncedRef(ignoreReactEvents);
114
+ return [
115
+ state,
116
+ useCallback((nextState) => {
117
+ setState((previousState) => {
118
+ if (nextState === void 0 || ignoreReactEventsRef.current && typeof nextState === "object" && (nextState.constructor.name === "SyntheticBaseEvent" || typeof nextState._reactName === "string")) {
119
+ return !previousState;
120
+ }
121
+ return Boolean(resolveHookState(nextState, previousState));
122
+ });
123
+ }, [])
124
+ ];
125
+ }
126
+ var getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols;
127
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
128
+ function combineComparators(comparatorA, comparatorB) {
129
+ return function isEqual(a, b, state) {
130
+ return comparatorA(a, b, state) && comparatorB(a, b, state);
131
+ };
132
+ }
133
+ function createIsCircular(areItemsEqual) {
134
+ return function isCircular(a, b, state) {
135
+ if (!a || !b || typeof a !== "object" || typeof b !== "object") {
136
+ return areItemsEqual(a, b, state);
137
+ }
138
+ var cache = state.cache;
139
+ var cachedA = cache.get(a);
140
+ var cachedB = cache.get(b);
141
+ if (cachedA && cachedB) {
142
+ return cachedA === b && cachedB === a;
143
+ }
144
+ cache.set(a, b);
145
+ cache.set(b, a);
146
+ var result = areItemsEqual(a, b, state);
147
+ cache.delete(a);
148
+ cache.delete(b);
149
+ return result;
150
+ };
151
+ }
152
+ function getStrictProperties(object) {
153
+ return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
154
+ }
155
+ var hasOwn = Object.hasOwn || function(object, property) {
156
+ return hasOwnProperty.call(object, property);
157
+ };
158
+ function sameValueZeroEqual(a, b) {
159
+ return a || b ? a === b : a === b || a !== a && b !== b;
160
+ }
161
+ var OWNER = "_owner";
162
+ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, keys$1 = Object.keys;
163
+ function areArraysEqual(a, b, state) {
164
+ var index = a.length;
165
+ if (b.length !== index) {
166
+ return false;
167
+ }
168
+ while (index-- > 0) {
169
+ if (!state.equals(a[index], b[index], index, index, a, b, state)) {
170
+ return false;
171
+ }
172
+ }
173
+ return true;
174
+ }
175
+ function areDatesEqual(a, b) {
176
+ return sameValueZeroEqual(a.getTime(), b.getTime());
177
+ }
178
+ function areMapsEqual(a, b, state) {
179
+ if (a.size !== b.size) {
180
+ return false;
181
+ }
182
+ var matchedIndices = {};
183
+ var aIterable = a.entries();
184
+ var index = 0;
185
+ var aResult;
186
+ var bResult;
187
+ while (aResult = aIterable.next()) {
188
+ if (aResult.done) {
189
+ break;
190
+ }
191
+ var bIterable = b.entries();
192
+ var hasMatch = false;
193
+ var matchIndex = 0;
194
+ while (bResult = bIterable.next()) {
195
+ if (bResult.done) {
196
+ break;
197
+ }
198
+ var _a = aResult.value, aKey = _a[0], aValue = _a[1];
199
+ var _b = bResult.value, bKey = _b[0], bValue = _b[1];
200
+ if (!hasMatch && !matchedIndices[matchIndex] && (hasMatch = state.equals(aKey, bKey, index, matchIndex, a, b, state) && state.equals(aValue, bValue, aKey, bKey, a, b, state))) {
201
+ matchedIndices[matchIndex] = true;
202
+ }
203
+ matchIndex++;
204
+ }
205
+ if (!hasMatch) {
206
+ return false;
207
+ }
208
+ index++;
209
+ }
210
+ return true;
211
+ }
212
+ function areObjectsEqual(a, b, state) {
213
+ var properties = keys$1(a);
214
+ var index = properties.length;
215
+ if (keys$1(b).length !== index) {
216
+ return false;
217
+ }
218
+ var property;
219
+ while (index-- > 0) {
220
+ property = properties[index];
221
+ if (property === OWNER && (a.$$typeof || b.$$typeof) && a.$$typeof !== b.$$typeof) {
222
+ return false;
223
+ }
224
+ if (!hasOwn(b, property) || !state.equals(a[property], b[property], property, property, a, b, state)) {
225
+ return false;
226
+ }
227
+ }
228
+ return true;
229
+ }
230
+ function areObjectsEqualStrict(a, b, state) {
231
+ var properties = getStrictProperties(a);
232
+ var index = properties.length;
233
+ if (getStrictProperties(b).length !== index) {
234
+ return false;
235
+ }
236
+ var property;
237
+ var descriptorA;
238
+ var descriptorB;
239
+ while (index-- > 0) {
240
+ property = properties[index];
241
+ if (property === OWNER && (a.$$typeof || b.$$typeof) && a.$$typeof !== b.$$typeof) {
242
+ return false;
243
+ }
244
+ if (!hasOwn(b, property)) {
245
+ return false;
246
+ }
247
+ if (!state.equals(a[property], b[property], property, property, a, b, state)) {
248
+ return false;
249
+ }
250
+ descriptorA = getOwnPropertyDescriptor(a, property);
251
+ descriptorB = getOwnPropertyDescriptor(b, property);
252
+ if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
253
+ return false;
254
+ }
255
+ }
256
+ return true;
257
+ }
258
+ function arePrimitiveWrappersEqual(a, b) {
259
+ return sameValueZeroEqual(a.valueOf(), b.valueOf());
260
+ }
261
+ function areRegExpsEqual(a, b) {
262
+ return a.source === b.source && a.flags === b.flags;
263
+ }
264
+ function areSetsEqual(a, b, state) {
265
+ if (a.size !== b.size) {
266
+ return false;
267
+ }
268
+ var matchedIndices = {};
269
+ var aIterable = a.values();
270
+ var aResult;
271
+ var bResult;
272
+ while (aResult = aIterable.next()) {
273
+ if (aResult.done) {
274
+ break;
275
+ }
276
+ var bIterable = b.values();
277
+ var hasMatch = false;
278
+ var matchIndex = 0;
279
+ while (bResult = bIterable.next()) {
280
+ if (bResult.done) {
281
+ break;
282
+ }
283
+ if (!hasMatch && !matchedIndices[matchIndex] && (hasMatch = state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state))) {
284
+ matchedIndices[matchIndex] = true;
285
+ }
286
+ matchIndex++;
287
+ }
288
+ if (!hasMatch) {
289
+ return false;
290
+ }
291
+ }
292
+ return true;
293
+ }
294
+ function areTypedArraysEqual(a, b) {
295
+ var index = a.length;
296
+ if (b.length !== index) {
297
+ return false;
298
+ }
299
+ while (index-- > 0) {
300
+ if (a[index] !== b[index]) {
301
+ return false;
302
+ }
303
+ }
304
+ return true;
305
+ }
306
+ var ARGUMENTS_TAG = "[object Arguments]";
307
+ var BOOLEAN_TAG = "[object Boolean]";
308
+ var DATE_TAG = "[object Date]";
309
+ var MAP_TAG = "[object Map]";
310
+ var NUMBER_TAG = "[object Number]";
311
+ var OBJECT_TAG = "[object Object]";
312
+ var REG_EXP_TAG = "[object RegExp]";
313
+ var SET_TAG = "[object Set]";
314
+ var STRING_TAG = "[object String]";
315
+ var isArray = Array.isArray;
316
+ var isTypedArray = typeof ArrayBuffer === "function" && ArrayBuffer.isView ? ArrayBuffer.isView : null;
317
+ var assign = Object.assign;
318
+ var getTag = Object.prototype.toString.call.bind(Object.prototype.toString);
319
+ function createEqualityComparator(_a) {
320
+ var areArraysEqual2 = _a.areArraysEqual, areDatesEqual2 = _a.areDatesEqual, areMapsEqual2 = _a.areMapsEqual, areObjectsEqual2 = _a.areObjectsEqual, arePrimitiveWrappersEqual2 = _a.arePrimitiveWrappersEqual, areRegExpsEqual2 = _a.areRegExpsEqual, areSetsEqual2 = _a.areSetsEqual, areTypedArraysEqual2 = _a.areTypedArraysEqual;
321
+ return function comparator(a, b, state) {
322
+ if (a === b) {
323
+ return true;
324
+ }
325
+ if (a == null || b == null || typeof a !== "object" || typeof b !== "object") {
326
+ return a !== a && b !== b;
327
+ }
328
+ var constructor = a.constructor;
329
+ if (constructor !== b.constructor) {
330
+ return false;
331
+ }
332
+ if (constructor === Object) {
333
+ return areObjectsEqual2(a, b, state);
334
+ }
335
+ if (isArray(a)) {
336
+ return areArraysEqual2(a, b, state);
337
+ }
338
+ if (isTypedArray != null && isTypedArray(a)) {
339
+ return areTypedArraysEqual2(a, b, state);
340
+ }
341
+ if (constructor === Date) {
342
+ return areDatesEqual2(a, b, state);
343
+ }
344
+ if (constructor === RegExp) {
345
+ return areRegExpsEqual2(a, b, state);
346
+ }
347
+ if (constructor === Map) {
348
+ return areMapsEqual2(a, b, state);
349
+ }
350
+ if (constructor === Set) {
351
+ return areSetsEqual2(a, b, state);
352
+ }
353
+ var tag = getTag(a);
354
+ if (tag === DATE_TAG) {
355
+ return areDatesEqual2(a, b, state);
356
+ }
357
+ if (tag === REG_EXP_TAG) {
358
+ return areRegExpsEqual2(a, b, state);
359
+ }
360
+ if (tag === MAP_TAG) {
361
+ return areMapsEqual2(a, b, state);
362
+ }
363
+ if (tag === SET_TAG) {
364
+ return areSetsEqual2(a, b, state);
365
+ }
366
+ if (tag === OBJECT_TAG) {
367
+ return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state);
368
+ }
369
+ if (tag === ARGUMENTS_TAG) {
370
+ return areObjectsEqual2(a, b, state);
371
+ }
372
+ if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) {
373
+ return arePrimitiveWrappersEqual2(a, b, state);
374
+ }
375
+ return false;
376
+ };
377
+ }
378
+ function createEqualityComparatorConfig(_a) {
379
+ var circular = _a.circular, createCustomConfig = _a.createCustomConfig, strict = _a.strict;
380
+ var config = {
381
+ areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
382
+ areDatesEqual,
383
+ areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
384
+ areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
385
+ arePrimitiveWrappersEqual,
386
+ areRegExpsEqual,
387
+ areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
388
+ areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual
389
+ };
390
+ if (createCustomConfig) {
391
+ config = assign({}, config, createCustomConfig(config));
392
+ }
393
+ if (circular) {
394
+ var areArraysEqual$1 = createIsCircular(config.areArraysEqual);
395
+ var areMapsEqual$1 = createIsCircular(config.areMapsEqual);
396
+ var areObjectsEqual$1 = createIsCircular(config.areObjectsEqual);
397
+ var areSetsEqual$1 = createIsCircular(config.areSetsEqual);
398
+ config = assign({}, config, {
399
+ areArraysEqual: areArraysEqual$1,
400
+ areMapsEqual: areMapsEqual$1,
401
+ areObjectsEqual: areObjectsEqual$1,
402
+ areSetsEqual: areSetsEqual$1
403
+ });
404
+ }
405
+ return config;
406
+ }
407
+ function createInternalEqualityComparator(compare) {
408
+ return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
409
+ return compare(a, b, state);
410
+ };
411
+ }
412
+ function createIsEqual(_a) {
413
+ var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
414
+ if (createState) {
415
+ return function isEqual(a, b) {
416
+ var _a2 = createState(), _b = _a2.cache, cache = _b === void 0 ? circular ? /* @__PURE__ */ new WeakMap() : void 0 : _b, meta = _a2.meta;
417
+ return comparator(a, b, {
418
+ cache,
419
+ equals,
420
+ meta,
421
+ strict
422
+ });
423
+ };
424
+ }
425
+ if (circular) {
426
+ return function isEqual(a, b) {
427
+ return comparator(a, b, {
428
+ cache: /* @__PURE__ */ new WeakMap(),
429
+ equals,
430
+ meta: void 0,
431
+ strict
432
+ });
433
+ };
434
+ }
435
+ var state = {
436
+ cache: void 0,
437
+ equals,
438
+ meta: void 0,
439
+ strict
440
+ };
441
+ return function isEqual(a, b) {
442
+ return comparator(a, b, state);
443
+ };
444
+ }
445
+ var deepEqual = createCustomEqual();
446
+ createCustomEqual({ strict: true });
447
+ createCustomEqual({ circular: true });
448
+ createCustomEqual({
449
+ circular: true,
450
+ strict: true
451
+ });
452
+ var shallowEqual = createCustomEqual({
453
+ createInternalComparator: function() {
454
+ return sameValueZeroEqual;
455
+ }
456
+ });
457
+ createCustomEqual({
458
+ strict: true,
459
+ createInternalComparator: function() {
460
+ return sameValueZeroEqual;
461
+ }
462
+ });
463
+ createCustomEqual({
464
+ circular: true,
465
+ createInternalComparator: function() {
466
+ return sameValueZeroEqual;
467
+ }
468
+ });
469
+ createCustomEqual({
470
+ circular: true,
471
+ createInternalComparator: function() {
472
+ return sameValueZeroEqual;
473
+ },
474
+ strict: true
475
+ });
476
+ function createCustomEqual(options) {
477
+ if (options === void 0) {
478
+ options = {};
479
+ }
480
+ var _a = options.circular, circular = _a === void 0 ? false : _a, createCustomInternalComparator = options.createInternalComparator, createState = options.createState, _b = options.strict, strict = _b === void 0 ? false : _b;
481
+ var config = createEqualityComparatorConfig(options);
482
+ var comparator = createEqualityComparator(config);
483
+ var equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
484
+ return createIsEqual({ circular, comparator, createState, equals, strict });
485
+ }
486
+ var modalContent = "_1yqpph0";
487
+ var modalBody = "_1yqpph1";
488
+ var modalHeader = "_1yqpph2";
489
+ var modalCloseButtonBox = "_1yqpph3";
490
+ var modalCloseButton = "_1yqpph4";
491
+ function useSetState(initialState) {
492
+ const [state, _setState] = useState(initialState);
493
+ const setState = useCallback(
494
+ (statePartial) => _setState((current) => {
495
+ const next = {
496
+ ...current,
497
+ ...typeof statePartial === "function" ? statePartial(current) : statePartial
498
+ };
499
+ return shallowEqual(current, next) ? current : next;
500
+ }),
501
+ []
502
+ );
503
+ return [state, setState];
504
+ }
505
+ function useUpdateEffect(callback, deps) {
506
+ const render = useRef(false);
507
+ const effect = useRef(false);
508
+ useCustomCompareEffect(
509
+ () => {
510
+ const mounted = render.current;
511
+ const run = mounted && effect.current;
512
+ if (run) {
513
+ return callback();
514
+ }
515
+ effect.current = true;
516
+ },
517
+ deps,
518
+ shallowEqual
519
+ );
520
+ useEffect(() => {
521
+ render.current = true;
522
+ return () => {
523
+ render.current = false;
524
+ };
525
+ }, []);
526
+ }
527
+ var cssReactFlow = "_2h8g8h0";
528
+ var cssDisablePan = "_2h8g8h1";
529
+ var cssTransparentBg = "_2h8g8h2";
530
+ var cssNoControls = "_2h8g8h3";
531
+ const theme = createTheme({
532
+ primaryColor: "indigo",
533
+ cursorType: "pointer",
534
+ headings: {
535
+ fontWeight: "500",
536
+ sizes: {
537
+ h1: {
538
+ // fontSize: '2rem',
539
+ fontWeight: "600"
540
+ },
541
+ h2: {
542
+ // fontSize: '1.85rem',
543
+ }
544
+ }
545
+ }
546
+ });
547
+ function EnsureMantine({ colorMode, children }) {
548
+ const mantineCtx = useContext(MantineContext);
549
+ if (mantineCtx) {
550
+ mantineCtx.getRootElement;
551
+ return /* @__PURE__ */ jsx(Fragment, { children });
552
+ }
553
+ return /* @__PURE__ */ jsx(
554
+ MantineProvider,
555
+ {
556
+ ...colorMode && {
557
+ forceColorScheme: colorMode
558
+ },
559
+ theme,
560
+ defaultColorScheme: "auto",
561
+ children
562
+ }
563
+ );
564
+ }
565
+ const useDiagramStateValue = ({
566
+ isNodeInteractive,
567
+ view,
568
+ fitViewPadding,
569
+ readonly,
570
+ disableHovercards,
571
+ eventHandlers
572
+ }) => {
573
+ const hasEventHandlers = {
574
+ hasOnChange: !!eventHandlers.onChange,
575
+ hasOnNavigateTo: !!eventHandlers.onNavigateTo,
576
+ hasOnNodeClick: !!eventHandlers.onNodeClick,
577
+ hasOnNodeContextMenu: !!eventHandlers.onNodeContextMenu,
578
+ hasOnCanvasContextMenu: !!eventHandlers.onCanvasContextMenu,
579
+ hasOnEdgeContextMenu: !!eventHandlers.onEdgeContextMenu,
580
+ hasOnContextMenu: !!eventHandlers.onNodeContextMenu || !!eventHandlers.onCanvasContextMenu || !!eventHandlers.onEdgeContextMenu,
581
+ hasOnEdgeClick: !!eventHandlers.onEdgeClick,
582
+ hasOnCanvasClick: !!eventHandlers.onCanvasClick || !!eventHandlers.onCanvasDblClick
583
+ };
584
+ const [state, setState] = useSetState({
585
+ viewportInitialized: false,
586
+ // User moved the viewport
587
+ viewportMoved: false,
588
+ hoveredNodeId: null,
589
+ hoveredEdgeId: null
590
+ });
591
+ const readonlyProps = {
592
+ readonly,
593
+ disableHovercards,
594
+ isNodeInteractive,
595
+ viewId: view.id,
596
+ viewLayout: view.autoLayout,
597
+ viewWidth: view.width,
598
+ viewHeight: view.height,
599
+ fitViewPadding
600
+ };
601
+ const _state = useCustomCompareMemo(
602
+ () => ({
603
+ ...readonlyProps,
604
+ ...hasEventHandlers,
605
+ ...state
606
+ }),
607
+ [state, readonlyProps, hasEventHandlers],
608
+ shallowEqual
609
+ );
610
+ return [_state, setState];
611
+ };
612
+ const {
613
+ Provider: DiagramStateProvider,
614
+ useTracked: useDiagramStateTracked,
615
+ useTrackedState: useDiagramState,
616
+ useUpdate: useUpdateDiagramState,
617
+ useSelector: useDiagramStateSelector
618
+ } = /* @__PURE__ */ createContainer(useDiagramStateValue, {
619
+ concurrentMode: false,
620
+ stateContextName: "DiagramStateContext"
621
+ });
622
+ var wrapper = "_14qhjro0";
623
+ function KeepAspectRatio({
624
+ children,
625
+ width,
626
+ height,
627
+ enabled,
628
+ className,
629
+ style,
630
+ ...rest
631
+ }) {
632
+ if (!enabled) {
633
+ return /* @__PURE__ */ jsx(Fragment, { children });
634
+ }
635
+ return /* @__PURE__ */ jsx(
636
+ Box,
637
+ {
638
+ ...rest,
639
+ className: clsx(wrapper, className),
640
+ style: {
641
+ ...style,
642
+ aspectRatio: `${width}/${height}`,
643
+ maxHeight: height
644
+ },
645
+ children
646
+ }
647
+ );
648
+ }
649
+ var __spreadArray = function(to, from, pack) {
650
+ if (pack || arguments.length === 2)
651
+ for (var i = 0, l = from.length, ar; i < l; i++) {
652
+ if (ar || !(i in from)) {
653
+ if (!ar)
654
+ ar = Array.prototype.slice.call(from, 0, i);
655
+ ar[i] = from[i];
656
+ }
657
+ }
658
+ return to.concat(ar || Array.prototype.slice.call(from));
659
+ };
660
+ function purry(fn, args, lazyFactory) {
661
+ var callArgs = Array.from(args);
662
+ var diff = fn.length - args.length;
663
+ if (diff === 0) {
664
+ return fn.apply(void 0, callArgs);
665
+ }
666
+ if (diff === 1) {
667
+ var ret = function(data) {
668
+ return fn.apply(void 0, __spreadArray([data], callArgs, false));
669
+ };
670
+ var lazy = lazyFactory !== null && lazyFactory !== void 0 ? lazyFactory : fn.lazy;
671
+ return lazy === void 0 ? ret : Object.assign(ret, { lazy, lazyArgs: args });
672
+ }
673
+ throw new Error("Wrong number of arguments");
674
+ }
675
+ function isTruthy(data) {
676
+ return Boolean(data);
677
+ }
678
+ function hasAtLeast() {
679
+ var args = [];
680
+ for (var _i = 0; _i < arguments.length; _i++) {
681
+ args[_i] = arguments[_i];
682
+ }
683
+ return purry(hasAtLeastImplementation, args);
684
+ }
685
+ var hasAtLeastImplementation = function(data, minimum) {
686
+ return data.length >= minimum;
687
+ };
688
+ function isNullish(data) {
689
+ return data === null || data === void 0;
690
+ }
691
+ function keys() {
692
+ return purry(Object.keys, arguments);
693
+ }
694
+ (function(keys2) {
695
+ keys2.strict = keys2;
696
+ })(keys || (keys = {}));
697
+ function takeWhile() {
698
+ return purry(_takeWhile, arguments);
699
+ }
700
+ function _takeWhile(array, fn) {
701
+ var ret = [];
702
+ for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
703
+ var item = array_1[_i];
704
+ if (!fn(item)) {
705
+ break;
706
+ }
707
+ ret.push(item);
708
+ }
709
+ return ret;
710
+ }
711
+ var XYFlowNode;
712
+ ((XYFlowNode2) => {
713
+ function isCompound(node) {
714
+ return isNode(node) && node.type === "compound";
715
+ }
716
+ XYFlowNode2.isCompound = isCompound;
717
+ function isElement(node) {
718
+ return isNode(node) && node.type === "element";
719
+ }
720
+ XYFlowNode2.isElement = isElement;
721
+ XYFlowNode2.is = (node) => isCompound(node) || isElement(node);
722
+ })(XYFlowNode || (XYFlowNode = {}));
723
+ var XYFlowEdge;
724
+ ((XYFlowEdge2) => {
725
+ XYFlowEdge2.isRelationship = (e) => e.type === "relationship" && isTruthy(e.data);
726
+ })(XYFlowEdge || (XYFlowEdge = {}));
727
+ function createMap() {
728
+ return new IndexedMap();
729
+ }
730
+ class IndexedMap {
731
+ constructor() {
732
+ __publicField(this, "index", {});
733
+ __publicField(this, "array", []);
734
+ }
735
+ /**
736
+ * Returns the number of items in the array.
737
+ */
738
+ size() {
739
+ return this.array.length;
740
+ }
741
+ /**
742
+ * Returns true if the array is empty.
743
+ */
744
+ empty() {
745
+ return this.array.length === 0;
746
+ }
747
+ /**
748
+ * Returns the item at the given array index.
749
+ *
750
+ * @param index The integer index of the desired item.
751
+ */
752
+ itemAt(index) {
753
+ return this.array[index];
754
+ }
755
+ /**
756
+ * Returns true if the key is in the array, false otherwise.
757
+ *
758
+ * @param key The key to locate in the array.
759
+ */
760
+ contains(key) {
761
+ return this.index[key.id()] !== void 0;
762
+ }
763
+ /**
764
+ * Returns the pair associated with the given key, or undefined.
765
+ *
766
+ * @param key The key to locate in the array.
767
+ */
768
+ find(key) {
769
+ const i = this.index[key.id()];
770
+ return i === void 0 ? void 0 : this.array[i];
771
+ }
772
+ /**
773
+ * Returns the pair associated with the key if it exists.
774
+ *
775
+ * If the key does not exist, a new pair will be created and
776
+ * inserted using the value created by the given factory.
777
+ *
778
+ * @param key The key to locate in the array.
779
+ * @param factory The function which creates the default value.
780
+ */
781
+ setDefault(key, factory) {
782
+ const i = this.index[key.id()];
783
+ if (i === void 0) {
784
+ const pair = new Pair(key, factory());
785
+ this.index[key.id()] = this.array.length;
786
+ this.array.push(pair);
787
+ return pair;
788
+ } else {
789
+ return this.array[i];
790
+ }
791
+ }
792
+ /**
793
+ * Insert the pair into the array and return the pair.
794
+ *
795
+ * This will overwrite any existing entry in the array.
796
+ *
797
+ * @param key The key portion of the pair.
798
+ * @param value The value portion of the pair.
799
+ */
800
+ insert(key, value) {
801
+ const pair = new Pair(key, value);
802
+ const i = this.index[key.id()];
803
+ if (i === void 0) {
804
+ this.index[key.id()] = this.array.length;
805
+ this.array.push(pair);
806
+ } else {
807
+ this.array[i] = pair;
808
+ }
809
+ return pair;
810
+ }
811
+ /**
812
+ * Removes and returns the pair for the given key, or undefined.
813
+ *
814
+ * @param key The key to remove from the map.
815
+ */
816
+ erase(key) {
817
+ const i = this.index[key.id()];
818
+ if (i === void 0) {
819
+ return void 0;
820
+ }
821
+ this.index[key.id()] = void 0;
822
+ const pair = this.array[i];
823
+ const last = this.array.pop();
824
+ if (pair !== last) {
825
+ this.array[i] = last;
826
+ this.index[last.first.id()] = i;
827
+ }
828
+ return pair;
829
+ }
830
+ /**
831
+ * Create a copy of this associative array.
832
+ */
833
+ copy() {
834
+ const copy = new IndexedMap();
835
+ for (let i = 0; i < this.array.length; i++) {
836
+ const pair = this.array[i].copy();
837
+ copy.array[i] = pair;
838
+ copy.index[pair.first.id()] = i;
839
+ }
840
+ return copy;
841
+ }
842
+ }
843
+ class Pair {
844
+ /**
845
+ * Construct a new Pair object.
846
+ *
847
+ * @param first The first item of the pair.
848
+ * @param second The second item of the pair.
849
+ */
850
+ constructor(first, second) {
851
+ __publicField(this, "first");
852
+ __publicField(this, "second");
853
+ this.first = first;
854
+ this.second = second;
855
+ }
856
+ /**
857
+ * Create a copy of the pair.
858
+ */
859
+ copy() {
860
+ return new Pair(this.first, this.second);
861
+ }
862
+ }
863
+ class Variable {
864
+ constructor(name = "") {
865
+ __publicField(this, "_name");
866
+ __publicField(this, "_value", 0);
867
+ __publicField(this, "_context", null);
868
+ __publicField(this, "_id", VarId++);
869
+ this._name = name;
870
+ }
871
+ /**
872
+ * Returns the unique id number of the variable.
873
+ * @private
874
+ */
875
+ id() {
876
+ return this._id;
877
+ }
878
+ /**
879
+ * Returns the name of the variable.
880
+ *
881
+ * @return {String} name of the variable
882
+ */
883
+ name() {
884
+ return this._name;
885
+ }
886
+ /**
887
+ * Set the name of the variable.
888
+ *
889
+ * @param {String} name Name of the variable
890
+ */
891
+ setName(name) {
892
+ this._name = name;
893
+ }
894
+ /**
895
+ * Returns the user context object of the variable.
896
+ * @private
897
+ */
898
+ context() {
899
+ return this._context;
900
+ }
901
+ /**
902
+ * Set the user context object of the variable.
903
+ * @private
904
+ */
905
+ setContext(context) {
906
+ this._context = context;
907
+ }
908
+ /**
909
+ * Returns the value of the variable.
910
+ *
911
+ * @return {Number} Calculated value
912
+ */
913
+ value() {
914
+ return this._value;
915
+ }
916
+ /**
917
+ * Set the value of the variable.
918
+ * @private
919
+ */
920
+ setValue(value) {
921
+ this._value = value;
922
+ }
923
+ /**
924
+ * Creates a new Expression by adding a number, variable or expression
925
+ * to the variable.
926
+ *
927
+ * @param {Number|Variable|Expression} value Value to add.
928
+ * @return {Expression} expression
929
+ */
930
+ plus(value) {
931
+ return new Expression(this, value);
932
+ }
933
+ /**
934
+ * Creates a new Expression by substracting a number, variable or expression
935
+ * from the variable.
936
+ *
937
+ * @param {Number|Variable|Expression} value Value to substract.
938
+ * @return {Expression} expression
939
+ */
940
+ minus(value) {
941
+ return new Expression(this, typeof value === "number" ? -value : [-1, value]);
942
+ }
943
+ /**
944
+ * Creates a new Expression by multiplying with a fixed number.
945
+ *
946
+ * @param {Number} coefficient Coefficient to multiply with.
947
+ * @return {Expression} expression
948
+ */
949
+ multiply(coefficient) {
950
+ return new Expression([coefficient, this]);
951
+ }
952
+ /**
953
+ * Creates a new Expression by dividing with a fixed number.
954
+ *
955
+ * @param {Number} coefficient Coefficient to divide by.
956
+ * @return {Expression} expression
957
+ */
958
+ divide(coefficient) {
959
+ return new Expression([1 / coefficient, this]);
960
+ }
961
+ /**
962
+ * Returns the JSON representation of the variable.
963
+ * @private
964
+ */
965
+ toJSON() {
966
+ return {
967
+ name: this._name,
968
+ value: this._value
969
+ };
970
+ }
971
+ toString() {
972
+ return this._context + "[" + this._name + ":" + this._value + "]";
973
+ }
974
+ }
975
+ let VarId = 0;
976
+ class Expression {
977
+ constructor() {
978
+ __publicField(this, "_terms");
979
+ __publicField(this, "_constant");
980
+ let parsed = parseArgs(arguments);
981
+ this._terms = parsed.terms;
982
+ this._constant = parsed.constant;
983
+ }
984
+ /**
985
+ * Returns the mapping of terms in the expression.
986
+ *
987
+ * This *must* be treated as const.
988
+ * @private
989
+ */
990
+ terms() {
991
+ return this._terms;
992
+ }
993
+ /**
994
+ * Returns the constant of the expression.
995
+ * @private
996
+ */
997
+ constant() {
998
+ return this._constant;
999
+ }
1000
+ /**
1001
+ * Returns the computed value of the expression.
1002
+ *
1003
+ * @private
1004
+ * @return {Number} computed value of the expression
1005
+ */
1006
+ value() {
1007
+ let result = this._constant;
1008
+ for (let i = 0, n = this._terms.size(); i < n; i++) {
1009
+ let pair = this._terms.itemAt(i);
1010
+ result += pair.first.value() * pair.second;
1011
+ }
1012
+ return result;
1013
+ }
1014
+ /**
1015
+ * Creates a new Expression by adding a number, variable or expression
1016
+ * to the expression.
1017
+ *
1018
+ * @param {Number|Variable|Expression} value Value to add.
1019
+ * @return {Expression} expression
1020
+ */
1021
+ plus(value) {
1022
+ return new Expression(this, value);
1023
+ }
1024
+ /**
1025
+ * Creates a new Expression by substracting a number, variable or expression
1026
+ * from the expression.
1027
+ *
1028
+ * @param {Number|Variable|Expression} value Value to substract.
1029
+ * @return {Expression} expression
1030
+ */
1031
+ minus(value) {
1032
+ return new Expression(this, typeof value === "number" ? -value : [-1, value]);
1033
+ }
1034
+ /**
1035
+ * Creates a new Expression by multiplying with a fixed number.
1036
+ *
1037
+ * @param {Number} coefficient Coefficient to multiply with.
1038
+ * @return {Expression} expression
1039
+ */
1040
+ multiply(coefficient) {
1041
+ return new Expression([coefficient, this]);
1042
+ }
1043
+ /**
1044
+ * Creates a new Expression by dividing with a fixed number.
1045
+ *
1046
+ * @param {Number} coefficient Coefficient to divide by.
1047
+ * @return {Expression} expression
1048
+ */
1049
+ divide(coefficient) {
1050
+ return new Expression([1 / coefficient, this]);
1051
+ }
1052
+ isConstant() {
1053
+ return this._terms.size() == 0;
1054
+ }
1055
+ toString() {
1056
+ let result = this._terms.array.map(function(pair) {
1057
+ return pair.second + "*" + pair.first.toString();
1058
+ }).join(" + ");
1059
+ if (!this.isConstant() && this._constant !== 0) {
1060
+ result += " + ";
1061
+ }
1062
+ result += this._constant;
1063
+ return result;
1064
+ }
1065
+ }
1066
+ function parseArgs(args) {
1067
+ let constant = 0;
1068
+ let factory = () => 0;
1069
+ let terms = createMap();
1070
+ for (let i = 0, n = args.length; i < n; ++i) {
1071
+ let item = args[i];
1072
+ if (typeof item === "number") {
1073
+ constant += item;
1074
+ } else if (item instanceof Variable) {
1075
+ terms.setDefault(item, factory).second += 1;
1076
+ } else if (item instanceof Expression) {
1077
+ constant += item.constant();
1078
+ let terms2 = item.terms();
1079
+ for (let j = 0, k = terms2.size(); j < k; j++) {
1080
+ let termPair = terms2.itemAt(j);
1081
+ terms.setDefault(termPair.first, factory).second += termPair.second;
1082
+ }
1083
+ } else if (item instanceof Array) {
1084
+ if (item.length !== 2) {
1085
+ throw new Error("array must have length 2");
1086
+ }
1087
+ let value = item[0];
1088
+ let value2 = item[1];
1089
+ if (typeof value !== "number") {
1090
+ throw new Error("array item 0 must be a number");
1091
+ }
1092
+ if (value2 instanceof Variable) {
1093
+ terms.setDefault(value2, factory).second += value;
1094
+ } else if (value2 instanceof Expression) {
1095
+ constant += value2.constant() * value;
1096
+ let terms2 = value2.terms();
1097
+ for (let j = 0, k = terms2.size(); j < k; j++) {
1098
+ let termPair = terms2.itemAt(j);
1099
+ terms.setDefault(termPair.first, factory).second += termPair.second * value;
1100
+ }
1101
+ } else {
1102
+ throw new Error("array item 1 must be a variable or expression");
1103
+ }
1104
+ } else {
1105
+ throw new Error("invalid Expression argument: " + item);
1106
+ }
1107
+ }
1108
+ return { terms, constant };
1109
+ }
1110
+ const _Strength = class _Strength {
1111
+ /**
1112
+ * Create a new symbolic strength.
1113
+ *
1114
+ * @param a strong
1115
+ * @param b medium
1116
+ * @param c weak
1117
+ * @param [w] weight
1118
+ * @return strength
1119
+ */
1120
+ static create(a, b, c, w = 1) {
1121
+ let result = 0;
1122
+ result += Math.max(0, Math.min(1e3, a * w)) * 1e6;
1123
+ result += Math.max(0, Math.min(1e3, b * w)) * 1e3;
1124
+ result += Math.max(0, Math.min(1e3, c * w));
1125
+ return result;
1126
+ }
1127
+ /**
1128
+ * Clip a symbolic strength to the allowed min and max.
1129
+ * @private
1130
+ */
1131
+ static clip(value) {
1132
+ return Math.max(0, Math.min(_Strength.required, value));
1133
+ }
1134
+ };
1135
+ /**
1136
+ * The 'required' symbolic strength.
1137
+ */
1138
+ __publicField(_Strength, "required", _Strength.create(1e3, 1e3, 1e3));
1139
+ /**
1140
+ * The 'strong' symbolic strength.
1141
+ */
1142
+ __publicField(_Strength, "strong", _Strength.create(1, 0, 0));
1143
+ /**
1144
+ * The 'medium' symbolic strength.
1145
+ */
1146
+ __publicField(_Strength, "medium", _Strength.create(0, 1, 0));
1147
+ /**
1148
+ * The 'weak' symbolic strength.
1149
+ */
1150
+ __publicField(_Strength, "weak", _Strength.create(0, 0, 1));
1151
+ let Strength = _Strength;
1152
+ var Operator;
1153
+ (function(Operator2) {
1154
+ Operator2[Operator2["Le"] = 0] = "Le";
1155
+ Operator2[Operator2["Ge"] = 1] = "Ge";
1156
+ Operator2[Operator2["Eq"] = 2] = "Eq";
1157
+ })(Operator || (Operator = {}));
1158
+ class Constraint {
1159
+ constructor(expression, operator, rhs, strength = Strength.required) {
1160
+ __publicField(this, "_expression");
1161
+ __publicField(this, "_operator");
1162
+ __publicField(this, "_strength");
1163
+ __publicField(this, "_id", CnId++);
1164
+ this._operator = operator;
1165
+ this._strength = Strength.clip(strength);
1166
+ if (rhs === void 0 && expression instanceof Expression) {
1167
+ this._expression = expression;
1168
+ } else {
1169
+ this._expression = expression.minus(rhs);
1170
+ }
1171
+ }
1172
+ /**
1173
+ * Returns the unique id number of the constraint.
1174
+ * @private
1175
+ */
1176
+ id() {
1177
+ return this._id;
1178
+ }
1179
+ /**
1180
+ * Returns the expression of the constraint.
1181
+ *
1182
+ * @return {Expression} expression
1183
+ */
1184
+ expression() {
1185
+ return this._expression;
1186
+ }
1187
+ /**
1188
+ * Returns the relational operator of the constraint.
1189
+ *
1190
+ * @return {Operator} linear constraint operator
1191
+ */
1192
+ op() {
1193
+ return this._operator;
1194
+ }
1195
+ /**
1196
+ * Returns the strength of the constraint.
1197
+ *
1198
+ * @return {Number} strength
1199
+ */
1200
+ strength() {
1201
+ return this._strength;
1202
+ }
1203
+ toString() {
1204
+ return this._expression.toString() + " " + ["<=", ">=", "="][this._operator] + " 0 (" + this._strength.toString() + ")";
1205
+ }
1206
+ }
1207
+ let CnId = 0;
1208
+ class Solver {
1209
+ /**
1210
+ * Construct a new Solver.
1211
+ */
1212
+ constructor() {
1213
+ /**
1214
+ * @type {number} - The max number of solver iterations before an error
1215
+ * is thrown, in order to prevent infinite iteration. Default: `10,000`.
1216
+ */
1217
+ __publicField(this, "maxIterations", 1e3);
1218
+ __publicField(this, "_cnMap", createCnMap());
1219
+ __publicField(this, "_rowMap", createRowMap());
1220
+ __publicField(this, "_varMap", createVarMap());
1221
+ __publicField(this, "_editMap", createEditMap());
1222
+ __publicField(this, "_infeasibleRows", []);
1223
+ __publicField(this, "_objective", new Row());
1224
+ __publicField(this, "_artificial", null);
1225
+ __publicField(this, "_idTick", 0);
1226
+ }
1227
+ /**
1228
+ * Creates and add a constraint to the solver.
1229
+ *
1230
+ * @param {Expression|Variable} lhs Left hand side of the expression
1231
+ * @param {Operator} operator Operator
1232
+ * @param {Expression|Variable|Number} rhs Right hand side of the expression
1233
+ * @param {Number} [strength=Strength.required] Strength
1234
+ */
1235
+ createConstraint(lhs, operator, rhs, strength = Strength.required) {
1236
+ let cn = new Constraint(lhs, operator, rhs, strength);
1237
+ this.addConstraint(cn);
1238
+ return cn;
1239
+ }
1240
+ /**
1241
+ * Add a constraint to the solver.
1242
+ *
1243
+ * @param {Constraint} constraint Constraint to add to the solver
1244
+ */
1245
+ addConstraint(constraint) {
1246
+ let cnPair = this._cnMap.find(constraint);
1247
+ if (cnPair !== void 0) {
1248
+ throw new Error("duplicate constraint");
1249
+ }
1250
+ let data = this._createRow(constraint);
1251
+ let row = data.row;
1252
+ let tag = data.tag;
1253
+ let subject = this._chooseSubject(row, tag);
1254
+ if (subject.type() === SymbolType.Invalid && row.allDummies()) {
1255
+ if (!nearZero(row.constant())) {
1256
+ throw new Error("unsatisfiable constraint");
1257
+ } else {
1258
+ subject = tag.marker;
1259
+ }
1260
+ }
1261
+ if (subject.type() === SymbolType.Invalid) {
1262
+ if (!this._addWithArtificialVariable(row)) {
1263
+ throw new Error("unsatisfiable constraint");
1264
+ }
1265
+ } else {
1266
+ row.solveFor(subject);
1267
+ this._substitute(subject, row);
1268
+ this._rowMap.insert(subject, row);
1269
+ }
1270
+ this._cnMap.insert(constraint, tag);
1271
+ this._optimize(this._objective);
1272
+ }
1273
+ /**
1274
+ * Remove a constraint from the solver.
1275
+ *
1276
+ * @param {Constraint} constraint Constraint to remove from the solver
1277
+ */
1278
+ removeConstraint(constraint) {
1279
+ let cnPair = this._cnMap.erase(constraint);
1280
+ if (cnPair === void 0) {
1281
+ throw new Error("unknown constraint");
1282
+ }
1283
+ this._removeConstraintEffects(constraint, cnPair.second);
1284
+ let marker = cnPair.second.marker;
1285
+ let rowPair = this._rowMap.erase(marker);
1286
+ if (rowPair === void 0) {
1287
+ let leaving = this._getMarkerLeavingSymbol(marker);
1288
+ if (leaving.type() === SymbolType.Invalid) {
1289
+ throw new Error("failed to find leaving row");
1290
+ }
1291
+ rowPair = this._rowMap.erase(leaving);
1292
+ rowPair.second.solveForEx(leaving, marker);
1293
+ this._substitute(marker, rowPair.second);
1294
+ }
1295
+ this._optimize(this._objective);
1296
+ }
1297
+ /**
1298
+ * Test whether the solver contains the constraint.
1299
+ *
1300
+ * @param {Constraint} constraint Constraint to test for
1301
+ * @return {Bool} true or false
1302
+ */
1303
+ hasConstraint(constraint) {
1304
+ return this._cnMap.contains(constraint);
1305
+ }
1306
+ /**
1307
+ * Get an array of the current constraints.
1308
+ *
1309
+ * @return {Constraint[]}
1310
+ */
1311
+ getConstraints() {
1312
+ return this._cnMap.array.map(({ first }) => first);
1313
+ }
1314
+ /**
1315
+ * Add an edit variable to the solver.
1316
+ *
1317
+ * @param {Variable} variable Edit variable to add to the solver
1318
+ * @param {Number} strength Strength, should be less than `Strength.required`
1319
+ */
1320
+ addEditVariable(variable, strength) {
1321
+ let editPair = this._editMap.find(variable);
1322
+ if (editPair !== void 0) {
1323
+ throw new Error("duplicate edit variable");
1324
+ }
1325
+ strength = Strength.clip(strength);
1326
+ if (strength === Strength.required) {
1327
+ throw new Error("bad required strength");
1328
+ }
1329
+ let expr = new Expression(variable);
1330
+ let cn = new Constraint(expr, Operator.Eq, void 0, strength);
1331
+ this.addConstraint(cn);
1332
+ let tag = this._cnMap.find(cn).second;
1333
+ let info = { tag, constraint: cn, constant: 0 };
1334
+ this._editMap.insert(variable, info);
1335
+ }
1336
+ /**
1337
+ * Remove an edit variable from the solver.
1338
+ *
1339
+ * @param {Variable} variable Edit variable to remove from the solver
1340
+ */
1341
+ removeEditVariable(variable) {
1342
+ let editPair = this._editMap.erase(variable);
1343
+ if (editPair === void 0) {
1344
+ throw new Error("unknown edit variable");
1345
+ }
1346
+ this.removeConstraint(editPair.second.constraint);
1347
+ }
1348
+ /**
1349
+ * Test whether the solver contains the edit variable.
1350
+ *
1351
+ * @param {Variable} variable Edit variable to test for
1352
+ * @return {Bool} true or false
1353
+ */
1354
+ hasEditVariable(variable) {
1355
+ return this._editMap.contains(variable);
1356
+ }
1357
+ /**
1358
+ * Suggest the value of an edit variable.
1359
+ *
1360
+ * @param {Variable} variable Edit variable to suggest a value for
1361
+ * @param {Number} value Suggested value
1362
+ */
1363
+ suggestValue(variable, value) {
1364
+ let editPair = this._editMap.find(variable);
1365
+ if (editPair === void 0) {
1366
+ throw new Error("unknown edit variable");
1367
+ }
1368
+ let rows = this._rowMap;
1369
+ let info = editPair.second;
1370
+ let delta = value - info.constant;
1371
+ info.constant = value;
1372
+ let marker = info.tag.marker;
1373
+ let rowPair = rows.find(marker);
1374
+ if (rowPair !== void 0) {
1375
+ if (rowPair.second.add(-delta) < 0) {
1376
+ this._infeasibleRows.push(marker);
1377
+ }
1378
+ this._dualOptimize();
1379
+ return;
1380
+ }
1381
+ let other = info.tag.other;
1382
+ rowPair = rows.find(other);
1383
+ if (rowPair !== void 0) {
1384
+ if (rowPair.second.add(delta) < 0) {
1385
+ this._infeasibleRows.push(other);
1386
+ }
1387
+ this._dualOptimize();
1388
+ return;
1389
+ }
1390
+ for (let i = 0, n = rows.size(); i < n; ++i) {
1391
+ let rowPair2 = rows.itemAt(i);
1392
+ let row = rowPair2.second;
1393
+ let coeff = row.coefficientFor(marker);
1394
+ if (coeff !== 0 && row.add(delta * coeff) < 0 && rowPair2.first.type() !== SymbolType.External) {
1395
+ this._infeasibleRows.push(rowPair2.first);
1396
+ }
1397
+ }
1398
+ this._dualOptimize();
1399
+ }
1400
+ /**
1401
+ * Update the values of the variables.
1402
+ */
1403
+ updateVariables() {
1404
+ let vars2 = this._varMap;
1405
+ let rows = this._rowMap;
1406
+ for (let i = 0, n = vars2.size(); i < n; ++i) {
1407
+ let pair = vars2.itemAt(i);
1408
+ let rowPair = rows.find(pair.second);
1409
+ if (rowPair !== void 0) {
1410
+ pair.first.setValue(rowPair.second.constant());
1411
+ } else {
1412
+ pair.first.setValue(0);
1413
+ }
1414
+ }
1415
+ }
1416
+ /**
1417
+ * Get the symbol for the given variable.
1418
+ *
1419
+ * If a symbol does not exist for the variable, one will be created.
1420
+ * @private
1421
+ */
1422
+ _getVarSymbol(variable) {
1423
+ let factory = () => this._makeSymbol(SymbolType.External);
1424
+ return this._varMap.setDefault(variable, factory).second;
1425
+ }
1426
+ /**
1427
+ * Create a new Row object for the given constraint.
1428
+ *
1429
+ * The terms in the constraint will be converted to cells in the row.
1430
+ * Any term in the constraint with a coefficient of zero is ignored.
1431
+ * This method uses the `_getVarSymbol` method to get the symbol for
1432
+ * the variables added to the row. If the symbol for a given cell
1433
+ * variable is basic, the cell variable will be substituted with the
1434
+ * basic row.
1435
+ *
1436
+ * The necessary slack and error variables will be added to the row.
1437
+ * If the constant for the row is negative, the sign for the row
1438
+ * will be inverted so the constant becomes positive.
1439
+ *
1440
+ * Returns the created Row and the tag for tracking the constraint.
1441
+ * @private
1442
+ */
1443
+ _createRow(constraint) {
1444
+ let expr = constraint.expression();
1445
+ let row = new Row(expr.constant());
1446
+ let terms = expr.terms();
1447
+ for (let i = 0, n = terms.size(); i < n; ++i) {
1448
+ let termPair = terms.itemAt(i);
1449
+ if (!nearZero(termPair.second)) {
1450
+ let symbol = this._getVarSymbol(termPair.first);
1451
+ let basicPair = this._rowMap.find(symbol);
1452
+ if (basicPair !== void 0) {
1453
+ row.insertRow(basicPair.second, termPair.second);
1454
+ } else {
1455
+ row.insertSymbol(symbol, termPair.second);
1456
+ }
1457
+ }
1458
+ }
1459
+ let objective = this._objective;
1460
+ let strength = constraint.strength();
1461
+ let tag = { marker: INVALID_SYMBOL, other: INVALID_SYMBOL };
1462
+ switch (constraint.op()) {
1463
+ case Operator.Le:
1464
+ case Operator.Ge: {
1465
+ let coeff = constraint.op() === Operator.Le ? 1 : -1;
1466
+ let slack = this._makeSymbol(SymbolType.Slack);
1467
+ tag.marker = slack;
1468
+ row.insertSymbol(slack, coeff);
1469
+ if (strength < Strength.required) {
1470
+ let error = this._makeSymbol(SymbolType.Error);
1471
+ tag.other = error;
1472
+ row.insertSymbol(error, -coeff);
1473
+ objective.insertSymbol(error, strength);
1474
+ }
1475
+ break;
1476
+ }
1477
+ case Operator.Eq: {
1478
+ if (strength < Strength.required) {
1479
+ let errplus = this._makeSymbol(SymbolType.Error);
1480
+ let errminus = this._makeSymbol(SymbolType.Error);
1481
+ tag.marker = errplus;
1482
+ tag.other = errminus;
1483
+ row.insertSymbol(errplus, -1);
1484
+ row.insertSymbol(errminus, 1);
1485
+ objective.insertSymbol(errplus, strength);
1486
+ objective.insertSymbol(errminus, strength);
1487
+ } else {
1488
+ let dummy = this._makeSymbol(SymbolType.Dummy);
1489
+ tag.marker = dummy;
1490
+ row.insertSymbol(dummy);
1491
+ }
1492
+ break;
1493
+ }
1494
+ }
1495
+ if (row.constant() < 0) {
1496
+ row.reverseSign();
1497
+ }
1498
+ return { row, tag };
1499
+ }
1500
+ /**
1501
+ * Choose the subject for solving for the row.
1502
+ *
1503
+ * This method will choose the best subject for using as the solve
1504
+ * target for the row. An invalid symbol will be returned if there
1505
+ * is no valid target.
1506
+ *
1507
+ * The symbols are chosen according to the following precedence:
1508
+ *
1509
+ * 1) The first symbol representing an external variable.
1510
+ * 2) A negative slack or error tag variable.
1511
+ *
1512
+ * If a subject cannot be found, an invalid symbol will be returned.
1513
+ *
1514
+ * @private
1515
+ */
1516
+ _chooseSubject(row, tag) {
1517
+ let cells = row.cells();
1518
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1519
+ let pair = cells.itemAt(i);
1520
+ if (pair.first.type() === SymbolType.External) {
1521
+ return pair.first;
1522
+ }
1523
+ }
1524
+ let type = tag.marker.type();
1525
+ if (type === SymbolType.Slack || type === SymbolType.Error) {
1526
+ if (row.coefficientFor(tag.marker) < 0) {
1527
+ return tag.marker;
1528
+ }
1529
+ }
1530
+ type = tag.other.type();
1531
+ if (type === SymbolType.Slack || type === SymbolType.Error) {
1532
+ if (row.coefficientFor(tag.other) < 0) {
1533
+ return tag.other;
1534
+ }
1535
+ }
1536
+ return INVALID_SYMBOL;
1537
+ }
1538
+ /**
1539
+ * Add the row to the tableau using an artificial variable.
1540
+ *
1541
+ * This will return false if the constraint cannot be satisfied.
1542
+ *
1543
+ * @private
1544
+ */
1545
+ _addWithArtificialVariable(row) {
1546
+ let art = this._makeSymbol(SymbolType.Slack);
1547
+ this._rowMap.insert(art, row.copy());
1548
+ this._artificial = row.copy();
1549
+ this._optimize(this._artificial);
1550
+ let success = nearZero(this._artificial.constant());
1551
+ this._artificial = null;
1552
+ let pair = this._rowMap.erase(art);
1553
+ if (pair !== void 0) {
1554
+ let basicRow = pair.second;
1555
+ if (basicRow.isConstant()) {
1556
+ return success;
1557
+ }
1558
+ let entering = this._anyPivotableSymbol(basicRow);
1559
+ if (entering.type() === SymbolType.Invalid) {
1560
+ return false;
1561
+ }
1562
+ basicRow.solveForEx(art, entering);
1563
+ this._substitute(entering, basicRow);
1564
+ this._rowMap.insert(entering, basicRow);
1565
+ }
1566
+ let rows = this._rowMap;
1567
+ for (let i = 0, n = rows.size(); i < n; ++i) {
1568
+ rows.itemAt(i).second.removeSymbol(art);
1569
+ }
1570
+ this._objective.removeSymbol(art);
1571
+ return success;
1572
+ }
1573
+ /**
1574
+ * Substitute the parametric symbol with the given row.
1575
+ *
1576
+ * This method will substitute all instances of the parametric symbol
1577
+ * in the tableau and the objective function with the given row.
1578
+ *
1579
+ * @private
1580
+ */
1581
+ _substitute(symbol, row) {
1582
+ let rows = this._rowMap;
1583
+ for (let i = 0, n = rows.size(); i < n; ++i) {
1584
+ let pair = rows.itemAt(i);
1585
+ pair.second.substitute(symbol, row);
1586
+ if (pair.second.constant() < 0 && pair.first.type() !== SymbolType.External) {
1587
+ this._infeasibleRows.push(pair.first);
1588
+ }
1589
+ }
1590
+ this._objective.substitute(symbol, row);
1591
+ if (this._artificial) {
1592
+ this._artificial.substitute(symbol, row);
1593
+ }
1594
+ }
1595
+ /**
1596
+ * Optimize the system for the given objective function.
1597
+ *
1598
+ * This method performs iterations of Phase 2 of the simplex method
1599
+ * until the objective function reaches a minimum.
1600
+ *
1601
+ * @private
1602
+ */
1603
+ _optimize(objective) {
1604
+ let iterations = 0;
1605
+ while (iterations < this.maxIterations) {
1606
+ let entering = this._getEnteringSymbol(objective);
1607
+ if (entering.type() === SymbolType.Invalid) {
1608
+ return;
1609
+ }
1610
+ let leaving = this._getLeavingSymbol(entering);
1611
+ if (leaving.type() === SymbolType.Invalid) {
1612
+ throw new Error("the objective is unbounded");
1613
+ }
1614
+ let row = this._rowMap.erase(leaving).second;
1615
+ row.solveForEx(leaving, entering);
1616
+ this._substitute(entering, row);
1617
+ this._rowMap.insert(entering, row);
1618
+ iterations++;
1619
+ }
1620
+ throw new Error("solver iterations exceeded");
1621
+ }
1622
+ /**
1623
+ * Optimize the system using the dual of the simplex method.
1624
+ *
1625
+ * The current state of the system should be such that the objective
1626
+ * function is optimal, but not feasible. This method will perform
1627
+ * an iteration of the dual simplex method to make the solution both
1628
+ * optimal and feasible.
1629
+ *
1630
+ * @private
1631
+ */
1632
+ _dualOptimize() {
1633
+ let rows = this._rowMap;
1634
+ let infeasible = this._infeasibleRows;
1635
+ while (infeasible.length !== 0) {
1636
+ let leaving = infeasible.pop();
1637
+ let pair = rows.find(leaving);
1638
+ if (pair !== void 0 && pair.second.constant() < 0) {
1639
+ let entering = this._getDualEnteringSymbol(pair.second);
1640
+ if (entering.type() === SymbolType.Invalid) {
1641
+ throw new Error("dual optimize failed");
1642
+ }
1643
+ let row = pair.second;
1644
+ rows.erase(leaving);
1645
+ row.solveForEx(leaving, entering);
1646
+ this._substitute(entering, row);
1647
+ rows.insert(entering, row);
1648
+ }
1649
+ }
1650
+ }
1651
+ /**
1652
+ * Compute the entering variable for a pivot operation.
1653
+ *
1654
+ * This method will return first symbol in the objective function which
1655
+ * is non-dummy and has a coefficient less than zero. If no symbol meets
1656
+ * the criteria, it means the objective function is at a minimum, and an
1657
+ * invalid symbol is returned.
1658
+ *
1659
+ * @private
1660
+ */
1661
+ _getEnteringSymbol(objective) {
1662
+ let cells = objective.cells();
1663
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1664
+ let pair = cells.itemAt(i);
1665
+ let symbol = pair.first;
1666
+ if (pair.second < 0 && symbol.type() !== SymbolType.Dummy) {
1667
+ return symbol;
1668
+ }
1669
+ }
1670
+ return INVALID_SYMBOL;
1671
+ }
1672
+ /**
1673
+ * Compute the entering symbol for the dual optimize operation.
1674
+ *
1675
+ * This method will return the symbol in the row which has a positive
1676
+ * coefficient and yields the minimum ratio for its respective symbol
1677
+ * in the objective function. The provided row *must* be infeasible.
1678
+ * If no symbol is found which meats the criteria, an invalid symbol
1679
+ * is returned.
1680
+ *
1681
+ * @private
1682
+ */
1683
+ _getDualEnteringSymbol(row) {
1684
+ let ratio = Number.MAX_VALUE;
1685
+ let entering = INVALID_SYMBOL;
1686
+ let cells = row.cells();
1687
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1688
+ let pair = cells.itemAt(i);
1689
+ let symbol = pair.first;
1690
+ let c = pair.second;
1691
+ if (c > 0 && symbol.type() !== SymbolType.Dummy) {
1692
+ let coeff = this._objective.coefficientFor(symbol);
1693
+ let r = coeff / c;
1694
+ if (r < ratio) {
1695
+ ratio = r;
1696
+ entering = symbol;
1697
+ }
1698
+ }
1699
+ }
1700
+ return entering;
1701
+ }
1702
+ /**
1703
+ * Compute the symbol for pivot exit row.
1704
+ *
1705
+ * This method will return the symbol for the exit row in the row
1706
+ * map. If no appropriate exit symbol is found, an invalid symbol
1707
+ * will be returned. This indicates that the objective function is
1708
+ * unbounded.
1709
+ *
1710
+ * @private
1711
+ */
1712
+ _getLeavingSymbol(entering) {
1713
+ let ratio = Number.MAX_VALUE;
1714
+ let found = INVALID_SYMBOL;
1715
+ let rows = this._rowMap;
1716
+ for (let i = 0, n = rows.size(); i < n; ++i) {
1717
+ let pair = rows.itemAt(i);
1718
+ let symbol = pair.first;
1719
+ if (symbol.type() !== SymbolType.External) {
1720
+ let row = pair.second;
1721
+ let temp = row.coefficientFor(entering);
1722
+ if (temp < 0) {
1723
+ let temp_ratio = -row.constant() / temp;
1724
+ if (temp_ratio < ratio) {
1725
+ ratio = temp_ratio;
1726
+ found = symbol;
1727
+ }
1728
+ }
1729
+ }
1730
+ }
1731
+ return found;
1732
+ }
1733
+ /**
1734
+ * Compute the leaving symbol for a marker variable.
1735
+ *
1736
+ * This method will return a symbol corresponding to a basic row
1737
+ * which holds the given marker variable. The row will be chosen
1738
+ * according to the following precedence:
1739
+ *
1740
+ * 1) The row with a restricted basic varible and a negative coefficient
1741
+ * for the marker with the smallest ratio of -constant / coefficient.
1742
+ *
1743
+ * 2) The row with a restricted basic variable and the smallest ratio
1744
+ * of constant / coefficient.
1745
+ *
1746
+ * 3) The last unrestricted row which contains the marker.
1747
+ *
1748
+ * If the marker does not exist in any row, an invalid symbol will be
1749
+ * returned. This indicates an internal solver error since the marker
1750
+ * *should* exist somewhere in the tableau.
1751
+ *
1752
+ * @private
1753
+ */
1754
+ _getMarkerLeavingSymbol(marker) {
1755
+ let dmax = Number.MAX_VALUE;
1756
+ let r1 = dmax;
1757
+ let r2 = dmax;
1758
+ let invalid = INVALID_SYMBOL;
1759
+ let first = invalid;
1760
+ let second = invalid;
1761
+ let third = invalid;
1762
+ let rows = this._rowMap;
1763
+ for (let i = 0, n = rows.size(); i < n; ++i) {
1764
+ let pair = rows.itemAt(i);
1765
+ let row = pair.second;
1766
+ let c = row.coefficientFor(marker);
1767
+ if (c === 0) {
1768
+ continue;
1769
+ }
1770
+ let symbol = pair.first;
1771
+ if (symbol.type() === SymbolType.External) {
1772
+ third = symbol;
1773
+ } else if (c < 0) {
1774
+ let r = -row.constant() / c;
1775
+ if (r < r1) {
1776
+ r1 = r;
1777
+ first = symbol;
1778
+ }
1779
+ } else {
1780
+ let r = row.constant() / c;
1781
+ if (r < r2) {
1782
+ r2 = r;
1783
+ second = symbol;
1784
+ }
1785
+ }
1786
+ }
1787
+ if (first !== invalid) {
1788
+ return first;
1789
+ }
1790
+ if (second !== invalid) {
1791
+ return second;
1792
+ }
1793
+ return third;
1794
+ }
1795
+ /**
1796
+ * Remove the effects of a constraint on the objective function.
1797
+ *
1798
+ * @private
1799
+ */
1800
+ _removeConstraintEffects(cn, tag) {
1801
+ if (tag.marker.type() === SymbolType.Error) {
1802
+ this._removeMarkerEffects(tag.marker, cn.strength());
1803
+ }
1804
+ if (tag.other.type() === SymbolType.Error) {
1805
+ this._removeMarkerEffects(tag.other, cn.strength());
1806
+ }
1807
+ }
1808
+ /**
1809
+ * Remove the effects of an error marker on the objective function.
1810
+ *
1811
+ * @private
1812
+ */
1813
+ _removeMarkerEffects(marker, strength) {
1814
+ let pair = this._rowMap.find(marker);
1815
+ if (pair !== void 0) {
1816
+ this._objective.insertRow(pair.second, -strength);
1817
+ } else {
1818
+ this._objective.insertSymbol(marker, -strength);
1819
+ }
1820
+ }
1821
+ /**
1822
+ * Get the first Slack or Error symbol in the row.
1823
+ *
1824
+ * If no such symbol is present, an invalid symbol will be returned.
1825
+ *
1826
+ * @private
1827
+ */
1828
+ _anyPivotableSymbol(row) {
1829
+ let cells = row.cells();
1830
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1831
+ let pair = cells.itemAt(i);
1832
+ let type = pair.first.type();
1833
+ if (type === SymbolType.Slack || type === SymbolType.Error) {
1834
+ return pair.first;
1835
+ }
1836
+ }
1837
+ return INVALID_SYMBOL;
1838
+ }
1839
+ /**
1840
+ * Returns a new Symbol of the given type.
1841
+ *
1842
+ * @private
1843
+ */
1844
+ _makeSymbol(type) {
1845
+ return new Symbol$1(type, this._idTick++);
1846
+ }
1847
+ }
1848
+ function nearZero(value) {
1849
+ let eps = 1e-8;
1850
+ return value < 0 ? -value < eps : value < eps;
1851
+ }
1852
+ function createCnMap() {
1853
+ return createMap();
1854
+ }
1855
+ function createRowMap() {
1856
+ return createMap();
1857
+ }
1858
+ function createVarMap() {
1859
+ return createMap();
1860
+ }
1861
+ function createEditMap() {
1862
+ return createMap();
1863
+ }
1864
+ var SymbolType;
1865
+ (function(SymbolType2) {
1866
+ SymbolType2[SymbolType2["Invalid"] = 0] = "Invalid";
1867
+ SymbolType2[SymbolType2["External"] = 1] = "External";
1868
+ SymbolType2[SymbolType2["Slack"] = 2] = "Slack";
1869
+ SymbolType2[SymbolType2["Error"] = 3] = "Error";
1870
+ SymbolType2[SymbolType2["Dummy"] = 4] = "Dummy";
1871
+ })(SymbolType || (SymbolType = {}));
1872
+ let Symbol$1 = class Symbol2 {
1873
+ /**
1874
+ * Construct a new Symbol
1875
+ *
1876
+ * @param [type] The type of the symbol.
1877
+ * @param [id] The unique id number of the symbol.
1878
+ */
1879
+ constructor(type, id) {
1880
+ __publicField(this, "_id");
1881
+ __publicField(this, "_type");
1882
+ this._id = id;
1883
+ this._type = type;
1884
+ }
1885
+ /**
1886
+ * Returns the unique id number of the symbol.
1887
+ */
1888
+ id() {
1889
+ return this._id;
1890
+ }
1891
+ /**
1892
+ * Returns the type of the symbol.
1893
+ */
1894
+ type() {
1895
+ return this._type;
1896
+ }
1897
+ };
1898
+ let INVALID_SYMBOL = new Symbol$1(SymbolType.Invalid, -1);
1899
+ class Row {
1900
+ /**
1901
+ * Construct a new Row.
1902
+ */
1903
+ constructor(constant = 0) {
1904
+ __publicField(this, "_cellMap", createMap());
1905
+ __publicField(this, "_constant");
1906
+ this._constant = constant;
1907
+ }
1908
+ /**
1909
+ * Returns the mapping of symbols to coefficients.
1910
+ */
1911
+ cells() {
1912
+ return this._cellMap;
1913
+ }
1914
+ /**
1915
+ * Returns the constant for the row.
1916
+ */
1917
+ constant() {
1918
+ return this._constant;
1919
+ }
1920
+ /**
1921
+ * Returns true if the row is a constant value.
1922
+ */
1923
+ isConstant() {
1924
+ return this._cellMap.empty();
1925
+ }
1926
+ /**
1927
+ * Returns true if the Row has all dummy symbols.
1928
+ */
1929
+ allDummies() {
1930
+ let cells = this._cellMap;
1931
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1932
+ let pair = cells.itemAt(i);
1933
+ if (pair.first.type() !== SymbolType.Dummy) {
1934
+ return false;
1935
+ }
1936
+ }
1937
+ return true;
1938
+ }
1939
+ /**
1940
+ * Create a copy of the row.
1941
+ */
1942
+ copy() {
1943
+ let theCopy = new Row(this._constant);
1944
+ theCopy._cellMap = this._cellMap.copy();
1945
+ return theCopy;
1946
+ }
1947
+ /**
1948
+ * Add a constant value to the row constant.
1949
+ *
1950
+ * Returns the new value of the constant.
1951
+ */
1952
+ add(value) {
1953
+ return this._constant += value;
1954
+ }
1955
+ /**
1956
+ * Insert the symbol into the row with the given coefficient.
1957
+ *
1958
+ * If the symbol already exists in the row, the coefficient
1959
+ * will be added to the existing coefficient. If the resulting
1960
+ * coefficient is zero, the symbol will be removed from the row.
1961
+ */
1962
+ insertSymbol(symbol, coefficient = 1) {
1963
+ let pair = this._cellMap.setDefault(symbol, () => 0);
1964
+ if (nearZero(pair.second += coefficient)) {
1965
+ this._cellMap.erase(symbol);
1966
+ }
1967
+ }
1968
+ /**
1969
+ * Insert a row into this row with a given coefficient.
1970
+ *
1971
+ * The constant and the cells of the other row will be
1972
+ * multiplied by the coefficient and added to this row. Any
1973
+ * cell with a resulting coefficient of zero will be removed
1974
+ * from the row.
1975
+ */
1976
+ insertRow(other, coefficient = 1) {
1977
+ this._constant += other._constant * coefficient;
1978
+ let cells = other._cellMap;
1979
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1980
+ let pair = cells.itemAt(i);
1981
+ this.insertSymbol(pair.first, pair.second * coefficient);
1982
+ }
1983
+ }
1984
+ /**
1985
+ * Remove a symbol from the row.
1986
+ */
1987
+ removeSymbol(symbol) {
1988
+ this._cellMap.erase(symbol);
1989
+ }
1990
+ /**
1991
+ * Reverse the sign of the constant and cells in the row.
1992
+ */
1993
+ reverseSign() {
1994
+ this._constant = -this._constant;
1995
+ let cells = this._cellMap;
1996
+ for (let i = 0, n = cells.size(); i < n; ++i) {
1997
+ let pair = cells.itemAt(i);
1998
+ pair.second = -pair.second;
1999
+ }
2000
+ }
2001
+ /**
2002
+ * Solve the row for the given symbol.
2003
+ *
2004
+ * This method assumes the row is of the form
2005
+ * a * x + b * y + c = 0 and (assuming solve for x) will modify
2006
+ * the row to represent the right hand side of
2007
+ * x = -b/a * y - c / a. The target symbol will be removed from
2008
+ * the row, and the constant and other cells will be multiplied
2009
+ * by the negative inverse of the target coefficient.
2010
+ *
2011
+ * The given symbol *must* exist in the row.
2012
+ */
2013
+ solveFor(symbol) {
2014
+ let cells = this._cellMap;
2015
+ let pair = cells.erase(symbol);
2016
+ let coeff = -1 / pair.second;
2017
+ this._constant *= coeff;
2018
+ for (let i = 0, n = cells.size(); i < n; ++i) {
2019
+ cells.itemAt(i).second *= coeff;
2020
+ }
2021
+ }
2022
+ /**
2023
+ * Solve the row for the given symbols.
2024
+ *
2025
+ * This method assumes the row is of the form
2026
+ * x = b * y + c and will solve the row such that
2027
+ * y = x / b - c / b. The rhs symbol will be removed from the
2028
+ * row, the lhs added, and the result divided by the negative
2029
+ * inverse of the rhs coefficient.
2030
+ *
2031
+ * The lhs symbol *must not* exist in the row, and the rhs
2032
+ * symbol must* exist in the row.
2033
+ */
2034
+ solveForEx(lhs, rhs) {
2035
+ this.insertSymbol(lhs, -1);
2036
+ this.solveFor(rhs);
2037
+ }
2038
+ /**
2039
+ * Returns the coefficient for the given symbol.
2040
+ */
2041
+ coefficientFor(symbol) {
2042
+ let pair = this._cellMap.find(symbol);
2043
+ return pair !== void 0 ? pair.second : 0;
2044
+ }
2045
+ /**
2046
+ * Substitute a symbol with the data from another row.
2047
+ *
2048
+ * Given a row of the form a * x + b and a substitution of the
2049
+ * form x = 3 * y + c the row will be updated to reflect the
2050
+ * expression 3 * a * y + a * c + b.
2051
+ *
2052
+ * If the symbol does not exist in the row, this is a no-op.
2053
+ */
2054
+ substitute(symbol, row) {
2055
+ let pair = this._cellMap.erase(symbol);
2056
+ if (pair !== void 0) {
2057
+ this.insertRow(row, pair.second);
2058
+ }
2059
+ }
2060
+ }
2061
+ class Rect {
2062
+ constructor() {
2063
+ __publicField(this, "id");
2064
+ __publicField(this, "minX", new Variable());
2065
+ __publicField(this, "minY", new Variable());
2066
+ __publicField(this, "maxX", new Variable());
2067
+ __publicField(this, "maxY", new Variable());
2068
+ }
2069
+ get x() {
2070
+ return this.minX;
2071
+ }
2072
+ get y() {
2073
+ return this.minY;
2074
+ }
2075
+ get positionAbsolute() {
2076
+ return {
2077
+ x: this.x.value(),
2078
+ y: this.y.value()
2079
+ };
2080
+ }
2081
+ // Position relative to parent
2082
+ get position() {
2083
+ const positionAbsolute = this.positionAbsolute;
2084
+ return this.parent ? {
2085
+ x: positionAbsolute.x - this.parent.x.value(),
2086
+ y: positionAbsolute.y - this.parent.y.value()
2087
+ } : positionAbsolute;
2088
+ }
2089
+ }
2090
+ class Compound extends Rect {
2091
+ constructor(solver, xynode, parent = null) {
2092
+ super();
2093
+ __publicField(this, "children", []);
2094
+ this.solver = solver;
2095
+ this.parent = parent;
2096
+ this.id = xynode.id;
2097
+ solver.createConstraint(this.maxX, Operator.Ge, this.minX);
2098
+ solver.createConstraint(this.maxY, Operator.Ge, this.minY);
2099
+ if (parent) {
2100
+ parent.addChild(this);
2101
+ }
2102
+ }
2103
+ addChild(rect) {
2104
+ this.children.push(rect);
2105
+ const leftPadding = new Expression(
2106
+ rect.minX,
2107
+ [-1, this.minX]
2108
+ );
2109
+ const { weak } = Strength;
2110
+ this.solver.createConstraint(leftPadding, Operator.Ge, 40);
2111
+ this.solver.createConstraint(leftPadding, Operator.Eq, 40, weak);
2112
+ const topPadding = new Expression(
2113
+ rect.minY,
2114
+ [-1, this.minY]
2115
+ );
2116
+ this.solver.createConstraint(topPadding, Operator.Ge, 60);
2117
+ this.solver.createConstraint(topPadding, Operator.Eq, 60, weak);
2118
+ const rightPadding = new Expression(
2119
+ this.maxX,
2120
+ [-1, rect.maxX]
2121
+ );
2122
+ this.solver.createConstraint(rightPadding, Operator.Ge, 40);
2123
+ this.solver.createConstraint(rightPadding, Operator.Eq, 40, weak);
2124
+ const bottomPadding = new Expression(
2125
+ this.maxY,
2126
+ [-1, rect.maxY]
2127
+ );
2128
+ this.solver.createConstraint(bottomPadding, Operator.Ge, 40);
2129
+ this.solver.createConstraint(bottomPadding, Operator.Eq, 40, weak);
2130
+ }
2131
+ }
2132
+ class Leaf extends Rect {
2133
+ constructor(solver, xynode, parent = null, isEditing = false) {
2134
+ var _a, _b, _c;
2135
+ super();
2136
+ __publicField(this, "id");
2137
+ this.parent = parent;
2138
+ this.isEditing = isEditing;
2139
+ this.id = xynode.id;
2140
+ const pos = ((_a = xynode.computed) == null ? void 0 : _a.positionAbsolute) ?? {
2141
+ x: xynode.data.element.position[0],
2142
+ y: xynode.data.element.position[1]
2143
+ };
2144
+ const width = ((_b = xynode.computed) == null ? void 0 : _b.width) ?? xynode.data.element.width;
2145
+ const height = ((_c = xynode.computed) == null ? void 0 : _c.height) ?? xynode.data.element.height;
2146
+ this.maxX = new Expression(this.minX, width);
2147
+ this.maxY = new Expression(this.minY, height);
2148
+ if (isEditing) {
2149
+ const superStrong = Strength.create(100, 0, 0);
2150
+ solver.addEditVariable(this.minX, superStrong);
2151
+ solver.addEditVariable(this.minY, superStrong);
2152
+ solver.suggestValue(this.minX, pos.x);
2153
+ solver.suggestValue(this.minY, pos.y);
2154
+ } else {
2155
+ const halfMedium = Strength.create(0, 1, 0, 0.5);
2156
+ solver.createConstraint(this.minX, Operator.Eq, pos.x, halfMedium);
2157
+ solver.createConstraint(this.minY, Operator.Eq, pos.y, halfMedium);
2158
+ }
2159
+ if (parent) {
2160
+ parent.addChild(this);
2161
+ }
2162
+ }
2163
+ }
2164
+ function createLayoutConstraints(xyflow, draggingNodeId) {
2165
+ const solver = new Solver();
2166
+ const rects = /* @__PURE__ */ new Map();
2167
+ const xynodes = xyflow.getNodes();
2168
+ const rootNodes = xynodes.filter((n) => isNullish(n.parentNode));
2169
+ const traverse = rootNodes.map((xynode) => ({
2170
+ xynode,
2171
+ parent: null
2172
+ }));
2173
+ while (traverse.length > 0) {
2174
+ const { xynode, parent } = traverse.pop();
2175
+ const isDragging = xynode.dragging === true || xynode.id === draggingNodeId;
2176
+ const isCompound = !isDragging && xynode.type === "compound" && isAncestor(xynode.id, draggingNodeId);
2177
+ const rect = isCompound ? new Compound(solver, xynode, parent) : new Leaf(solver, xynode, parent, isDragging);
2178
+ rects.set(xynode.id, rect);
2179
+ if (isCompound) {
2180
+ const children = xynodes.flatMap(
2181
+ (child) => child.parentNode === xynode.id ? {
2182
+ xynode: child,
2183
+ parent: rect
2184
+ } : []
2185
+ );
2186
+ traverse.push(
2187
+ ...children
2188
+ );
2189
+ }
2190
+ }
2191
+ solver.updateVariables();
2192
+ solver.maxIterations = 1e3;
2193
+ function updateXYFlowNodes() {
2194
+ solver.updateVariables();
2195
+ xyflow.setNodes(
2196
+ (nodes) => nodes.map((n) => {
2197
+ if (n.id === draggingNodeId || n.dragging === true) {
2198
+ return n;
2199
+ }
2200
+ const rect = rects.get(n.id);
2201
+ if (!rect) {
2202
+ return n;
2203
+ }
2204
+ const newPosition = rect.position;
2205
+ n.position.x = newPosition.x;
2206
+ n.position.y = newPosition.y;
2207
+ n.width = rect.maxX.value() - rect.minX.value();
2208
+ n.height = rect.maxY.value() - rect.minY.value();
2209
+ return n;
2210
+ })
2211
+ );
2212
+ }
2213
+ let animationFrameId = null;
2214
+ function onNodeDrag(xynode) {
2215
+ var _a;
2216
+ const pos = nonNullable((_a = xynode.computed) == null ? void 0 : _a.positionAbsolute, "No positionAbsolute");
2217
+ const rect = nonNullable(rects.get(xynode.id));
2218
+ solver.suggestValue(rect.minX, pos.x);
2219
+ solver.suggestValue(rect.minY, pos.y);
2220
+ animationFrameId ?? (animationFrameId = window.requestAnimationFrame(() => {
2221
+ updateXYFlowNodes();
2222
+ animationFrameId = null;
2223
+ }));
2224
+ }
2225
+ return {
2226
+ onNodeDrag,
2227
+ updateXYFlowNodes
2228
+ };
2229
+ }
2230
+ function useLayoutConstraints(xyflow) {
2231
+ const solverRef = useRef();
2232
+ const constraintsRef = useRef();
2233
+ constraintsRef.current ?? (constraintsRef.current = {
2234
+ onNodeDragStart: (event, xynode) => {
2235
+ invariant(xyflow.current, "xyflow.current should be defined");
2236
+ invariant(!solverRef.current, "solverRef.current should be undefined");
2237
+ solverRef.current = createLayoutConstraints(xyflow.current, xynode.id);
2238
+ },
2239
+ onNodeDrag: (event, xynode) => {
2240
+ var _a;
2241
+ invariant(solverRef.current, "solverRef.current should be defined");
2242
+ (_a = solverRef.current) == null ? void 0 : _a.onNodeDrag(xynode);
2243
+ },
2244
+ onNodeDragStop: (event, xynode) => {
2245
+ solverRef.current = void 0;
2246
+ }
2247
+ });
2248
+ return constraintsRef.current;
2249
+ }
2250
+ const useXYFlow = useReactFlow;
2251
+ const useXYNodesData = useNodesData;
2252
+ const EventHandlersContext = createContext(null);
2253
+ function useXYFlowEvents() {
2254
+ const ctx = useContext(EventHandlersContext);
2255
+ return nonNullable(ctx, "useXYFlowEvents could be used only inside XYFlowEventHandlers");
2256
+ }
2257
+ function XYFlowEventHandlers({
2258
+ children,
2259
+ eventHandlers
2260
+ }) {
2261
+ const originalsRef = useRef(eventHandlers);
2262
+ originalsRef.current = eventHandlers;
2263
+ const xyflowRef = useSyncedRef(useXYFlow());
2264
+ const dblclickTimeout = useRef();
2265
+ const [xyFlowEvents] = useState(() => ({
2266
+ onPanelClick: (event) => {
2267
+ var _a, _b;
2268
+ if (!originalsRef.current.onCanvasDblClick) {
2269
+ (_b = (_a = originalsRef.current).onCanvasClick) == null ? void 0 : _b.call(_a, event);
2270
+ return;
2271
+ }
2272
+ if (dblclickTimeout.current) {
2273
+ window.clearTimeout(dblclickTimeout.current);
2274
+ dblclickTimeout.current = void 0;
2275
+ originalsRef.current.onCanvasDblClick(event);
2276
+ return;
2277
+ }
2278
+ dblclickTimeout.current = window.setTimeout(() => {
2279
+ var _a2, _b2;
2280
+ dblclickTimeout.current = void 0;
2281
+ (_b2 = (_a2 = originalsRef.current).onCanvasClick) == null ? void 0 : _b2.call(_a2, event);
2282
+ }, 300);
2283
+ },
2284
+ onNodeContextMenu: (event, xynode) => {
2285
+ var _a, _b;
2286
+ (_b = (_a = originalsRef.current).onNodeContextMenu) == null ? void 0 : _b.call(_a, {
2287
+ element: xynode.data.element,
2288
+ xynode,
2289
+ event
2290
+ });
2291
+ },
2292
+ onPaneContextMenu: (event) => {
2293
+ var _a, _b;
2294
+ (_b = (_a = originalsRef.current).onCanvasContextMenu) == null ? void 0 : _b.call(_a, event);
2295
+ },
2296
+ onEdgeContextMenu: (event, xyedge) => {
2297
+ var _a, _b;
2298
+ (_b = (_a = originalsRef.current).onEdgeContextMenu) == null ? void 0 : _b.call(_a, {
2299
+ relation: xyedge.data.edge,
2300
+ xyedge,
2301
+ event
2302
+ });
2303
+ },
2304
+ onNodeClick: (event, xynode) => {
2305
+ var _a, _b;
2306
+ (_b = (_a = originalsRef.current).onNodeClick) == null ? void 0 : _b.call(_a, {
2307
+ element: xynode.data.element,
2308
+ xynode,
2309
+ event
2310
+ });
2311
+ },
2312
+ onEdgeClick: (event, xyedge) => {
2313
+ var _a, _b;
2314
+ (_b = (_a = originalsRef.current).onEdgeClick) == null ? void 0 : _b.call(_a, {
2315
+ relation: xyedge.data.edge,
2316
+ xyedge,
2317
+ event
2318
+ });
2319
+ },
2320
+ onNavigateTo: (xynodeId, event) => {
2321
+ if (!originalsRef.current.onNavigateTo) {
2322
+ return;
2323
+ }
2324
+ const xynode = xyflowRef.current.getNode(xynodeId);
2325
+ invariant(xynode, `node not found: ${xynodeId}`);
2326
+ const navigateTo = xynode.data.element.navigateTo;
2327
+ invariant(navigateTo, `node is not navigable: ${xynodeId}`);
2328
+ originalsRef.current.onNavigateTo({
2329
+ element: xynode.data.element,
2330
+ xynode,
2331
+ event
2332
+ });
2333
+ },
2334
+ onChange: (change2) => {
2335
+ var _a, _b;
2336
+ const changes = Array.isArray(change2) ? change2 : [change2];
2337
+ invariant(hasAtLeast$1(changes, 1), "no changes");
2338
+ (_b = (_a = originalsRef.current).onChange) == null ? void 0 : _b.call(_a, { changes });
2339
+ }
2340
+ }));
2341
+ return /* @__PURE__ */ jsx(EventHandlersContext.Provider, { value: xyFlowEvents, children });
2342
+ }
2343
+ const {
2344
+ primary,
2345
+ secondary,
2346
+ muted,
2347
+ ...otherColors
2348
+ } = defaultTheme.elements;
2349
+ const themedColors = [
2350
+ { key: "primary", value: primary.fill },
2351
+ { key: "secondary", value: secondary.fill },
2352
+ { key: "muted", value: muted.fill }
2353
+ ];
2354
+ const colors = keys.strict(otherColors).map((key) => ({
2355
+ key,
2356
+ value: defaultTheme.elements[key].fill
2357
+ }));
2358
+ function NodeOptions({ selectedNodeIds }) {
2359
+ const { onChange } = useXYFlowEvents();
2360
+ const nodes = useXYNodesData(selectedNodeIds);
2361
+ const api = useXYFlow();
2362
+ if (!hasAtLeast(nodes, 1)) {
2363
+ return null;
2364
+ }
2365
+ const showShapeOption = nodes.some((node) => node.type === "element");
2366
+ const [firstNode, ...rest] = nodes;
2367
+ return /* @__PURE__ */ jsxs(Stack, { children: [
2368
+ /* @__PURE__ */ jsx(Box, { maw: 200, children: /* @__PURE__ */ jsx(Text, { size: "xs", c: rest.length > 0 ? "dimmed" : "", truncate: true, children: rest.length === 0 ? firstNode.data.element.title : `[ multiple ]` }) }),
2369
+ showShapeOption && /* @__PURE__ */ jsx(
2370
+ ShapeOption,
2371
+ {
2372
+ nodes,
2373
+ onShapeChange: (shape) => {
2374
+ const targets = [];
2375
+ for (const nd of nodes) {
2376
+ api.updateNodeData(nd.id, ({ data }) => {
2377
+ if (data.element.shape === shape) {
2378
+ return data;
2379
+ }
2380
+ return {
2381
+ ...data,
2382
+ element: {
2383
+ ...data.element,
2384
+ shape
2385
+ }
2386
+ };
2387
+ });
2388
+ targets.push(nd.data.element.id);
2389
+ }
2390
+ if (hasAtLeast(targets, 1)) {
2391
+ onChange({
2392
+ op: "change-shape",
2393
+ shape,
2394
+ targets
2395
+ });
2396
+ }
2397
+ }
2398
+ }
2399
+ ),
2400
+ /* @__PURE__ */ jsx(
2401
+ Colors,
2402
+ {
2403
+ nodes,
2404
+ onColorChange: (color) => {
2405
+ const targets = [];
2406
+ for (const nd of nodes) {
2407
+ api.updateNodeData(nd.id, ({ data }) => {
2408
+ if (data.element.color === color) {
2409
+ return data;
2410
+ }
2411
+ return {
2412
+ ...data,
2413
+ element: {
2414
+ ...data.element,
2415
+ color
2416
+ }
2417
+ };
2418
+ });
2419
+ targets.push(nd.data.element.id);
2420
+ }
2421
+ if (hasAtLeast(targets, 1)) {
2422
+ onChange({
2423
+ op: "change-color",
2424
+ color,
2425
+ targets
2426
+ });
2427
+ }
2428
+ }
2429
+ }
2430
+ ),
2431
+ /* @__PURE__ */ jsx(NavigateToOption, { nodes })
2432
+ ] });
2433
+ }
2434
+ function Colors({
2435
+ nodes: [firstNode, ...nodes],
2436
+ onColorChange
2437
+ }) {
2438
+ let selectedColor = firstNode.data.element.color;
2439
+ takeWhile(nodes, (node) => {
2440
+ if (node.data.element.color !== selectedColor) {
2441
+ selectedColor = null;
2442
+ return false;
2443
+ }
2444
+ return true;
2445
+ });
2446
+ const changeColor = (color) => () => {
2447
+ if (selectedColor === color) {
2448
+ return;
2449
+ }
2450
+ onColorChange(color);
2451
+ };
2452
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Tooltip.Group, { openDelay: 400, closeDelay: 300, children: [
2453
+ /* @__PURE__ */ jsx(Divider, { label: "color", labelPosition: "left" }),
2454
+ /* @__PURE__ */ jsx(Flex, { mt: "xs", maw: 150, gap: "xs", justify: "flex-start", align: "flex-start", direction: "row", wrap: "wrap", children: themedColors.map(({ key, value }) => /* @__PURE__ */ jsx(
2455
+ Tooltip,
2456
+ {
2457
+ label: key,
2458
+ fz: "xs",
2459
+ color: "dark",
2460
+ offset: 2,
2461
+ transitionProps: { duration: 140, transition: "slide-up" },
2462
+ children: /* @__PURE__ */ jsx(
2463
+ ColorSwatch,
2464
+ {
2465
+ color: value,
2466
+ size: 20,
2467
+ withShadow: true,
2468
+ onClick: changeColor(key),
2469
+ style: { color: "#fff", cursor: "pointer" },
2470
+ children: selectedColor === key && /* @__PURE__ */ jsx(CheckIcon, { style: { width: rem(12), height: rem(12) } })
2471
+ }
2472
+ )
2473
+ },
2474
+ key
2475
+ )) }),
2476
+ /* @__PURE__ */ jsx(Flex, { mt: "sm", maw: 150, gap: "xs", justify: "flex-start", align: "flex-start", direction: "row", wrap: "wrap", children: colors.map(({ key, value }) => /* @__PURE__ */ jsx(
2477
+ Tooltip,
2478
+ {
2479
+ label: key,
2480
+ fz: "xs",
2481
+ color: "dark",
2482
+ offset: 2,
2483
+ transitionProps: { duration: 140, transition: "slide-up" },
2484
+ children: /* @__PURE__ */ jsx(
2485
+ ColorSwatch,
2486
+ {
2487
+ color: value,
2488
+ size: 20,
2489
+ onClick: changeColor(key),
2490
+ style: { color: "#fff", cursor: "pointer" },
2491
+ children: selectedColor === key && /* @__PURE__ */ jsx(CheckIcon, { style: { width: rem(12), height: rem(12) } })
2492
+ }
2493
+ )
2494
+ },
2495
+ key
2496
+ )) })
2497
+ ] }) });
2498
+ }
2499
+ function ShapeOption({
2500
+ nodes: [firstNode, ...nodes],
2501
+ onShapeChange
2502
+ }) {
2503
+ let selectedShape = firstNode.data.element.shape;
2504
+ takeWhile(nodes, (node) => {
2505
+ if (node.data.element.shape !== selectedShape) {
2506
+ selectedShape = null;
2507
+ return false;
2508
+ }
2509
+ return true;
2510
+ });
2511
+ return /* @__PURE__ */ jsxs(Box, { children: [
2512
+ /* @__PURE__ */ jsx(Divider, { label: "shape", labelPosition: "left" }),
2513
+ /* @__PURE__ */ jsx(
2514
+ Select,
2515
+ {
2516
+ mt: "xs",
2517
+ size: "xs",
2518
+ variant: "filled",
2519
+ value: selectedShape,
2520
+ placeholder: "[ multiple ]",
2521
+ data: ElementShapes,
2522
+ allowDeselect: false,
2523
+ checkIconPosition: "right",
2524
+ onChange: (value) => {
2525
+ if (!value || value === selectedShape) {
2526
+ return;
2527
+ }
2528
+ onShapeChange(value);
2529
+ }
2530
+ }
2531
+ )
2532
+ ] });
2533
+ }
2534
+ function NavigateToOption({
2535
+ nodes: [node, ...nodes]
2536
+ }) {
2537
+ const isMultiple = nodes.length >= 1;
2538
+ return /* @__PURE__ */ jsxs(Box, { children: [
2539
+ /* @__PURE__ */ jsx(Divider, { label: "navigate to", labelPosition: "left" }),
2540
+ /* @__PURE__ */ jsx(
2541
+ Select,
2542
+ {
2543
+ mt: "xs",
2544
+ size: "xs",
2545
+ variant: "filled",
2546
+ value: !isMultiple ? node.data.element.navigateTo ?? null : null,
2547
+ disabled: isMultiple,
2548
+ placeholder: isMultiple ? "[ multiple ]" : "select",
2549
+ data: node.data.element.navigateTo ? [{ value: node.data.element.navigateTo, label: node.data.element.navigateTo }] : [],
2550
+ allowDeselect: true,
2551
+ checkIconPosition: "right"
2552
+ }
2553
+ )
2554
+ ] });
2555
+ }
2556
+ var panel = "_1lmzt1h0";
2557
+ const OptionsPanelMemo = /* @__PURE__ */ memo(function OptionsPanel() {
2558
+ const [selectedNodes, setSelectedNodes] = useState([]);
2559
+ useOnSelectionChange({
2560
+ onChange: ({ nodes, edges }) => {
2561
+ const next = nodes.map((n) => n.id).sort();
2562
+ setSelectedNodes((prev) => {
2563
+ return shallowEqual(prev, next) ? prev : next;
2564
+ });
2565
+ }
2566
+ });
2567
+ return /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: selectedNodes.length > 0 && /* @__PURE__ */ jsx(
2568
+ motion.div,
2569
+ {
2570
+ initial: { opacity: 0, scale: 0.85 },
2571
+ animate: { opacity: 1, scale: 1 },
2572
+ exit: {
2573
+ opacity: 0,
2574
+ scale: 0.85
2575
+ },
2576
+ transition: { duration: 0.14 },
2577
+ className: clsx("react-flow__panel", panel),
2578
+ style: {
2579
+ transformOrigin: "center right"
2580
+ },
2581
+ children: /* @__PURE__ */ jsx(Card, { shadow: "sm", children: /* @__PURE__ */ jsx(NodeOptions, { selectedNodeIds: selectedNodes }) })
2582
+ }
2583
+ ) });
2584
+ });
2585
+ const OptionsPanel2 = OptionsPanelMemo;
2586
+ function deriveEdgePoints(bezierSpline) {
2587
+ let [start, ...bezierPoints] = bezierSpline;
2588
+ invariant(start, "start should be defined");
2589
+ const handles = [
2590
+ // start
2591
+ ];
2592
+ while (hasAtLeast(bezierPoints, 3)) {
2593
+ const [cp1, cp2, end, ...rest] = bezierPoints;
2594
+ const [centerX, centerY] = getBezierEdgeCenter({
2595
+ sourceX: start[0],
2596
+ sourceY: start[1],
2597
+ targetX: end[0],
2598
+ targetY: end[1],
2599
+ sourceControlX: cp1[0],
2600
+ sourceControlY: cp1[1],
2601
+ targetControlX: cp2[0],
2602
+ targetControlY: cp2[1]
2603
+ });
2604
+ handles.push(
2605
+ [centerX, centerY]
2606
+ );
2607
+ bezierPoints = rest;
2608
+ start = end;
2609
+ }
2610
+ invariant(bezierPoints.length === 0, "all points should be consumed");
2611
+ return handles;
2612
+ }
2613
+ function nodeZIndex(node) {
2614
+ return node.children.length > 0 ? 0 : node.level + 1;
2615
+ }
2616
+ function diagramViewToXYFlowData(view, dragEnabled = true) {
2617
+ const editor = {
2618
+ nodes: [],
2619
+ edges: []
2620
+ };
2621
+ const ns = "";
2622
+ const nodeById = (id) => nonNullable(view.nodes.find((n) => n.id === id));
2623
+ const createNode = (node) => {
2624
+ const isCompound = hasAtLeast(node.children, 1);
2625
+ const id = ns + node.id;
2626
+ const position = {
2627
+ x: node.position[0],
2628
+ y: node.position[1]
2629
+ };
2630
+ const parent = node.parent ? nodeById(node.parent) : null;
2631
+ if (parent) {
2632
+ position.x -= parent.position[0];
2633
+ position.y -= parent.position[1];
2634
+ }
2635
+ const zIndex = nodeZIndex(node);
2636
+ editor.nodes.push({
2637
+ id,
2638
+ type: isCompound ? "compound" : "element",
2639
+ data: {
2640
+ id,
2641
+ element: node
2642
+ },
2643
+ draggable: dragEnabled && (!parent || parent.children.length > 1),
2644
+ deletable: false,
2645
+ position,
2646
+ zIndex,
2647
+ width: node.width,
2648
+ height: node.height,
2649
+ // handles: [
2650
+ // ...outEdges.map(out => ({
2651
+ // id: `${out.id}`,
2652
+ // type: 'source' as const,
2653
+ // position: Position.Bottom,
2654
+ // x: out.points[0][0],
2655
+ // y: out.points[0][1],
2656
+ // width: 10,
2657
+ // height: 10
2658
+ // })),
2659
+ // ...inEdges.map(out => ({
2660
+ // id: out.id,
2661
+ // type: 'target' as const,
2662
+ // position: Position.Top,
2663
+ // x: out.points[0][0],
2664
+ // y: out.points[0][1],
2665
+ // width: 10,
2666
+ // height: 10
2667
+ // }))
2668
+ // ],
2669
+ ...parent ? {
2670
+ parentNode: ns + parent.id
2671
+ } : {}
2672
+ });
2673
+ };
2674
+ for (const node of view.nodes.toSorted(compareByFqnHierarchically)) {
2675
+ createNode(node);
2676
+ }
2677
+ const createEdge = (edge) => {
2678
+ const source = edge.source;
2679
+ const target = edge.target;
2680
+ const id = ns + edge.id;
2681
+ const controlPoints = deriveEdgePoints(edge.points);
2682
+ invariant(hasAtLeast(edge.points, 2), "edge should have at least 2 points");
2683
+ const level = Math.min(nodeById(source).level, nodeById(target).level);
2684
+ editor.edges.push({
2685
+ id,
2686
+ type: "relationship",
2687
+ source: ns + source,
2688
+ target: ns + target,
2689
+ zIndex: level + 1,
2690
+ deletable: false,
2691
+ data: {
2692
+ edge,
2693
+ type: "bezier",
2694
+ controlPoints,
2695
+ headPoint: edge.headArrowPoint ?? null,
2696
+ tailPoint: edge.tailArrowPoint ?? null,
2697
+ label: edge.labelBBox && edge.label ? {
2698
+ bbox: edge.labelBBox,
2699
+ // text: edge.labels ? edge.labels.map(l => l.text).join('\n') : ''
2700
+ text: edge.label
2701
+ } : null
2702
+ },
2703
+ // markerEnd: {
2704
+ // type: MarkerType.ArrowClosed
2705
+ // },
2706
+ interactionWidth: 20
2707
+ });
2708
+ };
2709
+ for (const edge of view.edges) {
2710
+ createEdge(edge);
2711
+ }
2712
+ return editor;
2713
+ }
2714
+ const ZIndexes = {
2715
+ Compound: 1,
2716
+ Edge: 2,
2717
+ Element: 3
2718
+ };
2719
+ const MinZoom = 0.01;
2720
+ function FitViewOnDiagramChange() {
2721
+ const [state, updateState] = useDiagramStateTracked();
2722
+ const xyflow = useXYFlow();
2723
+ const nodeInitialized = useNodesInitialized({
2724
+ includeHiddenNodes: true
2725
+ });
2726
+ const isReady = nodeInitialized && xyflow.viewportInitialized;
2727
+ const viewLayout = state.viewId + "_" + state.viewLayout + "_" + state.fitViewPadding;
2728
+ const prevViewLayoutRef = useRef(viewLayout);
2729
+ useDebouncedEffect(
2730
+ () => {
2731
+ if (!isReady || prevViewLayoutRef.current === viewLayout) {
2732
+ return;
2733
+ }
2734
+ const zoom = xyflow.getZoom();
2735
+ xyflow.setCenter(state.viewWidth / 2, state.viewHeight / 2, {
2736
+ duration: 150,
2737
+ zoom
2738
+ });
2739
+ xyflow.fitView({
2740
+ duration: 350,
2741
+ padding: state.fitViewPadding,
2742
+ minZoom: MinZoom,
2743
+ maxZoom: Math.max(1, zoom)
2744
+ });
2745
+ updateState({ viewportMoved: false });
2746
+ prevViewLayoutRef.current = viewLayout;
2747
+ },
2748
+ [isReady, viewLayout],
2749
+ 50
2750
+ );
2751
+ return null;
2752
+ }
2753
+ function UpdateOnDiagramChange({
2754
+ nodesDraggable,
2755
+ view: {
2756
+ nodes,
2757
+ edges
2758
+ }
2759
+ }) {
2760
+ const xyflow = useXYFlow();
2761
+ const initialized = xyflow.viewportInitialized;
2762
+ useUpdateEffect(
2763
+ () => {
2764
+ if (!initialized) {
2765
+ return;
2766
+ }
2767
+ const updates = diagramViewToXYFlowData({
2768
+ nodes,
2769
+ edges
2770
+ }, nodesDraggable);
2771
+ xyflow.setNodes(
2772
+ (prev) => updates.nodes.map((update) => {
2773
+ const existing = prev.find((p) => p.id === update.id);
2774
+ if (existing && existing.type == update.type) {
2775
+ const { data, parentNode, ...rest } = update;
2776
+ if (!deepEqual(existing.data, data)) {
2777
+ existing.data = data;
2778
+ }
2779
+ if (!isNullish(parentNode)) {
2780
+ existing.parentNode = parentNode;
2781
+ } else {
2782
+ delete existing.parentNode;
2783
+ }
2784
+ return Object.assign(existing, rest);
2785
+ }
2786
+ return update;
2787
+ })
2788
+ );
2789
+ xyflow.setEdges(
2790
+ (prev) => updates.edges.map((update) => {
2791
+ const existing = prev.find((e) => e.id === update.id);
2792
+ if (existing) {
2793
+ if (deepEqual(existing.data.edge, update.data.edge)) {
2794
+ return existing;
2795
+ }
2796
+ return {
2797
+ ...existing,
2798
+ ...update
2799
+ };
2800
+ }
2801
+ return update;
2802
+ })
2803
+ );
2804
+ },
2805
+ [initialized, nodesDraggable, nodes, edges]
2806
+ );
2807
+ return null;
2808
+ }
2809
+ function literalToEnum(value) {
2810
+ switch (value) {
2811
+ case "dots":
2812
+ return BackgroundVariant.Dots;
2813
+ case "lines":
2814
+ return BackgroundVariant.Lines;
2815
+ case "cross":
2816
+ return BackgroundVariant.Cross;
2817
+ default:
2818
+ nonexhaustive(value);
2819
+ }
2820
+ }
2821
+ const XYFlowBackground = memo(({ background }) => {
2822
+ if (typeof background === "string") {
2823
+ return /* @__PURE__ */ jsx(Background, { variant: literalToEnum(background) });
2824
+ }
2825
+ const { variant, ...rest } = background;
2826
+ return /* @__PURE__ */ jsx(Background, { variant: literalToEnum(variant), ...rest });
2827
+ }, deepEqual);
2828
+ var container$1 = "bexn7q0";
2829
+ var edgePathBg = "bexn7q1";
2830
+ var fillStrokeCtx = "bexn7q2";
2831
+ var cssEdgePath = "bexn7q3";
2832
+ var edgeLabel = "bexn7q4";
2833
+ var edgeLabelBody = "bexn7q5";
2834
+ function getNodeIntersection(intersectionNode, targetNode) {
2835
+ var _a, _b, _c, _d, _e, _f;
2836
+ const intersectionNodeWidth = ((_a = intersectionNode.computed) == null ? void 0 : _a.width) ?? intersectionNode.data.element.width;
2837
+ const intersectionNodeHeight = ((_b = intersectionNode.computed) == null ? void 0 : _b.height) ?? intersectionNode.data.element.height;
2838
+ const intersectionNodePosition = ((_c = intersectionNode.computed) == null ? void 0 : _c.positionAbsolute) ?? { x: intersectionNode.data.element.position[0], y: intersectionNode.data.element.position[1] };
2839
+ const targetPosition = ((_d = targetNode.computed) == null ? void 0 : _d.positionAbsolute) ?? { x: targetNode.data.element.position[0], y: targetNode.data.element.position[1] };
2840
+ const w = intersectionNodeWidth / 2;
2841
+ const h = intersectionNodeHeight / 2;
2842
+ const x2 = intersectionNodePosition.x + w;
2843
+ const y2 = intersectionNodePosition.y + h;
2844
+ const x1 = targetPosition.x + (((_e = targetNode.computed) == null ? void 0 : _e.width) ?? targetNode.data.element.width) / 2;
2845
+ const y1 = targetPosition.y + (((_f = targetNode.computed) == null ? void 0 : _f.height) ?? targetNode.data.element.height) / 2;
2846
+ const xx1 = (x1 - x2) / (2 * w) - (y1 - y2) / (2 * h);
2847
+ const yy1 = (x1 - x2) / (2 * w) + (y1 - y2) / (2 * h);
2848
+ const a = 1 / (Math.abs(xx1) + Math.abs(yy1));
2849
+ const xx3 = a * xx1;
2850
+ const yy3 = a * yy1;
2851
+ const x = w * (xx3 + yy3) + x2;
2852
+ const y = h * (-xx3 + yy3) + y2;
2853
+ return { x, y };
2854
+ }
2855
+ function getPointPosition(node, intersectionPoint) {
2856
+ var _a, _b, _c;
2857
+ const n = {
2858
+ x: node.data.element.position[0],
2859
+ y: node.data.element.position[1],
2860
+ ...(_a = node.computed) == null ? void 0 : _a.positionAbsolute,
2861
+ width: ((_b = node.computed) == null ? void 0 : _b.width) ?? node.data.element.width,
2862
+ height: ((_c = node.computed) == null ? void 0 : _c.height) ?? node.data.element.height
2863
+ };
2864
+ const nx = Math.round(n.x);
2865
+ const ny = Math.round(n.y);
2866
+ const px = Math.round(intersectionPoint.x);
2867
+ const py = Math.round(intersectionPoint.y);
2868
+ let handlePosition = Position.Top;
2869
+ if (px <= nx + 1) {
2870
+ handlePosition = Position.Left;
2871
+ } else if (px >= nx + n.width - 1) {
2872
+ handlePosition = Position.Right;
2873
+ } else if (py <= ny + 1) {
2874
+ handlePosition = Position.Top;
2875
+ } else if (py >= n.y + n.height - 1) {
2876
+ handlePosition = Position.Bottom;
2877
+ }
2878
+ let handleWidth = 8, handleHeight = 8;
2879
+ let offsetX = 0;
2880
+ let offsetY = 0;
2881
+ switch (handlePosition) {
2882
+ case Position.Left:
2883
+ offsetX = -handleWidth;
2884
+ break;
2885
+ case Position.Right:
2886
+ offsetX = handleWidth;
2887
+ break;
2888
+ case Position.Top:
2889
+ offsetY = -handleHeight;
2890
+ break;
2891
+ case Position.Bottom:
2892
+ offsetY = handleHeight;
2893
+ break;
2894
+ }
2895
+ return [
2896
+ intersectionPoint.x + offsetX,
2897
+ intersectionPoint.y + offsetY,
2898
+ handlePosition
2899
+ ];
2900
+ }
2901
+ function getEdgeParams(source, target) {
2902
+ const sourceIntersectionPoint = getNodeIntersection(source, target);
2903
+ const targetIntersectionPoint = getNodeIntersection(target, source);
2904
+ const [sx, sy, sourcePos] = getPointPosition(source, sourceIntersectionPoint);
2905
+ const [tx, ty, targetPos] = getPointPosition(target, targetIntersectionPoint);
2906
+ return {
2907
+ sx,
2908
+ sy,
2909
+ tx,
2910
+ ty,
2911
+ sourcePos,
2912
+ targetPos
2913
+ };
2914
+ }
2915
+ function bezierPath(bezierSpline) {
2916
+ let [start, ...points] = bezierSpline;
2917
+ invariant(start, "start should be defined");
2918
+ let path = `M ${start[0]},${start[1]}`;
2919
+ while (hasAtLeast(points, 3)) {
2920
+ const [cp1, cp2, end, ...rest] = points;
2921
+ path = path + ` C ${cp1[0]},${cp1[1]} ${cp2[0]},${cp2[1]} ${end[0]},${end[1]}`;
2922
+ points = rest;
2923
+ }
2924
+ invariant(points.length === 0, "all points should be consumed");
2925
+ return path;
2926
+ }
2927
+ const isEqualProps$2 = (prev, next) => prev.id === next.id && prev.source === next.source && prev.target === next.target && prev.sourceX === next.sourceX && prev.sourceY === next.sourceY && prev.targetX === next.targetX && prev.targetY === next.targetY && deepEqual(prev.data, next.data);
2928
+ const RelationshipEdge = /* @__PURE__ */ memo(function RelationshipEdgeR({
2929
+ id,
2930
+ data,
2931
+ selected,
2932
+ markerEnd,
2933
+ style,
2934
+ source,
2935
+ target,
2936
+ interactionWidth
2937
+ }) {
2938
+ var _a, _b;
2939
+ const xyflow = useXYFlow();
2940
+ const isModified = useStore(
2941
+ useCallback((s) => {
2942
+ var _a2, _b2;
2943
+ const sourceNode = s.nodeLookup.get(source);
2944
+ const targetNode = s.nodeLookup.get(target);
2945
+ invariant(XYFlowNode.is(sourceNode));
2946
+ invariant(XYFlowNode.is(targetNode));
2947
+ const isSourceModified = !!((_a2 = sourceNode.computed) == null ? void 0 : _a2.positionAbsolute) && !shallowEqual(sourceNode.computed.positionAbsolute, {
2948
+ x: sourceNode.data.element.position[0],
2949
+ y: sourceNode.data.element.position[1]
2950
+ });
2951
+ if (isSourceModified) {
2952
+ return true;
2953
+ }
2954
+ return !!((_b2 = targetNode.computed) == null ? void 0 : _b2.positionAbsolute) && !shallowEqual(targetNode.computed.positionAbsolute, {
2955
+ x: targetNode.data.element.position[0],
2956
+ y: targetNode.data.element.position[1]
2957
+ });
2958
+ }, [source, target]),
2959
+ deepEqual
2960
+ );
2961
+ invariant(data, "data isd required");
2962
+ const {
2963
+ edge,
2964
+ controlPoints
2965
+ } = data;
2966
+ const color = edge.color ?? "gray";
2967
+ const isHovered = useDiagramStateSelector((state) => state.hoveredEdgeId === id);
2968
+ const line = edge.line ?? "dashed";
2969
+ const isDotted = line === "dotted";
2970
+ const isDashed = isDotted || line === "dashed";
2971
+ let strokeDasharray;
2972
+ if (isDotted) {
2973
+ strokeDasharray = "1,8";
2974
+ } else if (isDashed) {
2975
+ strokeDasharray = "8,10";
2976
+ }
2977
+ const marker = `url(#arrow-${id})`;
2978
+ let edgePath, labelX, labelY;
2979
+ if (isModified) {
2980
+ const sourceNode = xyflow.getNode(source);
2981
+ const targetNode = xyflow.getNode(target);
2982
+ const { sx, sy, tx, ty, sourcePos, targetPos } = getEdgeParams(sourceNode, targetNode);
2983
+ const [_edgePath, _labelX, _labelY] = getBezierPath({
2984
+ sourceX: sx,
2985
+ sourceY: sy,
2986
+ sourcePosition: sourcePos,
2987
+ targetPosition: targetPos,
2988
+ targetX: tx,
2989
+ targetY: ty
2990
+ });
2991
+ edgePath = _edgePath;
2992
+ labelX = _labelX;
2993
+ labelY = _labelY;
2994
+ } else {
2995
+ edgePath = bezierPath(edge.points);
2996
+ labelX = ((_a = data.label) == null ? void 0 : _a.bbox.x) ?? 0;
2997
+ labelY = ((_b = data.label) == null ? void 0 : _b.bbox.y) ?? 0;
2998
+ }
2999
+ return /* @__PURE__ */ jsxs("g", { className: clsx(container$1), "data-likec4-color": color, "data-edge-hovered": isHovered, children: [
3000
+ /* @__PURE__ */ jsx("g", { className: clsx(fillStrokeCtx), children: /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
3001
+ "marker",
3002
+ {
3003
+ id: `arrow-${id}`,
3004
+ viewBox: "0 0 10 8",
3005
+ refX: "0",
3006
+ refY: "4",
3007
+ markerWidth: "5",
3008
+ markerHeight: "5",
3009
+ markerUnits: "strokeWidth",
3010
+ preserveAspectRatio: "xMaxYMid meet",
3011
+ orient: "auto-start-reverse",
3012
+ children: /* @__PURE__ */ jsx("path", { d: "M 0 0 L 10 4 L 0 8 z", stroke: "context-stroke", fill: "context-fill" })
3013
+ }
3014
+ ) }) }),
3015
+ /* @__PURE__ */ jsx(
3016
+ "path",
3017
+ {
3018
+ className: clsx("react-flow__edge-path", edgePathBg),
3019
+ d: edgePath,
3020
+ style,
3021
+ strokeLinecap: "round"
3022
+ }
3023
+ ),
3024
+ /* @__PURE__ */ jsx(
3025
+ "path",
3026
+ {
3027
+ className: clsx("react-flow__edge-path", cssEdgePath),
3028
+ d: edgePath,
3029
+ style,
3030
+ strokeLinecap: "round",
3031
+ // strokeLinecap={isDotted ? 'butt' : 'round'}
3032
+ // strokeMiterlimit={10}
3033
+ // strokeLinejoin="bevel"
3034
+ ...strokeDasharray ? { strokeDasharray } : {},
3035
+ ...edge.headArrow ? { markerEnd: marker } : {},
3036
+ ...edge.tailArrow ? { markerStart: marker } : {}
3037
+ }
3038
+ ),
3039
+ /* @__PURE__ */ jsx(
3040
+ "path",
3041
+ {
3042
+ className: clsx("react-flow__edge-interaction"),
3043
+ d: edgePath,
3044
+ fill: "none",
3045
+ strokeOpacity: 0,
3046
+ strokeWidth: interactionWidth ?? 10
3047
+ }
3048
+ ),
3049
+ data.label && /* @__PURE__ */ jsx(EdgeLabelRenderer, { children: /* @__PURE__ */ jsx(
3050
+ Box,
3051
+ {
3052
+ className: clsx(container$1, edgeLabel),
3053
+ "data-likec4-color": color,
3054
+ style: {
3055
+ top: labelY,
3056
+ left: labelX,
3057
+ maxWidth: data.label.bbox.width + 10,
3058
+ zIndex: ZIndexes.Edge
3059
+ },
3060
+ mod: {
3061
+ "data-edge-hovered": isHovered
3062
+ },
3063
+ children: /* @__PURE__ */ jsx(Box, { className: edgeLabelBody, children: data.label.text })
3064
+ }
3065
+ ) })
3066
+ ] });
3067
+ }, isEqualProps$2);
3068
+ function getVarName(variable) {
3069
+ var matches = variable.match(/^var\((.*)\)$/);
3070
+ if (matches) {
3071
+ return matches[1];
3072
+ }
3073
+ return variable;
3074
+ }
3075
+ function get(obj, path) {
3076
+ var result = obj;
3077
+ for (var key of path) {
3078
+ if (!(key in result)) {
3079
+ throw new Error("Path ".concat(path.join(" -> "), " does not exist in object"));
3080
+ }
3081
+ result = result[key];
3082
+ }
3083
+ return result;
3084
+ }
3085
+ function walkObject(obj, fn) {
3086
+ var path = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
3087
+ var clone = {};
3088
+ for (var key in obj) {
3089
+ var _value = obj[key];
3090
+ var currentPath = [...path, key];
3091
+ if (typeof _value === "string" || typeof _value === "number" || _value == null) {
3092
+ clone[key] = fn(_value, currentPath);
3093
+ } else if (typeof _value === "object" && !Array.isArray(_value)) {
3094
+ clone[key] = walkObject(_value, fn, currentPath);
3095
+ } else {
3096
+ console.warn('Skipping invalid key "'.concat(currentPath.join("."), '". Should be a string, number, null or object. Received: "').concat(Array.isArray(_value) ? "Array" : typeof _value, '"'));
3097
+ }
3098
+ }
3099
+ return clone;
3100
+ }
3101
+ function assignInlineVars(varsOrContract, tokens) {
3102
+ var styles = {};
3103
+ if (typeof tokens === "object") {
3104
+ var _contract = varsOrContract;
3105
+ walkObject(tokens, (value2, path) => {
3106
+ if (value2 == null) {
3107
+ return;
3108
+ }
3109
+ var varName2 = get(_contract, path);
3110
+ styles[getVarName(varName2)] = String(value2);
3111
+ });
3112
+ } else {
3113
+ var _vars = varsOrContract;
3114
+ for (var varName in _vars) {
3115
+ var value = _vars[varName];
3116
+ if (value == null) {
3117
+ continue;
3118
+ }
3119
+ styles[getVarName(varName)] = value;
3120
+ }
3121
+ }
3122
+ Object.defineProperty(styles, "toString", {
3123
+ value: function value2() {
3124
+ return Object.keys(this).map((key) => "".concat(key, ":").concat(this[key])).join(";");
3125
+ },
3126
+ writable: false
3127
+ });
3128
+ return styles;
3129
+ }
3130
+ const Channel = {
3131
+ /* CLAMP */
3132
+ min: {
3133
+ r: 0,
3134
+ g: 0,
3135
+ b: 0,
3136
+ s: 0,
3137
+ l: 0,
3138
+ a: 0
3139
+ },
3140
+ max: {
3141
+ r: 255,
3142
+ g: 255,
3143
+ b: 255,
3144
+ h: 360,
3145
+ s: 100,
3146
+ l: 100,
3147
+ a: 1
3148
+ },
3149
+ clamp: {
3150
+ r: (r) => r >= 255 ? 255 : r < 0 ? 0 : r,
3151
+ g: (g) => g >= 255 ? 255 : g < 0 ? 0 : g,
3152
+ b: (b) => b >= 255 ? 255 : b < 0 ? 0 : b,
3153
+ h: (h) => h % 360,
3154
+ s: (s) => s >= 100 ? 100 : s < 0 ? 0 : s,
3155
+ l: (l) => l >= 100 ? 100 : l < 0 ? 0 : l,
3156
+ a: (a) => a >= 1 ? 1 : a < 0 ? 0 : a
3157
+ },
3158
+ /* CONVERSION */
3159
+ //SOURCE: https://planetcalc.com/7779
3160
+ toLinear: (c) => {
3161
+ const n = c / 255;
3162
+ return c > 0.03928 ? Math.pow((n + 0.055) / 1.055, 2.4) : n / 12.92;
3163
+ },
3164
+ //SOURCE: https://gist.github.com/mjackson/5311256
3165
+ hue2rgb: (p, q, t) => {
3166
+ if (t < 0)
3167
+ t += 1;
3168
+ if (t > 1)
3169
+ t -= 1;
3170
+ if (t < 1 / 6)
3171
+ return p + (q - p) * 6 * t;
3172
+ if (t < 1 / 2)
3173
+ return q;
3174
+ if (t < 2 / 3)
3175
+ return p + (q - p) * (2 / 3 - t) * 6;
3176
+ return p;
3177
+ },
3178
+ hsl2rgb: ({ h, s, l }, channel) => {
3179
+ if (!s)
3180
+ return l * 2.55;
3181
+ h /= 360;
3182
+ s /= 100;
3183
+ l /= 100;
3184
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
3185
+ const p = 2 * l - q;
3186
+ switch (channel) {
3187
+ case "r":
3188
+ return Channel.hue2rgb(p, q, h + 1 / 3) * 255;
3189
+ case "g":
3190
+ return Channel.hue2rgb(p, q, h) * 255;
3191
+ case "b":
3192
+ return Channel.hue2rgb(p, q, h - 1 / 3) * 255;
3193
+ }
3194
+ },
3195
+ rgb2hsl: ({ r, g, b }, channel) => {
3196
+ r /= 255;
3197
+ g /= 255;
3198
+ b /= 255;
3199
+ const max = Math.max(r, g, b);
3200
+ const min = Math.min(r, g, b);
3201
+ const l = (max + min) / 2;
3202
+ if (channel === "l")
3203
+ return l * 100;
3204
+ if (max === min)
3205
+ return 0;
3206
+ const d = max - min;
3207
+ const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
3208
+ if (channel === "s")
3209
+ return s * 100;
3210
+ switch (max) {
3211
+ case r:
3212
+ return ((g - b) / d + (g < b ? 6 : 0)) * 60;
3213
+ case g:
3214
+ return ((b - r) / d + 2) * 60;
3215
+ case b:
3216
+ return ((r - g) / d + 4) * 60;
3217
+ default:
3218
+ return -1;
3219
+ }
3220
+ }
3221
+ };
3222
+ const Lang = {
3223
+ /* API */
3224
+ clamp: (number, lower, upper) => {
3225
+ if (lower > upper)
3226
+ return Math.min(lower, Math.max(upper, number));
3227
+ return Math.min(upper, Math.max(lower, number));
3228
+ },
3229
+ round: (number) => {
3230
+ return Math.round(number * 1e10) / 1e10;
3231
+ }
3232
+ };
3233
+ const lang = Lang;
3234
+ const Unit = {
3235
+ /* API */
3236
+ dec2hex: (dec) => {
3237
+ const hex = Math.round(dec).toString(16);
3238
+ return hex.length > 1 ? hex : `0${hex}`;
3239
+ }
3240
+ };
3241
+ const unit = Unit;
3242
+ const Utils = {
3243
+ channel: Channel,
3244
+ lang,
3245
+ unit
3246
+ };
3247
+ const DEC2HEX = {};
3248
+ for (let i = 0; i <= 255; i++)
3249
+ DEC2HEX[i] = Utils.unit.dec2hex(i);
3250
+ const TYPE = {
3251
+ ALL: 0,
3252
+ RGB: 1,
3253
+ HSL: 2
3254
+ };
3255
+ class Type {
3256
+ constructor() {
3257
+ this.type = TYPE.ALL;
3258
+ }
3259
+ /* API */
3260
+ get() {
3261
+ return this.type;
3262
+ }
3263
+ set(type) {
3264
+ if (this.type && this.type !== type)
3265
+ throw new Error("Cannot change both RGB and HSL channels at the same time");
3266
+ this.type = type;
3267
+ }
3268
+ reset() {
3269
+ this.type = TYPE.ALL;
3270
+ }
3271
+ is(type) {
3272
+ return this.type === type;
3273
+ }
3274
+ }
3275
+ class Channels {
3276
+ /* CONSTRUCTOR */
3277
+ constructor(data, color) {
3278
+ this.color = color;
3279
+ this.changed = false;
3280
+ this.data = data;
3281
+ this.type = new Type();
3282
+ }
3283
+ /* API */
3284
+ set(data, color) {
3285
+ this.color = color;
3286
+ this.changed = false;
3287
+ this.data = data;
3288
+ this.type.type = TYPE.ALL;
3289
+ return this;
3290
+ }
3291
+ /* HELPERS */
3292
+ _ensureHSL() {
3293
+ const data = this.data;
3294
+ const { h, s, l } = data;
3295
+ if (h === void 0)
3296
+ data.h = Utils.channel.rgb2hsl(data, "h");
3297
+ if (s === void 0)
3298
+ data.s = Utils.channel.rgb2hsl(data, "s");
3299
+ if (l === void 0)
3300
+ data.l = Utils.channel.rgb2hsl(data, "l");
3301
+ }
3302
+ _ensureRGB() {
3303
+ const data = this.data;
3304
+ const { r, g, b } = data;
3305
+ if (r === void 0)
3306
+ data.r = Utils.channel.hsl2rgb(data, "r");
3307
+ if (g === void 0)
3308
+ data.g = Utils.channel.hsl2rgb(data, "g");
3309
+ if (b === void 0)
3310
+ data.b = Utils.channel.hsl2rgb(data, "b");
3311
+ }
3312
+ /* GETTERS */
3313
+ get r() {
3314
+ const data = this.data;
3315
+ const r = data.r;
3316
+ if (!this.type.is(TYPE.HSL) && r !== void 0)
3317
+ return r;
3318
+ this._ensureHSL();
3319
+ return Utils.channel.hsl2rgb(data, "r");
3320
+ }
3321
+ get g() {
3322
+ const data = this.data;
3323
+ const g = data.g;
3324
+ if (!this.type.is(TYPE.HSL) && g !== void 0)
3325
+ return g;
3326
+ this._ensureHSL();
3327
+ return Utils.channel.hsl2rgb(data, "g");
3328
+ }
3329
+ get b() {
3330
+ const data = this.data;
3331
+ const b = data.b;
3332
+ if (!this.type.is(TYPE.HSL) && b !== void 0)
3333
+ return b;
3334
+ this._ensureHSL();
3335
+ return Utils.channel.hsl2rgb(data, "b");
3336
+ }
3337
+ get h() {
3338
+ const data = this.data;
3339
+ const h = data.h;
3340
+ if (!this.type.is(TYPE.RGB) && h !== void 0)
3341
+ return h;
3342
+ this._ensureRGB();
3343
+ return Utils.channel.rgb2hsl(data, "h");
3344
+ }
3345
+ get s() {
3346
+ const data = this.data;
3347
+ const s = data.s;
3348
+ if (!this.type.is(TYPE.RGB) && s !== void 0)
3349
+ return s;
3350
+ this._ensureRGB();
3351
+ return Utils.channel.rgb2hsl(data, "s");
3352
+ }
3353
+ get l() {
3354
+ const data = this.data;
3355
+ const l = data.l;
3356
+ if (!this.type.is(TYPE.RGB) && l !== void 0)
3357
+ return l;
3358
+ this._ensureRGB();
3359
+ return Utils.channel.rgb2hsl(data, "l");
3360
+ }
3361
+ get a() {
3362
+ return this.data.a;
3363
+ }
3364
+ /* SETTERS */
3365
+ set r(r) {
3366
+ this.type.set(TYPE.RGB);
3367
+ this.changed = true;
3368
+ this.data.r = r;
3369
+ }
3370
+ set g(g) {
3371
+ this.type.set(TYPE.RGB);
3372
+ this.changed = true;
3373
+ this.data.g = g;
3374
+ }
3375
+ set b(b) {
3376
+ this.type.set(TYPE.RGB);
3377
+ this.changed = true;
3378
+ this.data.b = b;
3379
+ }
3380
+ set h(h) {
3381
+ this.type.set(TYPE.HSL);
3382
+ this.changed = true;
3383
+ this.data.h = h;
3384
+ }
3385
+ set s(s) {
3386
+ this.type.set(TYPE.HSL);
3387
+ this.changed = true;
3388
+ this.data.s = s;
3389
+ }
3390
+ set l(l) {
3391
+ this.type.set(TYPE.HSL);
3392
+ this.changed = true;
3393
+ this.data.l = l;
3394
+ }
3395
+ set a(a) {
3396
+ this.changed = true;
3397
+ this.data.a = a;
3398
+ }
3399
+ }
3400
+ const Channels$1 = Channels;
3401
+ const channels = new Channels$1({ r: 0, g: 0, b: 0, a: 0 }, "transparent");
3402
+ const Hex = {
3403
+ /* VARIABLES */
3404
+ re: /^#((?:[a-f0-9]{2}){2,4}|[a-f0-9]{3})$/i,
3405
+ /* API */
3406
+ parse: (color) => {
3407
+ if (color.charCodeAt(0) !== 35)
3408
+ return;
3409
+ const match = color.match(Hex.re);
3410
+ if (!match)
3411
+ return;
3412
+ const hex = match[1];
3413
+ const dec = parseInt(hex, 16);
3414
+ const length = hex.length;
3415
+ const hasAlpha = length % 4 === 0;
3416
+ const isFullLength = length > 4;
3417
+ const multiplier = isFullLength ? 1 : 17;
3418
+ const bits = isFullLength ? 8 : 4;
3419
+ const bitsOffset = hasAlpha ? 0 : -1;
3420
+ const mask = isFullLength ? 255 : 15;
3421
+ return channels.set({
3422
+ r: (dec >> bits * (bitsOffset + 3) & mask) * multiplier,
3423
+ g: (dec >> bits * (bitsOffset + 2) & mask) * multiplier,
3424
+ b: (dec >> bits * (bitsOffset + 1) & mask) * multiplier,
3425
+ a: hasAlpha ? (dec & mask) * multiplier / 255 : 1
3426
+ }, color);
3427
+ },
3428
+ stringify: (channels2) => {
3429
+ const { r, g, b, a } = channels2;
3430
+ if (a < 1) {
3431
+ return `#${DEC2HEX[Math.round(r)]}${DEC2HEX[Math.round(g)]}${DEC2HEX[Math.round(b)]}${DEC2HEX[Math.round(a * 255)]}`;
3432
+ } else {
3433
+ return `#${DEC2HEX[Math.round(r)]}${DEC2HEX[Math.round(g)]}${DEC2HEX[Math.round(b)]}`;
3434
+ }
3435
+ }
3436
+ };
3437
+ const HSL = {
3438
+ /* VARIABLES */
3439
+ re: /^hsla?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(?:deg|grad|rad|turn)?)\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?%)\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?%)(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(%)?))?\s*?\)$/i,
3440
+ hueRe: /^(.+?)(deg|grad|rad|turn)$/i,
3441
+ /* HELPERS */
3442
+ _hue2deg: (hue) => {
3443
+ const match = hue.match(HSL.hueRe);
3444
+ if (match) {
3445
+ const [, number, unit2] = match;
3446
+ switch (unit2) {
3447
+ case "grad":
3448
+ return Utils.channel.clamp.h(parseFloat(number) * 0.9);
3449
+ case "rad":
3450
+ return Utils.channel.clamp.h(parseFloat(number) * 180 / Math.PI);
3451
+ case "turn":
3452
+ return Utils.channel.clamp.h(parseFloat(number) * 360);
3453
+ }
3454
+ }
3455
+ return Utils.channel.clamp.h(parseFloat(hue));
3456
+ },
3457
+ /* API */
3458
+ parse: (color) => {
3459
+ const charCode = color.charCodeAt(0);
3460
+ if (charCode !== 104 && charCode !== 72)
3461
+ return;
3462
+ const match = color.match(HSL.re);
3463
+ if (!match)
3464
+ return;
3465
+ const [, h, s, l, a, isAlphaPercentage] = match;
3466
+ return channels.set({
3467
+ h: HSL._hue2deg(h),
3468
+ s: Utils.channel.clamp.s(parseFloat(s)),
3469
+ l: Utils.channel.clamp.l(parseFloat(l)),
3470
+ a: a ? Utils.channel.clamp.a(isAlphaPercentage ? parseFloat(a) / 100 : parseFloat(a)) : 1
3471
+ }, color);
3472
+ },
3473
+ stringify: (channels2) => {
3474
+ const { h, s, l, a } = channels2;
3475
+ if (a < 1) {
3476
+ return `hsla(${Utils.lang.round(h)}, ${Utils.lang.round(s)}%, ${Utils.lang.round(l)}%, ${a})`;
3477
+ } else {
3478
+ return `hsl(${Utils.lang.round(h)}, ${Utils.lang.round(s)}%, ${Utils.lang.round(l)}%)`;
3479
+ }
3480
+ }
3481
+ };
3482
+ const Keyword = {
3483
+ /* VARIABLES */
3484
+ colors: {
3485
+ aliceblue: "#f0f8ff",
3486
+ antiquewhite: "#faebd7",
3487
+ aqua: "#00ffff",
3488
+ aquamarine: "#7fffd4",
3489
+ azure: "#f0ffff",
3490
+ beige: "#f5f5dc",
3491
+ bisque: "#ffe4c4",
3492
+ black: "#000000",
3493
+ blanchedalmond: "#ffebcd",
3494
+ blue: "#0000ff",
3495
+ blueviolet: "#8a2be2",
3496
+ brown: "#a52a2a",
3497
+ burlywood: "#deb887",
3498
+ cadetblue: "#5f9ea0",
3499
+ chartreuse: "#7fff00",
3500
+ chocolate: "#d2691e",
3501
+ coral: "#ff7f50",
3502
+ cornflowerblue: "#6495ed",
3503
+ cornsilk: "#fff8dc",
3504
+ crimson: "#dc143c",
3505
+ cyanaqua: "#00ffff",
3506
+ darkblue: "#00008b",
3507
+ darkcyan: "#008b8b",
3508
+ darkgoldenrod: "#b8860b",
3509
+ darkgray: "#a9a9a9",
3510
+ darkgreen: "#006400",
3511
+ darkgrey: "#a9a9a9",
3512
+ darkkhaki: "#bdb76b",
3513
+ darkmagenta: "#8b008b",
3514
+ darkolivegreen: "#556b2f",
3515
+ darkorange: "#ff8c00",
3516
+ darkorchid: "#9932cc",
3517
+ darkred: "#8b0000",
3518
+ darksalmon: "#e9967a",
3519
+ darkseagreen: "#8fbc8f",
3520
+ darkslateblue: "#483d8b",
3521
+ darkslategray: "#2f4f4f",
3522
+ darkslategrey: "#2f4f4f",
3523
+ darkturquoise: "#00ced1",
3524
+ darkviolet: "#9400d3",
3525
+ deeppink: "#ff1493",
3526
+ deepskyblue: "#00bfff",
3527
+ dimgray: "#696969",
3528
+ dimgrey: "#696969",
3529
+ dodgerblue: "#1e90ff",
3530
+ firebrick: "#b22222",
3531
+ floralwhite: "#fffaf0",
3532
+ forestgreen: "#228b22",
3533
+ fuchsia: "#ff00ff",
3534
+ gainsboro: "#dcdcdc",
3535
+ ghostwhite: "#f8f8ff",
3536
+ gold: "#ffd700",
3537
+ goldenrod: "#daa520",
3538
+ gray: "#808080",
3539
+ green: "#008000",
3540
+ greenyellow: "#adff2f",
3541
+ grey: "#808080",
3542
+ honeydew: "#f0fff0",
3543
+ hotpink: "#ff69b4",
3544
+ indianred: "#cd5c5c",
3545
+ indigo: "#4b0082",
3546
+ ivory: "#fffff0",
3547
+ khaki: "#f0e68c",
3548
+ lavender: "#e6e6fa",
3549
+ lavenderblush: "#fff0f5",
3550
+ lawngreen: "#7cfc00",
3551
+ lemonchiffon: "#fffacd",
3552
+ lightblue: "#add8e6",
3553
+ lightcoral: "#f08080",
3554
+ lightcyan: "#e0ffff",
3555
+ lightgoldenrodyellow: "#fafad2",
3556
+ lightgray: "#d3d3d3",
3557
+ lightgreen: "#90ee90",
3558
+ lightgrey: "#d3d3d3",
3559
+ lightpink: "#ffb6c1",
3560
+ lightsalmon: "#ffa07a",
3561
+ lightseagreen: "#20b2aa",
3562
+ lightskyblue: "#87cefa",
3563
+ lightslategray: "#778899",
3564
+ lightslategrey: "#778899",
3565
+ lightsteelblue: "#b0c4de",
3566
+ lightyellow: "#ffffe0",
3567
+ lime: "#00ff00",
3568
+ limegreen: "#32cd32",
3569
+ linen: "#faf0e6",
3570
+ magenta: "#ff00ff",
3571
+ maroon: "#800000",
3572
+ mediumaquamarine: "#66cdaa",
3573
+ mediumblue: "#0000cd",
3574
+ mediumorchid: "#ba55d3",
3575
+ mediumpurple: "#9370db",
3576
+ mediumseagreen: "#3cb371",
3577
+ mediumslateblue: "#7b68ee",
3578
+ mediumspringgreen: "#00fa9a",
3579
+ mediumturquoise: "#48d1cc",
3580
+ mediumvioletred: "#c71585",
3581
+ midnightblue: "#191970",
3582
+ mintcream: "#f5fffa",
3583
+ mistyrose: "#ffe4e1",
3584
+ moccasin: "#ffe4b5",
3585
+ navajowhite: "#ffdead",
3586
+ navy: "#000080",
3587
+ oldlace: "#fdf5e6",
3588
+ olive: "#808000",
3589
+ olivedrab: "#6b8e23",
3590
+ orange: "#ffa500",
3591
+ orangered: "#ff4500",
3592
+ orchid: "#da70d6",
3593
+ palegoldenrod: "#eee8aa",
3594
+ palegreen: "#98fb98",
3595
+ paleturquoise: "#afeeee",
3596
+ palevioletred: "#db7093",
3597
+ papayawhip: "#ffefd5",
3598
+ peachpuff: "#ffdab9",
3599
+ peru: "#cd853f",
3600
+ pink: "#ffc0cb",
3601
+ plum: "#dda0dd",
3602
+ powderblue: "#b0e0e6",
3603
+ purple: "#800080",
3604
+ rebeccapurple: "#663399",
3605
+ red: "#ff0000",
3606
+ rosybrown: "#bc8f8f",
3607
+ royalblue: "#4169e1",
3608
+ saddlebrown: "#8b4513",
3609
+ salmon: "#fa8072",
3610
+ sandybrown: "#f4a460",
3611
+ seagreen: "#2e8b57",
3612
+ seashell: "#fff5ee",
3613
+ sienna: "#a0522d",
3614
+ silver: "#c0c0c0",
3615
+ skyblue: "#87ceeb",
3616
+ slateblue: "#6a5acd",
3617
+ slategray: "#708090",
3618
+ slategrey: "#708090",
3619
+ snow: "#fffafa",
3620
+ springgreen: "#00ff7f",
3621
+ tan: "#d2b48c",
3622
+ teal: "#008080",
3623
+ thistle: "#d8bfd8",
3624
+ transparent: "#00000000",
3625
+ turquoise: "#40e0d0",
3626
+ violet: "#ee82ee",
3627
+ wheat: "#f5deb3",
3628
+ white: "#ffffff",
3629
+ whitesmoke: "#f5f5f5",
3630
+ yellow: "#ffff00",
3631
+ yellowgreen: "#9acd32"
3632
+ },
3633
+ /* API */
3634
+ parse: (color) => {
3635
+ color = color.toLowerCase();
3636
+ const hex = Keyword.colors[color];
3637
+ if (!hex)
3638
+ return;
3639
+ return Hex.parse(hex);
3640
+ },
3641
+ stringify: (channels2) => {
3642
+ const hex = Hex.stringify(channels2);
3643
+ for (const name in Keyword.colors) {
3644
+ if (Keyword.colors[name] === hex)
3645
+ return name;
3646
+ }
3647
+ return;
3648
+ }
3649
+ };
3650
+ const RGB = {
3651
+ /* VARIABLES */
3652
+ re: /^rgba?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?)))?\s*?\)$/i,
3653
+ /* API */
3654
+ parse: (color) => {
3655
+ const charCode = color.charCodeAt(0);
3656
+ if (charCode !== 114 && charCode !== 82)
3657
+ return;
3658
+ const match = color.match(RGB.re);
3659
+ if (!match)
3660
+ return;
3661
+ const [, r, isRedPercentage, g, isGreenPercentage, b, isBluePercentage, a, isAlphaPercentage] = match;
3662
+ return channels.set({
3663
+ r: Utils.channel.clamp.r(isRedPercentage ? parseFloat(r) * 2.55 : parseFloat(r)),
3664
+ g: Utils.channel.clamp.g(isGreenPercentage ? parseFloat(g) * 2.55 : parseFloat(g)),
3665
+ b: Utils.channel.clamp.b(isBluePercentage ? parseFloat(b) * 2.55 : parseFloat(b)),
3666
+ a: a ? Utils.channel.clamp.a(isAlphaPercentage ? parseFloat(a) / 100 : parseFloat(a)) : 1
3667
+ }, color);
3668
+ },
3669
+ stringify: (channels2) => {
3670
+ const { r, g, b, a } = channels2;
3671
+ if (a < 1) {
3672
+ return `rgba(${Utils.lang.round(r)}, ${Utils.lang.round(g)}, ${Utils.lang.round(b)}, ${Utils.lang.round(a)})`;
3673
+ } else {
3674
+ return `rgb(${Utils.lang.round(r)}, ${Utils.lang.round(g)}, ${Utils.lang.round(b)})`;
3675
+ }
3676
+ }
3677
+ };
3678
+ const Color = {
3679
+ /* VARIABLES */
3680
+ format: {
3681
+ keyword: Keyword,
3682
+ hex: Hex,
3683
+ rgb: RGB,
3684
+ rgba: RGB,
3685
+ hsl: HSL,
3686
+ hsla: HSL
3687
+ },
3688
+ /* API */
3689
+ parse: (color) => {
3690
+ if (typeof color !== "string")
3691
+ return color;
3692
+ const channels2 = Hex.parse(color) || RGB.parse(color) || HSL.parse(color) || Keyword.parse(color);
3693
+ if (channels2)
3694
+ return channels2;
3695
+ throw new Error(`Unsupported color format: "${color}"`);
3696
+ },
3697
+ stringify: (channels2) => {
3698
+ if (!channels2.changed && channels2.color)
3699
+ return channels2.color;
3700
+ if (channels2.type.is(TYPE.HSL) || channels2.data.r === void 0) {
3701
+ return HSL.stringify(channels2);
3702
+ } else if (channels2.a < 1 || !Number.isInteger(channels2.r) || !Number.isInteger(channels2.g) || !Number.isInteger(channels2.b)) {
3703
+ return RGB.stringify(channels2);
3704
+ } else {
3705
+ return Hex.stringify(channels2);
3706
+ }
3707
+ }
3708
+ };
3709
+ const change = (color, channels2) => {
3710
+ const ch = Color.parse(color);
3711
+ for (const c in channels2) {
3712
+ ch[c] = Utils.channel.clamp[c](channels2[c]);
3713
+ }
3714
+ return Color.stringify(ch);
3715
+ };
3716
+ const toHex = (color) => {
3717
+ return Color.format.hex.stringify(Color.parse(color));
3718
+ };
3719
+ const adjust = (color, channels2) => {
3720
+ const ch = Color.parse(color);
3721
+ const changes = {};
3722
+ for (const c in channels2) {
3723
+ if (!channels2[c])
3724
+ continue;
3725
+ changes[c] = ch[c] + channels2[c];
3726
+ }
3727
+ return change(color, changes);
3728
+ };
3729
+ const scale = (color, channels2) => {
3730
+ const ch = Color.parse(color);
3731
+ const adjustments = {};
3732
+ const delta = (amount, weight, max) => weight > 0 ? (max - amount) * weight / 100 : amount * weight / 100;
3733
+ for (const c in channels2) {
3734
+ adjustments[c] = delta(ch[c], channels2[c], Utils.channel.max[c]);
3735
+ }
3736
+ return adjust(color, adjustments);
3737
+ };
3738
+ var vars = { likec4: { font: "var(--likec4-font-family)", backgroundColor: "var(--likec4-background-color)" }, compound: { font: "var(--likec4-compound-font-family)", titleColor: "var(--likec4-compound-title-color)" }, element: { font: "var(--likec4-element-font-family)", fill: "var(--likec4-element-fill)", stroke: "var(--likec4-element-stroke)", hiContrast: "var(--likec4-element-hiContrast)", loContrast: "var(--likec4-element-loContrast)" }, relation: { lineColor: "var(--likec4-relation-lineColor)", labelColor: "var(--likec4-relation-labelColor)", labelBgColor: "var(--likec4-relation-labelBg)" } };
3739
+ function toDomPrecision(v) {
3740
+ if (v === null) {
3741
+ return 0.01;
3742
+ }
3743
+ return Math.round(v * 100) / 100;
3744
+ }
3745
+ const Link = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
3746
+ "svg",
3747
+ {
3748
+ ref,
3749
+ className: clsx("icon icon-tabler", className),
3750
+ stroke: "currentColor",
3751
+ fill: "currentColor",
3752
+ strokeWidth: "0",
3753
+ viewBox: "0 0 20 20",
3754
+ height: "20",
3755
+ width: "20",
3756
+ xmlns: "http://www.w3.org/2000/svg",
3757
+ ...props,
3758
+ children: /* @__PURE__ */ jsx(
3759
+ "path",
3760
+ {
3761
+ fillRule: "evenodd",
3762
+ d: "M12.586 4.586a2 2 0 112.828 2.828l-3 3a2 2 0 01-2.828 0 1 1 0 00-1.414 1.414 4 4 0 005.656 0l3-3a4 4 0 00-5.656-5.656l-1.5 1.5a1 1 0 101.414 1.414l1.5-1.5zm-5 5a2 2 0 012.828 0 1 1 0 101.414-1.414 4 4 0 00-5.656 0l-3 3a4 4 0 105.656 5.656l1.5-1.5a1 1 0 10-1.414-1.414l-1.5 1.5a2 2 0 11-2.828-2.828l3-3z",
3763
+ clipRule: "evenodd"
3764
+ }
3765
+ )
3766
+ }
3767
+ ));
3768
+ const ZoomIn = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxs(
3769
+ "svg",
3770
+ {
3771
+ ref,
3772
+ xmlns: "http://www.w3.org/2000/svg",
3773
+ className: clsx("icon icon-tabler icon-tabler-zoom-in", className),
3774
+ width: "24",
3775
+ height: "24",
3776
+ viewBox: "0 0 24 24",
3777
+ strokeWidth: "1.5",
3778
+ stroke: "currentColor",
3779
+ fill: "none",
3780
+ strokeLinecap: "round",
3781
+ strokeLinejoin: "round",
3782
+ ...props,
3783
+ children: [
3784
+ /* @__PURE__ */ jsx("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }),
3785
+ /* @__PURE__ */ jsx("path", { d: "M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" }),
3786
+ /* @__PURE__ */ jsx("path", { d: "M7 10l6 0" }),
3787
+ /* @__PURE__ */ jsx("path", { d: "M10 7l0 6" }),
3788
+ /* @__PURE__ */ jsx("path", { d: "M21 21l-6 -6" })
3789
+ ]
3790
+ }
3791
+ ));
3792
+ function NavigateToBtn({ xynodeId, className }) {
3793
+ const { onNavigateTo } = useXYFlowEvents();
3794
+ return /* @__PURE__ */ jsx(
3795
+ ActionIcon,
3796
+ {
3797
+ className: clsx("nodrag nopan", className),
3798
+ radius: "xl",
3799
+ autoFocus: false,
3800
+ onClick: (event) => {
3801
+ event.stopPropagation();
3802
+ event.preventDefault();
3803
+ onNavigateTo(xynodeId, event);
3804
+ },
3805
+ children: /* @__PURE__ */ jsx(ZoomIn, {})
3806
+ }
3807
+ );
3808
+ }
3809
+ var cssContainer = "lbtzdo0";
3810
+ var cssCompound = "lbtzdo2";
3811
+ var cssTitle = "lbtzdo4";
3812
+ var cssIndicator = "lbtzdo6";
3813
+ var cssNavigateBtn$1 = "lbtzdo7";
3814
+ const isEqualProps$1 = (prev, next) => prev.id === next.id && prev.selected === next.selected && prev.width === next.width && prev.height === next.height && deepEqual(prev.data, next.data);
3815
+ const compoundColor = (color, depth) => toHex(
3816
+ scale(color, {
3817
+ l: -35 - 5 * depth,
3818
+ s: -15 - 5 * depth
3819
+ })
3820
+ );
3821
+ const CompoundNodeMemo = /* @__PURE__ */ memo(function CompoundNode({
3822
+ id,
3823
+ data: {
3824
+ element
3825
+ },
3826
+ width,
3827
+ height
3828
+ }) {
3829
+ const { color, depth = 0, ...compound } = element;
3830
+ const colors2 = useMemo(() => {
3831
+ const colors22 = defaultTheme.elements[color];
3832
+ return {
3833
+ ...colors22,
3834
+ fill: compoundColor(colors22.fill, depth),
3835
+ stroke: compoundColor(colors22.stroke, depth)
3836
+ };
3837
+ }, [color, depth]);
3838
+ const w = toDomPrecision(width ?? compound.width);
3839
+ const h = toDomPrecision(height ?? compound.height);
3840
+ const diagramState = useDiagramState();
3841
+ const isnavigable = diagramState.hasOnNavigateTo && !!compound.navigateTo;
3842
+ const isHovered = useDiagramStateSelector((state) => state.hoveredNodeId === id);
3843
+ return /* @__PURE__ */ jsxs(
3844
+ Box,
3845
+ {
3846
+ className: clsx(cssContainer, "likec4-compound-node"),
3847
+ style: assignInlineVars({ fill: vars.element.fill, stroke: vars.element.stroke }, {
3848
+ fill: colors2.fill,
3849
+ stroke: colors2.stroke
3850
+ }),
3851
+ mod: {
3852
+ "likec4-color": color,
3853
+ "likec4-shape": compound.shape,
3854
+ "likec4-navigable": isnavigable,
3855
+ hovered: isHovered
3856
+ },
3857
+ children: [
3858
+ /* @__PURE__ */ jsx(
3859
+ Handle,
3860
+ {
3861
+ type: "target",
3862
+ position: Position.Top,
3863
+ style: { visibility: "hidden" }
3864
+ }
3865
+ ),
3866
+ /* @__PURE__ */ jsx("svg", { className: cssIndicator, viewBox: `0 0 ${w} ${h}`, width: w, height: h, children: /* @__PURE__ */ jsx(
3867
+ "rect",
3868
+ {
3869
+ x: -1,
3870
+ y: -1,
3871
+ width: w + 2,
3872
+ height: h + 2,
3873
+ rx: 6
3874
+ }
3875
+ ) }),
3876
+ /* @__PURE__ */ jsx("div", { className: clsx(cssCompound, "likec4-compound"), children: /* @__PURE__ */ jsx(
3877
+ Text,
3878
+ {
3879
+ component: "div",
3880
+ className: clsx(cssTitle, "likec4-compound-title"),
3881
+ children: compound.title
3882
+ }
3883
+ ) }),
3884
+ isnavigable && /* @__PURE__ */ jsx(NavigateToBtn, { xynodeId: id, className: cssNavigateBtn$1 }),
3885
+ /* @__PURE__ */ jsx(
3886
+ Handle,
3887
+ {
3888
+ type: "source",
3889
+ position: Position.Bottom,
3890
+ style: { visibility: "hidden" }
3891
+ }
3892
+ )
3893
+ ]
3894
+ }
3895
+ );
3896
+ }, isEqualProps$1);
3897
+ var container = "_1b6tkn2";
3898
+ var indicator = "_1b6tkn4";
3899
+ var fillElementFill = "_1b6tkn5";
3900
+ var fillMixStroke = "_1b6tkn7";
3901
+ var title = "_1b6tkn8";
3902
+ var description = "_1b6tkn9";
3903
+ var technology = "_1b6tkna";
3904
+ var cssElement = "_1b6tknb";
3905
+ var iconMaxH = "var(--_1b6tknc)";
3906
+ var elementIcon = "_1b6tknd";
3907
+ var cssShapeSvg = "_1b6tkng";
3908
+ var cssNavigateBtn = "_1b6tknh";
3909
+ function ElementIcon({
3910
+ node,
3911
+ maxWidth,
3912
+ paddingX = 32,
3913
+ paddingY = 32
3914
+ }) {
3915
+ if (!node.icon) {
3916
+ return null;
3917
+ }
3918
+ const firstLabel = node.labels[0];
3919
+ if (!firstLabel) {
3920
+ return null;
3921
+ }
3922
+ const firstLabelY = Math.floor(firstLabel.pt[1] - firstLabel.fontSize * 1.25);
3923
+ const maxIconHeight = Math.floor(firstLabelY - paddingY - 16);
3924
+ maxWidth ?? node.width - paddingX * 2;
3925
+ return /* @__PURE__ */ jsx(
3926
+ "div",
3927
+ {
3928
+ className: clsx(elementIcon, "likec4-element-icon"),
3929
+ style: assignInlineVars({ iconMaxH }, {
3930
+ iconMaxH: maxIconHeight + "px"
3931
+ }),
3932
+ children: /* @__PURE__ */ jsx(
3933
+ "img",
3934
+ {
3935
+ src: node.icon,
3936
+ alt: node.title
3937
+ }
3938
+ )
3939
+ }
3940
+ );
3941
+ }
3942
+ var elementLink = "_4ysv0o0";
3943
+ var trigger = "_4ysv0o1";
3944
+ function ElementLink({
3945
+ element
3946
+ }) {
3947
+ if (!element.links) {
3948
+ return null;
3949
+ }
3950
+ return /* @__PURE__ */ jsx(
3951
+ motion.div,
3952
+ {
3953
+ className: elementLink,
3954
+ whileHover: {
3955
+ scale: 1.07
3956
+ },
3957
+ children: /* @__PURE__ */ jsxs(
3958
+ HoverCard,
3959
+ {
3960
+ position: "bottom-start",
3961
+ shadow: "lg",
3962
+ radius: "sm",
3963
+ transitionProps: {
3964
+ transition: "pop"
3965
+ },
3966
+ withinPortal: false,
3967
+ floatingStrategy: "fixed",
3968
+ openDelay: 350,
3969
+ closeDelay: 600,
3970
+ offset: {
3971
+ mainAxis: 5,
3972
+ crossAxis: -10
3973
+ },
3974
+ children: [
3975
+ /* @__PURE__ */ jsx(HoverCard.Target, { children: /* @__PURE__ */ jsxs(UnstyledButton, { className: clsx("nodrag nopan", trigger), children: [
3976
+ /* @__PURE__ */ jsx(Link, {}),
3977
+ /* @__PURE__ */ jsx("span", { children: "links" })
3978
+ ] }) }),
3979
+ /* @__PURE__ */ jsx(HoverCard.Dropdown, { p: "xs", children: /* @__PURE__ */ jsx(Stack, { onClick: (e) => e.stopPropagation(), gap: "xs", children: element.links.map((link, i) => /* @__PURE__ */ jsxs(Group, { wrap: "nowrap", gap: "sm", children: [
3980
+ /* @__PURE__ */ jsx(Box, { flex: "1", style: { overflow: "clip", maxWidth: 240 }, children: /* @__PURE__ */ jsx(Anchor, { href: link, target: "_blank", fz: "13", truncate: "end", children: link }) }),
3981
+ /* @__PURE__ */ jsx(CopyButton, { value: link, children: ({ copied, copy }) => /* @__PURE__ */ jsx(Button, { size: "compact-xs", fz: "12", onClick: copy, color: copied ? "teal" : "gray", children: copied ? "Copied" : "Copy" }) })
3982
+ ] }, link)) }) })
3983
+ ]
3984
+ }
3985
+ )
3986
+ }
3987
+ );
3988
+ }
3989
+ function cylinderSVGPath(diameter, height, tilt = 0.0725) {
3990
+ const radius = Math.round(diameter / 2);
3991
+ const rx = radius;
3992
+ const ry = Math.round(tilt * radius);
3993
+ const tiltAdjustedHeight = height - 2 * ry;
3994
+ const path = ` M ${diameter},${ry}
3995
+ a ${rx},${ry} 0,0,0 ${-diameter} 0
3996
+ l 0,${tiltAdjustedHeight}
3997
+ a ${rx},${ry} 0,0,0 ${diameter} 0
3998
+ l 0,${-tiltAdjustedHeight}
3999
+ z
4000
+ `.replace(/\s+/g, " ").trim();
4001
+ return {
4002
+ path,
4003
+ ry,
4004
+ rx
4005
+ };
4006
+ }
4007
+ function queueSVGPath(width, height, tilt = 0.2) {
4008
+ const diameter = height;
4009
+ const radius = Math.round(diameter / 2);
4010
+ const ry = radius;
4011
+ const rx = Math.round(diameter / 2 * tilt);
4012
+ const tiltAdjustedWidth = width - 2 * rx;
4013
+ const path = `
4014
+ M ${rx},0
4015
+ a ${rx},${ry} 0,0,0 0 ${diameter}
4016
+ l ${tiltAdjustedWidth},0
4017
+ a ${rx},${ry} 0,0,0 0 ${-diameter}
4018
+ z`.replace(/\s+/g, " ").trim();
4019
+ return {
4020
+ path,
4021
+ ry,
4022
+ rx
4023
+ };
4024
+ }
4025
+ const PersonIcon = {
4026
+ width: 115,
4027
+ height: 120,
4028
+ path: `M57.9197 0C10.9124 0 33.5766 54.75 33.5766 54.75C38.6131 62.25 45.3285 60.75 45.3285 66C45.3285 70.5 39.4526 72 33.5766 72.75C24.3431 72.75 15.9489 71.25 7.55474 84.75C2.51825 93 0 120 0 120H115C115 120 112.482 93 108.285 84.75C99.8905 70.5 91.4963 72.75 82.2628 72C76.3869 71.25 70.5109 69.75 70.5109 65.25C70.5109 60.75 77.2263 62.25 82.2628 54C82.2628 54.75 104.927 0 57.9197 0V0Z`
4029
+ };
4030
+ const ElementShapeSvg = /* @__PURE__ */ memo(({
4031
+ shape,
4032
+ w,
4033
+ h
4034
+ }) => {
4035
+ switch (shape) {
4036
+ case "mobile": {
4037
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4038
+ /* @__PURE__ */ jsx(
4039
+ "rect",
4040
+ {
4041
+ width: w,
4042
+ height: h,
4043
+ rx: 6,
4044
+ className: fillMixStroke,
4045
+ strokeWidth: 0
4046
+ }
4047
+ ),
4048
+ /* @__PURE__ */ jsxs("g", { className: fillElementFill, strokeWidth: 0, children: [
4049
+ /* @__PURE__ */ jsx("circle", { cx: 17, cy: h / 2, r: 12 }),
4050
+ /* @__PURE__ */ jsx("rect", { x: 33, y: 12, width: w - 44, height: h - 24, rx: 5 })
4051
+ ] })
4052
+ ] });
4053
+ }
4054
+ case "browser": {
4055
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4056
+ /* @__PURE__ */ jsx(
4057
+ "rect",
4058
+ {
4059
+ width: w,
4060
+ height: h,
4061
+ rx: 6,
4062
+ className: fillMixStroke,
4063
+ strokeWidth: 0
4064
+ }
4065
+ ),
4066
+ /* @__PURE__ */ jsxs("g", { className: fillElementFill, strokeWidth: 0, children: [
4067
+ /* @__PURE__ */ jsx("circle", { cx: 16, cy: 17, r: 7 }),
4068
+ /* @__PURE__ */ jsx("circle", { cx: 36, cy: 17, r: 7 }),
4069
+ /* @__PURE__ */ jsx("circle", { cx: 56, cy: 17, r: 7 }),
4070
+ /* @__PURE__ */ jsx("rect", { x: 70, y: 8, width: w - 80, height: 17, rx: 4 }),
4071
+ /* @__PURE__ */ jsx("rect", { x: 10, y: 32, width: w - 20, height: h - 42, rx: 4 })
4072
+ ] })
4073
+ ] });
4074
+ }
4075
+ case "person": {
4076
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4077
+ /* @__PURE__ */ jsx(
4078
+ "rect",
4079
+ {
4080
+ width: w,
4081
+ height: h,
4082
+ rx: 6,
4083
+ strokeWidth: 0
4084
+ }
4085
+ ),
4086
+ /* @__PURE__ */ jsx(
4087
+ "svg",
4088
+ {
4089
+ x: w - PersonIcon.width - 6,
4090
+ y: h - PersonIcon.height,
4091
+ width: PersonIcon.width,
4092
+ height: PersonIcon.height,
4093
+ viewBox: `0 0 ${PersonIcon.width} ${PersonIcon.height}`,
4094
+ className: fillMixStroke,
4095
+ children: /* @__PURE__ */ jsx(
4096
+ "path",
4097
+ {
4098
+ strokeWidth: 0,
4099
+ d: "M57.9197 0C10.9124 0 33.5766 54.75 33.5766 54.75C38.6131 62.25 45.3285 60.75 45.3285 66C45.3285 70.5 39.4526 72 33.5766 72.75C24.3431 72.75 15.9489 71.25 7.55474 84.75C2.51825 93 0 120 0 120H115C115 120 112.482 93 108.285 84.75C99.8905 70.5 91.4963 72.75 82.2628 72C76.3869 71.25 70.5109 69.75 70.5109 65.25C70.5109 60.75 77.2263 62.25 82.2628 54C82.2628 54.75 104.927 0 57.9197 0V0Z"
4100
+ }
4101
+ )
4102
+ }
4103
+ )
4104
+ ] });
4105
+ }
4106
+ case "queue": {
4107
+ const { path, rx, ry } = queueSVGPath(w, h);
4108
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4109
+ /* @__PURE__ */ jsx("path", { d: path, strokeWidth: 2 }),
4110
+ /* @__PURE__ */ jsx("ellipse", { cx: rx, cy: ry, ry: ry - 0.75, rx, className: fillMixStroke, strokeWidth: 2 })
4111
+ ] });
4112
+ }
4113
+ case "storage":
4114
+ case "cylinder": {
4115
+ const { path, rx, ry } = cylinderSVGPath(w, h);
4116
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4117
+ /* @__PURE__ */ jsx("path", { d: path, strokeWidth: 2 }),
4118
+ /* @__PURE__ */ jsx("ellipse", { cx: rx, cy: ry, ry, rx: rx - 0.75, className: fillMixStroke, strokeWidth: 2 })
4119
+ ] });
4120
+ }
4121
+ case "rectangle": {
4122
+ return /* @__PURE__ */ jsx(
4123
+ "rect",
4124
+ {
4125
+ width: w,
4126
+ height: h,
4127
+ rx: 6,
4128
+ strokeWidth: 0
4129
+ }
4130
+ );
4131
+ }
4132
+ default: {
4133
+ return nonexhaustive(shape);
4134
+ }
4135
+ }
4136
+ }, deepEqual);
4137
+ const SelectedIndicator = /* @__PURE__ */ memo(({
4138
+ shape,
4139
+ w,
4140
+ h
4141
+ }) => {
4142
+ switch (shape) {
4143
+ case "queue":
4144
+ case "storage":
4145
+ case "cylinder": {
4146
+ const { path } = shape === "queue" ? queueSVGPath(w, h) : cylinderSVGPath(w, h);
4147
+ return /* @__PURE__ */ jsx("path", { d: path });
4148
+ }
4149
+ default: {
4150
+ return /* @__PURE__ */ jsx(
4151
+ "rect",
4152
+ {
4153
+ x: -1,
4154
+ y: -1,
4155
+ width: w + 2,
4156
+ height: h + 2,
4157
+ rx: 6
4158
+ }
4159
+ );
4160
+ }
4161
+ }
4162
+ }, deepEqual);
4163
+ const isEqualProps = (prev, next) => prev.id === next.id && prev.width === next.width && prev.height === next.height && prev.selected === next.selected && deepEqual(prev.data, next.data);
4164
+ const variants = {
4165
+ idle: {
4166
+ transformOrigin: "50% 50%"
4167
+ },
4168
+ selected: {
4169
+ scale: 1.015
4170
+ },
4171
+ hover: {
4172
+ scale: 1.08,
4173
+ transition: {
4174
+ delay: 0.175
4175
+ // duration: 0.3
4176
+ }
4177
+ },
4178
+ tap: {
4179
+ scale: 0.97,
4180
+ transition: {
4181
+ type: "spring"
4182
+ }
4183
+ }
4184
+ };
4185
+ function ElementNode({
4186
+ id,
4187
+ data: {
4188
+ element
4189
+ },
4190
+ selected = false,
4191
+ width,
4192
+ height
4193
+ }) {
4194
+ const diagramState = useDiagramState();
4195
+ const isNodeInteractive = diagramState.isNodeInteractive;
4196
+ const isHovercards = diagramState.disableHovercards !== true;
4197
+ const isNavigable = diagramState.hasOnNavigateTo && !!element.navigateTo;
4198
+ const isHovered = useDiagramStateSelector((state) => state.hoveredNodeId === id);
4199
+ const w = toDomPrecision(width ?? element.width);
4200
+ const h = toDomPrecision(height ?? element.height);
4201
+ let animate = "idle";
4202
+ if (selected) {
4203
+ animate = "selected";
4204
+ }
4205
+ if (isHovered) {
4206
+ animate = "hover";
4207
+ }
4208
+ return /* @__PURE__ */ jsxs(
4209
+ motion.div,
4210
+ {
4211
+ id,
4212
+ className: clsx(container, "likec4-element-node"),
4213
+ "data-likec4-color": element.color,
4214
+ "data-likec4-shape": element.shape,
4215
+ variants,
4216
+ initial: "idle",
4217
+ ...isNodeInteractive && {
4218
+ whileTap: "tap",
4219
+ animate,
4220
+ ["data-likec4-interactive"]: true
4221
+ },
4222
+ children: [
4223
+ /* @__PURE__ */ jsx(
4224
+ Handle,
4225
+ {
4226
+ type: "target",
4227
+ position: Position.Top,
4228
+ style: { visibility: "hidden" }
4229
+ }
4230
+ ),
4231
+ /* @__PURE__ */ jsxs(
4232
+ "svg",
4233
+ {
4234
+ className: cssShapeSvg,
4235
+ viewBox: `0 0 ${w} ${h}`,
4236
+ width: w,
4237
+ height: h,
4238
+ children: [
4239
+ /* @__PURE__ */ jsx("g", { className: indicator, children: /* @__PURE__ */ jsx(
4240
+ SelectedIndicator,
4241
+ {
4242
+ shape: element.shape,
4243
+ w,
4244
+ h
4245
+ }
4246
+ ) }),
4247
+ /* @__PURE__ */ jsx(
4248
+ ElementShapeSvg,
4249
+ {
4250
+ shape: element.shape,
4251
+ w,
4252
+ h
4253
+ }
4254
+ )
4255
+ ]
4256
+ }
4257
+ ),
4258
+ /* @__PURE__ */ jsxs("div", { className: clsx(cssElement, "likec4-element"), children: [
4259
+ element.icon && /* @__PURE__ */ jsx(ElementIcon, { node: element }),
4260
+ /* @__PURE__ */ jsx(
4261
+ Text,
4262
+ {
4263
+ component: "div",
4264
+ className: clsx(title, "likec4-element-title"),
4265
+ children: element.title
4266
+ }
4267
+ ),
4268
+ element.technology && /* @__PURE__ */ jsx(
4269
+ Text,
4270
+ {
4271
+ component: "div",
4272
+ className: clsx(technology, "likec4-element-technology"),
4273
+ children: element.technology
4274
+ }
4275
+ ),
4276
+ element.description && /* @__PURE__ */ jsx(
4277
+ Text,
4278
+ {
4279
+ component: "div",
4280
+ className: clsx(description, "likec4-element-description"),
4281
+ children: element.description
4282
+ }
4283
+ )
4284
+ ] }),
4285
+ /* @__PURE__ */ jsx(
4286
+ Handle,
4287
+ {
4288
+ type: "source",
4289
+ position: Position.Bottom,
4290
+ style: { visibility: "hidden" }
4291
+ }
4292
+ ),
4293
+ isHovercards && /* @__PURE__ */ jsx(ElementLink, { element }),
4294
+ isNavigable && /* @__PURE__ */ jsx(NavigateToBtn, { xynodeId: id, className: cssNavigateBtn })
4295
+ ]
4296
+ }
4297
+ );
4298
+ }
4299
+ const ElementNodeMemo = memo(ElementNode, isEqualProps);
4300
+ const nodeTypes = {
4301
+ element: ElementNodeMemo,
4302
+ compound: CompoundNodeMemo
4303
+ };
4304
+ const edgeTypes = {
4305
+ relationship: RelationshipEdge
4306
+ };
4307
+ function XYFlowWrapper({
4308
+ className,
4309
+ children,
4310
+ defaultNodes,
4311
+ defaultEdges,
4312
+ fitView = true,
4313
+ colorMode: colorModeProp,
4314
+ readonly = false,
4315
+ pannable = true,
4316
+ zoomable = true,
4317
+ nodesSelectable = !readonly,
4318
+ nodesDraggable = !readonly,
4319
+ fitViewPadding = 0,
4320
+ style
4321
+ }) {
4322
+ const xyflowRef = useRef();
4323
+ const [editor, updateState] = useDiagramStateTracked();
4324
+ const layoutConstraints = useLayoutConstraints(xyflowRef);
4325
+ const handlers = useXYFlowEvents();
4326
+ const { colorScheme } = useMantineColorScheme();
4327
+ let colorMode = colorModeProp ?? (colorScheme !== "auto" ? colorScheme : void 0);
4328
+ return (
4329
+ // @ts-expect-error
4330
+ /* @__PURE__ */ jsx(
4331
+ ReactFlow,
4332
+ {
4333
+ className,
4334
+ style,
4335
+ ...colorMode && { colorMode },
4336
+ defaultNodes,
4337
+ defaultEdges,
4338
+ nodeTypes,
4339
+ edgeTypes,
4340
+ zoomOnPinch: zoomable,
4341
+ zoomOnScroll: !pannable && zoomable,
4342
+ ...!zoomable && {
4343
+ zoomActivationKeyCode: null
4344
+ },
4345
+ maxZoom: zoomable ? 1.9 : 1,
4346
+ minZoom: zoomable ? MinZoom : 1,
4347
+ fitView,
4348
+ fitViewOptions: {
4349
+ minZoom: MinZoom,
4350
+ maxZoom: 1,
4351
+ padding: fitViewPadding
4352
+ },
4353
+ defaultMarkerColor: "var(--xy-edge-stroke)",
4354
+ noDragClassName: "nodrag",
4355
+ noPanClassName: "nopan",
4356
+ panOnScroll: pannable,
4357
+ panOnDrag: pannable,
4358
+ elementsSelectable: nodesSelectable,
4359
+ ...!nodesSelectable && {
4360
+ selectionKeyCode: null
4361
+ },
4362
+ nodesDraggable,
4363
+ ...nodesDraggable && layoutConstraints,
4364
+ zoomOnDoubleClick: false,
4365
+ elevateNodesOnSelect: false,
4366
+ selectNodesOnDrag: false,
4367
+ onInit: useCallback((instance) => {
4368
+ xyflowRef.current = instance;
4369
+ updateState({ viewportInitialized: true });
4370
+ }, []),
4371
+ onEdgeMouseEnter: useCallback((event, edge) => {
4372
+ updateState({ hoveredEdgeId: edge.id });
4373
+ }, []),
4374
+ onEdgeMouseLeave: useCallback(() => {
4375
+ updateState({ hoveredEdgeId: null });
4376
+ }, []),
4377
+ ...editor.isNodeInteractive && {
4378
+ onNodeMouseEnter: (event, node) => {
4379
+ updateState({ hoveredNodeId: node.id });
4380
+ },
4381
+ onNodeMouseLeave: () => {
4382
+ updateState({ hoveredNodeId: null });
4383
+ }
4384
+ },
4385
+ ...editor.hasOnContextMenu && {
4386
+ onNodeContextMenu: handlers.onNodeContextMenu,
4387
+ onPaneContextMenu: handlers.onPaneContextMenu,
4388
+ onEdgeContextMenu: handlers.onEdgeContextMenu
4389
+ },
4390
+ ...editor.hasOnCanvasClick && {
4391
+ onPaneClick: handlers.onPanelClick
4392
+ },
4393
+ ...editor.hasOnNodeClick && {
4394
+ onNodeClick: handlers.onNodeClick
4395
+ },
4396
+ ...editor.hasOnEdgeClick && {
4397
+ onEdgeClick: handlers.onEdgeClick
4398
+ },
4399
+ children
4400
+ }
4401
+ )
4402
+ );
4403
+ }
4404
+ const isEquals = ({ children: _childrenA, ...a }, { children: _childrenB, ...b }) => deepEqual(a, b);
4405
+ const XYFlow = memo(XYFlowWrapper, isEquals);
4406
+ function LikeC4Diagram({
4407
+ view,
4408
+ className,
4409
+ fitView = true,
4410
+ fitViewPadding = 0,
4411
+ colorMode,
4412
+ readonly = true,
4413
+ pannable = true,
4414
+ zoomable = true,
4415
+ nodesSelectable = true,
4416
+ nodesDraggable = !readonly,
4417
+ background = "dots",
4418
+ controls = false,
4419
+ disableHovercards = false,
4420
+ initialWidth,
4421
+ initialHeight,
4422
+ keepAspectRatio = false,
4423
+ ...eventHandlers
4424
+ }) {
4425
+ const initialRef = useRef();
4426
+ if (!initialRef.current) {
4427
+ const initial = diagramViewToXYFlowData(view);
4428
+ initialRef.current = {
4429
+ defaultNodes: initial.nodes,
4430
+ defaultEdges: initial.edges,
4431
+ initialWidth: initialWidth ?? view.width,
4432
+ initialHeight: initialHeight ?? view.height
4433
+ };
4434
+ }
4435
+ const isBgWithPattern = background !== "transparent" && background !== "solid";
4436
+ const isNodeInteractive = nodesDraggable || nodesSelectable || !!eventHandlers.onNavigateTo || !!eventHandlers.onNavigateTo;
4437
+ return /* @__PURE__ */ jsx(EnsureMantine, { colorMode, children: /* @__PURE__ */ jsx(
4438
+ ReactFlowProvider,
4439
+ {
4440
+ fitView,
4441
+ ...initialRef.current,
4442
+ children: /* @__PURE__ */ jsx(
4443
+ DiagramStateProvider,
4444
+ {
4445
+ isNodeInteractive,
4446
+ view,
4447
+ fitViewPadding,
4448
+ readonly,
4449
+ disableHovercards,
4450
+ eventHandlers,
4451
+ children: /* @__PURE__ */ jsxs(XYFlowEventHandlers, { eventHandlers, children: [
4452
+ /* @__PURE__ */ jsx(
4453
+ KeepAspectRatio,
4454
+ {
4455
+ enabled: keepAspectRatio,
4456
+ width: view.width,
4457
+ height: view.height,
4458
+ children: /* @__PURE__ */ jsxs(
4459
+ XYFlow,
4460
+ {
4461
+ className: clsx(
4462
+ className,
4463
+ scope,
4464
+ cssReactFlow,
4465
+ controls === false && cssNoControls,
4466
+ pannable !== true && cssDisablePan,
4467
+ background === "transparent" && cssTransparentBg
4468
+ ),
4469
+ defaultNodes: initialRef.current.defaultNodes,
4470
+ defaultEdges: initialRef.current.defaultEdges,
4471
+ readonly,
4472
+ nodesDraggable,
4473
+ nodesSelectable,
4474
+ pannable,
4475
+ zoomable,
4476
+ fitView,
4477
+ colorMode,
4478
+ fitViewPadding,
4479
+ children: [
4480
+ isBgWithPattern && /* @__PURE__ */ jsx(XYFlowBackground, { background }),
4481
+ controls && /* @__PURE__ */ jsx(Controls, {}),
4482
+ readonly !== true && /* @__PURE__ */ jsx(OptionsPanel2, {}),
4483
+ fitView && /* @__PURE__ */ jsx(FitViewOnDiagramChange, {})
4484
+ ]
4485
+ }
4486
+ )
4487
+ }
4488
+ ),
4489
+ /* @__PURE__ */ jsx(
4490
+ UpdateOnDiagramChange,
4491
+ {
4492
+ view,
4493
+ nodesDraggable
4494
+ }
4495
+ )
4496
+ ] })
4497
+ }
4498
+ )
4499
+ }
4500
+ ) });
4501
+ }
4502
+ function StaticLikeC4Diagram({
4503
+ view,
4504
+ fitView = true,
4505
+ fitViewPadding = 0,
4506
+ background = "transparent",
4507
+ ...rest
4508
+ }) {
4509
+ return /* @__PURE__ */ jsx(
4510
+ LikeC4Diagram,
4511
+ {
4512
+ view,
4513
+ readonly: true,
4514
+ fitView,
4515
+ fitViewPadding,
4516
+ pannable: false,
4517
+ zoomable: false,
4518
+ controls: false,
4519
+ background,
4520
+ disableHovercards: true,
4521
+ nodesSelectable: false,
4522
+ nodesDraggable: false,
4523
+ ...rest
4524
+ }
4525
+ );
4526
+ }
4527
+ function EmbeddedLikeC4DiagramCmp({
4528
+ viewId,
4529
+ views,
4530
+ colorMode
4531
+ }) {
4532
+ const [isOpened, toggleOpened] = useToggle(false);
4533
+ const [browserViewId, setBrowserViewId] = useState(viewId);
4534
+ const view = views[viewId];
4535
+ invariant(view, `View with id ${viewId} not found`);
4536
+ const browserView = views[browserViewId];
4537
+ invariant(browserView, `View with id ${browserViewId} not found`);
4538
+ const closeBrowser = () => {
4539
+ toggleOpened(false);
4540
+ setBrowserViewId(viewId);
4541
+ };
4542
+ useUpdateEffect(closeBrowser, [viewId]);
4543
+ return /* @__PURE__ */ jsxs(EnsureMantine, { colorMode, children: [
4544
+ /* @__PURE__ */ jsx(
4545
+ KeepAspectRatio,
4546
+ {
4547
+ enabled: true,
4548
+ height: view.height,
4549
+ width: view.width,
4550
+ onClick: (e) => {
4551
+ e.stopPropagation();
4552
+ toggleOpened(true);
4553
+ },
4554
+ children: /* @__PURE__ */ jsx(
4555
+ StaticLikeC4Diagram,
4556
+ {
4557
+ colorMode,
4558
+ view,
4559
+ fitView: true,
4560
+ fitViewPadding: 0.01,
4561
+ background: "transparent",
4562
+ keepAspectRatio: false
4563
+ }
4564
+ )
4565
+ }
4566
+ ),
4567
+ /* @__PURE__ */ jsxs(Modal.Root, { opened: isOpened, onClose: closeBrowser, fullScreen: true, children: [
4568
+ /* @__PURE__ */ jsx(Modal.Overlay, { blur: 16 }),
4569
+ /* @__PURE__ */ jsx(Modal.Content, { className: modalContent, children: /* @__PURE__ */ jsxs(Modal.Body, { className: modalBody, children: [
4570
+ /* @__PURE__ */ jsx(Box, { className: modalHeader, children: /* @__PURE__ */ jsx(Title, { order: 4, children: browserView.title || browserView.id }) }),
4571
+ isOpened && /* @__PURE__ */ jsx(
4572
+ LikeC4Diagram,
4573
+ {
4574
+ readonly: true,
4575
+ view: browserView,
4576
+ colorMode,
4577
+ background: "transparent",
4578
+ fitViewPadding: 0.09,
4579
+ onCanvasDblClick: closeBrowser,
4580
+ onNavigateTo: ({ event, element }) => {
4581
+ event.stopPropagation();
4582
+ setBrowserViewId(element.navigateTo);
4583
+ }
4584
+ }
4585
+ ),
4586
+ /* @__PURE__ */ jsx(Box, { className: modalCloseButtonBox, children: /* @__PURE__ */ jsx(CloseButton, { className: modalCloseButton, onClick: closeBrowser }) })
4587
+ ] }) })
4588
+ ] })
4589
+ ] });
4590
+ }
4591
+ const EmbeddedLikeC4Diagram = memo(EmbeddedLikeC4DiagramCmp, shallowEqual);
4592
+ export {
4593
+ EmbeddedLikeC4Diagram,
4594
+ LikeC4Diagram,
4595
+ StaticLikeC4Diagram
4596
+ };