-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.ts
More file actions
37 lines (29 loc) · 905 Bytes
/
Copy pathutils.ts
File metadata and controls
37 lines (29 loc) · 905 Bytes
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
import css from 'css'
import bulmaCSS from 'bulma/css/bulma.css'
export const getBulmaCSSContent = () => {
return css.parse(bulmaCSS)
}
export const getDeclaration = (css: css.Stylesheet, className: string) => {
const declaration = css.stylesheet!.rules!.find(
(rule) => rule.type === 'rule' && rule.selectors.includes(`.${className}`)
) as css.Rule
if (declaration.selectors.length > 1) {
declaration.selectors = [`.${className}`]
}
return declaration
}
export const isValidSelector = (css: css.Stylesheet, selector: string) => {
const isValid = css.stylesheet!.rules!.some(
(rule) => rule.type === 'rule' && rule.selectors.includes(`.${selector}`)
)
return isValid
}
export const getStringFromCSS = (declaration: css.Rule) => {
const cssString = css.stringify({
type: 'stylesheet',
stylesheet: {
rules: [declaration]
}
})
return cssString
}