@litejs/dom 26.4.0 → 26.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css.js +34 -16
- package/dom.js +3 -0
- package/package.json +2 -2
package/css.js
CHANGED
|
@@ -19,10 +19,12 @@ var URL = global.URL || require("url").URL
|
|
|
19
19
|
, vars = opts && opts.var ? {} : null
|
|
20
20
|
, varFn = vars && function(_, n) { return vars[n] || _ }
|
|
21
21
|
return Array.prototype.map.call(rules, rule => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
var sel = rule.selectorText
|
|
23
|
+
, style = rule.style
|
|
24
|
+
if (vars && sel === ":root") {
|
|
25
|
+
if (style) for (var i = 0; i < style.length; i++) {
|
|
26
|
+
var n = style[i]
|
|
27
|
+
if (n.slice(0, 2) === "--") vars[n] = style[n].replace(varRe, varFn)
|
|
26
28
|
}
|
|
27
29
|
return ""
|
|
28
30
|
}
|
|
@@ -40,8 +42,8 @@ var URL = global.URL || require("url").URL
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
// Handle plugins on style rules
|
|
43
|
-
if (
|
|
44
|
-
for (var
|
|
45
|
+
if (style && style._plugins) {
|
|
46
|
+
for (var j = 0; j < style._plugins.length; j++) {
|
|
45
47
|
var idx = style._plugins[j][0]
|
|
46
48
|
, pn = style._plugins[j][1]
|
|
47
49
|
, k = style[idx]
|
|
@@ -49,7 +51,12 @@ var URL = global.URL || require("url").URL
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
if (opts && opts.used && sel) {
|
|
55
|
+
sel = filterSelectors(sel, opts.used)
|
|
56
|
+
if (!sel) return ""
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var text = clear(opts && style && style.__ ? sel + "{" + cssText(style, opts.prefix) + "}" : rule.cssText)
|
|
53
60
|
if (!text || /\{\s*\}$/.test(text)) return ""
|
|
54
61
|
if (vars) text = text.replace(varRe, (_, v, fb) => vars[v] || fb || _)
|
|
55
62
|
if (opts && opts.color) text = text.replace(colorRe, colorFn)
|
|
@@ -58,6 +65,16 @@ var URL = global.URL || require("url").URL
|
|
|
58
65
|
}).filter(Boolean).join("\n")
|
|
59
66
|
}
|
|
60
67
|
}
|
|
68
|
+
, filterSelectors = (text, used) => {
|
|
69
|
+
var classes = used.classes
|
|
70
|
+
, keep = used.keep
|
|
71
|
+
return require("./selector.js").selectorSplit(text).filter(sel => {
|
|
72
|
+
for (var m, classRe = /\.([-\w]+)/g; (m = classRe.exec(sel)); ) {
|
|
73
|
+
if (!(classes && classes.has(m[1]) || keep && keep.test(m[1]))) return false
|
|
74
|
+
}
|
|
75
|
+
return true
|
|
76
|
+
}).join(",")
|
|
77
|
+
}
|
|
61
78
|
, toUrl = (dir) => new URL((dir || ".").replace(/\/+$/, "") + "/", "file:///").href
|
|
62
79
|
, read = (root, url, baseURI, enc = "utf8") => require("fs").readFileSync(
|
|
63
80
|
new URL(url, new URL((baseURI || ".") + "/", new URL((root || ".").replace(/\/+$/, "") + "/", "file:///" + process.cwd() + "/"))).pathname.replace(/^\/(?=\w:)|[+#].*/, ""),
|
|
@@ -114,17 +131,18 @@ var URL = global.URL || require("url").URL
|
|
|
114
131
|
, toRgba = (rgbHex, alpha) => ("rgba(" + rgbHex.replace(/../g, x => parseInt(x, 16)+",") + alpha + ")").replace("0.", ".")
|
|
115
132
|
, colorRe = /\b(rgb|hsl)a?\s*\(\s*(\d+)(?:deg)?[\s,]+(\d+)[\s,%]+(\d+)%?(?:[\s,\/]+(0?\.?\d+)(%?))?\s*\)/g
|
|
116
133
|
, colorFn = (_, name, a, b, c, d, p) => (_ = toRgb[name](a, b, c), (p ? d/=100 : d) < 1 ? toRgba(_, d) : "#" + _.replace(/(\w)\1(\w)\2(\w)\3/, "$1$2$3"))
|
|
134
|
+
, cssText = (style, prefix) => {
|
|
135
|
+
for (var out = [], name, value, i = style.length; i--; ) {
|
|
136
|
+
name = style[i]
|
|
137
|
+
value = style.__[i] || style[name]
|
|
138
|
+
out[i] = name + ":" + value
|
|
139
|
+
if (prefix && prefix[name]) out[i] = prefix[name].join(out[i] + ";") + out[i] + ";" + out[i]
|
|
140
|
+
}
|
|
141
|
+
return out.join(";")
|
|
142
|
+
}
|
|
117
143
|
, styleHandler = {
|
|
118
144
|
get(style, prop) {
|
|
119
|
-
|
|
120
|
-
for (var out = [], name, value, i = style.length; i--; ) {
|
|
121
|
-
name = style[i]
|
|
122
|
-
value = style.__[i] || style[name]
|
|
123
|
-
out[i] = name + ":" + value
|
|
124
|
-
}
|
|
125
|
-
return out.join(";")
|
|
126
|
-
}
|
|
127
|
-
return style[prop] || ""
|
|
145
|
+
return prop === "cssText" ? cssText(style) : style[prop] || ""
|
|
128
146
|
},
|
|
129
147
|
set(style, prop, val) {
|
|
130
148
|
if (prop === "cssText") {
|
package/dom.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/dom",
|
|
3
|
-
"version": "26.4.
|
|
3
|
+
"version": "26.4.1",
|
|
4
4
|
"description": "A small DOM library for server-side testing, rendering, and handling of HTML files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lauri Rooden <lauri@rooden.ee>",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"url": "https://github.com/litejs/dom.git"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@litejs/cli": "26.
|
|
32
|
+
"@litejs/cli": "26.4.0"
|
|
33
33
|
}
|
|
34
34
|
}
|