@likec4/core 0.37.1 → 0.41.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 (147) hide show
  1. package/README.md +2 -6
  2. package/dist/cjs/colors/element.d.ts +68 -0
  3. package/dist/{colors.js → cjs/colors/element.js} +24 -46
  4. package/dist/cjs/colors/index.d.ts +132 -0
  5. package/dist/cjs/colors/index.js +27 -0
  6. package/dist/cjs/colors/relationships.d.ts +57 -0
  7. package/dist/cjs/colors/relationships.js +76 -0
  8. package/dist/cjs/errors/index.d.ts +45 -0
  9. package/dist/cjs/errors/index.js +137 -0
  10. package/dist/{index.d.ts → cjs/index.d.ts} +3 -5
  11. package/dist/{index.cjs → cjs/index.js} +16 -38
  12. package/dist/{types → cjs/types}/computed-view.d.ts +11 -7
  13. package/dist/{types → cjs/types}/diagram.d.ts +15 -11
  14. package/dist/{types → cjs/types}/expression.d.ts +1 -1
  15. package/dist/{types/index.cjs → cjs/types/index.js} +10 -10
  16. package/dist/cjs/types/relation.d.ts +22 -0
  17. package/dist/cjs/types/relation.js +12 -0
  18. package/dist/{types → cjs/types}/theme.d.ts +10 -6
  19. package/dist/{types → cjs/types}/view.d.ts +22 -4
  20. package/dist/{types/view.cjs → cjs/types/view.js} +1 -1
  21. package/dist/{utils → cjs/utils}/fqn.d.ts +6 -1
  22. package/dist/{utils/fqn.cjs → cjs/utils/fqn.js} +18 -5
  23. package/dist/{utils → cjs/utils}/guards.d.ts +1 -2
  24. package/dist/cjs/utils/guards.js +20 -0
  25. package/dist/{utils → cjs/utils}/index.d.ts +0 -1
  26. package/dist/{utils/index.cjs → cjs/utils/index.js} +3 -14
  27. package/dist/{utils/relations.cjs → cjs/utils/relations.js} +1 -1
  28. package/dist/esm/colors/element.d.ts +68 -0
  29. package/dist/esm/colors/element.js +82 -0
  30. package/dist/esm/colors/index.d.ts +132 -0
  31. package/dist/esm/colors/index.js +9 -0
  32. package/dist/esm/colors/relationships.d.ts +57 -0
  33. package/dist/esm/colors/relationships.js +64 -0
  34. package/dist/esm/errors/index.d.ts +45 -0
  35. package/dist/esm/errors/index.js +97 -0
  36. package/dist/esm/index.d.ts +6 -0
  37. package/dist/esm/index.js +4 -0
  38. package/dist/esm/types/_common.d.ts +3 -0
  39. package/dist/esm/types/computed-view.d.ts +44 -0
  40. package/dist/esm/types/diagram.d.ts +41 -0
  41. package/dist/esm/types/element.d.ts +29 -0
  42. package/dist/esm/types/expression.d.ts +56 -0
  43. package/dist/esm/types/index.d.ts +11 -0
  44. package/dist/esm/types/model.d.ts +14 -0
  45. package/dist/esm/types/opaque.d.ts +102 -0
  46. package/dist/esm/types/relation.d.ts +22 -0
  47. package/dist/esm/types/relation.js +3 -0
  48. package/dist/esm/types/theme.d.ts +26 -0
  49. package/dist/esm/types/view.d.ts +61 -0
  50. package/dist/{types → esm/types}/view.js +1 -1
  51. package/dist/esm/utils/fqn.d.ts +33 -0
  52. package/dist/{utils → esm/utils}/fqn.js +16 -4
  53. package/dist/esm/utils/guards.d.ts +4 -0
  54. package/dist/esm/utils/guards.js +7 -0
  55. package/dist/esm/utils/index.d.ts +3 -0
  56. package/dist/{utils → esm/utils}/index.js +0 -1
  57. package/dist/esm/utils/relations.d.ts +25 -0
  58. package/package.json +44 -61
  59. package/dist/colors.cjs +0 -124
  60. package/dist/colors.d.ts +0 -148
  61. package/dist/compute-view/EdgeBuilder.cjs +0 -37
  62. package/dist/compute-view/EdgeBuilder.d.ts +0 -6
  63. package/dist/compute-view/EdgeBuilder.js +0 -30
  64. package/dist/compute-view/compute-ctx.cjs +0 -89
  65. package/dist/compute-view/compute-ctx.d.ts +0 -19
  66. package/dist/compute-view/compute-ctx.js +0 -98
  67. package/dist/compute-view/compute-element-view.cjs +0 -91
  68. package/dist/compute-view/compute-element-view.d.ts +0 -3
  69. package/dist/compute-view/compute-element-view.js +0 -86
  70. package/dist/compute-view/compute-predicates.cjs +0 -363
  71. package/dist/compute-view/compute-predicates.d.ts +0 -16
  72. package/dist/compute-view/compute-predicates.js +0 -324
  73. package/dist/compute-view/compute.cjs +0 -46
  74. package/dist/compute-view/compute.d.ts +0 -14
  75. package/dist/compute-view/compute.js +0 -36
  76. package/dist/compute-view/index.cjs +0 -38
  77. package/dist/compute-view/index.d.ts +0 -3
  78. package/dist/compute-view/index.js +0 -3
  79. package/dist/compute-view/resolve-extended-views.cjs +0 -50
  80. package/dist/compute-view/resolve-extended-views.d.ts +0 -6
  81. package/dist/compute-view/resolve-extended-views.js +0 -38
  82. package/dist/compute-view/utils/anyPossibleRelations.cjs +0 -18
  83. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -2
  84. package/dist/compute-view/utils/anyPossibleRelations.js +0 -12
  85. package/dist/compute-view/utils/applyViewRuleStyles.cjs +0 -57
  86. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
  87. package/dist/compute-view/utils/applyViewRuleStyles.js +0 -50
  88. package/dist/compute-view/utils/sortNodes.cjs +0 -50
  89. package/dist/compute-view/utils/sortNodes.d.ts +0 -2
  90. package/dist/compute-view/utils/sortNodes.js +0 -40
  91. package/dist/errors/_base.cjs +0 -62
  92. package/dist/errors/_base.d.ts +0 -26
  93. package/dist/errors/_base.js +0 -41
  94. package/dist/errors/index.cjs +0 -60
  95. package/dist/errors/index.d.ts +0 -5
  96. package/dist/errors/index.js +0 -5
  97. package/dist/errors/invariant.cjs +0 -23
  98. package/dist/errors/invariant.d.ts +0 -6
  99. package/dist/errors/invariant.js +0 -13
  100. package/dist/errors/model-index.cjs +0 -23
  101. package/dist/errors/model-index.d.ts +0 -6
  102. package/dist/errors/model-index.js +0 -13
  103. package/dist/errors/non-nullable.cjs +0 -23
  104. package/dist/errors/non-nullable.d.ts +0 -6
  105. package/dist/errors/non-nullable.js +0 -13
  106. package/dist/errors/nonexhaustive.cjs +0 -23
  107. package/dist/errors/nonexhaustive.d.ts +0 -6
  108. package/dist/errors/nonexhaustive.js +0 -12
  109. package/dist/index.js +0 -6
  110. package/dist/model-index/ModelIndex.cjs +0 -140
  111. package/dist/model-index/ModelIndex.d.ts +0 -27
  112. package/dist/model-index/ModelIndex.js +0 -128
  113. package/dist/model-index/index.cjs +0 -13
  114. package/dist/model-index/index.d.ts +0 -1
  115. package/dist/model-index/index.js +0 -1
  116. package/dist/types/relation.d.ts +0 -10
  117. package/dist/types/relation.js +0 -0
  118. package/dist/types/theme.cjs +0 -1
  119. package/dist/utils/compute-node-levels.cjs +0 -48
  120. package/dist/utils/compute-node-levels.d.ts +0 -7
  121. package/dist/utils/compute-node-levels.js +0 -31
  122. package/dist/utils/guards.cjs +0 -22
  123. package/dist/utils/guards.js +0 -13
  124. /package/dist/{types → cjs/types}/_common.d.ts +0 -0
  125. /package/dist/{types/_common.cjs → cjs/types/_common.js} +0 -0
  126. /package/dist/{types/computed-view.cjs → cjs/types/computed-view.js} +0 -0
  127. /package/dist/{types/diagram.cjs → cjs/types/diagram.js} +0 -0
  128. /package/dist/{types → cjs/types}/element.d.ts +0 -0
  129. /package/dist/{types/element.cjs → cjs/types/element.js} +0 -0
  130. /package/dist/{types/expression.cjs → cjs/types/expression.js} +0 -0
  131. /package/dist/{types → cjs/types}/index.d.ts +0 -0
  132. /package/dist/{types → cjs/types}/model.d.ts +0 -0
  133. /package/dist/{types/model.cjs → cjs/types/model.js} +0 -0
  134. /package/dist/{types → cjs/types}/opaque.d.ts +0 -0
  135. /package/dist/{types/opaque.cjs → cjs/types/opaque.js} +0 -0
  136. /package/dist/{types/relation.cjs → cjs/types/theme.js} +0 -0
  137. /package/dist/{utils → cjs/utils}/relations.d.ts +0 -0
  138. /package/dist/{types → esm/types}/_common.js +0 -0
  139. /package/dist/{types → esm/types}/computed-view.js +0 -0
  140. /package/dist/{types → esm/types}/diagram.js +0 -0
  141. /package/dist/{types → esm/types}/element.js +0 -0
  142. /package/dist/{types → esm/types}/expression.js +0 -0
  143. /package/dist/{types → esm/types}/index.js +0 -0
  144. /package/dist/{types → esm/types}/model.js +0 -0
  145. /package/dist/{types → esm/types}/opaque.js +0 -0
  146. /package/dist/{types → esm/types}/theme.js +0 -0
  147. /package/dist/{utils → esm/utils}/relations.js +0 -0
