@likec4/core 1.20.3 → 1.21.1

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 (80) hide show
  1. package/dist/builder/index.cjs +24 -18
  2. package/dist/builder/index.d.cts +11 -5
  3. package/dist/builder/index.d.mts +11 -5
  4. package/dist/builder/index.d.ts +11 -5
  5. package/dist/builder/index.mjs +10 -4
  6. package/dist/compute-view/index.cjs +6 -6
  7. package/dist/compute-view/index.d.cts +4 -4
  8. package/dist/compute-view/index.d.mts +4 -4
  9. package/dist/compute-view/index.d.ts +4 -4
  10. package/dist/compute-view/index.mjs +6 -6
  11. package/dist/index.cjs +53 -14
  12. package/dist/index.d.cts +6 -6
  13. package/dist/index.d.mts +6 -6
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.mjs +47 -11
  16. package/dist/model/index.cjs +1 -1
  17. package/dist/model/index.d.cts +5 -5
  18. package/dist/model/index.d.mts +5 -5
  19. package/dist/model/index.d.ts +5 -5
  20. package/dist/model/index.mjs +1 -1
  21. package/dist/shared/{core.Cmfo_N4F.d.mts → core.5Z5cpENq.d.mts} +5 -4
  22. package/dist/shared/{core.D4wZW7zR.d.ts → core.BJfq046m.d.ts} +5 -4
  23. package/dist/shared/{core.C0ygs98j.d.cts → core.BS_nXBsP.d.cts} +9 -2
  24. package/dist/shared/{core.CajOK_t3.d.mts → core.BYs5deiY.d.cts} +1 -1
  25. package/dist/shared/{core.Bezy7K65.mjs → core.BfZZXtur.mjs} +2 -2
  26. package/dist/shared/{core.CwZmAghJ.d.cts → core.BgPZ8Tl8.d.cts} +5 -4
  27. package/dist/shared/{core.FACQZmma.cjs → core.BjR0D3IO.cjs} +15 -15
  28. package/dist/shared/{core.uxHtIZaH.cjs → core.CAkSSvJ6.cjs} +11 -5
  29. package/dist/shared/{core.El-gigOM.mjs → core.CE-kCVHA.mjs} +1 -1
  30. package/dist/shared/{core.DjMYkPMQ.d.mts → core.CJaCUZQ9.d.mts} +9 -2
  31. package/dist/shared/{core.88YY6vtF.d.mts → core.CT1nzYjO.d.cts} +2 -2
  32. package/dist/shared/{core.0PxLtLpP.mjs → core.CYNYaH2U.mjs} +5 -2
  33. package/dist/shared/{core.CCyhaU-4.mjs → core.CeefT_JU.mjs} +6 -6
  34. package/dist/shared/{core.BG1hfxpq.mjs → core.Cz9Oy_FA.mjs} +475 -409
  35. package/dist/shared/{core.BIZD3l1g.d.cts → core.D0KD4FiT.d.mts} +1 -1
  36. package/dist/shared/{core.DRfrKNT6.cjs → core.D91uYrqI.cjs} +551 -485
  37. package/dist/shared/{core.BtISRjMA.d.ts → core.DQCc-Jxk.d.ts} +1 -1
  38. package/dist/shared/{core.Db_OTRdC.cjs → core.DnPc_NDM.cjs} +1 -1
  39. package/dist/shared/{core.CNUzoKM7.d.ts → core.Dp3HTiRV.d.ts} +2 -2
  40. package/dist/shared/{core.CKYxnFEl.cjs → core.DqQrj2oQ.cjs} +2 -2
  41. package/dist/shared/{core.Bs71hdR4.d.ts → core.DsDq-blc.d.ts} +9 -2
  42. package/dist/shared/{core.Lh2RFJf1.d.cts → core.DuuS_BrY.d.mts} +2 -2
  43. package/dist/shared/{core.BJfn72tj.d.ts → core.QP35c488.d.cts} +33 -1
  44. package/dist/shared/{core.BJfn72tj.d.cts → core.QP35c488.d.mts} +33 -1
  45. package/dist/shared/{core.BJfn72tj.d.mts → core.QP35c488.d.ts} +33 -1
  46. package/dist/types/index.cjs +4 -1
  47. package/dist/types/index.d.cts +4 -4
  48. package/dist/types/index.d.mts +4 -4
  49. package/dist/types/index.d.ts +4 -4
  50. package/dist/types/index.mjs +1 -1
  51. package/dist/utils/index.cjs +3 -3
  52. package/dist/utils/index.d.cts +2 -2
  53. package/dist/utils/index.d.mts +2 -2
  54. package/dist/utils/index.d.ts +2 -2
  55. package/dist/utils/index.mjs +3 -3
  56. package/package.json +6 -6
  57. package/src/builder/Builder.ts +11 -5
  58. package/src/builder/Builder.view-common.ts +1 -0
  59. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +16 -4
  60. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +21 -5
  61. package/src/builder/_types.ts +9 -0
  62. package/src/compute-view/deployment-view/predicates/{elements.ts → deploymentRefs.ts} +32 -21
  63. package/src/compute-view/deployment-view/predicates/index.ts +1 -1
  64. package/src/compute-view/deployment-view/predicates/utils.ts +56 -1
  65. package/src/compute-view/deployment-view/predicates/wildcard.ts +20 -9
  66. package/src/compute-view/memory/AbstractStageExclude.ts +1 -1
  67. package/src/compute-view/utils/applyCustomElementProperties.ts +18 -1
  68. package/src/compute-view/utils/applyViewRuleStyles.ts +9 -0
  69. package/src/compute-view/utils/buildComputedNodes.ts +13 -9
  70. package/src/index.ts +1 -1
  71. package/src/model/DeploymentElementModel.ts +5 -2
  72. package/src/model/ElementModel.ts +10 -0
  73. package/src/{colors → theme}/element.ts +9 -9
  74. package/src/{colors → theme}/index.ts +41 -5
  75. package/src/{colors → theme}/relationships.ts +9 -9
  76. package/src/types/element.ts +19 -1
  77. package/src/types/expression.ts +4 -1
  78. package/src/types/index.ts +6 -0
  79. package/src/types/theme.ts +22 -1
  80. package/src/types/view.ts +5 -1
