This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (120 loc) · 4.04 KB
/
index.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// @ts-check
const req = require
/** @type { import('windicss/plugin')['default'] } */
const plugin = req('windicss/plugin')
module.exports = plugin(({ addUtilities, addDynamic, theme }) => {
addUtilities({
'.dir-rtl': {
direction: 'rtl',
},
'.dir-ltr': {
direction: 'ltr',
},
})
addUtilities({
'.text-start': {
textAlign: 'start',
},
'.text-end': {
textAlign: 'end',
},
})
createDynamicLogicalSpacing('ms', ['-webkit-margin-start', 'margin-inline-start'], theme('margin'))
createDynamicLogicalSpacing('me', ['-webkit-margin-end', 'margin-inline-end'], theme('margin'))
createDynamicLogicalSpacingWithoutNegative('ps', ['-webkit-padding-start', 'padding-inline-start'], theme('padding'))
createDynamicLogicalSpacingWithoutNegative('pe', ['-webkit-padding-end', 'padding-inline-end'], theme('padding'))
createDynamicLogicalSpacing('start', ['inset-inline-start'], theme('inset'))
createDynamicLogicalSpacing('end', ['inset-inline-end'], theme('inset'))
createDynamicRounded('rounded-s', ['border-start-start-radius', 'border-end-start-radius'])
createDynamicRounded('rounded-e', ['border-start-end-radius', 'border-end-end-radius'])
createDynamicRounded('rounded-te', 'border-start-end-radius')
createDynamicRounded('rounded-be', 'border-end-end-radius')
createDynamicRounded('rounded-ts', 'border-start-start-radius')
createDynamicRounded('rounded-bs', 'border-end-start-radius')
/**
* @param {string} className
* @param {string | string[]} prop
* @param {any} themeValues
*/
function createDynamicLogicalSpacing(className, prop, themeValues) {
addDynamic(className, ({ Utility }) => {
return Utility.handler
.handleStatic(themeValues)
.handleSquareBrackets()
.handleSpacing()
.handleFraction()
.handleSize()
.handleNegative()
.handleVariable()
.createProperty(prop)
}, {
group: 'logical',
completions: [
...Object.keys(themeValues),
// eslint-disable-next-line no-template-curly-in-string
'${var}',
'{value}',
'[value]',
].map(k => k[0] === '-' ? `-${className}-${k.substring(1)}` : `${className}-${k}`),
})
}
/**
* @param {string} className
* @param {string | string[]} prop
* @param {any} themeValues
*/
function createDynamicLogicalSpacingWithoutNegative(className, prop, themeValues) {
addDynamic(className, ({ Utility }) => {
return Utility.handler
.handleStatic(themeValues)
.handleSquareBrackets()
.handleSpacing()
.handleFraction()
.handleSize()
.handleVariable()
.createProperty(prop)
}, {
group: 'logical',
completions: [
...Object.keys(themeValues),
// eslint-disable-next-line no-template-curly-in-string
'${var}',
'{value}',
'[value]',
].map(k => k[0] === '-' ? `-${className}-${k.substring(1)}` : `${className}-${k}`),
})
}
/**
* @param {string} className
* @param {string | string[]} prop
*/
function createDynamicRounded(className, prop) {
const themeValues = theme('borderRadius')
const defaultRoundeds = ['rounded-s', 'rounded-e', 'rounded-ts', 'rounded-te', 'rounded-bs', 'rounded-be']
addDynamic(className, ({ Utility }) => {
const raw = defaultRoundeds.includes(Utility.raw) ? Utility.raw + '-DEFAULT' : Utility.raw
return Utility.clone(raw).handler
.handleStatic(themeValues)
.handleSquareBrackets()
.handleFraction()
.handleNxl(n => (n * 0.5) + 'rem')
.handleSize()
.handleVariable()
.createProperty(prop)
}, {
group: 'logical',
completions: [
...Object.keys(themeValues),
// eslint-disable-next-line no-template-curly-in-string
'${var}',
'{value}',
'[value]',
'Nxl',
].map(k =>
k === 'DEFAULT' ? `${className}` :
k[0] === '-' ? `-${className}-${k.substring(1)}` :
`${className}-${k}`
),
})
}
})