mirror of
https://github.com/MercuryWorkshop/dreamlandjs.git
synced 2025-05-15 07:10:00 -04:00
fix css parser
This commit is contained in:
parent
bd347052e9
commit
4fff09eebf
5 changed files with 19 additions and 16 deletions
15
src/css.js
15
src/css.js
|
@ -19,17 +19,19 @@ export function css(strings, ...values) {
|
|||
const styleElement = document.createElement('style')
|
||||
document.head.appendChild(styleElement)
|
||||
|
||||
// kind of a hack. when css nesting stablizes this can be removed
|
||||
styleElement.textContent = str
|
||||
let newstr = ''
|
||||
let selfstr = ''
|
||||
while (!styleElement.sheet.cssRules.length) {
|
||||
let [first, ...rest] = str.split('\n');
|
||||
if (!first) break;
|
||||
|
||||
// compat layer for older browsers. when css nesting stablizes this can be removed
|
||||
for (; ;) {
|
||||
let [first, ...rest] = str.split('\n')
|
||||
if (first.trim().endsWith('{')) break;
|
||||
|
||||
selfstr += first + '\n'
|
||||
str = rest.join('\n')
|
||||
styleElement.textContent = str
|
||||
}
|
||||
styleElement.textContent = str
|
||||
|
||||
|
||||
for (const rule of styleElement.sheet.cssRules) {
|
||||
rule.selectorText = `.${uid} ${rule.selectorText}`
|
||||
|
@ -37,6 +39,7 @@ export function css(strings, ...values) {
|
|||
}
|
||||
|
||||
styleElement.textContent = `.${uid} {${selfstr}}` + '\n' + newstr
|
||||
console.log(styleElement.textContent)
|
||||
|
||||
cssmap[str] = uid
|
||||
return uid
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue