@likec4/config 1.40.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.
- package/dist/index.d.mts +2183 -1400
- package/dist/index.mjs +1 -1
- package/dist/node/index.d.mts +5 -1
- package/dist/node/index.mjs +10 -6
- package/dist/shared/config.C9KUVBb7.mjs +307 -0
- package/node/package.json +4 -0
- package/package.json +18 -15
- package/schema.json +532 -1
- package/src/define-config.ts +83 -3
- package/src/index.ts +9 -0
- package/src/node/load-config.ts +8 -4
- package/src/schema.image-alias.ts +1 -1
- package/src/schema.theme.ts +249 -0
- package/src/schema.ts +17 -7
- package/dist/shared/config.BgYO9fOn.mjs +0 -3251
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ColorLiteral,
|
|
3
|
+
type ElementColorValues,
|
|
4
|
+
type RelationshipColorValues,
|
|
5
|
+
type ThemeColor,
|
|
6
|
+
type ThemeColorValues,
|
|
7
|
+
BorderStyles,
|
|
8
|
+
computeColorValues,
|
|
9
|
+
ElementShapes,
|
|
10
|
+
RelationshipArrowTypes,
|
|
11
|
+
Sizes,
|
|
12
|
+
ThemeColors,
|
|
13
|
+
} from '@likec4/core/styles'
|
|
14
|
+
import {
|
|
15
|
+
type LikeC4ProjectStyleDefaults,
|
|
16
|
+
type LikeC4ProjectStylesConfig,
|
|
17
|
+
type LikeC4ProjectTheme,
|
|
18
|
+
exact,
|
|
19
|
+
} from '@likec4/core/types'
|
|
20
|
+
import { fromKeys } from 'remeda'
|
|
21
|
+
import z from 'zod/v4'
|
|
22
|
+
|
|
23
|
+
const opacity = z
|
|
24
|
+
.number()
|
|
25
|
+
.min(0, 'Opacity must be between 0 and 100')
|
|
26
|
+
.max(100, 'Opacity must be between 0 and 100')
|
|
27
|
+
.meta({
|
|
28
|
+
id: 'Opacity',
|
|
29
|
+
description: 'Opacity 0%-100%',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const shape = z.literal(ElementShapes).meta({
|
|
33
|
+
id: 'ElementShape',
|
|
34
|
+
description: 'Element shape',
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const border = z.literal(BorderStyles).meta({
|
|
38
|
+
id: 'BorderStyle',
|
|
39
|
+
description: 'Border style',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const size = z.literal(Sizes).meta({
|
|
43
|
+
id: 'ElementSize',
|
|
44
|
+
description: 'Element size',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const arrow = z.literal(RelationshipArrowTypes).meta({
|
|
48
|
+
id: 'ArrowType',
|
|
49
|
+
description: 'Relationship arrow type',
|
|
50
|
+
})
|
|
51
|
+
const line = z
|
|
52
|
+
.literal(['dashed', 'solid', 'dotted'])
|
|
53
|
+
.meta({
|
|
54
|
+
id: 'LineType',
|
|
55
|
+
description: 'Default line type for relationships',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const themeColor = z.literal(ThemeColors).meta({
|
|
59
|
+
id: 'ThemeColor',
|
|
60
|
+
description: 'Reserved theme color name',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const color = z.union([
|
|
64
|
+
themeColor,
|
|
65
|
+
z.string().nonempty('Color name cannot be empty'),
|
|
66
|
+
])
|
|
67
|
+
.transform(value => value as ThemeColor)
|
|
68
|
+
.meta({
|
|
69
|
+
id: 'ColorName',
|
|
70
|
+
description: 'Color name (Theme color name or custom color name)',
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const colorValue = z
|
|
74
|
+
.string()
|
|
75
|
+
.nonempty('Color value cannot be empty')
|
|
76
|
+
.transform(value => value as ColorLiteral)
|
|
77
|
+
.meta({
|
|
78
|
+
id: 'ColorLiteral',
|
|
79
|
+
description: 'Color value in any valid CSS format: hex, rgb, rgba, hsl, hsla ...',
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// const ColorSchema = z.union([ColorValue, LightDarkTuple])
|
|
83
|
+
const colorSchema = colorValue
|
|
84
|
+
// type ColorValue = z.infer<typeof colorSchema>
|
|
85
|
+
|
|
86
|
+
const ElementColorValuesSchema = z
|
|
87
|
+
.object({
|
|
88
|
+
fill: colorSchema.meta({ description: 'Background color' }),
|
|
89
|
+
stroke: colorSchema.meta({ description: 'Stroke color (border, paths above background)' }),
|
|
90
|
+
hiContrast: colorSchema.meta({ description: 'High contrast text color (title)' }),
|
|
91
|
+
loContrast: colorSchema.meta({ description: 'Low contrast text color (description)' }),
|
|
92
|
+
})
|
|
93
|
+
.meta({
|
|
94
|
+
id: 'ElementColorValues',
|
|
95
|
+
description: 'Specific element colors',
|
|
96
|
+
})
|
|
97
|
+
.transform(value => value as ElementColorValues)
|
|
98
|
+
|
|
99
|
+
const RelationshipColorValuesSchema = z
|
|
100
|
+
.object({
|
|
101
|
+
line: colorSchema.meta({ description: 'Line color' }),
|
|
102
|
+
label: colorSchema.meta({ description: 'Label text color' }),
|
|
103
|
+
labelBg: colorSchema
|
|
104
|
+
.optional()
|
|
105
|
+
.default('rgba(0, 0, 0, 0)')
|
|
106
|
+
.meta({ description: 'Label background color' }),
|
|
107
|
+
})
|
|
108
|
+
.meta({
|
|
109
|
+
id: 'RelationshipColorValues',
|
|
110
|
+
description: 'Specefic relationship colors',
|
|
111
|
+
})
|
|
112
|
+
.transform(value => value as RelationshipColorValues)
|
|
113
|
+
|
|
114
|
+
export const ThemeColorValuesSchema = z
|
|
115
|
+
.union([
|
|
116
|
+
colorSchema,
|
|
117
|
+
z.object({
|
|
118
|
+
elements: z
|
|
119
|
+
.union([colorSchema, ElementColorValuesSchema])
|
|
120
|
+
.transform((value): ElementColorValues => {
|
|
121
|
+
if (typeof value === 'string') {
|
|
122
|
+
return computeColorValues(value).elements
|
|
123
|
+
}
|
|
124
|
+
return value
|
|
125
|
+
}),
|
|
126
|
+
relationships: z
|
|
127
|
+
.union([colorSchema, RelationshipColorValuesSchema])
|
|
128
|
+
.transform((value): RelationshipColorValues => {
|
|
129
|
+
if (typeof value === 'string') {
|
|
130
|
+
return computeColorValues(value).relationships
|
|
131
|
+
}
|
|
132
|
+
return value
|
|
133
|
+
}),
|
|
134
|
+
}),
|
|
135
|
+
])
|
|
136
|
+
.meta({
|
|
137
|
+
id: 'ThemeColorValues',
|
|
138
|
+
description: 'Exact value (hex, rgb, rgba, hsl, hsla ...) or break down of specific color values',
|
|
139
|
+
})
|
|
140
|
+
.transform((value): ThemeColorValues => {
|
|
141
|
+
if (typeof value === 'string') {
|
|
142
|
+
return computeColorValues(value)
|
|
143
|
+
}
|
|
144
|
+
return value
|
|
145
|
+
})
|
|
146
|
+
export type ThemeColorValuesInput = z.input<typeof ThemeColorValuesSchema>
|
|
147
|
+
|
|
148
|
+
const ThemeColorsSchema = z.union([
|
|
149
|
+
z.record(
|
|
150
|
+
color,
|
|
151
|
+
ThemeColorValuesSchema,
|
|
152
|
+
),
|
|
153
|
+
z.object(
|
|
154
|
+
fromKeys(ThemeColors, () => ThemeColorValuesSchema.optional()),
|
|
155
|
+
),
|
|
156
|
+
]).meta({
|
|
157
|
+
id: 'ThemeColors',
|
|
158
|
+
description: 'Override of theme colors',
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const DimensionsSchema = z.object({
|
|
162
|
+
width: z.number(),
|
|
163
|
+
height: z.number(),
|
|
164
|
+
}).meta({
|
|
165
|
+
id: 'Dimensions',
|
|
166
|
+
description: 'Dimensions',
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
export const LikeC4Config_Styles_Theme = z
|
|
170
|
+
.object({
|
|
171
|
+
colors: ThemeColorsSchema,
|
|
172
|
+
sizes: z
|
|
173
|
+
.object(fromKeys(Sizes, () => DimensionsSchema.optional()))
|
|
174
|
+
.meta({ description: 'Map of theme sizes.' }),
|
|
175
|
+
})
|
|
176
|
+
.partial()
|
|
177
|
+
.meta({
|
|
178
|
+
id: 'ThemeCustomization',
|
|
179
|
+
description: 'Theme customization',
|
|
180
|
+
})
|
|
181
|
+
.transform(({ colors, sizes }): LikeC4ProjectTheme => {
|
|
182
|
+
return exact({
|
|
183
|
+
colors: colors ? exact(colors) satisfies LikeC4ProjectTheme['colors'] : undefined,
|
|
184
|
+
sizes: sizes ? exact(sizes) satisfies LikeC4ProjectTheme['sizes'] : undefined,
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
export type LikeC4ConfigThemeInput = z.input<typeof LikeC4Config_Styles_Theme>
|
|
188
|
+
|
|
189
|
+
const LikeC4Config_Styles_Defaults = z
|
|
190
|
+
.object({
|
|
191
|
+
color,
|
|
192
|
+
opacity,
|
|
193
|
+
border,
|
|
194
|
+
size,
|
|
195
|
+
shape,
|
|
196
|
+
group: z.object({
|
|
197
|
+
color,
|
|
198
|
+
opacity,
|
|
199
|
+
border,
|
|
200
|
+
}).partial(),
|
|
201
|
+
relationship: z.object({
|
|
202
|
+
color,
|
|
203
|
+
line,
|
|
204
|
+
arrow,
|
|
205
|
+
}).partial(),
|
|
206
|
+
})
|
|
207
|
+
.partial()
|
|
208
|
+
.meta({
|
|
209
|
+
id: 'DefaultStyleValues',
|
|
210
|
+
description:
|
|
211
|
+
'Override default values for style properties\nThese values will be used if such property is not defined',
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
export const LikeC4StylesConfigSchema = z
|
|
215
|
+
.object({
|
|
216
|
+
theme: LikeC4Config_Styles_Theme,
|
|
217
|
+
defaults: LikeC4Config_Styles_Defaults,
|
|
218
|
+
// customCss: z
|
|
219
|
+
// .array(z.string())
|
|
220
|
+
// .meta({ description: 'List of custom CSS files' }),
|
|
221
|
+
})
|
|
222
|
+
.partial()
|
|
223
|
+
.meta({
|
|
224
|
+
id: 'StylesConfiguration',
|
|
225
|
+
description: 'Project styles customization',
|
|
226
|
+
})
|
|
227
|
+
.transform(({ theme, defaults }): LikeC4ProjectStylesConfig =>
|
|
228
|
+
exact({
|
|
229
|
+
defaults: normalizeDefaults(defaults),
|
|
230
|
+
theme,
|
|
231
|
+
})
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
export interface LikeC4StylesConfig extends z.infer<typeof LikeC4StylesConfigSchema> {}
|
|
235
|
+
export type LikeC4StylesConfigInput = z.input<typeof LikeC4StylesConfigSchema>
|
|
236
|
+
|
|
237
|
+
function normalizeDefaults(
|
|
238
|
+
defaults?: z.infer<typeof LikeC4Config_Styles_Defaults>,
|
|
239
|
+
): LikeC4ProjectStyleDefaults | undefined {
|
|
240
|
+
if (!defaults) {
|
|
241
|
+
return undefined
|
|
242
|
+
}
|
|
243
|
+
const { relationship, group, ...rest } = defaults
|
|
244
|
+
return exact({
|
|
245
|
+
...rest,
|
|
246
|
+
relationship: relationship && exact(relationship) as LikeC4ProjectStyleDefaults['relationship'],
|
|
247
|
+
group: group && exact(group) as LikeC4ProjectStyleDefaults['group'],
|
|
248
|
+
})
|
|
249
|
+
}
|
package/src/schema.ts
CHANGED
|
@@ -11,9 +11,11 @@ import type {
|
|
|
11
11
|
ProjectId,
|
|
12
12
|
} from '@likec4/core/types'
|
|
13
13
|
import JSON5 from 'json5'
|
|
14
|
+
import type { SimplifyDeep } from 'type-fest'
|
|
14
15
|
import type { URI } from 'vscode-uri'
|
|
15
|
-
import * as z from '
|
|
16
|
+
import * as z from 'zod/v4'
|
|
16
17
|
import { ImageAliasesSchema, validateImageAliases } from './schema.image-alias'
|
|
18
|
+
import { LikeC4StylesConfigSchema } from './schema.theme'
|
|
17
19
|
|
|
18
20
|
export const LikeC4ProjectJsonConfigSchema = z.object({
|
|
19
21
|
name: z.string()
|
|
@@ -26,7 +28,6 @@ export const LikeC4ProjectJsonConfigSchema = z.object({
|
|
|
26
28
|
abort: true,
|
|
27
29
|
error: 'Project name cannot contain ".", "@" or "#", try to use A-z, 0-9, _ and -',
|
|
28
30
|
})
|
|
29
|
-
.transform((value) => value as ProjectId)
|
|
30
31
|
.meta({ description: 'Project name, must be unique in the workspace' }),
|
|
31
32
|
title: z.string()
|
|
32
33
|
.nonempty('Project title cannot be empty if specified')
|
|
@@ -38,6 +39,8 @@ export const LikeC4ProjectJsonConfigSchema = z.object({
|
|
|
38
39
|
.meta({ description: 'A person who has been involved in creating or maintaining this project' }),
|
|
39
40
|
imageAliases: ImageAliasesSchema
|
|
40
41
|
.optional(),
|
|
42
|
+
styles: LikeC4StylesConfigSchema
|
|
43
|
+
.optional(),
|
|
41
44
|
exclude: z.array(z.string())
|
|
42
45
|
.optional()
|
|
43
46
|
.meta({ description: 'List of file patterns to exclude from the project, default is ["**/node_modules/**"]' }),
|
|
@@ -46,7 +49,7 @@ export const LikeC4ProjectJsonConfigSchema = z.object({
|
|
|
46
49
|
description: 'LikeC4 project configuration',
|
|
47
50
|
})
|
|
48
51
|
|
|
49
|
-
export type LikeC4ProjectJsonConfig = z.input<typeof LikeC4ProjectJsonConfigSchema
|
|
52
|
+
export type LikeC4ProjectJsonConfig = SimplifyDeep<z.input<typeof LikeC4ProjectJsonConfigSchema>>
|
|
50
53
|
|
|
51
54
|
const FunctionType = z.instanceof(Function)
|
|
52
55
|
export const GeneratorsSchema = z.record(z.string(), FunctionType)
|
|
@@ -172,7 +175,7 @@ export interface GeneratorFn {
|
|
|
172
175
|
* })
|
|
173
176
|
* ```
|
|
174
177
|
*/
|
|
175
|
-
export type LikeC4ProjectConfig = z.
|
|
178
|
+
export type LikeC4ProjectConfig = z.infer<typeof LikeC4ProjectJsonConfigSchema> & {
|
|
176
179
|
/**
|
|
177
180
|
* Add custom generators to the project
|
|
178
181
|
* @example
|
|
@@ -195,6 +198,12 @@ export type LikeC4ProjectConfig = z.input<typeof LikeC4ProjectJsonConfigSchema>
|
|
|
195
198
|
generators?: Record<string, GeneratorFn> | undefined
|
|
196
199
|
}
|
|
197
200
|
|
|
201
|
+
export type LikeC4ProjectConfigInput = SimplifyDeep<
|
|
202
|
+
z.input<typeof LikeC4ProjectJsonConfigSchema> & {
|
|
203
|
+
generators?: Record<string, GeneratorFn> | undefined
|
|
204
|
+
}
|
|
205
|
+
>
|
|
206
|
+
|
|
198
207
|
/**
|
|
199
208
|
* Validates JSON string or JSON object into a LikeC4ProjectConfig object.
|
|
200
209
|
*/
|
|
@@ -218,8 +227,9 @@ export function validateProjectConfig<C extends string | Record<string, unknown>
|
|
|
218
227
|
* Converts a LikeC4ProjectConfig object into a LikeC4ProjectJsonConfig object.
|
|
219
228
|
* Omit generators property (as it is not serializable)
|
|
220
229
|
*/
|
|
221
|
-
export function serializableLikeC4ProjectConfig(
|
|
222
|
-
|
|
223
|
-
|
|
230
|
+
export function serializableLikeC4ProjectConfig({
|
|
231
|
+
generators: _, // omit
|
|
232
|
+
...config
|
|
233
|
+
}: LikeC4ProjectConfig): LikeC4ProjectJsonConfig {
|
|
224
234
|
return LikeC4ProjectJsonConfigSchema.parse(config) as unknown as LikeC4ProjectJsonConfig
|
|
225
235
|
}
|