@@ -0,0 +1,82 @@
1
+ const blue = {
2
+ fill: "#3b82f6",
3
+ stroke: "#2563eb",
4
+ hiContrast: "#eff6ff",
5
+ loContrast: "#bfdbfe"
6
+ };
7
+ const sky = {
8
+ fill: "#0284c7",
9
+ stroke: "#0369a1",
10
+ hiContrast: "#f0f9ff",
11
+ loContrast: "#e0f2fe"
12
+ };
13
+ const slate = {
14
+ fill: "#64748b",
15
+ stroke: "#475569",
16
+ hiContrast: "#f8fafc",
17
+ loContrast: "#e2e8f0"
18
+ };
19
+ export const ElementColors = {
20
+ primary: blue,
21
+ blue,
22
+ secondary: sky,
23
+ sky,
24
+ muted: slate,
25
+ slate,
26
+ gray: {
27
+ // fill: colors.neutral[500],
28
+ // stroke: colors.neutral[600],
29
+ // hiContrast: colors.neutral[50],
30
+ // loContrast: colors.neutral[200],
31
+ fill: "#737373",
32
+ stroke: "#525252",
33
+ hiContrast: "#fafafa",
34
+ loContrast: "#e5e5e5"
35
+ },
36
+ red: {
37
+ // fill: colors.red[500],
38
+ // stroke: colors.red[600],
39
+ // hiContrast: colors.red[50],
40
+ // loContrast: colors.red[200],
41
+ fill: "#b54548",
42
+ stroke: "#8c333a",
43
+ // hiContrast: '#fef2f2',
44
+ // loContrast: '#fecaca',
45
+ // hiContrast: '#191111', // colors.gray[900],
46
+ // loContrast: '#3b1219' // colors.gray[800],
47
+ hiContrast: "#f8fafc",
48
+ // hiContrast: '#f8fafc',
49
+ // loContrast: '#fdd8d8' // radix black red 12
50
+ loContrast: "#F9C6C6"
51
+ },
52
+ green: {
53
+ fill: "#428a4f",
54
+ stroke: "#2d5d39",
55
+ hiContrast: "#f8fafc",
56
+ loContrast: "#c2f0c2"
57
+ },
58
+ amber: {
59
+ // fill: colors.amber[600],
60
+ // stroke: colors.amber[700],
61
+ // hiContrast: colors.amber[50],
62
+ // loContrast: colors.amber[200],
63
+ fill: "#d97706",
64
+ stroke: "#b45309",
65
+ // hiContrast: '#fffbeb',
66
+ // loContrast: '#fde68a',
67
+ hiContrast: "#f8fafc",
68
+ // colors.gray[900],
69
+ loContrast: "#ffe0c2"
70
+ // colors.gray[800],
71
+ },
72
+ indigo: {
73
+ // fill: colors.indigo[500],
74
+ // stroke: colors.indigo[600],
75
+ // hiContrast: colors.indigo[50],
76
+ // loContrast: colors.indigo[200],
77
+ fill: "#6366f1",
78
+ stroke: "#4f46e5",
79
+ hiContrast: "#eef2ff",
80
+ loContrast: "#c7d2fe"
81
+ }
82
+ };
@@ -0,0 +1,132 @@
1
+ import { ElementColors } from './element';
2
+ import { RelationshipColors } from './relationships';
3
+ export declare const defaultTheme: {
4
+ elements: {
5
+ readonly primary: {
6
+ fill: "#3b82f6";
7
+ stroke: "#2563eb";
8
+ hiContrast: "#eff6ff";
9
+ loContrast: "#bfdbfe";
10
+ };
11
+ readonly blue: {
12
+ fill: "#3b82f6";
13
+ stroke: "#2563eb";
14
+ hiContrast: "#eff6ff";
15
+ loContrast: "#bfdbfe";
16
+ };
17
+ readonly secondary: {
18
+ fill: "#0284c7";
19
+ stroke: "#0369a1";
20
+ hiContrast: "#f0f9ff";
21
+ loContrast: "#e0f2fe";
22
+ };
23
+ readonly sky: {
24
+ fill: "#0284c7";
25
+ stroke: "#0369a1";
26
+ hiContrast: "#f0f9ff";
27
+ loContrast: "#e0f2fe";
28
+ };
29
+ readonly muted: {
30
+ fill: "#64748b";
31
+ stroke: "#475569";
32
+ hiContrast: "#f8fafc";
33
+ loContrast: "#e2e8f0";
34
+ };
35
+ readonly slate: {
36
+ fill: "#64748b";
37
+ stroke: "#475569";
38
+ hiContrast: "#f8fafc";
39
+ loContrast: "#e2e8f0";
40
+ };
41
+ readonly gray: {
42
+ readonly fill: "#737373";
43
+ readonly stroke: "#525252";
44
+ readonly hiContrast: "#fafafa";
45
+ readonly loContrast: "#e5e5e5";
46
+ };
47
+ readonly red: {
48
+ readonly fill: "#b54548";
49
+ readonly stroke: "#8c333a";
50
+ readonly hiContrast: "#f8fafc";
51
+ readonly loContrast: "#F9C6C6";
52
+ };
53
+ readonly green: {
54
+ readonly fill: "#428a4f";
55
+ readonly stroke: "#2d5d39";
56
+ readonly hiContrast: "#f8fafc";
57
+ readonly loContrast: "#c2f0c2";
58
+ };
59
+ readonly amber: {
60
+ readonly fill: "#d97706";
61
+ readonly stroke: "#b45309";
62
+ readonly hiContrast: "#f8fafc";
63
+ readonly loContrast: "#ffe0c2";
64
+ };
65
+ readonly indigo: {
66
+ readonly fill: "#6366f1";
67
+ readonly stroke: "#4f46e5";
68
+ readonly hiContrast: "#eef2ff";
69
+ readonly loContrast: "#c7d2fe";
70
+ };
71
+ };
72
+ relationships: {
73
+ amber: {
74
+ lineColor: "#b45309";
75
+ labelBgColor: "#78350f";
76
+ labelColor: "#f59e0b";
77
+ };
78
+ blue: {
79
+ lineColor: "#3b82f6";
80
+ labelBgColor: "#172554";
81
+ labelColor: "#60a5fa";
82
+ };
83
+ gray: {
84
+ lineColor: "#6E6E6E";
85
+ labelBgColor: "#18191b";
86
+ labelColor: "#C6C6C6";
87
+ };
88
+ green: {
89
+ lineColor: "#15803d";
90
+ labelBgColor: "#052e16";
91
+ labelColor: "#22c55e";
92
+ };
93
+ indigo: {
94
+ lineColor: "#6366f1";
95
+ labelBgColor: "#1e1b4b";
96
+ labelColor: "#818cf8";
97
+ };
98
+ muted: {
99
+ lineColor: "#64748b";
100
+ labelBgColor: "#0f172a";
101
+ labelColor: "#cbd5e1";
102
+ };
103
+ primary: {
104
+ lineColor: "#3b82f6";
105
+ labelBgColor: "#172554";
106
+ labelColor: "#60a5fa";
107
+ };
108
+ red: {
109
+ lineColor: "#b91c1c";
110
+ labelBgColor: "#b91c1c";
111
+ labelColor: "#dc2626";
112
+ };
113
+ secondary: {
114
+ lineColor: "#0ea5e9";
115
+ labelBgColor: "#082f49";
116
+ labelColor: "#38bdf8";
117
+ };
118
+ sky: {
119
+ lineColor: "#0ea5e9";
120
+ labelBgColor: "#082f49";
121
+ labelColor: "#38bdf8";
122
+ };
123
+ slate: {
124
+ lineColor: "#64748b";
125
+ labelBgColor: "#0f172a";
126
+ labelColor: "#cbd5e1";
127
+ };
128
+ };
129
+ font: "Helvetica";
130
+ shadow: "#0a0a0a";
131
+ };
132
+ export { ElementColors, RelationshipColors };
@@ -0,0 +1,9 @@
1
+ import { ElementColors } from "./element.js";
2
+ import { RelationshipColors } from "./relationships.js";
3
+ export const defaultTheme = {
4
+ elements: ElementColors,
5
+ relationships: RelationshipColors,
6
+ font: "Helvetica",
7
+ shadow: "#0a0a0a"
8
+ };
9
+ export { ElementColors, RelationshipColors };
@@ -0,0 +1,57 @@
1
+ export declare const RelationshipColors: {
2
+ amber: {
3
+ lineColor: "#b45309";
4
+ labelBgColor: "#78350f";
5
+ labelColor: "#f59e0b";
6
+ };
7
+ blue: {
8
+ lineColor: "#3b82f6";
9
+ labelBgColor: "#172554";
10
+ labelColor: "#60a5fa";
11
+ };
12
+ gray: {
13
+ lineColor: "#6E6E6E";
14
+ labelBgColor: "#18191b";
15
+ labelColor: "#C6C6C6";
16
+ };
17
+ green: {
18
+ lineColor: "#15803d";
19
+ labelBgColor: "#052e16";
20
+ labelColor: "#22c55e";
21
+ };
22
+ indigo: {
23
+ lineColor: "#6366f1";
24
+ labelBgColor: "#1e1b4b";
25
+ labelColor: "#818cf8";
26
+ };
27
+ muted: {
28
+ lineColor: "#64748b";
29
+ labelBgColor: "#0f172a";
30
+ labelColor: "#cbd5e1";
31
+ };
32
+ primary: {
33
+ lineColor: "#3b82f6";
34
+ labelBgColor: "#172554";
35
+ labelColor: "#60a5fa";
36
+ };
37
+ red: {
38
+ lineColor: "#b91c1c";
39
+ labelBgColor: "#b91c1c";
40
+ labelColor: "#dc2626";
41
+ };
42
+ secondary: {
43
+ lineColor: "#0ea5e9";
44
+ labelBgColor: "#082f49";
45
+ labelColor: "#38bdf8";
46
+ };
47
+ sky: {
48
+ lineColor: "#0ea5e9";
49
+ labelBgColor: "#082f49";
50
+ labelColor: "#38bdf8";
51
+ };
52
+ slate: {
53
+ lineColor: "#64748b";
54
+ labelBgColor: "#0f172a";
55
+ labelColor: "#cbd5e1";
56
+ };
57
+ };
@@ -0,0 +1,64 @@
1
+ const gray = {
2
+ lineColor: "#6E6E6E",
3
+ labelBgColor: "#18191b",
4
+ labelColor: "#C6C6C6"
5
+ };
6
+ const slate = {
7
+ lineColor: "#64748b",
8
+ // 500
9
+ labelBgColor: "#0f172a",
10
+ // 900
11
+ labelColor: "#cbd5e1"
12
+ // 300
13
+ };
14
+ const blue = {
15
+ lineColor: "#3b82f6",
16
+ // 500
17
+ labelBgColor: "#172554",
18
+ // 950
19
+ labelColor: "#60a5fa"
20
+ // 400
21
+ };
22
+ const sky = {
23
+ lineColor: "#0ea5e9",
24
+ // 500
25
+ labelBgColor: "#082f49",
26
+ // 950
27
+ labelColor: "#38bdf8"
28
+ // 400
29
+ };
30
+ export const RelationshipColors = {
31
+ amber: {
32
+ lineColor: "#b45309",
33
+ labelBgColor: "#78350f",
34
+ labelColor: "#f59e0b"
35
+ },
36
+ blue,
37
+ gray,
38
+ green: {
39
+ lineColor: "#15803d",
40
+ // 700
41
+ labelBgColor: "#052e16",
42
+ //950
43
+ labelColor: "#22c55e"
44
+ // 500
45
+ },
46
+ indigo: {
47
+ lineColor: "#6366f1",
48
+ // 500
49
+ labelBgColor: "#1e1b4b",
50
+ // 950
51
+ labelColor: "#818cf8"
52
+ // 400
53
+ },
54
+ muted: slate,
55
+ primary: blue,
56
+ red: {
57
+ lineColor: "#b91c1c",
58
+ labelBgColor: "#b91c1c",
59
+ labelColor: "#dc2626"
60
+ },
61
+ secondary: sky,
62
+ sky,
63
+ slate
64
+ };
@@ -0,0 +1,45 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export interface BaseErrorOptions {
3
+ cause?: unknown;
4
+ }
5
+ /**
6
+ * Base class for all errors in the LikeC4 library.
7
+ */
8
+ export declare class BaseError extends CustomError {
9
+ constructor(message: string, options?: BaseErrorOptions);
10
+ }
11
+ export declare class InvalidArgError extends BaseError {
12
+ constructor(message: string, options?: BaseErrorOptions);
13
+ }
14
+ /**
15
+ * Unknown error, mosly probably a bug, unhandled case or coming from a third-party library.
16
+ */
17
+ export declare class UnknownError extends BaseError {
18
+ constructor(message: string, options?: BaseErrorOptions);
19
+ }
20
+ export declare class NullableError extends BaseError {
21
+ constructor(message: string, options?: BaseErrorOptions);
22
+ }
23
+ export declare class InvariantError extends BaseError {
24
+ constructor(message: string, options?: BaseErrorOptions);
25
+ }
26
+ export declare function nonNullable<T>(value: T, message?: string): T & {};
27
+ export declare class RelationRefError extends BaseError {
28
+ constructor(message: string, options?: BaseErrorOptions);
29
+ }
30
+ export declare function normalizeError(e: unknown): BaseError;
31
+ export declare function serializeError(e: unknown): {
32
+ name: string;
33
+ message: string;
34
+ error: BaseError;
35
+ };
36
+ export declare function throwNormalizedError(e: unknown): never;
37
+ export declare function invariant(condition: any, message?: string): asserts condition;
38
+ export declare class NonExhaustiveError extends BaseError {
39
+ constructor(message: string, options?: BaseErrorOptions);
40
+ }
41
+ export declare function nonexhaustive(value: never): never;
42
+ export declare class InvalidModelError extends BaseError {
43
+ constructor(message: string, options?: BaseErrorOptions);
44
+ }
45
+ export declare function ensureModel(condition: any, message?: string): asserts condition;
@@ -0,0 +1,97 @@
1
+ import stringify from "safe-stable-stringify";
2
+ import { CustomError } from "ts-custom-error";
3
+ import { isString } from "../utils/guards.js";
4
+ export class BaseError extends CustomError {
5
+ constructor(message, options) {
6
+ super(message, options);
7
+ Object.defineProperty(this, "name", { value: "BaseError" });
8
+ }
9
+ }
10
+ export class InvalidArgError extends BaseError {
11
+ constructor(message, options) {
12
+ super(message, options);
13
+ Object.defineProperty(this, "name", { value: "InvalidArgError" });
14
+ }
15
+ }
16
+ export class UnknownError extends BaseError {
17
+ constructor(message, options) {
18
+ super(message, options);
19
+ Object.defineProperty(this, "name", { value: "UnknownError" });
20
+ }
21
+ }
22
+ export class NullableError extends BaseError {
23
+ constructor(message, options) {
24
+ super(message, options);
25
+ Object.defineProperty(this, "name", { value: "NullableError" });
26
+ }
27
+ }
28
+ export class InvariantError extends BaseError {
29
+ constructor(message, options) {
30
+ super(message, options);
31
+ Object.defineProperty(this, "name", { value: "InvariantError" });
32
+ }
33
+ }
34
+ export function nonNullable(value, message) {
35
+ if (typeof value === "undefined" || value == null) {
36
+ throw new NullableError(message ?? `Expected defined value, but received ${value}`);
37
+ }
38
+ return value;
39
+ }
40
+ export class RelationRefError extends BaseError {
41
+ constructor(message, options) {
42
+ super(message, options);
43
+ Object.defineProperty(this, "name", { value: "RelationRefError" });
44
+ }
45
+ }
46
+ export function normalizeError(e) {
47
+ if (e instanceof BaseError) {
48
+ return e;
49
+ }
50
+ if (e instanceof Error) {
51
+ return new UnknownError(e.message, { cause: e });
52
+ }
53
+ if (e === null || e === void 0) {
54
+ return new UnknownError("Undefined error");
55
+ }
56
+ const message = isString(e) ? e : stringify(e);
57
+ return new UnknownError(message);
58
+ }
59
+ export function serializeError(e) {
60
+ const error = normalizeError(e);
61
+ return {
62
+ name: error.name,
63
+ message: error.stack ? error.stack : `${error.name}: ${error.message}`,
64
+ error
65
+ };
66
+ }
67
+ export function throwNormalizedError(e) {
68
+ throw normalizeError(e);
69
+ }
70
+ export function invariant(condition, message) {
71
+ if (condition) {
72
+ return;
73
+ }
74
+ throw new InvariantError(message ?? "Invariant failed");
75
+ }
76
+ export class NonExhaustiveError extends BaseError {
77
+ constructor(message, options) {
78
+ super(message, options);
79
+ Object.defineProperty(this, "name", { value: "NonExhaustiveError" });
80
+ }
81
+ }
82
+ export function nonexhaustive(value) {
83
+ const val = typeof value === "string" ? value : stringify(value);
84
+ throw new NonExhaustiveError(`NonExhaustive value: ${val}`);
85
+ }
86
+ export class InvalidModelError extends BaseError {
87
+ constructor(message, options) {
88
+ super(message, options);
89
+ Object.defineProperty(this, "name", { value: "InvalidModelError" });
90
+ }
91
+ }
92
+ export function ensureModel(condition, message) {
93
+ if (condition) {
94
+ return;
95
+ }
96
+ throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
97
+ }
@@ -0,0 +1,6 @@
1
+ export * from './colors';
2
+ export * from './errors';
3
+ export * from './types';
4
+ export * from './utils';
5
+ export type * as likec4 from './types';
6
+ export type * as c4 from './types';
@@ -0,0 +1,4 @@
1
+ export * from "./colors/index.js";
2
+ export * from "./errors/index.js";
3
+ export * from "./types/index.js";
4
+ export * from "./utils/index.js";
@@ -0,0 +1,3 @@
1
+ import type { Opaque } from './opaque';
2
+ export type NonEmptyArray<T> = [T, ...T[]];
3
+ export type IconUrl = Opaque<string, 'IconUrl'>;
@@ -0,0 +1,44 @@
1
+ import type { Opaque } from './opaque';
2
+ import type { ElementKind, ElementShape, Fqn, Tag } from './element';
3
+ import type { RelationID, RelationshipArrowType, RelationshipLineType } from './relation';
4
+ import type { BasicElementView, ViewID, ViewRuleAutoLayout } from './view';
5
+ import type { IconUrl, NonEmptyArray } from './_common';
6
+ import type { ThemeColor } from './theme';
7
+ export type NodeId = Fqn;
8
+ export type EdgeId = Opaque<string, 'EdgeId'>;
9
+ export interface ComputedNode {
10
+ id: NodeId;
11
+ kind: ElementKind;
12
+ parent: NodeId | null;
13
+ title: string;
14
+ description: string | null;
15
+ technology: string | null;
16
+ tags: NonEmptyArray<Tag> | null;
17
+ links: NonEmptyArray<string> | null;
18
+ children: NodeId[];
19
+ inEdges: EdgeId[];
20
+ outEdges: EdgeId[];
21
+ shape: ElementShape;
22
+ color: ThemeColor;
23
+ icon?: IconUrl;
24
+ navigateTo?: ViewID;
25
+ level: number;
26
+ }
27
+ export interface ComputedEdge {
28
+ id: EdgeId;
29
+ parent: NodeId | null;
30
+ source: NodeId;
31
+ target: NodeId;
32
+ label: string | null;
33
+ relations: RelationID[];
34
+ color?: ThemeColor;
35
+ line?: RelationshipLineType;
36
+ head?: RelationshipArrowType;
37
+ tail?: RelationshipArrowType;
38
+ }
39
+ export interface ComputedView extends Omit<BasicElementView, 'rules'> {
40
+ readonly extends?: ViewID;
41
+ readonly autoLayout: ViewRuleAutoLayout['autoLayout'];
42
+ readonly nodes: ComputedNode[];
43
+ readonly edges: ComputedEdge[];
44
+ }
@@ -0,0 +1,41 @@
1
+ import type { ColorLiteral } from './theme';
2
+ import type { ComputedEdge, ComputedNode, ComputedView } from './computed-view';
3
+ import type { NonEmptyArray } from './_common';
4
+ export type Point = [x: number, y: number];
5
+ export type BBox = {
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ };
11
+ export interface DiagramLabel {
12
+ align: 'left' | 'right' | 'center';
13
+ fontStyle?: 'bold' | 'normal';
14
+ color?: ColorLiteral;
15
+ fontSize: number;
16
+ pt: Point;
17
+ width: number;
18
+ text: string;
19
+ }
20
+ export interface DiagramNode extends ComputedNode {
21
+ size: {
22
+ width: number;
23
+ height: number;
24
+ };
25
+ labels: DiagramLabel[];
26
+ position: Point;
27
+ depth?: number;
28
+ }
29
+ export interface DiagramEdge extends ComputedEdge {
30
+ points: NonEmptyArray<Point>;
31
+ headArrow?: NonEmptyArray<Point>;
32
+ tailArrow?: NonEmptyArray<Point>;
33
+ labels?: NonEmptyArray<DiagramLabel>;
34
+ labelBBox?: BBox;
35
+ }
36
+ export interface DiagramView extends Omit<ComputedView, 'nodes' | 'edges'> {
37
+ readonly nodes: DiagramNode[];
38
+ readonly edges: DiagramEdge[];
39
+ readonly width: number;
40
+ readonly height: number;
41
+ }
@@ -0,0 +1,29 @@
1
+ import type { IconUrl, NonEmptyArray } from './_common';
2
+ import type { Opaque } from './opaque';
3
+ import type { ThemeColor } from './theme';
4
+ export type Fqn = Opaque<string, 'Fqn'>;
5
+ export declare function AsFqn(name: string, parent?: Fqn | null): Fqn;
6
+ export type ElementKind = Opaque<string, 'ElementKind'>;
7
+ export type ElementShape = 'rectangle' | 'person' | 'browser' | 'mobile' | 'cylinder' | 'storage' | 'queue';
8
+ export declare const DefaultThemeColor = "primary";
9
+ export declare const DefaultElementShape = "rectangle";
10
+ export interface ElementStyle {
11
+ shape?: ElementShape;
12
+ }
13
+ export type Tag = Opaque<string, 'Tag'>;
14
+ export interface TagSpec {
15
+ readonly id: Tag;
16
+ readonly style: ElementStyle;
17
+ }
18
+ export interface Element {
19
+ readonly id: Fqn;
20
+ readonly kind: ElementKind;
21
+ readonly title: string;
22
+ readonly description: string | null;
23
+ readonly technology: string | null;
24
+ readonly tags: NonEmptyArray<Tag> | null;
25
+ readonly links: NonEmptyArray<string> | null;
26
+ readonly icon?: IconUrl;
27
+ readonly shape?: ElementShape;
28
+ readonly color?: ThemeColor;
29
+ }
@@ -0,0 +1,56 @@
1
+ import type { ElementKind, Fqn, Tag } from './element';
2
+ interface BaseExpr {
3
+ element?: never;
4
+ elementKind?: never;
5
+ elementTag?: never;
6
+ isEqual?: never;
7
+ isDescedants?: never;
8
+ wildcard?: never;
9
+ source?: never;
10
+ target?: never;
11
+ inout?: never;
12
+ incoming?: never;
13
+ outgoing?: never;
14
+ }
15
+ export interface ElementRefExpr extends Omit<BaseExpr, 'element' | 'isDescedants'> {
16
+ element: Fqn;
17
+ isDescedants?: boolean;
18
+ }
19
+ export declare function isElementRef(expr: Expression): expr is ElementRefExpr;
20
+ export interface WildcardExpr extends Omit<BaseExpr, 'wildcard'> {
21
+ wildcard: true;
22
+ }
23
+ export declare function isWildcard(expr: Expression): expr is WildcardExpr;
24
+ export interface ElementKindExpr extends Omit<BaseExpr, 'elementKind' | 'isEqual'> {
25
+ elementKind: ElementKind;
26
+ isEqual: boolean;
27
+ }
28
+ export declare function isElementKindExpr(expr: Expression): expr is ElementKindExpr;
29
+ export interface ElementTagExpr extends Omit<BaseExpr, 'elementTag' | 'isEqual'> {
30
+ elementTag: Tag;
31
+ isEqual: boolean;
32
+ }
33
+ export declare function isElementTagExpr(expr: Expression): expr is ElementTagExpr;
34
+ export type ElementExpression = ElementRefExpr | WildcardExpr | ElementKindExpr | ElementTagExpr;
35
+ export declare function isElement(expr: Expression): expr is ElementExpression;
36
+ export interface RelationExpr extends Omit<BaseExpr, 'source' | 'target'> {
37
+ source: ElementExpression;
38
+ target: ElementExpression;
39
+ }
40
+ export declare function isRelation(expr: Expression): expr is RelationExpr;
41
+ export interface InOutExpr extends Omit<BaseExpr, 'inout'> {
42
+ inout: ElementExpression;
43
+ }
44
+ export declare function isInOut(expr: Expression): expr is InOutExpr;
45
+ export interface IncomingExpr extends Omit<BaseExpr, 'incoming'> {
46
+ incoming: ElementExpression;
47
+ }
48
+ export declare function isIncoming(expr: Expression): expr is IncomingExpr;
49
+ export interface OutgoingExpr extends Omit<BaseExpr, 'outgoing'> {
50
+ outgoing: ElementExpression;
51
+ }
52
+ export declare function isOutgoing(expr: Expression): expr is OutgoingExpr;
53
+ export type AnyRelationExpression = RelationExpr | InOutExpr | IncomingExpr | OutgoingExpr;
54
+ export declare function isAnyRelation(expr: Expression): expr is AnyRelationExpression;
55
+ export type Expression = ElementExpression | AnyRelationExpression;
56
+ export {};