-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.ts
103 lines (87 loc) · 2.09 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
export type SupportedLang = 'css' | 'js' | 'sass' | 'scss' | 'less' | 'stylus' | 'json'
interface TransformBaseParams {
/**
* The user preferences related to code transformation
* @example { useRem: true, rootFontSize: 16 }
*/
options: {
useRem: boolean
rootFontSize: number
}
}
interface TransformParams extends TransformBaseParams {
/**
* The generated CSS code
* @example 'background-color: red; color: blue;'
*/
code: string
/**
* The parsed CSS properties
* @example { 'background-color': 'red', 'color': 'blue' }
*/
style: Record<string, string>
}
interface TransformVariableParams extends TransformBaseParams {
/**
* The generated CSS variable code
* @example 'var(--color-primary, #6699cc)'
*/
code: string
/**
* The variable name
* @example 'color-primary'
*/
name: string
/**
* The variable value
* @example '#6699cc'
*/
value?: string
}
interface TransformPxParams extends TransformBaseParams {
/**
* The length value
* @example 16
*/
value: number
}
export type TransformOptions = {
/**
* The language of the code block for syntax highlighting
* @example 'scss'
*/
lang?: SupportedLang
/**
* Transform the generated CSS code
*/
transform?: (params: TransformParams) => string
/**
* Transform the generated CSS variable code
* @example 'var(--kui-color-primary, #6699cc)' -> '$ui-color-primary'
*/
transformVariable?: (params: TransformVariableParams) => string
/**
* Transform the pixel value to the desired unit and scale
* @example 16 -> '1rem'
*/
transformPx?: (params: TransformPxParams) => string
}
export type CodeBlockOptions =
| (TransformOptions & {
/**
* The title of the code block
* @example 'SCSS'
*/
title?: string
})
| false
type BuiltInCodeBlock = 'css' | 'js'
type CodeOptions = Partial<Record<BuiltInCodeBlock, CodeBlockOptions>> &
Record<string, CodeBlockOptions>
export type Plugin = {
name: string
code: CodeOptions
}
export function definePlugin(plugin: Plugin): Plugin {
return plugin
}