@likec4/core 1.32.2 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/builder/index.d.mts +6 -4
  2. package/dist/builder/index.mjs +45 -13
  3. package/dist/compute-view/index.d.mts +6 -4
  4. package/dist/compute-view/index.mjs +33 -10
  5. package/dist/compute-view/relationships-view/index.d.mts +6 -4
  6. package/dist/compute-view/relationships-view/index.mjs +6 -3
  7. package/dist/index.d.mts +9 -138
  8. package/dist/index.mjs +31 -3712
  9. package/dist/model/connection/deployment/index.d.mts +10 -0
  10. package/dist/model/connection/deployment/index.mjs +18 -0
  11. package/dist/model/connection/index.d.mts +70 -0
  12. package/dist/model/connection/index.mjs +23 -0
  13. package/dist/model/connection/model/index.d.mts +10 -0
  14. package/dist/model/connection/model/index.mjs +11 -0
  15. package/dist/model/index.d.mts +14 -256
  16. package/dist/model/index.mjs +27 -5
  17. package/dist/shared/{core.Bdz6fBF1.d.mts → core.1pNeDdRk.d.mts} +92 -81
  18. package/dist/shared/{core.BuO4ncfY.d.mts → core.668kXpZq.d.mts} +42 -52
  19. package/dist/shared/core.8KM0D6va.mjs +33 -0
  20. package/dist/shared/core.B0oEIXqd.mjs +47 -0
  21. package/dist/shared/core.BH9nN-_I.mjs +22 -0
  22. package/dist/shared/core.BMCb0wJI.mjs +177 -0
  23. package/dist/shared/core.BTnf14gD.mjs +331 -0
  24. package/dist/shared/core.BgvIuGGU.mjs +3 -0
  25. package/dist/shared/core.BoyJPEen.mjs +21 -0
  26. package/dist/shared/{core.CUYDgv2-.mjs → core.Br7Fab9l.mjs} +12 -15
  27. package/dist/shared/{core.BrCnZFTn.mjs → core.Btl47GOn.mjs} +3 -3
  28. package/dist/shared/core.ByrmCl9I.mjs +5 -0
  29. package/dist/shared/core.C80Z37Eu.mjs +29 -0
  30. package/dist/shared/{core.Pf5I9o0e.d.mts → core.CF82MWyh.d.mts} +1 -1
  31. package/dist/shared/{core.rmvsy0n3.mjs → core.C_C-3c1S.mjs} +5 -198
  32. package/dist/shared/core.CeQbbp7K.d.mts +41 -0
  33. package/dist/shared/{core.DoK86JEe.mjs → core.CpwrZi3D.mjs} +2 -73
  34. package/dist/shared/{core.CpXlRyE5.mjs → core.CtKXPqN_.mjs} +5 -36
  35. package/dist/shared/core.CxGKeL-L.mjs +144 -0
  36. package/dist/shared/core.CzdwsPmY.d.mts +69 -0
  37. package/dist/shared/{core.Cy9smucx.mjs → core.D4npX2q8.mjs} +1 -3
  38. package/dist/shared/core.D56nCp7e.mjs +168 -0
  39. package/dist/shared/core.D5qVzkws.mjs +724 -0
  40. package/dist/shared/core.DDAPzd3T.d.mts +87 -0
  41. package/dist/shared/{core.CBpKAlhj.mjs → core.DDynPqbh.mjs} +96 -56
  42. package/dist/shared/{core.Bk7wEZFG.mjs → core.DXRAwwDB.mjs} +3 -2
  43. package/dist/shared/core.DcS-0zys.mjs +10 -0
  44. package/dist/shared/{core.CBxTtXMi.d.mts → core.De___iBS.d.mts} +3 -2
  45. package/dist/shared/core.DsMrjY2q.mjs +34 -0
  46. package/dist/shared/core.DuSLYTG6.d.mts +57 -0
  47. package/dist/shared/core.Dy-F3xRP.d.mts +83 -0
  48. package/dist/shared/{core.DaAyklhe.d.mts → core.OLInHaJx.d.mts} +30 -22
  49. package/dist/shared/core.XptQjhMA.mjs +1295 -0
  50. package/dist/shared/{core.cbA9VZ02.mjs → core.hoq9W4rW.mjs} +28 -1073
  51. package/dist/shared/core.zLlww-07.mjs +3 -0
  52. package/dist/theme/index.d.mts +134 -0
  53. package/dist/theme/index.mjs +3709 -0
  54. package/dist/types/aux.d.mts +3 -2
  55. package/dist/types/index.d.mts +9 -5
  56. package/dist/types/index.mjs +17 -146
  57. package/dist/utils/index.d.mts +15 -100
  58. package/dist/utils/index.mjs +25 -1315
  59. package/dist/utils/iterable/index.d.mts +100 -0
  60. package/dist/utils/iterable/index.mjs +24 -0
  61. package/package.json +23 -7
  62. package/src/builder/Builder.ts +13 -4
  63. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +0 -13
  64. package/src/builder/__snapshots__/Builder-style2.compute-model.json5 +2 -6
  65. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +0 -7
  66. package/src/compute-view/deployment-view/__test__/fixture.ts +15 -5
  67. package/src/compute-view/deployment-view/utils.ts +13 -13
  68. package/src/compute-view/dynamic-view/compute.ts +2 -1
  69. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +2 -2
  70. package/src/compute-view/relationships-view/layout.ts +1 -1
  71. package/src/compute-view/utils/applyCustomElementProperties.ts +8 -0
  72. package/src/compute-view/utils/applyCustomRelationProperties.ts +2 -0
  73. package/src/compute-view/utils/buildComputedNodes.ts +4 -3
  74. package/src/compute-view/utils/merge-props-from-relationships.ts +6 -5
  75. package/src/compute-view/utils/view-hash.ts +24 -3
  76. package/src/model/DeploymentElementModel.ts +20 -16
  77. package/src/model/ElementModel.ts +9 -3
  78. package/src/model/RelationModel.ts +19 -16
  79. package/src/model/index.ts +2 -0
  80. package/src/model/types.ts +1 -0
  81. package/src/model/view/EdgeModel.ts +4 -3
  82. package/src/model/view/LikeC4ViewModel.ts +5 -0
  83. package/src/model/view/NodeModel.ts +4 -2
  84. package/src/theme/index.ts +12 -5
  85. package/src/types/RichText.ts +200 -0
  86. package/src/types/index.ts +2 -0
  87. package/src/types/model-deployment.ts +4 -3
  88. package/src/types/model-logical.ts +3 -3
  89. package/src/types/scalar.ts +47 -2
  90. package/src/types/view-common.ts +1 -1
  91. package/src/types/view-computed.ts +2 -4
  92. package/src/types/view-layouted.ts +9 -0
  93. package/src/utils/index.ts +4 -9
  94. package/src/utils/markdown/index.ts +2 -0
  95. package/src/utils/markdown/to-html.ts +32 -0
  96. package/src/utils/markdown/to-text.ts +14 -0
