mirror of
https://github.com/MercuryWorkshop/dreamlandjs.git
synced 2025-05-15 15:10:02 -04:00
zoopers
This commit is contained in:
parent
22b8abf97e
commit
f6367de472
1 changed files with 11 additions and 14 deletions
25
src/css.js
25
src/css.js
|
@ -1,8 +1,7 @@
|
||||||
Object.assign(window, { css, styled: { new: css, rule: css } })
|
Object.assign(window, { css, styled: { new: css, rule: css } })
|
||||||
const cssmap = {}
|
const cssmap = {}
|
||||||
|
|
||||||
|
export function css(strings, ...values) {
|
||||||
export function css(strings, values = []) {
|
|
||||||
let str = ''
|
let str = ''
|
||||||
for (let f of strings) {
|
for (let f of strings) {
|
||||||
str += f + (values.shift() || '')
|
str += f + (values.shift() || '')
|
||||||
|
@ -21,26 +20,24 @@ export function css(strings, values = []) {
|
||||||
const styleElement = document.createElement('style')
|
const styleElement = document.createElement('style')
|
||||||
document.head.appendChild(styleElement)
|
document.head.appendChild(styleElement)
|
||||||
|
|
||||||
|
|
||||||
// kind of a hack. when css nesting stablizes this can be removed
|
// kind of a hack. when css nesting stablizes this can be removed
|
||||||
styleElement.textContent = str;
|
styleElement.textContent = str
|
||||||
let newstr = "";
|
let newstr = ''
|
||||||
let selfstr = "";
|
let selfstr = ''
|
||||||
while (!styleElement.sheet.cssRules.length) {
|
while (!styleElement.sheet.cssRules.length) {
|
||||||
let [first, ...rest] = str.split("\n");
|
let [first, ...rest] = str.split('\n')
|
||||||
selfstr += first + "\n";
|
selfstr += first + '\n'
|
||||||
str = rest.join("\n");
|
str = rest.join('\n')
|
||||||
styleElement.textContent = str;
|
styleElement.textContent = str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (const rule of styleElement.sheet.cssRules) {
|
for (const rule of styleElement.sheet.cssRules) {
|
||||||
rule.selectorText = `.${uid} ${rule.selectorText}`
|
rule.selectorText = `.${uid} ${rule.selectorText}`
|
||||||
newstr += rule.cssText + "\n";
|
newstr += rule.cssText + '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
styleElement.textContent = `.${uid} {${selfstr}}` + "\n" + newstr;
|
styleElement.textContent = `.${uid} {${selfstr}}` + '\n' + newstr
|
||||||
console.log(styleElement.textContent);
|
console.log(styleElement.textContent)
|
||||||
|
|
||||||
cssmap[str] = uid
|
cssmap[str] = uid
|
||||||
return uid
|
return uid
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue