Skip to content

Commit

Permalink
Make sheet with min options
Browse files Browse the repository at this point in the history
lauriro committed Jan 6, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent cac6c98 commit a11b353
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions dom.js
Original file line number Diff line number Diff line change
@@ -111,10 +111,7 @@ var boolAttrs = {
this.parentNode.replaceChild(frag, this)
},
get sheet() {
if (this.tagName === "STYLE" || this.tagName === "LINK" && this.rel === "stylesheet" && this.href) return new CSSStyleSheet({
href: this.href,
ownerNode: this
}, this.tagName === "STYLE" && this.textContent)
return makeSheet(this)
},
get style() {
return this._style || (this._style = CSSStyleDeclaration(this.getAttribute("style") || ""))
@@ -187,7 +184,7 @@ var boolAttrs = {
},
toString(min) {
return rawTextElements[this.tagName] ? (
this.tagName === "STYLE" && (min === true || min && min.css) ? "\n" + this.sheet.toString(min.css || true) + "\n" :
this.tagName === "STYLE" && (min === true || min && min.css) ? "\n" + makeSheet(this, min.css || true) + "\n" :
this.textContent
) : this.childNodes.map(node => node.toString(min)).join("")
}
@@ -491,6 +488,14 @@ function getSibling(node, step, type) {
return type > 0 ? getElement(silbings, index + step, step, type) : silbings && silbings[index + step] || null
}

function makeSheet(el, min) {
if (el.tagName === "STYLE" || el.tagName === "LINK" && el.rel === "stylesheet" && el.href) return new CSSStyleSheet({
href: el.href,
ownerNode: el,
min
}, el.tagName === "STYLE" && el.textContent)
}

function mergeAttributes(source, target) {
if (source && target && source.attributes) {
source.attributes.names().forEach(attr => target.setAttribute(attr, source.getAttribute(attr)))

0 comments on commit a11b353

Please sign in to comment.