From a11b3532a07a3afa435f7b62a61257f9ba1e2fce Mon Sep 17 00:00:00 2001 From: Lauri Rooden Date: Mon, 6 Jan 2025 00:56:33 +0200 Subject: [PATCH] Make sheet with min options --- dom.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dom.js b/dom.js index c8a8b6b..c0b80e3 100644 --- a/dom.js +++ b/dom.js @@ -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)))