@@ -0,0 +1,41 @@
1
+ import { E as ElementModel, e as DeploymentElementModel } from './core.OLInHaJx.mjs';
2
+ import { A as Any } from './core.De___iBS.mjs';
3
+ import { F as Fqn } from './core.668kXpZq.mjs';
4
+
5
+ interface Connection<Elem = ElementModel<Any> | DeploymentElementModel<Any>, Id = string> {
6
+ readonly id: Id;
7
+ readonly source: Elem;
8
+ readonly target: Elem;
9
+ /**
10
+ * Common ancestor of the source and target elements.
11
+ * Represents the boundary of the connection.
12
+ */
13
+ readonly boundary: Elem | null;
14
+ /**
15
+ * Human readable expression of the connection
16
+ * Mostly used for testing and debugging
17
+ */
18
+ readonly expression: string;
19
+ mergeWith(this: Connection<Elem, Id>, other: typeof this): typeof this;
20
+ nonEmpty(): boolean;
21
+ difference(this: Connection<Elem, Id>, other: typeof this): typeof this;
22
+ intersect(this: Connection<Elem, Id>, other: typeof this): typeof this;
23
+ equals(other: Connection): boolean;
24
+ }
25
+ declare namespace Connection {
26
+ type ConnectionPredicate = <C extends Connection<{
27
+ id: string;
28
+ }, any>>(connection: C) => boolean;
29
+ type ElementId = Fqn | string;
30
+ export const isInside: (fqn: ElementId) => ConnectionPredicate;
31
+ export const isDirectedBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
32
+ export const isAnyBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
33
+ export const isIncoming: (target: ElementId) => ConnectionPredicate;
34
+ export const isOutgoing: (source: ElementId) => ConnectionPredicate;
35
+ export const isAnyInOut: (source: ElementId) => ConnectionPredicate;
36
+ export { };
37
+ }
38
+
39
+ declare const customInspectSymbol: unique symbol;
40
+
41
+ export { Connection as C, customInspectSymbol as c };
@@ -1,11 +1,8 @@
1
1
  import { u } from './core.DbRvwARP.mjs';
