Fix: Css custom properties #33
This commit is contained in:
21
package.json
21
package.json
@@ -14,13 +14,20 @@
|
|||||||
"utilDoc": "eustia doc src/lib/util.js -f md -o doc/UTIL_API.md -t \"Eruda Util Documentation\""
|
"utilDoc": "eustia doc src/lib/util.js -f md -o doc/UTIL_API.md -t \"Eruda Util Documentation\""
|
||||||
},
|
},
|
||||||
"eustia": {
|
"eustia": {
|
||||||
"files": "src/**/*.es6",
|
"eruda": {
|
||||||
"ignore": "**/Info/defInfo.es6",
|
"files": "src/**/*.es6",
|
||||||
"output": "src/lib/util.js",
|
"ignore": "**/Info/defInfo.es6",
|
||||||
"exclude": [
|
"output": "src/lib/util.js",
|
||||||
"createCfg"
|
"exclude": [
|
||||||
],
|
"createCfg"
|
||||||
"format": "commonjs"
|
],
|
||||||
|
"format": "commonjs"
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"files": ["test/**/*.js", "test/**/*.html"],
|
||||||
|
"output": "test/util.js",
|
||||||
|
"format": "global"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -355,6 +355,9 @@ let regColor = /rgba?\((.*?)\)/g,
|
|||||||
|
|
||||||
function processStyleRule(val)
|
function processStyleRule(val)
|
||||||
{
|
{
|
||||||
|
// For css custom properties, val is unable to retrieved.
|
||||||
|
val = util.toStr(val);
|
||||||
|
|
||||||
return val.replace(regColor, '<span class="eruda-style-color" style="background-color: $&"></span>$&')
|
return val.replace(regColor, '<span class="eruda-style-color" style="background-color: $&"></span>$&')
|
||||||
.replace(regCssUrl, (match, url) => `url("${wrapLink(url)}")`);
|
.replace(regCssUrl, (match, url) => `url("${wrapLink(url)}")`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script src="assets/eruda.js"></script>
|
<script src="assets/eruda.js"></script>
|
||||||
<script src="boot.js"></script>
|
<script src="boot.js"></script>
|
||||||
|
<script src="util.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>Manual Test</header>
|
<header>Manual Test</header>
|
||||||
@@ -24,6 +25,9 @@
|
|||||||
<li>
|
<li>
|
||||||
<a href="#" id="issue31">#31</a>
|
<a href="#" id="issue31">#31</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" id="issue33">#33</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<script>
|
<script>
|
||||||
@@ -76,6 +80,10 @@
|
|||||||
{
|
{
|
||||||
addEventListener('resize', function () {});
|
addEventListener('resize', function () {});
|
||||||
});
|
});
|
||||||
|
addClickEvent('issue33', function ()
|
||||||
|
{
|
||||||
|
_.evalCss(':root {--test: 10px;}');
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>boot();</script>
|
<script>boot();</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
35
test/util.js
Normal file
35
test/util.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Built by eustia.
|
||||||
|
window._ = (function()
|
||||||
|
{
|
||||||
|
var _ = {};
|
||||||
|
|
||||||
|
if (typeof window === 'object' && window._) _ = window._;
|
||||||
|
|
||||||
|
/* ------------------------------ evalCss ------------------------------ */
|
||||||
|
|
||||||
|
_.evalCss = (function ()
|
||||||
|
{
|
||||||
|
var mark = [];
|
||||||
|
|
||||||
|
function exports(css)
|
||||||
|
{
|
||||||
|
for (var i = 0, len = mark.length; i < len; i++)
|
||||||
|
{
|
||||||
|
if (mark[i] === css) return;
|
||||||
|
}
|
||||||
|
mark.push(css);
|
||||||
|
|
||||||
|
var container = exports.container || document.head,
|
||||||
|
style = document.createElement('style');
|
||||||
|
|
||||||
|
style.type = 'text/css';
|
||||||
|
style.textContent = css;
|
||||||
|
|
||||||
|
container.appendChild(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exports;
|
||||||
|
})();
|
||||||
|
|
||||||
|
return _;
|
||||||
|
})();
|
||||||
Reference in New Issue
Block a user