@likec4/core 1.41.0 → 1.42.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 (255) hide show
  1. package/builder/package.json +4 -0
  2. package/compute-view/package.json +4 -0
  3. package/compute-view/relationships/package.json +4 -0
  4. package/dist/builder/index.d.mts +13 -11
  5. package/dist/builder/index.mjs +111 -91
  6. package/dist/compute-view/index.d.mts +8 -7
  7. package/dist/compute-view/index.mjs +14 -11
  8. package/dist/compute-view/relationships-view/index.d.mts +9 -8
  9. package/dist/compute-view/relationships-view/index.mjs +6 -6
  10. package/dist/index.d.mts +7 -7
  11. package/dist/index.mjs +11 -11
  12. package/dist/model/connection/deployment/index.d.mts +11 -10
  13. package/dist/model/connection/deployment/index.mjs +2 -2
  14. package/dist/model/connection/index.d.mts +12 -11
  15. package/dist/model/connection/index.mjs +3 -3
  16. package/dist/model/connection/model/index.d.mts +11 -10
  17. package/dist/model/connection/model/index.mjs +2 -2
  18. package/dist/model/index.d.mts +14 -14
  19. package/dist/model/index.mjs +4 -5
  20. package/dist/shared/{core.Ae86Y3tB.mjs → core.01VTr9qu.mjs} +8 -26
  21. package/dist/shared/core.1vX5a9AY.mjs +86 -0
  22. package/dist/shared/{core.BVNaR17u.mjs → core.B7KhhkRY.mjs} +1 -1
  23. package/dist/shared/core.B85MJLTf.mjs +5 -0
  24. package/dist/shared/{core.DA5vzwZ9.mjs → core.BIqHjQiH.mjs} +56 -42
  25. package/dist/shared/core.BKlholso.mjs +3 -0
  26. package/dist/shared/core.BR4zXDH-.mjs +13 -0
  27. package/dist/shared/{core.CXy1NLUG.mjs → core.BYNkXQ8A.mjs} +21 -12
  28. package/dist/shared/{core.BuoXfSMj.mjs → core.BbE4y-yl.mjs} +1 -1
  29. package/dist/shared/core.BoYfZOBm.mjs +3 -0
  30. package/dist/shared/core.BsSXS-_R.mjs +7 -0
  31. package/dist/shared/{core.DJp8fgok.mjs → core.BzTakU3I.mjs} +14 -10
  32. package/dist/shared/{core.4u1dVmfX.mjs → core.C2TiyjI6.mjs} +2 -2
  33. package/dist/shared/{core.DLpidoWc.mjs → core.C3JowhaZ.mjs} +3 -3
  34. package/dist/shared/{core.CNGyqkJh.mjs → core.C4x8aaWa.mjs} +3 -1
  35. package/dist/shared/{core.BB6zA-UU.mjs → core.C8YY6Uub.mjs} +38 -9
  36. package/dist/shared/{core.Asc11Mjy.mjs → core.C8sl5Y8Z.mjs} +122 -58
  37. package/dist/shared/{core.BvMRMo7Z.mjs → core.CNgZvKb8.mjs} +3 -5198
  38. package/dist/shared/{core.CUG6vpyL.d.mts → core.CQngdcuj.d.mts} +85 -4
  39. package/dist/shared/{core.Be1n9a0i.mjs → core.C_Ni6yHl.mjs} +5 -4
  40. package/dist/shared/core.CbT8JVYL.mjs +5 -0
  41. package/dist/shared/core.CqAJJpK_.mjs +3 -0
  42. package/dist/shared/{core.BXsxn-hf.d.mts → core.D0PjZzIS.d.mts} +27 -15
  43. package/dist/shared/{core.DgesAwC8.d.mts → core.D5fzJWbF.d.mts} +2 -2
  44. package/dist/shared/{core.hfOE3RfK.d.mts → core.DACpKp35.d.mts} +5 -5
  45. package/dist/shared/core.DFi2dOTl.mjs +39548 -0
  46. package/dist/shared/{core.xSQO0XYD.d.mts → core.DIol3syK.d.mts} +2 -2
  47. package/dist/shared/{core.DlG1xWt2.mjs → core.DMMOWQqc.mjs} +3 -2
  48. package/dist/shared/core.DNbUPnve.mjs +3990 -0
  49. package/dist/shared/{core.CCD1ID81.mjs → core.DRJma0Ol.mjs} +4 -3
  50. package/dist/shared/{core.DgttqsJc.mjs → core.DRhg-gVU.mjs} +9 -9
  51. package/dist/shared/core.DSO_rTC2.mjs +5322 -0
  52. package/dist/shared/{core.FUPplpae.d.mts → core.D_vkffV4.d.mts} +4 -2
  53. package/dist/shared/core.DdMJk7nx.d.mts +476 -0
  54. package/dist/shared/{core.BhpgpOep.d.mts → core.Dgs6-nuz.d.mts} +2 -2
  55. package/dist/shared/{core.Be4Jy9Qx.mjs → core.FZ305VYd.mjs} +2 -2
  56. package/dist/shared/core.OHD4KXm9.mjs +5 -0
  57. package/dist/shared/{core.GTgsmXS_.mjs → core.QJD_fcrc.mjs} +2 -2
  58. package/dist/shared/core.RfnaEmgA.mjs +7 -0
  59. package/dist/shared/core.fHR_8Tnq.d.mts +450 -0
  60. package/dist/shared/{core.D0EgVMQK.mjs → core.lRvxPoao.mjs} +14 -12
  61. package/dist/shared/{core.CaT0SUUK.mjs → core.rCeaAqgW.mjs} +1 -84
  62. package/dist/shared/{core.zxTBF_PD.d.mts → core.s9uwOt60.d.mts} +4 -4
  63. package/dist/shared/core.yna0OdV5.d.mts +98 -0
  64. package/dist/styles/index.d.mts +106 -0
  65. package/dist/styles/index.mjs +1 -0
  66. package/dist/types/_aux.d.mts +2 -2
  67. package/dist/types/expression-model.d.mts +3 -4
  68. package/dist/types/expression.d.mts +3 -4
  69. package/dist/types/fqnRef.d.mts +2 -2
  70. package/dist/types/fqnRef.mjs +3 -3
  71. package/dist/types/index.d.mts +8 -8
  72. package/dist/types/index.mjs +150 -5
  73. package/dist/types/scalar.mjs +3 -2
  74. package/dist/utils/graphology/index.d.mts +1864 -0
  75. package/dist/utils/graphology/index.mjs +1 -0
  76. package/dist/utils/index.d.mts +11 -6
  77. package/dist/utils/index.mjs +21 -37
  78. package/dist/utils/iterable/index.d.mts +1 -1
  79. package/dist/utils/iterable/index.mjs +45 -7
  80. package/model/package.json +4 -0
  81. package/package.json +42 -24
  82. package/styles/package.json +4 -0
  83. package/types/package.json +4 -0
  84. package/utils/graphology/package.json +4 -0
  85. package/utils/package.json +4 -0
  86. package/dist/shared/core.6_Vp2iiN.mjs +0 -172
  87. package/dist/shared/core.CUw_2J9j.mjs +0 -47
  88. package/dist/shared/core.CzdwsPmY.d.mts +0 -69
  89. package/dist/shared/core.D-ZGWDDt.d.mts +0 -831
  90. package/dist/shared/core.DoM6aM9N.mjs +0 -7
  91. package/dist/shared/core.ILwny7BV.mjs +0 -38
  92. package/dist/theme/index.d.mts +0 -11
  93. package/dist/theme/index.mjs +0 -232
  94. package/src/builder/Builder.deployment.ts +0 -224
  95. package/src/builder/Builder.deploymentModel.ts +0 -449
  96. package/src/builder/Builder.element.ts +0 -241
  97. package/src/builder/Builder.model.ts +0 -494
  98. package/src/builder/Builder.ts +0 -946
  99. package/src/builder/Builder.view-common.ts +0 -273
  100. package/src/builder/Builder.view-deployment.ts +0 -135
  101. package/src/builder/Builder.view-element.ts +0 -202
  102. package/src/builder/Builder.views.ts +0 -399
  103. package/src/builder/Builder.with.ts +0 -156
  104. package/src/builder/_types.ts +0 -324
  105. package/src/builder/index.ts +0 -11
  106. package/src/compute-view/compute-view.ts +0 -80
  107. package/src/compute-view/deployment-view/_types.ts +0 -38
  108. package/src/compute-view/deployment-view/clean-connections.ts +0 -236
  109. package/src/compute-view/deployment-view/compute.ts +0 -94
  110. package/src/compute-view/deployment-view/memory/index.ts +0 -9
  111. package/src/compute-view/deployment-view/memory/memory.ts +0 -96
  112. package/src/compute-view/deployment-view/predicates/deploymentRefs-where.ts +0 -18
  113. package/src/compute-view/deployment-view/predicates/deploymentRefs.ts +0 -154
  114. package/src/compute-view/deployment-view/predicates/index.ts +0 -8
  115. package/src/compute-view/deployment-view/predicates/relation-direct.ts +0 -243
  116. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +0 -70
  117. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +0 -101
  118. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +0 -95
  119. package/src/compute-view/deployment-view/predicates/relation-where.ts +0 -18
  120. package/src/compute-view/deployment-view/predicates/utils.ts +0 -282
  121. package/src/compute-view/deployment-view/predicates/wildcard.ts +0 -41
  122. package/src/compute-view/deployment-view/stages/stage-exclude.ts +0 -5
  123. package/src/compute-view/deployment-view/stages/stage-final.ts +0 -245
  124. package/src/compute-view/deployment-view/stages/stage-include.ts +0 -95
  125. package/src/compute-view/deployment-view/utils.ts +0 -297
  126. package/src/compute-view/dynamic-view/compute.ts +0 -312
  127. package/src/compute-view/element-view/_types.ts +0 -47
  128. package/src/compute-view/element-view/clean-connections.ts +0 -117
  129. package/src/compute-view/element-view/compute.ts +0 -324
  130. package/src/compute-view/element-view/memory/NodeGroup.ts +0 -31
  131. package/src/compute-view/element-view/memory/index.ts +0 -10
  132. package/src/compute-view/element-view/memory/memory.ts +0 -178
  133. package/src/compute-view/element-view/memory/stage-exclude.ts +0 -59
  134. package/src/compute-view/element-view/memory/stage-final.ts +0 -129
  135. package/src/compute-view/element-view/memory/stage-include.ts +0 -130
  136. package/src/compute-view/element-view/predicates/_utils.ts +0 -91
  137. package/src/compute-view/element-view/predicates/element-expand.ts +0 -29
  138. package/src/compute-view/element-view/predicates/element-kind-tag.ts +0 -27
  139. package/src/compute-view/element-view/predicates/element-ref.ts +0 -24
  140. package/src/compute-view/element-view/predicates/relation-direct.ts +0 -321
  141. package/src/compute-view/element-view/predicates/relation-in-out.ts +0 -64
  142. package/src/compute-view/element-view/predicates/relation-in.ts +0 -115
  143. package/src/compute-view/element-view/predicates/relation-out.ts +0 -119
  144. package/src/compute-view/element-view/predicates/wildcard.ts +0 -88
  145. package/src/compute-view/element-view/utils.ts +0 -65
  146. package/src/compute-view/index.ts +0 -4
  147. package/src/compute-view/memory/AbstractMemory.ts +0 -45
  148. package/src/compute-view/memory/AbstractStageExclude.ts +0 -215
  149. package/src/compute-view/memory/AbstractStageInclude.ts +0 -200
  150. package/src/compute-view/memory/_types.ts +0 -148
  151. package/src/compute-view/memory/index.ts +0 -5
  152. package/src/compute-view/memory/ops.ts +0 -43
  153. package/src/compute-view/relationships-view/_types.ts +0 -16
  154. package/src/compute-view/relationships-view/compute.ts +0 -159
  155. package/src/compute-view/relationships-view/index.ts +0 -3
  156. package/src/compute-view/relationships-view/layout.ts +0 -358
  157. package/src/compute-view/relationships-view/utils.ts +0 -73
  158. package/src/compute-view/utils/ancestorsOfNode.ts +0 -19
  159. package/src/compute-view/utils/applyCustomElementProperties.ts +0 -107
  160. package/src/compute-view/utils/applyCustomRelationProperties.ts +0 -58
  161. package/src/compute-view/utils/applyViewRuleStyles.ts +0 -73
  162. package/src/compute-view/utils/buildComputedNodes.ts +0 -166
  163. package/src/compute-view/utils/buildElementNotations.ts +0 -64
  164. package/src/compute-view/utils/elementExpressionToPredicate.ts +0 -50
  165. package/src/compute-view/utils/link-nodes-with-edges.ts +0 -56
  166. package/src/compute-view/utils/merge-props-from-relationships.ts +0 -161
  167. package/src/compute-view/utils/relationExpressionToPredicates.ts +0 -55
  168. package/src/compute-view/utils/resolve-extended-views.ts +0 -85
  169. package/src/compute-view/utils/resolve-global-rules.ts +0 -88
  170. package/src/compute-view/utils/topological-sort.ts +0 -256
  171. package/src/compute-view/utils/view-hash.ts +0 -45
  172. package/src/compute-view/utils/with-readable-edges.ts +0 -40
  173. package/src/index.ts +0 -32
  174. package/src/model/DeploymentElementModel.ts +0 -712
  175. package/src/model/DeploymentModel.ts +0 -393
  176. package/src/model/ElementModel.ts +0 -316
  177. package/src/model/LikeC4Model.ts +0 -882
  178. package/src/model/RelationModel.ts +0 -152
  179. package/src/model/connection/Connection.ts +0 -72
  180. package/src/model/connection/deployment/DeploymentConnectionModel.ts +0 -185
  181. package/src/model/connection/deployment/find.ts +0 -120
  182. package/src/model/connection/deployment/index.ts +0 -8
  183. package/src/model/connection/index.ts +0 -22
  184. package/src/model/connection/model/ConnectionModel.ts +0 -158
  185. package/src/model/connection/model/find.ts +0 -117
  186. package/src/model/connection/model/index.ts +0 -8
  187. package/src/model/connection/ops.ts +0 -276
  188. package/src/model/guards.ts +0 -77
  189. package/src/model/index.ts +0 -72
  190. package/src/model/types.ts +0 -67
  191. package/src/model/utils.ts +0 -66
  192. package/src/model/view/EdgeModel.ts +0 -121
  193. package/src/model/view/LikeC4ViewModel.ts +0 -361
  194. package/src/model/view/LikeC4ViewsFolder.ts +0 -151
  195. package/src/model/view/NodeModel.ts +0 -247
  196. package/src/theme/element.ts +0 -61
  197. package/src/theme/index.ts +0 -127
  198. package/src/theme/relationships.ts +0 -54
  199. package/src/types/RichText.ts +0 -205
  200. package/src/types/_aux.ts +0 -317
  201. package/src/types/_common.ts +0 -102
  202. package/src/types/const.ts +0 -34
  203. package/src/types/expression-model.ts +0 -294
  204. package/src/types/expression.ts +0 -313
  205. package/src/types/fqnRef.ts +0 -91
  206. package/src/types/geometry.ts +0 -159
  207. package/src/types/global.ts +0 -21
  208. package/src/types/index.ts +0 -44
  209. package/src/types/model-data.ts +0 -77
  210. package/src/types/model-deployment.ts +0 -78
  211. package/src/types/model-dump.ts +0 -79
  212. package/src/types/model-logical.ts +0 -126
  213. package/src/types/model-spec.ts +0 -88
  214. package/src/types/operators.ts +0 -156
  215. package/src/types/project.ts +0 -14
  216. package/src/types/scalar.ts +0 -162
  217. package/src/types/styles.ts +0 -122
  218. package/src/types/view-changes.ts +0 -32
  219. package/src/types/view-common.ts +0 -157
  220. package/src/types/view-computed.ts +0 -126
  221. package/src/types/view-layouted.ts +0 -94
  222. package/src/types/view-parsed.deployment.ts +0 -39
  223. package/src/types/view-parsed.dynamic.ts +0 -89
  224. package/src/types/view-parsed.element.ts +0 -65
  225. package/src/types/view.ts +0 -113
  226. package/src/utils/common-head.ts +0 -22
  227. package/src/utils/compare-natural.ts +0 -60
  228. package/src/utils/const.ts +0 -1
  229. package/src/utils/fqn.ts +0 -302
  230. package/src/utils/getOrCreate.ts +0 -8
  231. package/src/utils/guards.ts +0 -9
  232. package/src/utils/index.ts +0 -68
  233. package/src/utils/invariant.ts +0 -29
  234. package/src/utils/iterable/_types.ts +0 -5
  235. package/src/utils/iterable/filter.ts +0 -55
  236. package/src/utils/iterable/find.ts +0 -38
  237. package/src/utils/iterable/first.ts +0 -48
  238. package/src/utils/iterable/flat.ts +0 -17
  239. package/src/utils/iterable/head.ts +0 -22
  240. package/src/utils/iterable/index.ts +0 -15
  241. package/src/utils/iterable/map.ts +0 -40
  242. package/src/utils/iterable/reduce.ts +0 -24
  243. package/src/utils/iterable/some.ts +0 -36
  244. package/src/utils/iterable/to.ts +0 -19
  245. package/src/utils/iterable/unique.ts +0 -23
  246. package/src/utils/markdown/index.ts +0 -2
  247. package/src/utils/markdown/to-html.ts +0 -32
  248. package/src/utils/markdown/to-text.ts +0 -14
  249. package/src/utils/memoize-prop.ts +0 -30
  250. package/src/utils/mnemonist.ts +0 -9
  251. package/src/utils/object-hash.ts +0 -14
  252. package/src/utils/promises.ts +0 -24
  253. package/src/utils/relations.ts +0 -36
  254. package/src/utils/set.ts +0 -83
  255. package/src/utils/string-hash.ts +0 -16
@@ -1,151 +0,0 @@
1
- import { isEmpty, last } from 'remeda'
2
- import type { aux, NonEmptyArray } from '../../types'
3
- import { invariant, memoizeProp } from '../../utils'
4
- import type { LikeC4Model } from '../LikeC4Model'
5
- import { LikeC4ViewModel } from './LikeC4ViewModel'
6
-
7
- export class LikeC4ViewsFolder<A extends aux.Any = aux.Any> {
8
- public readonly $model: LikeC4Model<A>
9
-
10
- /**
11
- * Path to this view folder, processed by {@link normalizeViewPath}
12
- *
13
- * @example
14
- * "Folder 1/Folder 2/Folder 3"
15
- */
16
- public readonly path: string
17
-
18
- /**
19
- * Title of this view folder.
20
- *
21
- * @example
22
- * // title is the last segment of the path
23
- * path = "Folder 1/Folder 2/Folder 3"
24
- * title = "Folder 3"
25
- */
26
- public readonly title: string
27
-
28
- /**
29
- * Whether this is the root view folder.
30
- *
31
- * !NOTE
32
- * Root folder is special folder with an empty path and used only for internal purposes. \
33
- * It is not visible to the user and should not be used in the code.
34
- */
35
- public readonly isRoot: boolean
36
-
37
- protected readonly parentPath: string | undefined
38
-
39
- protected readonly defaultViewId: aux.StrictViewId<A> | undefined
40
-
41
- constructor(
42
- $model: LikeC4Model<A>,
43
- path: NonEmptyArray<string>,
44
- defaultViewId: aux.StrictViewId<A> | undefined,
45
- ) {
46
- this.$model = $model
47
- this.path = path.join('/')
48
- this.isRoot = this.path === ''
49
- this.title = last(path)
50
- if (this.isRoot) {
51
- this.parentPath = undefined
52
- } else {
53
- this.parentPath = path.slice(0, -1).join('/')
54
- }
55
- this.defaultViewId = defaultViewId
56
- }
57
-
58
- /**
59
- * Default view of this view folder.\
60
- * It is for the case when there is a view at the same path as this folder.\
61
- * (if there are multiple views at the same path, the first one is chosen)
62
- *
63
- * @example
64
- * ```
65
- * // Assume the following views exist:
66
- * const views = [
67
- * "Folder 1/ Folder 2 / View",
68
- * "Folder 1/ Folder 2 / View / Subview",
69
- * ]
70
- * ```
71
- * Group with path `Folder 1/ Folder 2 / View`\
72
- * will have default view `Folder 1/ Folder 2 / View`
73
- */
74
- get defaultView(): LikeC4ViewModel<A> | null {
75
- if (!this.defaultViewId) {
76
- return null
77
- }
78
- return this.$model.view(this.defaultViewId)
79
- }
80
-
81
- /**
82
- * Returns path to this view folder as an array of ancestors (excluding root) and this view folder as the last element
83
- *
84
- * @throws Error if this is the root folder.
85
- */
86
- get breadcrumbs(): [...LikeC4ViewsFolder<A>[], this] {
87
- invariant(!this.isRoot, 'Root view folder has no breadcrumbs')
88
- return memoizeProp(this, 'breadcrumbs', () => {
89
- const parent = this.parent
90
- if (parent) {
91
- if (parent.isRoot) {
92
- return [parent, this]
93
- }
94
- return [...parent.breadcrumbs, this]
95
- }
96
- return [this]
97
- })
98
- }
99
-
100
- /**
101
- * Returns parent folder
102
- *
103
- * @throws Error if this is the root folder.
104
- */
105
- get parent(): LikeC4ViewsFolder<A> | null {
106
- invariant(!this.isRoot, 'Root view folder has no parent')
107
- if (isEmpty(this.parentPath)) {
108
- return null
109
- }
110
- return this.$model.viewFolder(this.parentPath)
111
- }
112
-
113
- /**
114
- * Returns sorted set of children
115
- * - First folders
116
- * - Then views
117
- */
118
- get children(): ReadonlySet<LikeC4ViewsFolder<A> | LikeC4ViewModel<A>> {
119
- return this.$model.viewFolderItems(this.path)
120
- }
121
-
122
- /**
123
- * Returns sorted array of children folders
124
- */
125
- get folders(): ReadonlyArray<LikeC4ViewsFolder<A>> {
126
- return memoizeProp(this, 'folders', () => {
127
- const folders: LikeC4ViewsFolder<A>[] = []
128
- for (const child of this.children) {
129
- if (child instanceof LikeC4ViewsFolder) {
130
- folders.push(child)
131
- }
132
- }
133
- return folders
134
- })
135
- }
136
-
137
- /**
138
- * Returns all views in this view folder.
139
- */
140
- get views(): ReadonlyArray<LikeC4ViewModel<A>> {
141
- return memoizeProp(this, 'views', () => {
142
- const views: LikeC4ViewModel<A>[] = []
143
- for (const child of this.children) {
144
- if (child instanceof LikeC4ViewModel) {
145
- views.push(child)
146
- }
147
- }
148
- return views
149
- })
150
- }
151
- }
@@ -1,247 +0,0 @@
1
- import { isTruthy } from 'remeda'
2
- import {
3
- type Any,
4
- type Color,
5
- type ComputedNode,
6
- type DiagramNode,
7
- type ElementShape as C4ElementShape,
8
- type ElementStyle,
9
- type ExtractOnStage,
10
- type IconUrl,
11
- type IteratorLike,
12
- type Link,
13
- type RichTextOrEmpty,
14
- type scalar,
15
- GroupElementKind,
16
- isGroupElementKind,
17
- RichText,
18
- } from '../../types'
19
- import type * as aux from '../../types/_aux'
20
- import { memoizeProp } from '../../utils'
21
- import type { DeployedInstanceModel, DeploymentElementModel } from '../DeploymentElementModel'
22
- import type { ElementModel } from '../ElementModel'
23
- import type { $View, IncomingFilter, OutgoingFilter, WithTags } from '../types'
24
- import type { EdgesIterator } from './EdgeModel'
25
- import type { LikeC4ViewModel } from './LikeC4ViewModel'
26
-
27
- export type NodesIterator<M extends Any, V extends $View<M>> = IteratorLike<NodeModel<M, V>>
28
-
29
- export class NodeModel<A extends Any = Any, V extends $View<A> = $View<A>> implements WithTags<A> {
30
- #node: ComputedNode<A> | DiagramNode<A>
31
-
32
- constructor(
33
- public readonly $view: LikeC4ViewModel<A, V>,
34
- public readonly $node: V['nodes'][number],
35
- ) {
36
- this.#node = $node
37
- }
38
-
39
- get id(): scalar.NodeId {
40
- return this.#node.id
41
- }
42
-
43
- get title(): string {
44
- return this.#node.title
45
- }
46
-
47
- get kind(): aux.ElementKind<A> | aux.DeploymentKind<A> | typeof GroupElementKind | 'instance' {
48
- return this.#node.kind as any
49
- }
50
-
51
- get description(): RichTextOrEmpty {
52
- return RichText.memoize(this, 'description', this.#node.description)
53
- }
54
-
55
- get technology(): string | null {
56
- return this.#node.technology ?? null
57
- }
58
-
59
- get parent(): NodeModel<A, V> | null {
60
- return this.#node.parent ? this.$view.node(this.#node.parent) : null
61
- }
62
-
63
- get element(): ElementModel<A> | null {
64
- const modelRef = this.#node.modelRef
65
- return modelRef ? this.$view.$model.element(modelRef) : null
66
- }
67
-
68
- get deployment(): DeploymentElementModel<A> | null {
69
- const modelRef = this.#node.deploymentRef
70
- return modelRef ? this.$view.$model.deployment.element(modelRef) : null
71
- }
72
-
73
- get shape(): C4ElementShape {
74
- return this.#node.shape
75
- }
76
-
77
- get color(): Color {
78
- return this.#node.color
79
- }
80
-
81
- get icon(): IconUrl | null {
82
- return this.#node.icon ?? null
83
- }
84
-
85
- get tags(): aux.Tags<A> {
86
- return this.#node.tags
87
- }
88
-
89
- get links(): ReadonlyArray<Link> {
90
- return this.#node.links ?? []
91
- }
92
-
93
- get navigateTo(): LikeC4ViewModel<A> | null {
94
- return this.#node.navigateTo ? this.$view.$model.view(this.#node.navigateTo) : null
95
- }
96
-
97
- get style(): ElementStyle {
98
- return this.#node.style
99
- }
100
-
101
- public children(): ReadonlySet<NodeModel<A, V>> {
102
- return memoizeProp(this, 'children', () => new Set(this.#node.children.map((child) => this.$view.node(child))))
103
- }
104
-
105
- /**
106
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
107
- * (from closest to root)
108
- */
109
- public *ancestors(): NodesIterator<A, V> {
110
- let parent = this.parent
111
- while (parent) {
112
- yield parent
113
- parent = parent.parent
114
- }
115
- return
116
- }
117
-
118
- public *siblings(): NodesIterator<A, V> {
119
- const siblings = this.parent?.children() ?? this.$view.roots()
120
- for (const sibling of siblings) {
121
- if (sibling.id !== this.id) {
122
- yield sibling
123
- }
124
- }
125
- return
126
- }
127
-
128
- public *incoming(filter: IncomingFilter = 'all'): EdgesIterator<A, V> {
129
- for (const edgeId of this.#node.inEdges) {
130
- const edge = this.$view.edge(edgeId)
131
- switch (true) {
132
- case filter === 'all':
133
- case filter === 'direct' && edge.target.id === this.id:
134
- case filter === 'to-descendants' && edge.target.id !== this.id:
135
- yield edge
136
- break
137
- }
138
- }
139
- return
140
- }
141
-
142
- public *incomers(filter: IncomingFilter = 'all'): NodesIterator<A, V> {
143
- const unique = new Set<aux.NodeId>()
144
- for (const r of this.incoming(filter)) {
145
- if (unique.has(r.source.id)) {
146
- continue
147
- }
148
- unique.add(r.source.id)
149
- yield r.source
150
- }
151
- return
152
- }
153
-
154
- public *outgoing(filter: OutgoingFilter = 'all'): EdgesIterator<A, V> {
155
- for (const edgeId of this.#node.outEdges) {
156
- const edge = this.$view.edge(edgeId)
157
- switch (true) {
158
- case filter === 'all':
159
- case filter === 'direct' && edge.source.id === this.id:
160
- case filter === 'from-descendants' && edge.source.id !== this.id:
161
- yield edge
162
- break
163
- }
164
- }
165
- return
166
- }
167
-
168
- public *outgoers(filter: OutgoingFilter = 'all'): NodesIterator<A, V> {
169
- const unique = new Set<aux.NodeId>()
170
- for (const r of this.outgoing(filter)) {
171
- if (unique.has(r.target.id)) {
172
- continue
173
- }
174
- unique.add(r.target.id)
175
- yield r.target
176
- }
177
- return
178
- }
179
-
180
- public isDiagramNode(this: NodeModel<any, any>): this is NodeModel<A, ExtractOnStage<V, 'layouted'>> {
181
- return 'width' in this.#node && 'height' in this.#node
182
- }
183
-
184
- public hasChildren(): boolean {
185
- return this.#node.children.length > 0
186
- }
187
-
188
- public hasParent(): this is NodeModel.WithParent<A, V> {
189
- return this.#node.parent !== null
190
- }
191
-
192
- /**
193
- * Check if this node references to logical model element.
194
- */
195
- public hasElement(): this is NodeModel.WithElement<A, V> {
196
- return isTruthy(this.#node.modelRef)
197
- }
198
- /**
199
- * Check if this node references to deployment element (Node or Instance).
200
- */
201
- public hasDeployment(): this is NodeModel.WithDeploymentElement<A, V> {
202
- return isTruthy(this.#node.deploymentRef)
203
- }
204
- /**
205
- * Check if this node references to deployed instance
206
- * Deployed instance always references to element and deployment element.
207
- */
208
- public hasDeployedInstance(): this is NodeModel.WithDeployedInstance<A, V> {
209
- return this.hasElement() && this.hasDeployment()
210
- }
211
-
212
- public isGroup(): this is NodeModel.IsGroup<A, V> {
213
- return isGroupElementKind(this.#node)
214
- }
215
-
216
- /**
217
- * Checks if the node has the given tag.
218
- */
219
- public isTagged(tag: aux.LooseTag<A>): boolean {
220
- return this.tags.includes(tag as aux.Tag<A>)
221
- }
222
- }
223
-
224
- export namespace NodeModel {
225
- export interface WithParent<A extends Any = Any, V extends $View<A> = $View<A>> extends NodeModel<A, V> {
226
- parent: NodeModel<A, V>
227
- }
228
- export interface WithElement<A extends Any = Any, V extends $View<A> = $View<A>> extends NodeModel<A, V> {
229
- kind: aux.ElementKind<A>
230
- element: ElementModel<A>
231
- }
232
- export interface WithDeploymentElement<A extends Any = Any, V extends $View<A> = $View<A>> extends NodeModel<A, V> {
233
- kind: aux.DeploymentKind<A>
234
- deployment: DeploymentElementModel<A>
235
- }
236
- export interface WithDeployedInstance<A extends Any = Any, V extends $View<A> = $View<A>> extends NodeModel<A, V> {
237
- kind: 'instance'
238
- element: ElementModel<A>
239
- deployment: DeployedInstanceModel<A>
240
- }
241
-
242
- export interface IsGroup<A extends Any = Any, V extends $View<A> = $View<A>> extends NodeModel<A, V> {
243
- kind: typeof GroupElementKind
244
- element: null
245
- deployment: null
246
- }
247
- }
@@ -1,61 +0,0 @@
1
- import type { ElementThemeColors, ElementThemeColorValues } from '../types'
2
-
3
- const blue = {
4
- fill: '#3b82f6',
5
- stroke: '#2563eb',
6
- hiContrast: '#eff6ff',
7
- loContrast: '#bfdbfe',
8
- } satisfies ElementThemeColorValues
9
-
10
- const sky = {
11
- fill: '#0284c7',
12
- stroke: '#0369a1',
13
- hiContrast: '#f0f9ff',
14
- loContrast: '#B6ECF7',
15
- } satisfies ElementThemeColorValues
16
-
17
- const slate = {
18
- fill: '#64748b',
19
- stroke: '#475569',
20
- hiContrast: '#f8fafc',
21
- loContrast: '#cbd5e1',
22
- } satisfies ElementThemeColorValues
23
-
24
- export const ElementColors: ElementThemeColors = {
25
- primary: blue,
26
- blue,
27
- secondary: sky,
28
- sky,
29
- muted: slate,
30
- slate,
31
- gray: {
32
- fill: '#737373',
33
- stroke: '#525252',
34
- hiContrast: '#fafafa',
35
- loContrast: '#d4d4d4',
36
- },
37
- red: {
38
- fill: '#AC4D39',
39
- stroke: '#853A2D',
40
- hiContrast: '#FBD3CB',
41
- loContrast: '#f5b2a3',
42
- },
43
- green: {
44
- fill: '#428a4f',
45
- stroke: '#2d5d39',
46
- hiContrast: '#f8fafc',
47
- loContrast: '#c2f0c2',
48
- },
49
- amber: {
50
- fill: '#A35829',
51
- stroke: '#7E451D',
52
- hiContrast: '#FFE0C2',
53
- loContrast: '#f9b27c',
54
- },
55
- indigo: {
56
- fill: '#6366f1',
57
- stroke: '#4f46e5',
58
- hiContrast: '#eef2ff',
59
- loContrast: '#c7d2fe',
60
- },
61
- }
@@ -1,127 +0,0 @@
1
- import { generateColors } from '@mantine/colors-generator'
2
- import chroma from 'chroma-js';
3
- import type { ColorLiteral, HexColor, LikeC4Theme, ThemeColorValues } from '../types'
4
- import { ElementColors } from './element'
5
- import { RelationshipColors } from './relationships'
6
- import { isDeepEqual } from 'remeda'
7
-
8
- const CONTRAST_MIN_WITH_FOREGROUND = 60
9
- const CONTRAST_START_TONE_DIFFERENCE = 2
10
- const CONTRAST_STEP_TONE_DIFFERENCE = 1
11
-
12
- export const defaultTheme: LikeC4Theme = {
13
- elements: ElementColors,
14
- relationships: RelationshipColors,
15
- font: 'Arial',
16
- shadow: '#0a0a0a',
17
- sizes: {
18
- xs: {
19
- width: 180,
20
- height: 100,
21
- },
22
- sm: {
23
- width: 240,
24
- height: 135,
25
- },
26
- md: {
27
- width: 320,
28
- height: 180,
29
- },
30
- lg: {
31
- width: 420,
32
- height: 234,
33
- },
34
- xl: {
35
- width: 520,
36
- height: 290,
37
- },
38
- },
39
- spacing: {
40
- xs: 8, // 0.5rem
41
- sm: 10, // 0.625rem
42
- md: 16, // 1rem
43
- lg: 24, // 1.5rem = 16px + 8px
44
- xl: 32, // 2rem
45
- },
46
- /**
47
- * Text sizes for titles
48
- * https://typescale.com/
49
- *
50
- * Scale: 1.2
51
- * Base: 16px
52
- */
53
- textSizes: {
54
- xs: 13.33,
55
- sm: 16,
56
- md: 19.2,
57
- lg: 23.04,
58
- xl: 27.65,
59
- },
60
- }
61
-
62
- export function computeColorValues(color: ColorLiteral): ThemeColorValues {
63
- if (color.match(/^#([0-9a-f]{3}){1,2}$/i)) {
64
- const colors = generateColors(color)
65
-
66
- const fillColor = colors[6]
67
- const contrastedColors = getContrastedColorsAPCA(fillColor)
68
-
69
- return {
70
- elements: {
71
- fill: fillColor as HexColor,
72
- stroke: colors[7] as HexColor,
73
- hiContrast: contrastedColors[0] as HexColor,
74
- loContrast: contrastedColors[1] as HexColor,
75
- },
76
- relationships: {
77
- lineColor: colors[4] as HexColor,
78
- labelColor: colors[3] as HexColor,
79
- labelBgColor: colors[9] as HexColor,
80
- },
81
- }
82
- } else {
83
- return {
84
- elements: defaultTheme.elements['primary'],
85
- relationships: defaultTheme.relationships['primary'],
86
- }
87
- }
88
- }
89
-
90
- function getContrastedColorsAPCA(refColor: string): [string, string] {
91
- const refColorChroma = chroma(refColor)
92
-
93
- // Start with 2 steps tone difference in the CIELAB color space from reference
94
- let lightColorRgb = refColorChroma.brighten(CONTRAST_START_TONE_DIFFERENCE);
95
- let darkColorRgb = refColorChroma.darken(CONTRAST_START_TONE_DIFFERENCE);
96
-
97
- let previousLight
98
- let previousDark
99
- let contrastWithLight
100
- let contrastWithDark
101
- do {
102
- // Store previous colors for loop condition
103
- previousLight = lightColorRgb
104
- previousDark = darkColorRgb
105
-
106
- // Change tone by 1 step each loop
107
- lightColorRgb = lightColorRgb.brighten(CONTRAST_STEP_TONE_DIFFERENCE)
108
- darkColorRgb = darkColorRgb.darken(CONTRAST_STEP_TONE_DIFFERENCE)
109
-
110
- // Calculate contrast of each color with the reference color
111
- contrastWithLight = chroma.contrastAPCA(refColorChroma, lightColorRgb);
112
- contrastWithDark = chroma.contrastAPCA(refColorChroma, darkColorRgb);
113
- }
114
- // Stop if one of the contrast is high enough or if we reach max value for each (aka when they are equal between two rounds)
115
- while (Math.abs(contrastWithLight) < CONTRAST_MIN_WITH_FOREGROUND
116
- && Math.abs(contrastWithDark) < CONTRAST_MIN_WITH_FOREGROUND
117
- && (!isDeepEqual(lightColorRgb, previousLight) || !isDeepEqual(darkColorRgb, previousDark)))
118
-
119
- // Choose the max contrast between the two
120
- if (Math.abs(contrastWithLight) > Math.abs(contrastWithDark)) {
121
- return [lightColorRgb.brighten(0.4).hex(), lightColorRgb.hex()]
122
- } else {
123
- return [darkColorRgb.darken(0.4).hex(), darkColorRgb.hex()]
124
- }
125
- }
126
-
127
- export { ElementColors, RelationshipColors }
@@ -1,54 +0,0 @@
1
- import type { RelationshipThemeColors, RelationshipThemeColorValues } from '../types/styles'
2
-
3
- const gray = {
4
- lineColor: '#6E6E6E',
5
- labelBgColor: '#18191b',
6
- labelColor: '#C6C6C6',
7
- } satisfies RelationshipThemeColorValues
8
- const slate = {
9
- lineColor: '#64748b', // 500
10
- labelBgColor: '#0f172a', // 900
11
- labelColor: '#cbd5e1', // 300
12
- } satisfies RelationshipThemeColorValues
13
-
14
- const blue = {
15
- lineColor: '#3b82f6', // 500
16
- labelBgColor: '#172554', // 950
17
- labelColor: '#60a5fa', // 400
18
- } satisfies RelationshipThemeColorValues
19
-
20
- const sky = {
21
- lineColor: '#0ea5e9', // 500
22
- labelBgColor: '#082f49', // 950
23
- labelColor: '#38bdf8', // 400
24
- } satisfies RelationshipThemeColorValues
25
-
26
- export const RelationshipColors: RelationshipThemeColors = {
27
- amber: {
28
- lineColor: '#b45309',
29
- labelBgColor: '#78350f',
30
- labelColor: '#FFE0C2',
31
- },
32
- blue,
33
- gray,
34
- green: {
35
- lineColor: '#15803d', // 700
36
- labelBgColor: '#052e16', // 950
37
- labelColor: '#22c55e', // 500
38
- },
39
- indigo: {
40
- lineColor: '#6366f1', // 500
41
- labelBgColor: '#1e1b4b', // 950
42
- labelColor: '#818cf8', // 400
43
- },
44
- muted: slate,
45
- primary: blue,
46
- red: {
47
- lineColor: '#AC4D39',
48
- labelBgColor: '#b91c1c',
49
- labelColor: '#f5b2a3',
50
- },
51
- secondary: sky,
52
- sky,
53
- slate,
54
- }