2
- import { t } from './core.rmvsy0n3.mjs';
3
- import { i as invariant } from './core.Cy9smucx.mjs';
2
+ import { i as invariant } from './core.D4npX2q8.mjs';
4
3
 
5
4
  function i(...e){return u(n,e)}var n=(e,r)=>e.length>=r;
6
5
 
7
- function m(...a){return u(o,a,p)}var o=(a,e)=>a.map(e),p=a=>(e,t,r)=>({done:false,hasNext:true,next:a(e,t,r)});
8
-
9
6
  var set = {};
10
7
 
11
8
  /**
@@ -376,74 +373,6 @@ function requireSet () {
376
373
 
377
374
  var setExports = /*@__PURE__*/ requireSet();
378
375
 
379
- function getOrCreate(map, key, create) {
380
- let entry = map.get(key);
381
- if (!entry) {
382
- entry = create(key);
383
- map.set(key, entry);
384
- }
385
- return entry;
386
- }
387
-
388
- function ifind(arg1, arg2) {
389
- const pred = arg2 ?? arg1;
390
- invariant(t(pred));
391
- function _find(iter) {
392
- for (const value of iter) {
393
- if (pred(value)) {
394
- return value;
395
- }
396
- }
397
- return;
398
- }
399
- if (!arg2) {
400
- return _find;
401
- }
402
- return _find(arg1);
403
- }
404
-
405
- function ihead(iterable) {
406
- if (!iterable) {
407
- return _head;
408
- }
409
- return _head(iterable);
410
- }
411
- function _head(iter) {
412
- for (const value of iter) {
413
- return value;
414
- }
415
- return;
416
- }
417
-
418
- function isome(arg1, arg2) {
419
- const pred = arg2 ?? arg1;
420
- invariant(t(pred));
421
- function _some(iter) {
422
- for (const value of iter) {
423
- if (pred(value)) {
424
- return true;
425
- }
426
- }
427
- return false;
428
- }
429
- if (!arg2) {
430
- return _some;
431
- }
432
- return _some(arg1);
433
- }
434
-
435
- function memoizeProp(obj, tag, fn) {
436
- const tagSymbol = typeof tag === "symbol" ? tag : Symbol.for(tag);
437
- if (!obj.hasOwnProperty(tagSymbol)) {
438
- Object.defineProperty(obj, tagSymbol, {
439
- enumerable: false,
440
- writable: false,
441
- value: fn()
442
- });
443
- }
444
- return obj[tagSymbol];
445
- }
446
-
447
376
  function union(...sets) {
448
377
  let result = /* @__PURE__ */ new Set();
449
378
  for (const set of sets) {
@@ -515,4 +444,4 @@ function stringHash(str) {
515
444
  return (hash >>> 0).toString(36);
516
445
  }
517
446
 
518
- export { intersection as a, isome as b, ifind as c, difference as d, ihead as e, memoizeProp as f, getOrCreate as g, hasIntersection as h, i, equals as j, stringHash as k, m, symmetricDifference as s, union as u };
447
+ export { intersection as a, stringHash as b, difference as d, equals as e, hasIntersection as h, i, symmetricDifference as s, union as u };
@@ -1,16 +1,13 @@
1
- import { g as getDefaultExportFromCjs, C } from './core.rmvsy0n3.mjs';
1
+ import { r as getDefaultExportFromCjs, C } from './core.C_C-3c1S.mjs';
2
2
  import { u as u$1 } from './core.DbRvwARP.mjs';
3
- import { m } from './core.DoK86JEe.mjs';
4
- import { i as invariant } from './core.Cy9smucx.mjs';
3
+ import { m } from './core.ByrmCl9I.mjs';
4
+ import { l } from './core.8KM0D6va.mjs';
5
+ import { i as invariant } from './core.D4npX2q8.mjs';
5
6
 
6
7
  function d(...e){return u$1(i,e,o$1)}var i=(e,n)=>e.length<n.length?e.map((t,r)=>[t,n[r]]):n.map((t,r)=>[e[r],t]),o$1=e=>(n,t)=>({hasNext:true,next:[n,e[t]],done:t>=e.length-1});
7
8
 
8
9
  function u(...e){return u$1(o,e)}function o(e,a){let n=[];for(let[i,r]of e.entries()){if(!a(r,i,e))break;n.push(r);}return n}
9
10
 
10
- function n(e){return e!==void 0}
11
-
12
- function l(n){return n!=null}
13
-
14
11
  var support = {};
15
12
 
16
13
  var hasRequiredSupport;
@@ -446,34 +443,6 @@ function commonHead(sources, targets, equals) {
446
443
  );
447
444
  }
448
445
 
449
- function isIterable(something) {
450
- return l(something) && typeof something === "object" && Symbol.iterator in something;
451
- }
452
-
453
- function iflat(iterable) {
454
- return iterable ? _iflat(iterable) : _iflat;
455
- }
456
- function* _iflat(iterable) {
457
- for (const inner of iterable) {
458
- yield* inner;
459
- }
460
- return;
461
- }
462
-
463
- function iunique(iterable) {
464
- return iterable ? _iunique(iterable) : _iunique;
465
- }
466
- function* _iunique(iterable) {
467
- const seen = /* @__PURE__ */ new Set();
468
- for (const item of iterable) {
469
- if (!seen.has(item)) {
470
- seen.add(item);
471
- yield item;
472
- }
473
- }
474
- return;
475
- }
476
-
477
446
  function commonjsRequire(path) {
478
447
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
479
448
  }
@@ -505,4 +474,4 @@ function objectHash(value) {
505
474
  });
