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 } })
|
||||
const cssmap = {}
|
||||
|
||||
|
||||
export function css(strings, values = []) {
|
||||
export function css(strings, ...values) {
|
||||
let str = ''
|
||||
for (let f of strings) {
|
||||
str += f + (values.shift() || '')
|
||||
|
@ -21,26 +20,24 @@ 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 = "";
|
||||
styleElement.textContent = str
|
||||
let newstr = ''
|
||||
let selfstr = ''
|
||||
while (!styleElement.sheet.cssRules.length) {
|
||||
let [first, ...rest] = str.split("\n");
|
||||
selfstr += first + "\n";
|
||||
str = rest.join("\n");
|
||||
styleElement.textContent = str;
|
||||
let [first, ...rest] = str.split('\n')
|
||||
selfstr += first + '\n'
|
||||
str = rest.join('\n')
|
||||
styleElement.textContent = str
|
||||
}
|
||||
|
||||
|
||||
for (const rule of styleElement.sheet.cssRules) {
|
||||
rule.selectorText = `.${uid} ${rule.selectorText}`
|
||||
newstr += rule.cssText + "\n";
|
||||
newstr += rule.cssText + '\n'
|
||||
}
|
||||
|
||||
styleElement.textContent = `.${uid} {${selfstr}}` + "\n" + newstr;
|
||||
console.log(styleElement.textContent);
|
||||
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