@@ -16,6 +16,7 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
16
16
  "shape": "rectangle",
17
17
  "style": {
18
18
  "opacity": 10,
19
+ "size": "lg",
19
20
  },
20
21
  "tags": null,
21
22
  "technology": null,
@@ -28,7 +29,9 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
28
29
  "kind": "component",
29
30
  "links": null,
30
31
  "shape": "browser",
31
- "style": {},
32
+ "style": {
33
+ "textSize": "sm",
34
+ },
32
35
  "tags": null,
33
36
  "technology": null,
34
37
  "title": "c1",
@@ -42,6 +45,7 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
42
45
  "shape": "rectangle",
43
46
  "style": {
44
47
  "opacity": 10,
48
+ "size": "lg",
45
49
  },
46
50
  "tags": null,
47
51
  "technology": null,
@@ -54,7 +58,9 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
54
58
  "kind": "component",
55
59
  "links": null,
56
60
  "shape": "browser",
57
- "style": {},
61
+ "style": {
62
+ "textSize": "sm",
63
+ },
58
64
  "tags": null,
59
65
  "technology": null,
60
66
  "title": "Component s2.1",
@@ -66,7 +72,9 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
66
72
  "kind": "component",
67
73
  "links": null,
68
74
  "shape": "browser",
69
- "style": {},
75
+ "style": {
76
+ "textSize": "sm",
77
+ },
70
78
  "tags": null,
71
79
  "technology": null,
72
80
  "title": "Component s2.1.2",
@@ -78,7 +86,9 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
78
86
  "kind": "component",
79
87
  "links": null,
80
88
  "shape": "browser",
81
- "style": {},
89
+ "style": {
90
+ "textSize": "sm",
91
+ },
82
92
  "tags": null,
83
93
  "technology": null,
84
94
  "title": "c3",
@@ -115,12 +125,14 @@ exports[`Builder (style1) > should build nested elements and relTo 1`] = `
115
125
  "component": {
116
126
  "style": {
117
127
  "shape": "browser",
128
+ "textSize": "sm",
118
129
  },
119
130
  },
120
131
  "system": {
121
132
  "style": {
122
133
  "color": "green",
123
134
  "opacity": 10,
135
+ "size": "lg",
124
136
  },
125
137
  },
126
138
  },
@@ -10,7 +10,9 @@ exports[`Builder (style 2) > should build 1`] = `
10
10
  "id": "dev",
11
11
  "kind": "env",
12
12
  "shape": "rectangle",
13
- "style": {},
13
+ "style": {
14
+ "size": "lg",
15
+ },
14
16
  "tags": null,
15
17
  "technology": null,
16
18
  "title": "dev",
@@ -32,7 +34,9 @@ exports[`Builder (style 2) > should build 1`] = `
32
34
  "id": "prod",
33
35
  "kind": "env",
34
36
  "shape": "rectangle",
35
- "style": {},
37
+ "style": {
38
+ "size": "lg",
39
+ },
36
40
  "tags": null,
37
41
  "technology": null,
38
42
  "title": "prod",
@@ -63,7 +67,10 @@ exports[`Builder (style 2) > should build 1`] = `
63
67
  "kind": "system",
64
68
  "links": null,
65
69
  "shape": "rectangle",
66
- "style": {},
70
+ "style": {
71
+ "size": "lg",
72
+ "textSize": "sm",
73
+ },
67
74
  "tags": null,
68
75
  "technology": null,
69
76
  "title": "cloud",
@@ -101,13 +108,22 @@ exports[`Builder (style 2) > should build 1`] = `
101
108
  "relations": {},
102
109
  "specification": {
103
110
  "deployments": {
104
- "env": {},
111
+ "env": {
112
+ "style": {
113
+ "size": "lg",
114
+ },
115
+ },
105
116
  "node": {},
106
117
  },
107
118
  "elements": {
108
119
  "actor": {},
109
120
  "component": {},
110
- "system": {},
121
+ "system": {
122
+ "style": {
123
+ "size": "lg",
124
+ "textSize": "sm",
125
+ },
126
+ },
111
127
  },
112
128
  "relationships": {},
113
129
  "tags": [],
@@ -12,6 +12,9 @@ import type {
12
12
  RelationshipArrowType,
13
13
  RelationshipKindSpecification,
14
14
  RelationshipLineType,
15
+ ShapeSize,
16
+ SpacingSize,
17
+ TextSize,
15
18
  } from '../types'
16
19
  import type { ExpressionV2 } from '../types/expression-v2'
17
20
  import type { Builder } from './Builder'
@@ -47,6 +50,9 @@ export type NewElementProps<Tag, Metadata> = {
47
50
  border?: BorderStyle
48
51
  // 0-100
49
52
  opacity?: number
53
+ size?: ShapeSize
54
+ padding?: SpacingSize
55
+ textSize?: TextSize
50
56
  }
51
57
  }
52
58
 
@@ -64,6 +70,9 @@ export type NewDeploymentNodeProps<Tag, Metadata> = {
64
70
  border?: BorderStyle
65
71
  // 0-100
66
72
  opacity?: number
73
+ size?: ShapeSize
74
+ padding?: SpacingSize
75
+ textSize?: TextSize
67
76
  }
68
77
  }
69
78
 
@@ -1,4 +1,4 @@
1
- import { pipe, reduce } from 'remeda'
1
+ import { filter, forEach, pipe, reduce } from 'remeda'
2
2
  import { isDeployedInstance } from '../../../model'
3
3
  import { findConnectionsBetween, findConnectionsWithin } from '../../../model/connection/deployment'
4
4
  import type { DeploymentElementModel, DeploymentNodeModel } from '../../../model/DeploymentElementModel'
@@ -7,15 +7,18 @@ import type { Elem, IncludePredicateCtx, PredicateExecutor } from '../_types'
7
7
  import { cleanCrossBoundary, cleanRedundantRelationships } from '../clean-connections'
8
8
  import type { StageInclude } from '../memory'
9
9
  import { deploymentExpressionToPredicate } from '../utils'
10
+ import { applyElementPredicate } from './utils'
10
11
 
11
12
  export const DeploymentRefPredicate: PredicateExecutor<FqnExpr.DeploymentRef> = {
12
13
  include: (ctx) => {
13
- const { expr } = ctx
14
+ const { expr, where } = ctx
14
15
  const el = ctx.model.element(expr.ref.deployment)
15
16
 
16
17
  if (isDeployedInstance(el)) {
17
- ctx.stage.addExplicit(el)
18
- ctx.stage.connectWithExisting(el)
18
+ if (applyElementPredicate(el, where)) {
19
+ ctx.stage.addExplicit(el)
20
+ ctx.stage.connectWithExisting(el)
21
+ }
19
22
  return ctx.stage
20
23
  }
21
24
 
@@ -30,16 +33,23 @@ export const DeploymentRefPredicate: PredicateExecutor<FqnExpr.DeploymentRef> =
30
33
  includeDeployedNodeDescendants(el, ctx)
31
34
  break
32
35
  default: {
33
- ctx.stage.addExplicit(el)
34
- ctx.stage.connectWithExisting(el)
36
+ if (applyElementPredicate(el, where)) {
37
+ ctx.stage.addExplicit(el)
38
+ ctx.stage.connectWithExisting(el)
39
+ }
35
40
  }
36
41
  }
37
42
  return ctx.stage
38
43
  },
39
44
 
40
- exclude: ({ expr, stage, memory }) => {
45
+ exclude: ({ expr, stage, memory, where }) => {
41
46
  const exprPredicate = deploymentExpressionToPredicate(expr)
42
- stage.exclude([...memory.elements].filter(exprPredicate))
47
+ const toExclude = pipe(
48
+ [...memory.elements],
49
+ filter<DeploymentElementModel>(exprPredicate),
50
+ applyElementPredicate(where),
51
+ )
52
+ stage.exclude(toExclude)
43
53
  return stage
44
54
  },
45
55
  }
@@ -49,9 +59,9 @@ export const DeploymentRefPredicate: PredicateExecutor<FqnExpr.DeploymentRef> =
49
59
  */
50
60
  function includeDeployedNodeChildren(
51
61
  node: DeploymentNodeModel,
52
- { stage }: IncludePredicateCtx,
62
+ { stage, where }: IncludePredicateCtx,
53
63
  ) {
54
- const children = [...node.children()]
64
+ const children = applyElementPredicate([...node.children()], where)
55
65
  if (children.length === 0) {
56
66
  return
57
67
  }
@@ -68,12 +78,12 @@ function includeDeployedNodeChildren(
68
78
  */
69
79
  function includeDeployedNodeWithExpanded(
70
80
  node: DeploymentNodeModel,
71
- { memory, stage }: IncludePredicateCtx,
81
+ { memory, stage, where }: IncludePredicateCtx,
72
82
  ) {
73
- const children = [...node.children()]
74
83
  stage.addImplicit(node)
75
84
  stage.connectWithExisting(node)
76
85
 
86
+ const children = applyElementPredicate([...node.children()], where)
77
87
  let hasConnectionsWithVisible = false
78
88
  for (const child of children) {
79
89
  if (findConnectionsBetween(child, memory.elements).length > 0) {
@@ -99,7 +109,7 @@ function includeDeployedNodeWithExpanded(
99
109
  */
100
110
  function includeDeployedNodeDescendants(
101
111
  node: DeploymentNodeModel,
102
- { stage }: IncludePredicateCtx,
112
+ { stage, where }: IncludePredicateCtx,
103
113
  ) {
104
114
  const dfs = (node: DeploymentNodeModel): DeploymentElementModel[] => {
105
115
  const children = [] as DeploymentElementModel[]
@@ -107,7 +117,9 @@ function includeDeployedNodeDescendants(
107
117
  if (child.isDeploymentNode()) {
108
118
  children.push(...dfs(child))
109
119
  }
110
- children.push(child)
120
+ if (applyElementPredicate(child, where)) {
121
+ children.push(child)
122
+ }
111
123
  }
112
124
  stage.connectWithExisting(children, 'in')
113
125
  stage.addConnections(findConnectionsWithin(children))
@@ -120,14 +132,13 @@ function includeDeployedNodeDescendants(
120
132
  return
121
133
  }
122
134
  stage.connectWithExisting(descendants, 'out')
123
- // stage.addImplicit(descendants)
124
135
 
125
- const allconnected = findConnectedElements(stage)
126
- descendants.forEach((desc) => {
127
- if (allconnected.has(desc)) {
128
- stage.addExplicit(desc)
129
- }
130
- })
136
+ const allConnected = findConnectedElements(stage)
137
+ pipe(
138
+ descendants,
139
+ filter(desc => allConnected.has(desc)),
140
+ forEach(desc => stage.addExplicit(desc)),
141
+ )
131
142
  }
132
143
 
133
144
  function findConnectedElements(stage: StageInclude) {
@@ -1,4 +1,4 @@
1
- export * from './elements'
1
+ export * from './deploymentRefs'
2
2
  export * from './relation-direct'
3
3
  export * from './relation-in-out'
4
4
  export * from './relation-incoming'
@@ -14,7 +14,7 @@ import { type Filterable, type OperatorPredicate, FqnExpr, RelationExpr } from '
14
14
  import { hasIntersection, intersection } from '../../../utils/set'
15
15
  import type { ExcludePredicateCtx, PredicateCtx } from '../_types'
16
16
  import type { StageExclude, StageInclude } from '../memory'
17
- import { DeploymentRefPredicate } from './elements'
17
+ import { DeploymentRefPredicate } from './deploymentRefs'
18
18
  import { DirectRelationPredicate } from './relation-direct'
19
19
  import { InOutRelationPredicate } from './relation-in-out'
20
20
  import { IncomingRelationPredicate } from './relation-incoming'
@@ -37,6 +37,7 @@ export function predicateToPatch(
37
37
  return DeploymentRefPredicate[op]({ ...ctx, expr, where } as any)
38
38
  case FqnExpr.isWildcard(expr):
39
39
  return WildcardPredicate[op]({ ...ctx, expr, where } as any)
40
+
40
41
  case RelationExpr.isDirect(expr):
41
42
  return DirectRelationPredicate[op]({ ...ctx, expr, where } as any)
42
43
  case RelationExpr.isInOut(expr):
@@ -155,6 +156,60 @@ export function applyPredicate<M extends AnyAux>(
155
156
  })
156
157
  }
157
158
 
159
+ /**
160
+ * Checks elements using the provided predicate.
161
+ *
162
+ * @param c The collection of element to apply the predicate to
163
+ * @param where The predicate
164
+ * @returns Returns array of elements those match the predicate
165
+ */
166
+ export function applyElementPredicate<M extends AnyAux>(
167
+ c: readonly DeploymentElementModel<M>[],
168
+ where: OperatorPredicate<Filterable> | null,
169
+ ): readonly DeploymentElementModel<M>[]
170
+ /**
171
+ * Checks element using the provided predicate.
172
+ *
173
+ * @param c The element to apply the predicate to
174
+ * @param where The predicate
175
+ * @returns The result of the check
176
+ */
177
+ export function applyElementPredicate<M extends AnyAux, E extends DeploymentElementModel<M>>(
178
+ c: E,
179
+ where: OperatorPredicate<Filterable> | null,
180
+ ): boolean
181
+ /**
182
+ * Creates a function that filters elemetns using the provided predicate.
183
+ *
184
+ * @param where The predicate
185
+ * @returns A function to filter elements
186
+ */
187
+ export function applyElementPredicate<M extends AnyAux, E extends DeploymentElementModel<M>>(
188
+ where: OperatorPredicate<Filterable> | null,
189
+ ): (data: readonly E[]) => readonly E[]
190
+ export function applyElementPredicate<M extends AnyAux, E extends DeploymentElementModel<M>>(
191
+ ...args:
192
+ | [readonly E[], OperatorPredicate<Filterable> | null]
193
+ | [OperatorPredicate<Filterable> | null]
194
+ | [c: E, OperatorPredicate<Filterable> | null]
195
+ ):
196
+ | boolean
197
+ | readonly E[]
198
+ | ((data: readonly E[]) => readonly E[])
199
+ {
200
+ if (args.length === 1) {
201
+ return x => applyElementPredicate(x, args[0]) as readonly E[]
202
+ }
203
+
204
+ const [c, where] = args
205
+
206
+ if (isArray(c)) {
207
+ return c.filter(x => applyElementPredicate(x, where))
208
+ }
209
+
210
+ return where?.(toFilterable(c, c)) ?? true
211
+ }
212
+
158
213
  export function matchConnections<M extends AnyAux>(
159
214
  connections: readonly DeploymentConnectionModel<M>[],
160
215
  where: OperatorPredicate<Filterable> | null,
@@ -1,17 +1,22 @@
1
+ import { map, pipe } from 'remeda'
1
2
  import { findConnectionsWithin } from '../../../model/connection/deployment'
2
3
  import type { FqnExpr } from '../../../types'
3
4
  import { type Elem, type PredicateExecutor } from '../_types'
5
+ import { applyElementPredicate } from './utils'
4
6
 
5
7
  export const WildcardPredicate: PredicateExecutor<FqnExpr.Wildcard> = {
6
- include: ({ model, stage }) => {
8
+ include: ({ model, stage, where }) => {
7
9
  const children = [] as Elem[]
8
10
 
9
- const rootElements = [...model.roots()].map(root => {
10
- if (!root.onlyOneInstance()) {
11
- children.push(...root.children())
12
- }
13
- return root
14
- })
11
+ const rootElements = pipe(
12
+ [...model.roots()],
13
+ applyElementPredicate(where),
14
+ map(root => {
15
+ if (!root.onlyOneInstance()) {
16
+ children.push(...root.children())
17
+ }
18
+ return root
19
+ }))
15
20
 
16
21
  stage.addExplicit(rootElements)
17
22
  if (children.length > 1) {
@@ -22,8 +27,14 @@ export const WildcardPredicate: PredicateExecutor<FqnExpr.Wildcard> = {
22
27
  }
23
28
  return stage
24
29
  },
25
- exclude: ({ stage, memory }) => {
26
- stage.exclude(memory.elements)
30
+ exclude: ({ stage, memory, where }) => {
31
+ const elementsToExclude = pipe(
32
+ [...memory.elements],
33
+ applyElementPredicate(where),
34
+ )
35
+
36
+ stage.exclude(elementsToExclude)
37
+
27
38
  return stage
28
39
  },
29
40
  }
@@ -209,7 +209,7 @@ export abstract class AbstractStageExclude<T extends AnyCtx> implements StageExc
209
209
  state = this.removeElements(state)
210
210
  }
211
211
 
212
- state = this.moveDisconnectedExplicitsToImplicits(state)
212
+ //state = this.moveDisconnectedExplicitsToImplicits(state)
213
213
 
214
214
  return this.memory.update(this.postcommit(state))
215
215
  }
@@ -27,7 +27,15 @@ export function applyCustomElementProperties(_rules: ViewRule[], _nodes: Compute
27
27
  custom: { expr, ...props },
28
28
  } of rules
29
29
  ) {
30
- const { border, opacity, multiple, ...rest } = omitBy(props, isNullish)
30
+ const {
31
+ border,
32
+ opacity,
33
+ multiple,
34
+ padding,
35
+ size,
36
+ textSize,
37
+ ...rest
38
+ } = omitBy(props, isNullish)
31
39
  const notEmpty = !isEmpty(rest)
32
40
  const satisfies = elementExprToPredicate(expr)
33
41
  nodes.forEach((node, i) => {
@@ -52,6 +60,15 @@ export function applyCustomElementProperties(_rules: ViewRule[], _nodes: Compute
52
60
  if (multiple !== undefined) {
53
61
  styleOverride = { ...styleOverride, multiple }
54
62
  }
63
+ if (padding !== undefined) {
64
+ styleOverride = { ...styleOverride, padding }
65
+ }
66
+ if (size !== undefined) {
67
+ styleOverride = { ...styleOverride, size }
68
+ }
69
+ if (textSize !== undefined) {
70
+ styleOverride = { ...styleOverride, textSize }
71
+ }
55
72
  if (styleOverride) {
56
73
  node = {
57
74
  ...node,
@@ -34,6 +34,15 @@ export function applyViewRuleStyle<Rule extends CommonViewRuleStyle>(
34
34
  if (isDefined(rule.style.multiple)) {
35
35
  styleOverride = { ...styleOverride, multiple: rule.style.multiple }
36
36
  }
37
+ if (isDefined(rule.style.padding)) {
38
+ styleOverride = { ...styleOverride, padding: rule.style.padding }
39
+ }
40
+ if (isDefined(rule.style.size)) {
41
+ styleOverride = { ...styleOverride, size: rule.style.size }
42
+ }
43
+ if (isDefined(rule.style.textSize)) {
44
+ styleOverride = { ...styleOverride, textSize: rule.style.textSize }
45
+ }
37
46
  if (styleOverride) {
38
47
  n.style = {
39
48
  ...n.style,
@@ -2,12 +2,12 @@ import type { Simplify } from 'type-fest'
2
2
  import { nonNullable } from '../../errors'
3
3
  import {
4
4
  type ComputedNode,
5
+ type Element,
6
+ type Fqn,
7
+ type NodeId,
5
8
  DefaultElementShape,
6
9
  DefaultThemeColor,
7
- type Element,
8
10
  ElementKind,
9
- type Fqn,
10
- type NodeId
11
11
  } from '../../types'
12
12
  import { compareByFqnHierarchically, parentFqn } from '../../utils/fqn'
13
13
  import { NodesGroup } from '../element-view/memory'
@@ -28,7 +28,7 @@ function updateDepthOfAncestors(node: ComputedNode, nodes: ReadonlyMap<Fqn, Comp
28
28
  const modelElementAsNodeSource = (element: Element): ComputedNodeSource => {
29
29
  return {
30
30
  ...element,
31
- modelRef: 1
31
+ modelRef: 1,
32
32
  }
33
33
  }
34
34
 
@@ -44,7 +44,7 @@ export function buildComputedNodesFromElements(elements: ReadonlyArray<Element>,
44
44
 
45
45
  export function buildComputedNodes(
46
46
  elements: ReadonlyArray<ComputedNodeSource>,
47
- groups?: ReadonlyArray<NodesGroup>
47
+ groups?: ReadonlyArray<NodesGroup>,
48
48
  ): ReadonlyMap<Fqn, ComputedNode> {
49
49
  const nodesMap = new Map<Fqn, ComputedNode>()
50
50
 
@@ -72,8 +72,12 @@ export function buildComputedNodes(
72
72
  links: null,
73
73
  style: {
74
74
  border: viewRule.border ?? 'dashed',
75
- opacity: viewRule.opacity ?? 0
76
- }
75
+ opacity: viewRule.opacity ?? 0,
76
+ size: viewRule.size ?? 'md',
77
+ multiple: viewRule.multiple ?? false,
78
+ padding: viewRule.padding ?? 'md',
79
+ textSize: viewRule.textSize ?? 'md',
80
+ },
77
81
  })
78
82
  for (const e of elements) {
79
83
  elementToGroup.set(e.id, id)
@@ -128,8 +132,8 @@ export function buildComputedNodes(
128
132
  outEdges: [],
129
133
  ...el,
130
134
  style: {
131
- ...style
132
- }
135
+ ...style,
136
+ },
133
137
  }
134
138
  nodesMap.set(id, node)
135
139
  })
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ export {
3
3
  defaultTheme,
4
4
  ElementColors,
5
5
  RelationshipColors,
6
- } from './colors'
6
+ } from './theme'
7
7
 
8
8
  export {
9
9
  invariant,
@@ -18,6 +18,7 @@ import {
18
18
  DefaultElementShape,
19
19
  DefaultThemeColor,
20
20
  } from '../types'
21
+ import { DefaultShapeSize } from '../types/element'
21
22
  import { commonAncestor, hierarchyLevel } from '../utils'
22
23
  import { difference, intersection, union } from '../utils/set'
23
24
  import type { LikeC4DeploymentModel } from './DeploymentModel'
@@ -43,10 +44,11 @@ abstract class AbstractDeploymentElementModel<M extends AnyAux = AnyAux> {
43
44
  abstract readonly $model: LikeC4DeploymentModel<M>
44
45
  abstract readonly $node: DeploymentNode | DeployedInstance
45
46
 
46
- get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color'> {
47
+ get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color' | 'size'> {
47
48
  return {
48
49
  shape: DefaultElementShape,
49
50
  color: DefaultThemeColor,
51
+ size: DefaultShapeSize,
50
52
  ...this.$node.style,
51
53
  }
52
54
  }
@@ -349,11 +351,12 @@ export class DeployedInstanceModel<M extends AnyAux = AnyAux> extends AbstractDe
349
351
  return nonNullable(this.$model.parent(this), `Parent of ${this.id} not found`)
350
352
  }
351
353
 
352
- override get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color'> {
354
+ override get style(): SetRequired<DeploymentElementStyle, 'shape' | 'color' | 'size'> {
353
355
  const { icon, style } = this.element.$element
354
356
  return {
355
357
  shape: this.element.shape,
356
358
  color: this.element.color,
359
+ size: DefaultShapeSize,
357
360
  ...icon && { icon },
358
361
  ...style,
359
362
  ...this.$instance.style,
@@ -1,8 +1,10 @@
1
1
  import { isTruthy } from 'remeda'
2
+ import type { SetRequired } from 'type-fest'
2
3
  import {
3
4
  type Element as C4Element,
4
5
  type ElementKind as C4ElementKind,
5
6
  type ElementShape as C4ElementShape,
7
+ type ElementStyle,
6
8
  type IconUrl,
7
9
  type IteratorLike,
8
10
  type Link,
@@ -11,6 +13,7 @@ import {
11
13
  DefaultElementShape,
12
14
  DefaultThemeColor,
13
15
  } from '../types'
16
+ import { DefaultShapeSize } from '../types/element'
14
17
  import { commonAncestor, hierarchyLevel, isAncestor, sortNaturalByFqn } from '../utils'
15
18
  import { type DeployedInstancesIterator } from './DeploymentElementModel'
16
19
  import type { LikeC4Model } from './LikeC4Model'
@@ -80,6 +83,13 @@ export class ElementModel<M extends AnyAux = AnyAux> {
80
83
  return this.parent === null
81
84
  }
82
85
 
86
+ get style(): SetRequired<ElementStyle, 'size'> {
87
+ return {
88
+ size: DefaultShapeSize,
89
+ ...this.$element.style,
90
+ }
91
+ }
92
+
83
93
  public isAncestorOf(another: ElementModel<M>): boolean {
84
94
  return isAncestor(this, another)
85
95
  }
@@ -4,21 +4,21 @@ const blue = {
4
4
  fill: '#3b82f6',
5
5
  stroke: '#2563eb',
6
6
  hiContrast: '#eff6ff',
7
- loContrast: '#bfdbfe'
7
+ loContrast: '#bfdbfe',
8
8
  } satisfies ElementThemeColorValues
9
9
 
10
10
  const sky = {
11
11
  fill: '#0284c7',
12
12
  stroke: '#0369a1',
13
13
  hiContrast: '#f0f9ff',
14
- loContrast: '#B6ECF7'
14
+ loContrast: '#B6ECF7',
15
15
  } satisfies ElementThemeColorValues
16
16
 
17
17
  const slate = {
18
18
  fill: '#64748b',
19
19
  stroke: '#475569',
20
20
  hiContrast: '#f8fafc',
21
- loContrast: '#cbd5e1'
21
+ loContrast: '#cbd5e1',
22
22
  } satisfies ElementThemeColorValues
23
23
 
24
24
  export const ElementColors = {
@@ -36,7 +36,7 @@ export const ElementColors = {
36
36
  fill: '#737373',
37
37
  stroke: '#525252',
38
38
  hiContrast: '#fafafa',
39
- loContrast: '#d4d4d4'
39
+ loContrast: '#d4d4d4',
40
40
  },
41
41
  red: {
42
42
  // fill: colors.red[500],
@@ -53,19 +53,19 @@ export const ElementColors = {
53
53
  hiContrast: '#FBD3CB',
54
54
  // hiContrast: '#f8fafc',
55
55
  // loContrast: '#fdd8d8' // radix black red 12
56
- loContrast: '#f5b2a3'
56
+ loContrast: '#f5b2a3',
57
57
  },
58
58
  green: {
59
59
  fill: '#428a4f',
60
60
  stroke: '#2d5d39',
61
61
  hiContrast: '#f8fafc',
62
- loContrast: '#c2f0c2'
62
+ loContrast: '#c2f0c2',
63
63
  },
64
64
  amber: {
65
65
  fill: '#A35829',
66
66
  stroke: '#7E451D',
67
67
  hiContrast: '#FFE0C2',
68
- loContrast: '#f9b27c'
68
+ loContrast: '#f9b27c',
69
69
  },
70
70
  indigo: {
71
71
  // fill: colors.indigo[500],
@@ -75,6 +75,6 @@ export const ElementColors = {
75
75
  fill: '#6366f1',
76
76
  stroke: '#4f46e5',
77
77
  hiContrast: '#eef2ff',
78
- loContrast: '#c7d2fe'
79
- }
78
+ loContrast: '#c7d2fe',
79
+ },
80
80
  } as const satisfies ElementThemeColors