506
475
  }
507
476
 
508
- export { Stack as S, requireIterator as a, iunique as b, commonHead as c, d, iflat as e, isIterable as i, l, n, objectHash as o, requireForeach as r, u };
477
+ export { Stack as S, requireIterator as a, commonHead as c, d, objectHash as o, requireForeach as r, u };
@@ -0,0 +1,144 @@
1
+ import { i as invariant } from './core.D4npX2q8.mjs';
2
+
3
+ var BBox;
4
+ ((BBox2) => {
5
+ function center({ x, y, width, height }) {
6
+ return {
7
+ x: x + width / 2,
8
+ y: y + height / 2
9
+ };
10
+ }
11
+ BBox2.center = center;
12
+ function fromPoints(points) {
13
+ const { x1, y1, x2, y2 } = RectBox.fromPoints(points);
14
+ return {
15
+ x: x1,
16
+ y: y1,
17
+ width: x2 - x1,
18
+ height: y2 - y1
19
+ };
20
+ }
21
+ BBox2.fromPoints = fromPoints;
22
+ function merge(...boxes) {
23
+ invariant(boxes.length > 0, "No boxes provided");
24
+ let minX = Infinity;
25
+ let minY = Infinity;
26
+ let maxX = -Infinity;
27
+ let maxY = -Infinity;
28
+ for (const box of boxes) {
29
+ minX = Math.min(minX, box.x);
30
+ minY = Math.min(minY, box.y);
31
+ maxX = Math.max(maxX, box.x + box.width);
32
+ maxY = Math.max(maxY, box.y + box.height);
33
+ }
34
+ return {
35
+ x: minX,
36
+ y: minY,
37
+ width: maxX - minX,
38
+ height: maxY - minY
39
+ };
40
+ }
41
+ BBox2.merge = merge;
42
+ function toRectBox(box) {
43
+ return {
44
+ x1: box.x,
45
+ y1: box.y,
46
+ x2: box.x + box.width,
47
+ y2: box.y + box.height
48
+ };
49
+ }
50
+ BBox2.toRectBox = toRectBox;
51
+ })(BBox || (BBox = {}));
52
+ var RectBox;
53
+ ((RectBox2) => {
54
+ function center({ x1, y1, x2, y2 }) {
55
+ return {
56
+ x: (x1 + x2) / 2,
57
+ y: (y1 + y2) / 2
58
+ };
59
+ }
60
+ RectBox2.center = center;
61
+ function fromPoints(points) {
62
+ invariant(points.length > 0, "At least one point is required");
63
+ let minX = Infinity;
64
+ let minY = Infinity;
65
+ let maxX = -Infinity;
66
+ let maxY = -Infinity;
67
+ for (const [x, y] of points) {
68
+ minX = Math.min(minX, x);
69
+ minY = Math.min(minY, y);
70
+ maxX = Math.max(maxX, x);
71
+ maxY = Math.max(maxY, y);
72
+ }
73
+ return {
74
+ x1: minX,
75
+ y1: minY,
76
+ x2: maxX,
77
+ y2: maxY
78
+ };
79
+ }
80
+ RectBox2.fromPoints = fromPoints;
81
+ function merge(...boxes) {
82
+ invariant(boxes.length > 0, "No boxes provided");
83
+ let minX = Infinity;
84
+ let minY = Infinity;
85
+ let maxX = -Infinity;
86
+ let maxY = -Infinity;
87
+ for (const box of boxes) {
88
+ minX = Math.min(minX, box.x1);
89
+ minY = Math.min(minY, box.y1);
90
+ maxX = Math.max(maxX, box.x2);
91
+ maxY = Math.max(maxY, box.y2);
92
+ }
93
+ return {
94
+ x1: minX,
95
+ y1: minY,
96
+ x2: maxX,
97
+ y2: maxY
98
+ };
99
+ }
100
+ RectBox2.merge = merge;
101
+ function toBBox(box) {
102
+ return {
103
+ x: box.x1,
104
+ y: box.y1,
105
+ width: box.x2 - box.x1,
106
+ height: box.y2 - box.y1
107
+ };
108
+ }
109
+ RectBox2.toBBox = toBBox;
110
+ })(RectBox || (RectBox = {}));
111
+
112
+ function isTagColorSpecified(spec) {
113
+ const color = typeof spec === "string" ? spec : spec.color;
114
+ return color.startsWith("#") || color.startsWith("rgb");
115
+ }
116
+
117
+ const BorderStyles = ["solid", "dashed", "dotted", "none"];
118
+ const ElementShapes = [
119
+ "rectangle",
120
+ "person",
121
+ "browser",
122
+ "mobile",
123
+ "cylinder",
124
+ "storage",
125
+ "queue"
126
+ ];
127
+ const ThemeColors = [
128
+ "amber",
129
+ "blue",
130
+ "gray",
131
+ "slate",
132
+ "green",
133
+ "indigo",
134
+ "muted",
135
+ "primary",
136
+ "red",
137
+ "secondary",
138
+ "sky"
139
+ ];
140
+ function isThemeColor(color) {
141
+ return ThemeColors.includes(color);
142
+ }
143
+
144
+ export { BBox as B, ElementShapes as E, RectBox as R, ThemeColors as T, BorderStyles as a, isThemeColor as b, isTagColorSpecified as i };
@@ -0,0 +1,69 @@
1
+ import { TupleToUnion, Tagged } from 'type-fest';
2
+
3
+ /**
4
+ * For padding, margin, etc.
5
+ */
6
+ type SpacingSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
7
+ type TextSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
8
+ type ShapeSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
9
+ declare const BorderStyles: readonly ["solid", "dashed", "dotted", "none"];
10
+ type BorderStyle = TupleToUnion<typeof BorderStyles>;
11
+ declare const ElementShapes: readonly ["rectangle", "person", "browser", "mobile", "cylinder", "storage", "queue"];
12
+ type ElementShape = TupleToUnion<typeof ElementShapes>;
13
+ type HexColor = `#${string}`;
14
+ type ColorLiteral = HexColor | `rgb(${number},${number},${number})` | `rgba(${number},${number},${number},${number})`;
15
+ type CustomColor<T = string> = Tagged<T, 'CustomColor'>;
16
+ type CustomColorDefinitions = {
17
+ [key: string]: ThemeColorValues;
18
+ };
19
+ type RelationshipLineType = 'dashed' | 'solid' | 'dotted';
20
+ type RelationshipArrowType = 'none' | 'normal' | 'onormal' | 'dot' | 'odot' | 'diamond' | 'odiamond' | 'crow' | 'open' | 'vee';
21
+ declare const ThemeColors: readonly ["amber", "blue", "gray", "slate", "green", "indigo", "muted", "primary", "red", "secondary", "sky"];
22
+ type ThemeColor = typeof ThemeColors[number];
23
+ /**
24
+ * Backward compatibility alias
25
+ * @deprecated Use {@link ThemeColor} instead
26
+ */
27
+ type Color = ThemeColor | ColorLiteral;
28
+ declare function isThemeColor(color: string): color is ThemeColor;
29
+ interface ElementThemeColorValues {
30
+ fill: ColorLiteral;
31
+ stroke: ColorLiteral;
32
+ hiContrast: ColorLiteral;
33
+ loContrast: ColorLiteral;
34
+ }
35
+ type ElementThemeColors = {
36
+ [key in ThemeColor]: ElementThemeColorValues;
37
+ };
38
+ interface RelationshipThemeColorValues {
39
+ lineColor: ColorLiteral;
40
+ labelBgColor: ColorLiteral;
41
+ labelColor: ColorLiteral;
42
+ }
43
+ interface ThemeColorValues {
44
+ elements: ElementThemeColorValues;
45
+ relationships: RelationshipThemeColorValues;
46
+ }
47
+ type RelationshipThemeColors = {
48
+ [key in ThemeColor]: RelationshipThemeColorValues;
49
+ };
50
+ interface LikeC4Theme {
51
+ font: 'Arial';
52
+ shadow: ColorLiteral;
53
+ relationships: RelationshipThemeColors;
54
+ elements: ElementThemeColors;
55
+ sizes: {
56
+ [key in ShapeSize]: {
57
+ width: number;
58
+ height: number;
59
+ };
60
+ };
61
+ spacing: {
62
+ [key in SpacingSize]: number;
63
+ };
64
+ textSizes: {
65
+ [key in TextSize]: number;
66
+ };
67
+ }
68
+
69
+ export { BorderStyles as B, type ColorLiteral as C, ElementShapes as E, type HexColor as H, type LikeC4Theme as L, type RelationshipLineType as R, type SpacingSize as S, type TextSize as T, type ShapeSize as a, type BorderStyle as b, type ElementShape as c, type CustomColor as d, type CustomColorDefinitions as e, type RelationshipArrowType as f, ThemeColors as g, type ThemeColor as h, type Color as i, isThemeColor as j, type ElementThemeColorValues as k, type ElementThemeColors as l, type RelationshipThemeColorValues as m, type ThemeColorValues as n, type RelationshipThemeColors as o };
@@ -1,5 +1,3 @@
1
- function t(r){return typeof r=="string"}
2
-
3
1
  function nonNullable(value, message) {
4
2
  if (typeof value === "undefined" || value == null) {
5
3
  const msg = typeof message === "function" ? message() : message;
@@ -17,4 +15,4 @@ function nonexhaustive(value) {
17
15
  throw new Error(`NonExhaustive value: ${value}`);
18
16
  }
19
17
 
20
- export { nonexhaustive as a, invariant as i, nonNullable as n, t };
18
+ export { nonNullable as a, invariant as i, nonexhaustive as n };
@@ -0,0 +1,168 @@
1
+ import { m as memoizeProp, b as markdownToText, a as markdownToHtml } from './core.B0oEIXqd.mjs';
2
+ import { n as nonexhaustive } from './core.D4npX2q8.mjs';
3
+
4
+ function n(e){return !!e}
5
+
6
+ const DefaultThemeColor = "primary";
7
+ const DefaultElementShape = "rectangle";
8
+ const DefaultShapeSize = "md";
9
+ const DefaultPaddingSize = "md";
10
+ const DefaultTextSize = "md";
11
+ const DefaultLineStyle = "dashed";
12
+ const DefaultArrowType = "normal";
13
+ const DefaultRelationshipColor = "gray";
14
+
15
+ const richtxt = Symbol.for("richtxt");
16
+ const symb_text = Symbol.for("text");
17
+ const symb_html = Symbol.for("html");
18
+ const emptyTxt = "";
19
+ class RichText {
20
+ static _cache = /* @__PURE__ */ new WeakMap();
21
+ /**
22
+ * Creates and memoizes a RichText instance.
23
+ * @see ElementModel.description
24
+ * @example
25
+ *
26
+ * get description(): RichTextOrEmpty {
27
+ * return RichText.memoize(this, this.$element.description)
28
+ * }
29
+ */
30
+ static memoize(obj, source) {
31
+ return memoizeProp(obj, richtxt, () => RichText.from(source));
32
+ }
33
+ /**
34
+ * Creates a RichText instance from a source.
35
+ */
36
+ static from(source) {
37
+ if (source === null || source === void 0 || source === RichText.EMPTY) {
38
+ return RichText.EMPTY;
39
+ }
40
+ if (source instanceof RichText) {
41
+ return source;
42
+ }
43
+ if (typeof source === "string") {
44
+ return RichText.from({ txt: source });
45
+ }
46
+ if ("isEmpty" in source && source.isEmpty) {
47
+ return RichText.EMPTY;
48
+ }
49
+ if ("md" in source && source.md.trim() === emptyTxt) {
50
+ return RichText.EMPTY;
51
+ }
52
+ if ("txt" in source && source.txt.trim() === emptyTxt) {
53
+ return RichText.EMPTY;
54
+ }
55
+ const _source = source;
56
+ const cached = RichText._cache.get(_source);
57
+ if (cached) {
58
+ return cached;
59
+ }
60
+ const rt = new RichText(_source);
61
+ RichText._cache.set(_source, rt);
62
+ return rt;
63
+ }
64
+ /**
65
+ * This is a workaround for the fact that we need instance of RichText for `instanceof` checks
66
+ * It is invalid inheritance (returning `null` from getters), and we cast to @see RichTextEmpty
67
+ */
68
+ static EMPTY = new class extends RichText {
69
+ isEmpty = true;
70
+ nonEmpty = false;
71
+ isMarkdown = false;
72
+ $source = null;
73
+ constructor() {
74
+ super({ txt: emptyTxt });
75
+ }
76
+ get text() {
77
+ return null;
78
+ }
79
+ get md() {
80
+ return null;
81
+ }
82
+ get html() {
83
+ return null;
84
+ }
85
+ }();
86
+ $source;
87
+ isEmpty;
88
+ nonEmpty;
89
+ isMarkdown;
90
+ /**
91
+ * Private constructor to prevent direct instantiation.
92
+ * Use {@link RichText.from} or {@link RichText.memoize} instead.
93
+ */
94
+ constructor(source) {
95
+ this.isMarkdown = false;
96
+ if (typeof source === "string") {
97
+ this.$source = { txt: source };
98
+ this.isEmpty = source.trim() === emptyTxt;
99
+ } else {
100
+ this.$source = source;
101
+ this.isEmpty = true;
102
+ if ("md" in source) {
103
+ this.isEmpty = source.md === emptyTxt;
104
+ this.isMarkdown = true;
105
+ } else {
106
+ this.isEmpty = source.txt === emptyTxt;
107
+ }
108
+ }
109
+ this.nonEmpty = !this.isEmpty;
110
+ }
111
+ /**
112
+ * Returns the text content of the rich text.
113
+ * If the source is a string, it returns the string.
114
+ * If the source is a markdown, it returns the markdown.
115
+ */
116
+ get text() {
117
+ if (this.isEmpty || this.$source === null) {
118
+ return emptyTxt;
119
+ }
120
+ const source = this.$source;
121
+ if ("txt" in source) {
122
+ return source.txt;
123
+ }
124
+ return memoizeProp(this, symb_text, () => markdownToText(source.md));
125
+ }
126
+ /**
127
+ * Returns the markdown content of the rich text.
128
+ * If the source is a string, it returns the string.
129
+ * If the source is a markdown, it returns the markdown.
130
+ */
131
+ get md() {
132
+ if (this.isEmpty || this.$source === null) {
133
+ return emptyTxt;
134
+ }
135
+ const source = this.$source;
136
+ if ("md" in source) {
137
+ return source.md;
138
+ }
139
+ if ("txt" in source) {
140
+ return source.txt;
141
+ }
142
+ nonexhaustive(source);
143
+ }
144
+ /**
145
+ * Returns the html content of the rich text.
146
+ * If the source is a string, it returns the string.
147
+ * If the source is a markdown, it returns the HTML.
148
+ */
149
+ get html() {
150
+ if (this.isEmpty || this.$source === null) {
151
+ return emptyTxt;
152
+ }
153
+ const markdown = this.$source.md ?? this.$source.txt;
154
+ return memoizeProp(this, symb_html, () => markdownToHtml(markdown));
155
+ }
156
+ equals(other) {
157
+ if (this === other) return true;
158
+ if (!(other instanceof RichText)) return false;
159
+ if (this.isEmpty && other.isEmpty) return true;
160
+ if (this.isEmpty !== other.isEmpty || this.isMarkdown !== other.isMarkdown) return false;
161
+ if (this.isMarkdown) {
162
+ return this.$source?.md === other.$source?.md;
163
+ }
164
+ return this.$source?.txt === other.$source?.txt;
165
+ }
166
+ }
167
+
168
+ export { DefaultThemeColor as D, RichText as R, DefaultElementShape as a, DefaultShapeSize as b, DefaultPaddingSize as c, DefaultTextSize as d, DefaultLineStyle as e, DefaultArrowType as f, DefaultRelationshipColor as g, n };