Skip to content

Commit 7c54cfa

Browse files
committed
fix: fix UI styles
1 parent 59c57d8 commit 7c54cfa

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/app/src/assets/css/main.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@import "@nuxt/ui";
33
@plugin "@tailwindcss/typography";
44

5-
@source "@farnabaz/mdc-editor";
65
@source "../../**";
76

87
@source inline('ring-orange-200 hover:ring-orange-300 hover:dark:ring-orange-700');

src/app/src/main.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import styles from './assets/css/main.css?inline'
77

88
import { createHead } from '@unhead/vue/client'
99
import { generateColors, tailwindColors } from './utils/colors'
10+
import { refineTailwindStyles } from './utils/styles.ts'
1011

1112
import App from './app.vue'
1213
import Content from './pages/content.vue'
@@ -53,9 +54,7 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
5354
styles: [
5455
tailwindColors,
5556
generateColors(),
56-
styles.replace(/:root/g, ':host')
57-
.replace(/([^-])html/g, '$1:host')
58-
.replace(/([^-])body/g, '$1:host'),
57+
refineTailwindStyles(styles),
5958
],
6059
},
6160
) as VueElementConstructor

src/app/src/utils/styles.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export function refineTailwindStyles(styles: string) {
2+
styles = convertPropertyToVar(styles)
3+
// Replace :root, html, and body with :host
4+
styles = styles.replace(/:root/g, ':host')
5+
.replace(/([^-])html/g, '$1:host')
6+
.replace(/([^-])body/g, '$1:host')
7+
8+
return styles
9+
}
10+
11+
export function convertPropertyToVar(cssText: string) {
12+
const propertyRegex = /@property\s+(--[\w-]+)\s*\{([^}]*)\}/g
13+
const cssVars: string[] = []
14+
15+
const result = cssText.replace(propertyRegex, (_, propertyName, propertyContent) => {
16+
const initialValueMatch = propertyContent.match(/initial-value\s*:([^;]+)(;|$)/)
17+
18+
if (initialValueMatch) {
19+
let initialValue = initialValueMatch[1].trim()
20+
21+
if (propertyContent.includes('<length>') && !initialValue.endsWith('px')) {
22+
initialValue = `${initialValue}px`
23+
}
24+
25+
cssVars.push(`${propertyName}: ${initialValue};`)
26+
}
27+
28+
return ''
29+
})
30+
31+
const cssVarsBlock = cssVars.length > 0 ? `:host {\n ${cssVars.join('\n ')}\n}` : ''
32+
33+
return cssVarsBlock + (cssVarsBlock && result.trim() ? '\n\n' : '') + result.trim()
34+
}

0 commit comments

Comments
 (0)