Skip to content

Commit fd9a954

Browse files
committed
Make sheet with min options
1 parent 956ab33 commit fd9a954

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

dom.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ var boolAttrs = {
111111
this.parentNode.replaceChild(frag, this)
112112
},
113113
get sheet() {
114-
if (this.tagName === "STYLE" || this.tagName === "LINK" && this.rel === "stylesheet" && this.href) return new CSSStyleSheet({
115-
href: this.href,
116-
ownerNode: this
117-
}, this.tagName === "STYLE" && this.textContent)
114+
return makeSheet(this)
118115
},
119116
get style() {
120117
return this._style || (this._style = CSSStyleDeclaration(this.getAttribute("style") || ""))
@@ -187,7 +184,7 @@ var boolAttrs = {
187184
},
188185
toString(min) {
189186
return rawTextElements[this.tagName] ? (
190-
this.tagName === "STYLE" && (min === true || min && min.css) ? "\n" + this.sheet.toString(min.css || true) + "\n" :
187+
this.tagName === "STYLE" && (min === true || min && min.css) ? "\n" + makeSheet(this, min.css || true) + "\n" :
191188
this.textContent
192189
) : this.childNodes.map(node => node.toString(min)).join("")
193190
}
@@ -491,6 +488,14 @@ function getSibling(node, step, type) {
491488
return type > 0 ? getElement(silbings, index + step, step, type) : silbings && silbings[index + step] || null
492489
}
493490

491+
function makeSheet(el, min) {
492+
if (el.tagName === "STYLE" || el.tagName === "LINK" && el.rel === "stylesheet" && el.href) return new CSSStyleSheet({
493+
href: el.href,
494+
ownerNode: el,
495+
min
496+
}, el.tagName === "STYLE" && el.textContent)
497+
}
498+
494499
function mergeAttributes(source, target) {
495500
if (source && target && source.attributes) {
496501
source.attributes.names().forEach(attr => target.setAttribute(attr, source.getAttribute(attr)))

test/css.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ describe("css.js {0}", describe.env === "browser" ? [["mock", exports], ["native
5050
})
5151

5252
test("color {i} '{1}'", [
53-
[ {}, ".a{color:rgb(255 0 153)}.b{color:rgb( 0 1 2 )}", ".a{color:rgb(255 0 153)}\n.b{color:rgb( 0 1 2 )}"],
53+
[ ".a{color:rgb(255 0 153)}.b{color:rgb( 0 1 2 )}", ".a{color:rgb(255 0 153)}\n.b{color:rgb( 0 1 2 )}"],
54+
], (text, expected, assert) => {
55+
const sheet = new CSSStyleSheet()
56+
sheet.replaceSync(text)
57+
assert.equal(sheet.toString(true), expected).end()
58+
})
59+
60+
test("color {i} '{1}'", [
5461
[ { color: true }, ".a{color:rgb(255,0,153)}.b{color:rgb( 0 1 2 )}", ".a{color:#f09}\n.b{color:#000102}"],
5562
[ { color: true }, ".a{color:hsl(0 0% 0%)}", ".a{color:#000}"],
5663
[ { color: true }, ".a{color:hsl(0 0% 100%)}", ".a{color:#fff}"],

test/parser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ describe("parser", () => {
8787
assert.end()
8888
})
8989

90+
test("svg void elements", assert => {
91+
var document = parser.parseFromString("<svg xmlns='http://www.w3.org/2000/svg'></svg>", "application/xml")
92+
document.documentElement.innerHTML = "<path d='m1'></path>"
93+
assert.equal(document.toString(true), '<svg xmlns="http://www.w3.org/2000/svg"><path d="m1"/></svg>')
94+
assert.end()
95+
})
96+
9097
test("document.title", assert => {
9198
var document = parser.parseFromString("<h1>Hi</h1>")
9299
assert.equal(document.querySelector("title"), null)

0 commit comments

Comments
 (0)