@plotdb/csscope
Advanced tools
Comparing version
# Change Logs | ||
## v4.1.0 | ||
- restructure code for node / browser and bundler | ||
- upgrade and audit fix modules | ||
- support local file system relative path fetching | ||
## v4.0.8 | ||
@@ -4,0 +11,0 @@ |
769
index.js
@@ -1,429 +0,406 @@ | ||
(function(){ | ||
var win, doc, fetch, semver, isScope, _fetch, csp, slice$ = [].slice; | ||
fetch = typeof window != 'undefined' && window !== null | ||
? window.fetch | ||
: (typeof module != 'undefined' && module !== null) && (typeof require != 'undefined' && require !== null) ? require("node-fetch") : null; | ||
semver = typeof window != 'undefined' && window !== null | ||
? window.semver | ||
: (typeof modeul != 'undefined' && modeul !== null) && (typeof require != 'undefined' && require !== null) ? require("@plotdb/semver") : null; | ||
isScope = function(it){ | ||
return /^:scope[ .:\[#]|^:scope$/.exec(it); | ||
}; | ||
_fetch = function(u, c){ | ||
return fetch(u, c).then(function(ret){ | ||
var ref$; | ||
if (ret && ret.ok) { | ||
return ret.text(); | ||
} | ||
if (!ret) { | ||
return Promise.reject((ref$ = new Error("404"), ref$.name = 'lderror', ref$.id = 404, ref$)); | ||
} | ||
return ret.clone().text().then(function(t){ | ||
var i, e, ref$, j, err; | ||
i = ret.status || 404; | ||
e = (ref$ = new Error(i + " " + t), ref$.name = 'lderror', ref$.id = i, ref$.message = t, ref$); | ||
try { | ||
if ((j = JSON.parse(t)) && j.name === 'lderror') { | ||
import$(e, j).json = j; | ||
} | ||
} catch (e$) { | ||
err = e$; | ||
var win, doc, isScope, _fetch, csp, slice$ = [].slice; | ||
isScope = function(it){ | ||
return /^:scope[ .:\[#]|^:scope$/.exec(it); | ||
}; | ||
_fetch = function(u, c){ | ||
if ((typeof fs != 'undefined' && fs !== null) && !/^https:/.exec(u)) { | ||
return new Promise(function(res, rej){ | ||
return fs.readFile(u, function(e, b){ | ||
if (e) { | ||
return rej(e); | ||
} else { | ||
return res(b.toString()); | ||
} | ||
return Promise.reject(e); | ||
}); | ||
}); | ||
}; | ||
csp = function(a, b, c, d){ | ||
if (!csp['default']) { | ||
csp['default'] = new csp.converter(); | ||
} | ||
return csp['default'].convert(a, b, c, d); | ||
}; | ||
csp.env = function(it){ | ||
} | ||
return fetch(u, c).then(function(ret){ | ||
var ref$; | ||
return ref$ = [it, it.document], win = ref$[0], doc = ref$[1], ref$; | ||
}; | ||
csp.id = function(o){ | ||
return o.id || o.url || (o.ns ? o.ns + ":" : '') + "" + o.name + "@" + (o.version || 'main') + ":" + (o.path || 'index.html'); | ||
}; | ||
csp.scope = function(o){ | ||
return o.scope || '_' + btoa(csp.id(o)).replace(/=/g, '_'); | ||
}; | ||
csp._cache = {}; | ||
csp._ver = { | ||
map: {}, | ||
list: {} | ||
}; | ||
csp.cache = function(o){ | ||
var that, ret, ref$, n, v, p, i$, to$, i, ver; | ||
if (typeof o === 'string') { | ||
o = { | ||
url: o | ||
}; | ||
if (ret && ret.ok) { | ||
return ret.text(); | ||
} | ||
if (!o.id) { | ||
o.id = csp.id(o); | ||
if (!ret) { | ||
return Promise.reject((ref$ = new Error("404"), ref$.name = 'lderror', ref$.id = 404, ref$)); | ||
} | ||
if (that = this._cache[o.id]) { | ||
return that; | ||
} | ||
if (o.id && !o.name) { | ||
ret = /^(\S+)@(\S+):(\S+)$/.exec(o.id); | ||
if (!ret) { | ||
ref$ = [o.id, '', ''], n = ref$[0], v = ref$[1], p = ref$[2]; | ||
} else { | ||
ref$ = [ret[1], ret[2], ret[3]], n = ref$[0], v = ref$[1], p = ref$[2]; | ||
return ret.clone().text().then(function(t){ | ||
var i, e, ref$, j, err; | ||
i = ret.status || 404; | ||
e = (ref$ = new Error(i + " " + t), ref$.name = 'lderror', ref$.id = i, ref$.message = t, ref$); | ||
try { | ||
if ((j = JSON.parse(t)) && j.name === 'lderror') { | ||
import$(e, j).json = j; | ||
} | ||
} catch (e$) { | ||
err = e$; | ||
} | ||
return Promise.reject(e); | ||
}); | ||
}); | ||
}; | ||
csp = function(a, b, c, d){ | ||
if (!csp['default']) { | ||
csp['default'] = new csp.converter(); | ||
} | ||
return csp['default'].convert(a, b, c, d); | ||
}; | ||
csp.env = function(it){ | ||
var ref$; | ||
return ref$ = [it, it.document], win = ref$[0], doc = ref$[1], ref$; | ||
}; | ||
csp.id = function(o){ | ||
return o.id || o.url || (o.ns ? o.ns + ":" : '') + "" + o.name + "@" + (o.version || 'main') + ":" + (o.path || 'index.html'); | ||
}; | ||
csp.scope = function(o){ | ||
return o.scope || '_' + btoa(csp.id(o)).replace(/=/g, '_'); | ||
}; | ||
csp._cache = {}; | ||
csp._ver = { | ||
map: {}, | ||
list: {} | ||
}; | ||
csp.cache = function(o){ | ||
var that, ret, ref$, n, v, p, i$, to$, i, ver; | ||
if (typeof o === 'string') { | ||
o = { | ||
url: o | ||
}; | ||
} | ||
if (!o.id) { | ||
o.id = csp.id(o); | ||
} | ||
if (that = this._cache[o.id]) { | ||
return that; | ||
} | ||
if (o.id && !o.name) { | ||
ret = /^(\S+)@(\S+):(\S+)$/.exec(o.id); | ||
if (!ret) { | ||
ref$ = [o.id, '', ''], n = ref$[0], v = ref$[1], p = ref$[2]; | ||
} else { | ||
ref$ = [o.name, o.version || '', o.path || ''], n = ref$[0], v = ref$[1], p = ref$[2]; | ||
ref$ = [ret[1], ret[2], ret[3]], n = ref$[0], v = ref$[1], p = ref$[2]; | ||
} | ||
if (/^[0-9.]+$/.exec(v)) { | ||
if (that = ((ref$ = this._ver.map)[n] || (ref$[n] = {}))[v]) { | ||
v = that; | ||
} else { | ||
ref$ = [o.name, o.version || '', o.path || ''], n = ref$[0], v = ref$[1], p = ref$[2]; | ||
} | ||
if (/^[0-9.]+$/.exec(v)) { | ||
if (that = ((ref$ = this._ver.map)[n] || (ref$[n] = {}))[v]) { | ||
v = that; | ||
} | ||
if (that = this._cache[csp.id({ | ||
name: n, | ||
version: v, | ||
path: p | ||
})]) { | ||
return that; | ||
} | ||
for (i$ = 0, to$ = ((ref$ = this._ver.list)[n] || (ref$[n] = [])).length; i$ < to$; ++i$) { | ||
i = i$; | ||
ver = this._ver.list[n][i]; | ||
if (!semver.fit(ver, v)) { | ||
continue; | ||
} | ||
if (that = this._cache[csp.id({ | ||
this._ver.map[n][v] = ver; | ||
o.id = csp.id({ | ||
name: n, | ||
version: v, | ||
version: ver, | ||
path: p | ||
})]) { | ||
}); | ||
if (that = this._cache[o.id]) { | ||
return that; | ||
} | ||
for (i$ = 0, to$ = ((ref$ = this._ver.list)[n] || (ref$[n] = [])).length; i$ < to$; ++i$) { | ||
i = i$; | ||
ver = this._ver.list[n][i]; | ||
if (!semver.fit(ver, v)) { | ||
continue; | ||
} | ||
this._ver.map[n][v] = ver; | ||
o.id = csp.id({ | ||
name: n, | ||
version: ver, | ||
path: p | ||
}); | ||
if (that = this._cache[o.id]) { | ||
return that; | ||
} | ||
} | ||
} | ||
if (!in$(v, (ref$ = this._ver.list)[n] || (ref$[n] = []))) { | ||
this._ver.list[n].push(v); | ||
} | ||
return this._cache[o.id] = o; | ||
}; | ||
csp.converter = function(opt){ | ||
var ifr; | ||
opt == null && (opt = {}); | ||
this.scopeTest = opt.scopeTest; | ||
this.node = doc.createElement("style"); | ||
this.iframe = ifr = doc.createElement("iframe"); | ||
ifr.setAttribute('title', "for csscope parsing"); | ||
ifr.style.display = 'none'; | ||
ifr.src = 'about:blank'; | ||
doc.body.appendChild(ifr); | ||
this.iframe.contentDocument.body.appendChild(this.node); | ||
this._idx = 0; | ||
return this; | ||
}; | ||
csp.converter.prototype = import$(Object.create(Object.prototype), { | ||
getNames: function(rules, defs){ | ||
var i$, len$, rule; | ||
defs == null && (defs = {}); | ||
for (i$ = 0, len$ = rules.length; i$ < len$; ++i$) { | ||
rule = rules[i$]; | ||
if (rule.name) { | ||
defs[rule.name] = true; | ||
} else if (rule.cssRules) { | ||
this.getNames(rule.cssRules, defs); | ||
} | ||
} | ||
if (!in$(v, (ref$ = this._ver.list)[n] || (ref$[n] = []))) { | ||
this._ver.list[n].push(v); | ||
} | ||
return this._cache[o.id] = o; | ||
}; | ||
csp.converter = function(opt){ | ||
var ifr; | ||
opt == null && (opt = {}); | ||
this.scopeTest = opt.scopeTest; | ||
this.node = doc.createElement("style"); | ||
this.iframe = ifr = doc.createElement("iframe"); | ||
ifr.setAttribute('title', "for csscope parsing"); | ||
ifr.style.display = 'none'; | ||
ifr.src = 'about:blank'; | ||
doc.body.appendChild(ifr); | ||
this.iframe.contentDocument.body.appendChild(this.node); | ||
this._idx = 0; | ||
return this; | ||
}; | ||
csp.converter.prototype = import$(Object.create(Object.prototype), { | ||
getNames: function(rules, defs){ | ||
var i$, len$, rule; | ||
defs == null && (defs = {}); | ||
for (i$ = 0, len$ = rules.length; i$ < len$; ++i$) { | ||
rule = rules[i$]; | ||
if (rule.name) { | ||
defs[rule.name] = true; | ||
} else if (rule.cssRules) { | ||
this.getNames(rule.cssRules, defs); | ||
return defs; | ||
}, | ||
_convert: function(rules, scopeRule, name, scopeTest, defs){ | ||
var ret, i$, len$, rule, matched, sel, code; | ||
defs == null && (defs = {}); | ||
ret = ""; | ||
for (i$ = 0, len$ = rules.length; i$ < len$; ++i$) { | ||
rule = rules[i$]; | ||
if (rule.style) { | ||
if (defs[rule.style.animationName]) { | ||
rule.style.animationName = name + "__" + rule.style.animationName; | ||
} else if (rule.style.animation) { | ||
matched = false; | ||
rule.style.animation = rule.style.animation.split(' ').map(fn$).join(' '); | ||
} | ||
} | ||
return defs; | ||
}, | ||
_convert: function(rules, scopeRule, name, scopeTest, defs){ | ||
var ret, i$, len$, rule, matched, sel, code; | ||
defs == null && (defs = {}); | ||
ret = ""; | ||
for (i$ = 0, len$ = rules.length; i$ < len$; ++i$) { | ||
rule = rules[i$]; | ||
if (rule.style) { | ||
if (defs[rule.style.animationName]) { | ||
rule.style.animationName = name + "__" + rule.style.animationName; | ||
} else if (rule.style.animation) { | ||
matched = false; | ||
rule.style.animation = rule.style.animation.split(' ').map(fn$).join(' '); | ||
} | ||
if (rule.selectorText) { | ||
if (!scopeTest) { | ||
sel = rule.selectorText.split(',').map(fn1$).map(fn2$).join(','); | ||
} else { | ||
sel = rule.selectorText.split(',').map(fn3$).map(fn4$).join(','); | ||
} | ||
if (rule.selectorText) { | ||
if (!scopeTest) { | ||
sel = rule.selectorText.split(',').map(fn1$).map(fn2$).join(','); | ||
} else { | ||
sel = rule.selectorText.split(',').map(fn3$).map(fn4$).join(','); | ||
} | ||
ret += sel + "{" + rule.style.cssText + "}"; | ||
/* | ||
ret += """ | ||
#sel { | ||
#{Array.from(rule.style).map(-> "#it:#{rule.style.getPropertyValue(it)}#{if rule.style.getPropertyPriority(it) == 'important' => '!important' else ''}").join(';')} | ||
} | ||
""" | ||
*/ | ||
rule.selectorText = sel; | ||
} else if (rule.name) { | ||
sel = rule.name.split(',').map(fn5$).map(fn6$).join(','); | ||
rule.name = sel; | ||
ret += "@keyframes " + sel + " {\n " + Array.from(rule.cssRules).map(fn7$).join('\n') + "\n}"; | ||
} else if (rule.cssRules) { | ||
code = this._convert(rule.cssRules, scopeRule, name, scopeTest, defs); | ||
ret += "@media " + rule.conditionText + " {\n " + code + "\n}"; | ||
ret += sel + "{" + rule.style.cssText + "}"; | ||
/* | ||
ret += """ | ||
#sel { | ||
#{Array.from(rule.style).map(-> "#it:#{rule.style.getPropertyValue(it)}#{if rule.style.getPropertyPriority(it) == 'important' => '!important' else ''}").join(';')} | ||
} | ||
""" | ||
*/ | ||
rule.selectorText = sel; | ||
} else if (rule.name) { | ||
sel = rule.name.split(',').map(fn5$).map(fn6$).join(','); | ||
rule.name = sel; | ||
ret += "@keyframes " + sel + " {\n " + Array.from(rule.cssRules).map(fn7$).join('\n') + "\n}"; | ||
} else if (rule.cssRules) { | ||
code = this._convert(rule.cssRules, scopeRule, name, scopeTest, defs); | ||
ret += "@media " + rule.conditionText + " {\n " + code + "\n}"; | ||
} | ||
return ret; | ||
function fn$(it){ | ||
var matched; | ||
if (matched || !defs[it]) { | ||
return it; | ||
} | ||
matched = true; | ||
return name + "__" + it; | ||
} | ||
return ret; | ||
function fn$(it){ | ||
var matched; | ||
if (matched || !defs[it]) { | ||
return it; | ||
} | ||
function fn1$(it){ | ||
return it.trim(); | ||
matched = true; | ||
return name + "__" + it; | ||
} | ||
function fn1$(it){ | ||
return it.trim(); | ||
} | ||
function fn2$(it){ | ||
if (isScope(it)) { | ||
return it.replace(/^:scope/, scopeRule); | ||
} else { | ||
return scopeRule + " " + it; | ||
} | ||
function fn2$(it){ | ||
if (isScope(it)) { | ||
return it.replace(/^:scope/, scopeRule); | ||
} else { | ||
return scopeRule + " " + it; | ||
} | ||
} | ||
function fn3$(it){ | ||
return it.trim(); | ||
} | ||
function fn4$(it){ | ||
var ref$, h, t, h1, h2; | ||
if (isScope(it)) { | ||
return it.replace(/^:scope/, scopeRule); | ||
} | ||
function fn3$(it){ | ||
ref$ = it.split(' ').map(function(it){ | ||
return it.trim(); | ||
}).filter(function(it){ | ||
return it; | ||
}), h = ref$[0], t = slice$.call(ref$, 1); | ||
ref$ = /^[a-zA-Z]/.exec(h) | ||
? [h, ''] | ||
: ['', h], h1 = ref$[0], h2 = ref$[1]; | ||
return /:[a-z-]+$/.exec(it) | ||
? (scopeRule + " :not(" + scopeTest + ") " + it + ",") + (scopeRule + " > " + h1 + h2 + " " + t.join(' ')) | ||
: (scopeRule + " :not(" + scopeTest + ") " + it + ",") + (scopeRule + " > " + h1 + ":not(" + scopeTest + ")" + h2 + " " + t.join(' ')); | ||
} | ||
function fn5$(it){ | ||
return it.trim(); | ||
} | ||
function fn6$(it){ | ||
return name + "__" + it; | ||
} | ||
function fn7$(it){ | ||
return it.cssText; | ||
} | ||
}, | ||
convert: function(a, b, c, d){ | ||
var opt, ref$, name, css, rule, scopeTest, rules, defs; | ||
ref$ = opt = typeof a === 'object' | ||
? a | ||
: { | ||
name: a, | ||
css: b, | ||
rule: c, | ||
scopeTest: d | ||
}, name = ref$.name, css = ref$.css, rule = ref$.rule, scopeTest = ref$.scopeTest; | ||
if (!rule) { | ||
rule = "." + name; | ||
} | ||
if (!name) { | ||
name = rule; | ||
} | ||
if (!scopeTest) { | ||
scopeTest = this.scopeTest; | ||
} | ||
rules = typeof css === 'object' | ||
? css | ||
: (this.node.textContent = (css || '') + ("/*" + (this._idx++) + "*/"), this.node.sheet.cssRules); | ||
defs = this.getNames(rules, {}); | ||
return this._convert(rules, rule, name, scopeTest, defs) || ''; | ||
} | ||
}); | ||
csp.manager = function(o){ | ||
o == null && (o = {}); | ||
this.attrName = "csscope"; | ||
this._cache = {}; | ||
this.converter = new csp.converter(); | ||
this.counter = 0; | ||
this.registry(o.registry || "/assets/lib/"); | ||
this.init(); | ||
return this; | ||
}; | ||
csp.manager.prototype = import$(Object.create(Object.prototype), { | ||
cache: function(o){ | ||
var that; | ||
if (typeof o === 'string') { | ||
o = { | ||
url: o | ||
}; | ||
} | ||
if (!o.id) { | ||
o.id = csp.id(o); | ||
} | ||
if (that = this._cache[o.id]) { | ||
return that; | ||
} | ||
return this._cache[o.id] = csp.cache(o); | ||
}, | ||
_ref: function(o){ | ||
var that; | ||
return typeof o === 'string' | ||
? o | ||
: (that = o.url) | ||
? that | ||
: this._reg.fetch | ||
? this._reg.fetch(o) | ||
: this._reg(o); | ||
}, | ||
registry: function(v){ | ||
if (typeof v === 'string') { | ||
if (v[v.length - 1] === '/') { | ||
v = v.substring(0, v.length - 1); | ||
} | ||
function fn4$(it){ | ||
var ref$, h, t, h1, h2; | ||
if (isScope(it)) { | ||
return it.replace(/^:scope/, scopeRule); | ||
} | ||
ref$ = it.split(' ').map(function(it){ | ||
return it.trim(); | ||
}).filter(function(it){ | ||
return it; | ||
}), h = ref$[0], t = slice$.call(ref$, 1); | ||
ref$ = /^[a-zA-Z]/.exec(h) | ||
? [h, ''] | ||
: ['', h], h1 = ref$[0], h2 = ref$[1]; | ||
return /:[a-z-]+$/.exec(it) | ||
? (scopeRule + " :not(" + scopeTest + ") " + it + ",") + (scopeRule + " > " + h1 + h2 + " " + t.join(' ')) | ||
: (scopeRule + " :not(" + scopeTest + ") " + it + ",") + (scopeRule + " > " + h1 + ":not(" + scopeTest + ")" + h2 + " " + t.join(' ')); | ||
} | ||
function fn5$(it){ | ||
return it.trim(); | ||
} | ||
function fn6$(it){ | ||
return name + "__" + it; | ||
} | ||
function fn7$(it){ | ||
return it.cssText; | ||
} | ||
}, | ||
convert: function(a, b, c, d){ | ||
var opt, ref$, name, css, rule, scopeTest, rules, defs; | ||
ref$ = opt = typeof a === 'object' | ||
? a | ||
: { | ||
name: a, | ||
css: b, | ||
rule: c, | ||
scopeTest: d | ||
}, name = ref$.name, css = ref$.css, rule = ref$.rule, scopeTest = ref$.scopeTest; | ||
if (!rule) { | ||
rule = "." + name; | ||
} | ||
if (!name) { | ||
name = rule; | ||
} | ||
if (!scopeTest) { | ||
scopeTest = this.scopeTest; | ||
} | ||
rules = typeof css === 'object' | ||
? css | ||
: (this.node.textContent = (css || '') + ("/*" + (this._idx++) + "*/"), this.node.sheet.cssRules); | ||
defs = this.getNames(rules, {}); | ||
return this._convert(rules, rule, name, scopeTest, defs) || ''; | ||
return this._reg = function(v){ | ||
return function(o){ | ||
return v + "/" + o.name + "/" + (o.version || 'main') + "/" + (o.path || 'index.min.css'); | ||
}; | ||
}(v); | ||
} else { | ||
return this._reg = v; | ||
} | ||
}); | ||
csp.manager = function(o){ | ||
o == null && (o = {}); | ||
this.attrName = "csscope"; | ||
this._cache = {}; | ||
this.converter = new csp.converter(); | ||
this.counter = 0; | ||
this.registry(o.registry || "/assets/lib/"); | ||
this.init(); | ||
return this; | ||
}; | ||
csp.manager.prototype = import$(Object.create(Object.prototype), { | ||
cache: function(o){ | ||
var that; | ||
if (typeof o === 'string') { | ||
o = { | ||
url: o | ||
}; | ||
}, | ||
init: function(){ | ||
if (this.inited) { | ||
return; | ||
} | ||
this.inited = true; | ||
this.styleNode = doc.createElement('style'); | ||
this.styleNode.setAttribute('type', 'text/css'); | ||
this.styleNode.setAttribute('data-name', "csscope.manager"); | ||
this.styleContent = []; | ||
return doc.body.appendChild(this.styleNode); | ||
}, | ||
scope: function(node, urls){ | ||
var ret; | ||
urls == null && (urls = []); | ||
ret = this.get(urls); | ||
node.classList.add.apply(node.classList, ret.map(function(it){ | ||
return it.scope; | ||
})); | ||
return ret; | ||
}, | ||
get: function(libs){ | ||
var this$ = this; | ||
libs == null && (libs = []); | ||
return (Array.isArray(libs) | ||
? libs | ||
: [libs]).map(function(it){ | ||
return this$.cache(it); | ||
}).filter(function(it){ | ||
return it.scope; | ||
}); | ||
}, | ||
load: function(libs, scopeTest, bundle){ | ||
var code, this$ = this; | ||
libs = (Array.isArray(libs) | ||
? libs | ||
: [libs]).map(function(o){ | ||
return this$.cache(o); | ||
}); | ||
code = []; | ||
return Promise.all(libs.map(function(o){ | ||
var ref, p; | ||
if (o.inited) { | ||
return Promise.resolve(); | ||
} | ||
if (!o.id) { | ||
o.id = csp.id(o); | ||
if (o.scope && o.code) { | ||
o.inited = true; | ||
code.push(o.code); | ||
return Promise.resolve(); | ||
} | ||
if (that = this._cache[o.id]) { | ||
return that; | ||
} | ||
return this._cache[o.id] = csp.cache(o); | ||
}, | ||
_ref: function(o){ | ||
var that; | ||
return typeof o === 'string' | ||
? o | ||
: (that = o.url) | ||
? that | ||
: this._reg.fetch | ||
? this._reg.fetch(o) | ||
: this._reg(o); | ||
}, | ||
registry: function(v){ | ||
if (typeof v === 'string') { | ||
if (v[v.length - 1] === '/') { | ||
v = v.substring(0, v.length - 1); | ||
} | ||
return this._reg = function(v){ | ||
return function(o){ | ||
return v + "/" + o.name + "/" + (o.version || 'main') + "/" + (o.path || 'index.min.css'); | ||
ref = this$._ref(o); | ||
p = ref.then | ||
? ref.then(function(it){ | ||
this$.cache((o.id = undefined, o.version = it.version, o)); | ||
return it; | ||
}) | ||
: _fetch(ref, { | ||
method: 'GET' | ||
}).then(function(it){ | ||
return { | ||
content: it | ||
}; | ||
}(v); | ||
} else { | ||
return this._reg = v; | ||
} | ||
}, | ||
init: function(){ | ||
if (this.inited) { | ||
return; | ||
} | ||
this.inited = true; | ||
this.styleNode = doc.createElement('style'); | ||
this.styleNode.setAttribute('type', 'text/css'); | ||
this.styleNode.setAttribute('data-name', "csscope.manager"); | ||
this.styleContent = []; | ||
return doc.body.appendChild(this.styleNode); | ||
}, | ||
scope: function(node, urls){ | ||
var ret; | ||
urls == null && (urls = []); | ||
ret = this.get(urls); | ||
node.classList.add.apply(node.classList, ret.map(function(it){ | ||
return it.scope; | ||
})); | ||
return ret; | ||
}, | ||
get: function(libs){ | ||
var this$ = this; | ||
libs == null && (libs = []); | ||
return (Array.isArray(libs) | ||
? libs | ||
: [libs]).map(function(it){ | ||
return this$.cache(it); | ||
}).filter(function(it){ | ||
return it.scope; | ||
}); | ||
return p.then(function(arg$){ | ||
var content; | ||
content = arg$.content; | ||
o.inited = true; | ||
o.scope = csp.scope(o); | ||
o.code = this$.converter.convert({ | ||
css: content, | ||
name: o.scope, | ||
scopeTest: scopeTest | ||
}); | ||
return code.push(o.code); | ||
}); | ||
}, | ||
bundle: function(libs, scopeTest){ | ||
var hash, res$, k, v, this$ = this; | ||
libs = Array.isArray(libs) | ||
? libs | ||
: [libs]; | ||
hash = {}; | ||
libs.map(function(o){ | ||
return this$.cache(o); | ||
}).filter(function(it){ | ||
return it && it.id; | ||
}).map(function(it){ | ||
return hash[it.id] = it; | ||
}); | ||
res$ = []; | ||
for (k in hash) { | ||
v = hash[k]; | ||
res$.push(v); | ||
})).then(function(){ | ||
if (bundle) { | ||
return libs; | ||
} | ||
libs = res$; | ||
return this.load(libs, scopeTest, true).then(function(libs){ | ||
return libs.map(function(it){ | ||
return it.code; | ||
}).join('\n'); | ||
}); | ||
}, | ||
load: function(libs, scopeTest, bundle){ | ||
var code, this$ = this; | ||
libs = (Array.isArray(libs) | ||
? libs | ||
: [libs]).map(function(o){ | ||
return this$.cache(o); | ||
}); | ||
code = []; | ||
return Promise.all(libs.map(function(o){ | ||
var ref, p; | ||
if (o.inited) { | ||
return Promise.resolve(); | ||
} | ||
if (o.scope && o.code) { | ||
o.inited = true; | ||
code.push(o.code); | ||
return Promise.resolve(); | ||
} | ||
ref = this$._ref(o); | ||
p = ref.then | ||
? ref.then(function(it){ | ||
this$.cache((o.id = undefined, o.version = it.version, o)); | ||
return it; | ||
}) | ||
: _fetch(ref, { | ||
method: 'GET' | ||
}).then(function(it){ | ||
return { | ||
content: it | ||
}; | ||
}); | ||
return p.then(function(arg$){ | ||
var content; | ||
content = arg$.content; | ||
o.inited = true; | ||
o.scope = csp.scope(o); | ||
o.code = this$.converter.convert({ | ||
css: content, | ||
name: o.scope, | ||
scopeTest: scopeTest | ||
}); | ||
return code.push(o.code); | ||
}); | ||
})).then(function(){ | ||
if (bundle) { | ||
return libs; | ||
} | ||
this$.styleContent.push.apply(this$.styleContent, code); | ||
this$.styleNode.textContent = this$.styleContent.join('\n'); | ||
return this$.get(libs); | ||
}); | ||
} | ||
}); | ||
csp.env(typeof self != 'undefined' && self !== null ? self : globalThis); | ||
if (typeof module != 'undefined' && module !== null) { | ||
module.exports = csp; | ||
} else if (typeof window != 'undefined' && window !== null) { | ||
window.csscope = csp; | ||
this$.styleContent.push.apply(this$.styleContent, code); | ||
this$.styleNode.textContent = this$.styleContent.join('\n'); | ||
return this$.get(libs); | ||
}); | ||
} | ||
function import$(obj, src){ | ||
var own = {}.hasOwnProperty; | ||
for (var key in src) if (own.call(src, key)) obj[key] = src[key]; | ||
return obj; | ||
} | ||
function in$(x, xs){ | ||
var i = -1, l = xs.length >>> 0; | ||
while (++i < l) if (x === xs[i]) return true; | ||
return false; | ||
} | ||
}).call(this); | ||
}); | ||
csp.env(typeof self != 'undefined' && self !== null ? self : globalThis); | ||
function import$(obj, src){ | ||
var own = {}.hasOwnProperty; | ||
for (var key in src) if (own.call(src, key)) obj[key] = src[key]; | ||
return obj; | ||
} | ||
function in$(x, xs){ | ||
var i = -1, l = xs.length >>> 0; | ||
while (++i < l) if (x === xs[i]) return true; | ||
return false; | ||
}if (typeof module != 'undefined' && module !== null) { | ||
module.exports = csp; | ||
} else if (typeof window != 'undefined' && window !== null) { | ||
window.csscope = csp; | ||
} |
@@ -1,1 +0,1 @@ | ||
!function(){var t,n,a,g,o,l,w=[].slice;function s(e,t){var n,r={}.hasOwnProperty;for(n in t)r.call(t,n)&&(e[n]=t[n]);return e}n="undefined"!=typeof window&&null!==window?window.fetch:"undefined"!=typeof module&&null!==module&&"undefined"!=typeof require&&null!==require?require("node-fetch"):null,a="undefined"!=typeof window&&null!==window?window.semver:"undefined"!=typeof modeul&&null!==modeul&&"undefined"!=typeof require&&null!==require?require("@plotdb/semver"):null,g=function(e){return/^:scope[ .:\[#]|^:scope$/.exec(e)},o=function(e,t){return n(e,t).then(function(i){var e;return i&&i.ok?i.text():i?i.clone().text().then(function(e){var t,n=i.status||404,r=new Error(n+" "+e);r.name="lderror",r.id=n,r.message=e,n=r;try{(t=JSON.parse(e))&&"lderror"===t.name&&(s(n,t).json=t)}catch(e){0}return Promise.reject(n)}):Promise.reject(((e=new Error("404")).name="lderror",e.id=404,e))})},(l=function(e,t,n,r){return(l.default=l.default?l.default:new l.converter).convert(e,t,n,r)}).env=function(e){e=[e,e.document];return t=e[1],e},l.id=function(e){return e.id||e.url||(e.ns?e.ns+":":"")+e.name+"@"+(e.version||"main")+":"+(e.path||"index.html")},l.scope=function(e){return e.scope||"_"+btoa(l.id(e)).replace(/=/g,"_")},l._cache={},l._ver={map:{},list:{}},l.cache=function(e){var t,n,r,i,o,s,c,u;if((e="string"==typeof e?{url:e}:e).id||(e.id=l.id(e)),t=this._cache[e.id])return t;if(o=(i=(r=(n=e.id&&!e.name?(n=/^(\S+)@(\S+):(\S+)$/.exec(e.id))?[n[1],n[2],n[3]]:[e.id,"",""]:[e.name,e.version||"",e.path||""])[0],n[1]),n[2]),/^[0-9.]+$/.exec(i)){if((t=((n=this._ver.map)[r]||(n[r]={}))[i])&&(i=t),t=this._cache[l.id({name:r,version:i,path:o})])return t;for(s=0,c=((n=this._ver.list)[r]||(n[r]=[])).length;s<c;++s)if(u=s,u=this._ver.list[r][u],a.fit(u,i)&&(this._ver.map[r][i]=u,e.id=l.id({name:r,version:u,path:o}),t=this._cache[e.id]))return t}return function(e,t){var n=-1,r=t.length>>>0;for(;++n<r;)if(e===t[n])return!0;return!1}(i,(n=this._ver.list)[r]||(n[r]=[]))||this._ver.list[r].push(i),this._cache[e.id]=e},(l.converter=function(e){return this.scopeTest=(e=null==e?{}:e).scopeTest,this.node=t.createElement("style"),this.iframe=e=t.createElement("iframe"),e.setAttribute("title","for csscope parsing"),e.style.display="none",e.src="about:blank",t.body.appendChild(e),this.iframe.contentDocument.body.appendChild(this.node),this._idx=0,this}).prototype=s(Object.create(Object.prototype),{getNames:function(e,t){var n,r,i;for(null==t&&(t={}),n=0,r=e.length;n<r;++n)(i=e[n]).name?t[i.name]=!0:i.cssRules&&this.getNames(i.cssRules,t);return t},_convert:function(e,i,t,o,n){var r,s,c,u,a,l;for(null==n&&(n={}),r="",s=0,c=e.length;s<c;++s)(u=e[s]).style&&(n[u.style.animationName]?u.style.animationName=t+"__"+u.style.animationName:u.style.animation&&(u.style.animation=u.style.animation.split(" ").map(d).join(" "))),u.selectorText?(r+=(a=(o?u.selectorText.split(",").map(p).map(m):u.selectorText.split(",").map(f).map(h)).join(","))+"{"+u.style.cssText+"}",u.selectorText=a):u.name?(a=u.name.split(",").map(y).map(v).join(","),r+="@keyframes "+(u.name=a)+" {\n "+Array.from(u.cssRules).map(_).join("\n")+"\n}"):u.cssRules&&(l=this._convert(u.cssRules,i,t,o,n),r+="@media "+u.conditionText+" {\n "+l+"\n}");return r;function d(e){return n[e]?t+"__"+e:e}function f(e){return e.trim()}function h(e){return g(e)?e.replace(/^:scope/,i):i+" "+e}function p(e){return e.trim()}function m(e){var t,n,r;return g(e)?e.replace(/^:scope/,i):(n=(r=e.split(" ").map(function(e){return e.trim()}).filter(function(e){return e}))[0],t=w.call(r,1),n=(r=/^[a-zA-Z]/.exec(n)?[n,""]:["",n])[0],r=r[1],/:[a-z-]+$/.exec(e)?i+" :not("+o+") "+e+","+i+" > "+n+r+" "+t.join(" "):i+" :not("+o+") "+e+","+i+" > "+n+":not("+o+")"+r+" "+t.join(" "))}function y(e){return e.trim()}function v(e){return t+"__"+e}function _(e){return e.cssText}},convert:function(e,t,n,r){var i,e="object"==typeof e?e:{name:e,css:t,rule:n,scopeTest:r},t=e.name,n=e.css,r=e.rule,e=e.scopeTest;return r=r||"."+t,t=t||r,e=e||this.scopeTest,n="object"==typeof n?n:(this.node.textContent=(n||"")+("/*"+this._idx++)+"*/",this.node.sheet.cssRules),i=this.getNames(n,{}),this._convert(n,r,t,e,i)||""}}),(l.manager=function(e){return null==e&&(e={}),this.attrName="csscope",this._cache={},this.converter=new l.converter,this.counter=0,this.registry(e.registry||"/assets/lib/"),this.init(),this}).prototype=s(Object.create(Object.prototype),{cache:function(e){var t;return(e="string"==typeof e?{url:e}:e).id||(e.id=l.id(e)),(t=this._cache[e.id])?t:this._cache[e.id]=l.cache(e)},_ref:function(e){var t;return"string"==typeof e?e:(t=e.url)?t:this._reg.fetch?this._reg.fetch(e):this._reg(e)},registry:function(e){return"string"==typeof e?("/"===e[e.length-1]&&(e=e.substring(0,e.length-1)),this._reg=(t=e,function(e){return t+"/"+e.name+"/"+(e.version||"main")+"/"+(e.path||"index.min.css")})):this._reg=e;var t},init:function(){if(!this.inited)return this.inited=!0,this.styleNode=t.createElement("style"),this.styleNode.setAttribute("type","text/css"),this.styleNode.setAttribute("data-name","csscope.manager"),this.styleContent=[],t.body.appendChild(this.styleNode)},scope:function(e,t){t=this.get(t=null==t?[]:t);return e.classList.add.apply(e.classList,t.map(function(e){return e.scope})),t},get:function(e){var t=this;return null==e&&(e=[]),(Array.isArray(e)?e:[e]).map(function(e){return t.cache(e)}).filter(function(e){return e.scope})},bundle:function(e,t){var n,r,i,o,s=this;for(i in e=Array.isArray(e)?e:[e],n={},e.map(function(e){return s.cache(e)}).filter(function(e){return e&&e.id}).map(function(e){return n[e.id]=e}),r=[],n)o=n[i],r.push(o);return e=r,this.load(e,t,!0).then(function(e){return e.map(function(e){return e.code}).join("\n")})},load:function(e,n,t){var r,i=this;return e=(Array.isArray(e)?e:[e]).map(function(e){return i.cache(e)}),r=[],Promise.all(e.map(function(t){var e;return t.inited?Promise.resolve():t.scope&&t.code?(t.inited=!0,r.push(t.code),Promise.resolve()):((e=i._ref(t)).then?e.then(function(e){return i.cache((t.id=void 0,t.version=e.version,t)),e}):o(e,{method:"GET"}).then(function(e){return{content:e}})).then(function(e){e=e.content;return t.inited=!0,t.scope=l.scope(t),t.code=i.converter.convert({css:e,name:t.scope,scopeTest:n}),r.push(t.code)})})).then(function(){return t?e:(i.styleContent.push.apply(i.styleContent,r),i.styleNode.textContent=i.styleContent.join("\n"),i.get(e))})}}),l.env("undefined"!=typeof self&&null!==self?self:globalThis),"undefined"!=typeof module&&null!==module?module.exports=l:"undefined"!=typeof window&&null!==window&&(window.csscope=l)}.call(this); | ||
var win,doc,isScope,_fetch,csp,slice$=[].slice;function import$(e,t){var n,r={}.hasOwnProperty;for(n in t)r.call(t,n)&&(e[n]=t[n]);return e}function in$(e,t){for(var n=-1,r=t.length>>>0;++n<r;)if(e===t[n])return!0;return!1}isScope=function(e){return/^:scope[ .:\[#]|^:scope$/.exec(e)},_fetch=function(e,t){return"undefined"==typeof fs||null===fs||/^https:/.exec(e)?fetch(e,t).then(function(s){var e;return s&&s.ok?s.text():s?s.clone().text().then(function(e){var t,n=s.status||404,r=new Error(n+" "+e);r.name="lderror",r.id=n,r.message=e,n=r;try{(t=JSON.parse(e))&&"lderror"===t.name&&(import$(n,t).json=t)}catch(e){0}return Promise.reject(n)}):Promise.reject(((e=new Error("404")).name="lderror",e.id=404,e))}):new Promise(function(n,r){return fs.readFile(e,function(e,t){return e?r(e):n(t.toString())})})},(csp=function(e,t,n,r){return csp.default||(csp.default=new csp.converter),csp.default.convert(e,t,n,r)}).env=function(e){e=[e,e.document];return win=e[0],doc=e[1],e},csp.id=function(e){return e.id||e.url||(e.ns?e.ns+":":"")+e.name+"@"+(e.version||"main")+":"+(e.path||"index.html")},csp.scope=function(e){return e.scope||"_"+btoa(csp.id(e)).replace(/=/g,"_")},csp._cache={},csp._ver={map:{},list:{}},csp.cache=function(e){var t,n,r,s,i,c,o,a;if((e="string"==typeof e?{url:e}:e).id||(e.id=csp.id(e)),t=this._cache[e.id])return t;if(i=(s=(r=(n=e.id&&!e.name?(n=/^(\S+)@(\S+):(\S+)$/.exec(e.id))?[n[1],n[2],n[3]]:[e.id,"",""]:[e.name,e.version||"",e.path||""])[0],n[1]),n[2]),/^[0-9.]+$/.exec(s)){if((t=((n=this._ver.map)[r]||(n[r]={}))[s])&&(s=t),t=this._cache[csp.id({name:r,version:s,path:i})])return t;for(c=0,o=((n=this._ver.list)[r]||(n[r]=[])).length;c<o;++c)if(a=c,a=this._ver.list[r][a],semver.fit(a,s)&&(this._ver.map[r][s]=a,e.id=csp.id({name:r,version:a,path:i}),t=this._cache[e.id]))return t}return in$(s,(n=this._ver.list)[r]||(n[r]=[]))||this._ver.list[r].push(s),this._cache[e.id]=e},csp.converter=function(e){return this.scopeTest=(e=null==e?{}:e).scopeTest,this.node=doc.createElement("style"),this.iframe=e=doc.createElement("iframe"),e.setAttribute("title","for csscope parsing"),e.style.display="none",e.src="about:blank",doc.body.appendChild(e),this.iframe.contentDocument.body.appendChild(this.node),this._idx=0,this},csp.converter.prototype=import$(Object.create(Object.prototype),{getNames:function(e,t){var n,r,s;for(null==t&&(t={}),n=0,r=e.length;n<r;++n)(s=e[n]).name?t[s.name]=!0:s.cssRules&&this.getNames(s.cssRules,t);return t},_convert:function(e,s,t,i,n){var r,c,o,a,u,p;for(null==n&&(n={}),r="",c=0,o=e.length;c<o;++c)(a=e[c]).style&&(n[a.style.animationName]?a.style.animationName=t+"__"+a.style.animationName:a.style.animation&&(a.style.animation=a.style.animation.split(" ").map(l).join(" "))),a.selectorText?(r+=(u=(i?a.selectorText.split(",").map(d).map(m):a.selectorText.split(",").map(h).map(f)).join(","))+"{"+a.style.cssText+"}",a.selectorText=u):a.name?(u=a.name.split(",").map(y).map(v).join(","),r+="@keyframes "+(a.name=u)+" {\n "+Array.from(a.cssRules).map(_).join("\n")+"\n}"):a.cssRules&&(p=this._convert(a.cssRules,s,t,i,n),r+="@media "+a.conditionText+" {\n "+p+"\n}");return r;function l(e){return n[e]?t+"__"+e:e}function h(e){return e.trim()}function f(e){return isScope(e)?e.replace(/^:scope/,s):s+" "+e}function d(e){return e.trim()}function m(e){var t,n,r;return isScope(e)?e.replace(/^:scope/,s):(n=(r=e.split(" ").map(function(e){return e.trim()}).filter(function(e){return e}))[0],t=slice$.call(r,1),n=(r=/^[a-zA-Z]/.exec(n)?[n,""]:["",n])[0],r=r[1],/:[a-z-]+$/.exec(e)?s+" :not("+i+") "+e+","+s+" > "+n+r+" "+t.join(" "):s+" :not("+i+") "+e+","+s+" > "+n+":not("+i+")"+r+" "+t.join(" "))}function y(e){return e.trim()}function v(e){return t+"__"+e}function _(e){return e.cssText}},convert:function(e,t,n,r){var s,e="object"==typeof e?e:{name:e,css:t,rule:n,scopeTest:r},t=e.name,n=e.css,r=e.rule,e=e.scopeTest;return r=r||"."+t,t=t||r,e=e||this.scopeTest,n="object"==typeof n?n:(this.node.textContent=(n||"")+("/*"+this._idx++)+"*/",this.node.sheet.cssRules),s=this.getNames(n,{}),this._convert(n,r,t,e,s)||""}}),csp.manager=function(e){return null==e&&(e={}),this.attrName="csscope",this._cache={},this.converter=new csp.converter,this.counter=0,this.registry(e.registry||"/assets/lib/"),this.init(),this},csp.manager.prototype=import$(Object.create(Object.prototype),{cache:function(e){var t;return(e="string"==typeof e?{url:e}:e).id||(e.id=csp.id(e)),(t=this._cache[e.id])?t:this._cache[e.id]=csp.cache(e)},_ref:function(e){var t;return"string"==typeof e?e:(t=e.url)?t:this._reg.fetch?this._reg.fetch(e):this._reg(e)},registry:function(e){return"string"==typeof e?("/"===e[e.length-1]&&(e=e.substring(0,e.length-1)),this._reg=(t=e,function(e){return t+"/"+e.name+"/"+(e.version||"main")+"/"+(e.path||"index.min.css")})):this._reg=e;var t},init:function(){if(!this.inited)return this.inited=!0,this.styleNode=doc.createElement("style"),this.styleNode.setAttribute("type","text/css"),this.styleNode.setAttribute("data-name","csscope.manager"),this.styleContent=[],doc.body.appendChild(this.styleNode)},scope:function(e,t){t=this.get(t=null==t?[]:t);return e.classList.add.apply(e.classList,t.map(function(e){return e.scope})),t},get:function(e){var t=this;return null==e&&(e=[]),(Array.isArray(e)?e:[e]).map(function(e){return t.cache(e)}).filter(function(e){return e.scope})},load:function(e,n,t){var r,s=this;return e=(Array.isArray(e)?e:[e]).map(function(e){return s.cache(e)}),r=[],Promise.all(e.map(function(t){var e;return t.inited?Promise.resolve():t.scope&&t.code?(t.inited=!0,r.push(t.code),Promise.resolve()):((e=s._ref(t)).then?e.then(function(e){return s.cache((t.id=void 0,t.version=e.version,t)),e}):_fetch(e,{method:"GET"}).then(function(e){return{content:e}})).then(function(e){e=e.content;return t.inited=!0,t.scope=csp.scope(t),t.code=s.converter.convert({css:e,name:t.scope,scopeTest:n}),r.push(t.code)})})).then(function(){return t?e:(s.styleContent.push.apply(s.styleContent,r),s.styleNode.textContent=s.styleContent.join("\n"),s.get(e))})}}),csp.env("undefined"!=typeof self&&null!==self?self:globalThis),"undefined"!=typeof module&&null!==module?module.exports=csp:"undefined"!=typeof window&&null!==window&&(window.csscope=csp); |
@@ -1,1 +0,1 @@ | ||
{"author":"zbryikt","name":"@plotdb/csscope","license":"MIT","description":"add scope to any css code","version":"4.0.8","homepage":"https://github.com/plotdb/csscope","browser":"index.min.js","main":"index.min.js","repository":{"type":"git","url":"https://github.com/plotdb/csscope"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.4","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.2","@zbryikt/template":"^2.3.33","bootstrap":"^4.5.2","bootstrap.native":"^3.0.13","fedep":"^1.1.5","jsdom":"^19.0.0","ldcover":"^3.0.1","ldview":"^1.0.0","livescript":"^1.6.0","puppeteer-core":"^13.2.0","uglify-js":"^3.13.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","bootstrap.native","@loadingio/bootstrap.ext","@loadingio/ldquery","@loadingio/debounce.js","@plotdb/semver","ldview","ldcover"]},"dependencies":{"@plotdb/semver":"^0.0.2","node-fetch":"^2.6.7"}} | ||
{"author":"zbryikt","name":"@plotdb/csscope","license":"MIT","description":"add scope to any css code","version":"4.1.0","homepage":"https://github.com/plotdb/csscope","browser":"index.min.js","main":"node.js","repository":{"type":"git","url":"https://github.com/plotdb/csscope"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.4","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.4","@zbryikt/template":"^2.3.42","bootstrap":"^4.5.2","bootstrap.native":"^3.0.13","fedep":"^1.1.7","jsdom":"^19.0.0","ldcover":"^3.0.1","ldview":"^1.0.0","livescript":"^1.6.0","puppeteer-core":"^13.2.0","uglify-js":"^3.13.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","bootstrap.native","@loadingio/bootstrap.ext","@loadingio/ldquery","@loadingio/debounce.js","@plotdb/semver","ldview","ldcover"]},"dependencies":{"@plotdb/semver":"^0.0.2","node-fetch":"^2.6.7"}} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
56248
105.68%8
60%1320
190.11%0
-100%3
-25%2
100%