diff --git a/background/background-worker.js b/background/background-worker.js
index 366b7b3c..81387aac 100644
--- a/background/background-worker.js
+++ b/background/background-worker.js
@@ -12,6 +12,7 @@ createAPI({
compileUsercss,
parseUsercssMeta(text, indexOffset = 0) {
loadScript(
+ '/js/polyfill.js',
'/vendor/usercss-meta/usercss-meta.min.js',
'/vendor-overwrites/colorpicker/colorconverter.js',
'/js/meta-parser.js'
@@ -20,6 +21,7 @@ createAPI({
},
nullifyInvalidVars(vars) {
loadScript(
+ '/js/polyfill.js',
'/vendor/usercss-meta/usercss-meta.min.js',
'/vendor-overwrites/colorpicker/colorconverter.js',
'/js/meta-parser.js'
diff --git a/background/background.js b/background/background.js
index 0ea3e0cf..ac2927e7 100644
--- a/background/background.js
+++ b/background/background.js
@@ -38,6 +38,12 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
openEditor,
updateIconBadge(count) {
+ // TODO: remove once our manifest's minimum_chrome_version is 50+
+ // Chrome 49 doesn't report own extension pages in webNavigation apparently
+ // so we do a force update which doesn't use the cache.
+ if (CHROME && CHROME < 2661 && this.sender.tab.url.startsWith(URLS.ownOrigin)) {
+ return updateIconBadgeForce(this.sender.tab.id, count);
+ }
return updateIconBadge(this.sender.tab.id, count);
},
@@ -347,6 +353,11 @@ function updateIconBadge(tabId, count) {
}
}
+function updateIconBadgeForce(tabId, count) {
+ refreshIconBadgeText(tabId, {count});
+ refreshIcon(tabId, {count});
+}
+
function refreshIconBadgeText(tabId, icon) {
iconUtil.setBadgeText({
text: prefs.get('show-badge') && icon.count ? String(icon.count) : '',
diff --git a/content/install-hook-usercss.js b/content/install-hook-usercss.js
index 622b3143..f52d5a0f 100644
--- a/content/install-hook-usercss.js
+++ b/content/install-hook-usercss.js
@@ -54,6 +54,18 @@
}
function fetchText(url) {
+ // XHR throws in Chrome 49
+ // FIXME: choose a correct version
+ // https://github.com/openstyles/stylus/issues/560
+ if (getChromeVersion() <= 49) {
+ return fetch(url)
+ .then(r => r.text())
+ .catch(() => fetchTextXHR(url));
+ }
+ return fetchTextXHR(url);
+ }
+
+ function fetchTextXHR(url) {
return new Promise((resolve, reject) => {
// you can't use fetch in Chrome under 'file:' protocol
const xhr = new XMLHttpRequest();
@@ -64,6 +76,11 @@
});
}
+ function getChromeVersion() {
+ const match = navigator.userAgent.match(/chrome\/(\d+)/i);
+ return match ? Number(match[1]) : undefined;
+ }
+
function start() {
timer = timer || setTimeout(check, DELAY);
}
diff --git a/edit.html b/edit.html
index da439c2b..9185bd42 100644
--- a/edit.html
+++ b/edit.html
@@ -63,6 +63,7 @@
+
diff --git a/edit/editor-worker.js b/edit/editor-worker.js
index 62ef380c..6ef51eef 100644
--- a/edit/editor-worker.js
+++ b/edit/editor-worker.js
@@ -16,6 +16,7 @@ createAPI({
},
metalint: code => {
loadScript(
+ '/js/polyfill.js',
'/vendor/usercss-meta/usercss-meta.min.js',
'/vendor-overwrites/colorpicker/colorconverter.js',
'/js/meta-parser.js'
diff --git a/install-usercss.html b/install-usercss.html
index 177431cc..6b9ad478 100644
--- a/install-usercss.html
+++ b/install-usercss.html
@@ -9,6 +9,7 @@
+
diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js
index 47194fce..889da8b8 100644
--- a/install-usercss/install-usercss.js
+++ b/install-usercss/install-usercss.js
@@ -231,6 +231,7 @@
.then(init)
.catch(err => {
$('#header').classList.add('meta-init-error');
+ console.error(err);
showError(err);
});
}
diff --git a/js/msg.js b/js/msg.js
index cca8fa86..23e80428 100644
--- a/js/msg.js
+++ b/js/msg.js
@@ -19,7 +19,8 @@ const msg = (() => {
const EXTENSION_URL = chrome.runtime.getURL('');
let handler;
const RX_NO_RECEIVER = /Receiving end does not exist/;
- const RX_PORT_CLOSED = /The message port closed before a response was received/;
+ // typo in Chrome 49
+ const RX_PORT_CLOSED = /The message port closed before a res?ponse was received/;
return {
send,
sendTab,
diff --git a/js/polyfill.js b/js/polyfill.js
new file mode 100644
index 00000000..7de2c83c
--- /dev/null
+++ b/js/polyfill.js
@@ -0,0 +1,53 @@
+'use strict';
+
+(() => {
+ if (!Object.entries) {
+ Object.entries = obj => Object.keys(obj).map(k => [k, obj[k]]);
+ }
+ if (!Object.values) {
+ Object.values = obj => Object.keys(obj).map(k => obj[k]);
+ }
+ if (typeof document === 'object') {
+ const ELEMENT_METH = {
+ append: {
+ base: [Element, Document, DocumentFragment],
+ fn: (node, frag) => {
+ node.appendChild(frag);
+ }
+ },
+ prepend: {
+ base: [Element, Document, DocumentFragment],
+ fn: (node, frag) => {
+ node.insertBefore(frag, node.firstChild);
+ }
+ },
+ before: {
+ base: [Element, CharacterData, DocumentType],
+ fn: (node, frag) => {
+ node.parentNode.insertBefore(frag, node);
+ }
+ },
+ after: {
+ base: [Element, CharacterData, DocumentType],
+ fn: (node, frag) => {
+ node.parentNode.insertBefore(frag, node.nextSibling);
+ }
+ }
+ };
+
+ for (const [key, {base, fn}] of Object.entries(ELEMENT_METH)) {
+ for (const cls of base) {
+ if (cls.prototype[key]) {
+ continue;
+ }
+ cls.prototype[key] = function (...nodes) {
+ const frag = document.createDocumentFragment();
+ for (const node of nodes) {
+ frag.appendChild(typeof node === 'string' ? document.createTextNode(node) : node);
+ }
+ fn(this, frag);
+ };
+ }
+ }
+ }
+})();
diff --git a/js/usercss.js b/js/usercss.js
index 27bc9c92..03e37c18 100644
--- a/js/usercss.js
+++ b/js/usercss.js
@@ -41,8 +41,9 @@ const usercss = (() => {
})
.then(({metadata}) => {
style.usercssData = metadata;
- for (const [key, value = key] of Object.entries(GLOBAL_METAS)) {
- style[value] = metadata[key];
+ // https://github.com/openstyles/stylus/issues/560#issuecomment-440561196
+ for (const [key, value] of Object.entries(GLOBAL_METAS)) {
+ style[value || key] = metadata[key];
}
return style;
});
diff --git a/manage.html b/manage.html
index dc8176f9..ecf81d09 100644
--- a/manage.html
+++ b/manage.html
@@ -146,6 +146,7 @@
+
diff --git a/manage/config-dialog.css b/manage/config-dialog.css
index abdcd89d..f9cf08d8 100644
--- a/manage/config-dialog.css
+++ b/manage/config-dialog.css
@@ -6,6 +6,10 @@
padding: 8px 16px;
}
+#stylus-popup .config-dialog > div {
+ position: relative;
+}
+
#stylus-popup .config-body label {
padding: .5em 0;
}
diff --git a/manifest.json b/manifest.json
index 11489478..2fe717f0 100644
--- a/manifest.json
+++ b/manifest.json
@@ -24,6 +24,7 @@
],
"background": {
"scripts": [
+ "js/polyfill.js",
"js/promisify.js",
"js/messaging.js",
"js/msg.js",
@@ -62,7 +63,7 @@
"run_at": "document_start",
"all_frames": true,
"match_about_blank": true,
- "js": ["js/promisify.js", "js/msg.js", "js/prefs.js", "content/apply.js"]
+ "js": ["js/polyfill.js", "js/promisify.js", "js/msg.js", "js/prefs.js", "content/apply.js"]
},
{
"matches": ["http://userstyles.org/*", "https://userstyles.org/*"],
diff --git a/options.html b/options.html
index 996ca894..d20834b5 100644
--- a/options.html
+++ b/options.html
@@ -19,6 +19,7 @@
}
+
diff --git a/package.json b/package.json
index bb369eac..b6c2159a 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
"stylelint-bundle": "^8.0.0",
"stylus-lang-bundle": "^0.54.5",
"updates": "^5.1.2",
- "usercss-meta": "^0.8.3",
+ "usercss-meta": "^0.8.4",
"web-ext": "^2.9.2",
"webext-tx-fix": "^0.3.1",
"zipjs-browserify": "^1.0.1"
diff --git a/popup.html b/popup.html
index 1149d95d..4890c313 100644
--- a/popup.html
+++ b/popup.html
@@ -150,6 +150,7 @@
+
diff --git a/vendor/usercss-meta/README.md b/vendor/usercss-meta/README.md
index ba6cc75e..4dde15c1 100644
--- a/vendor/usercss-meta/README.md
+++ b/vendor/usercss-meta/README.md
@@ -1,5 +1,5 @@
-## usercss-meta v0.8.3
+## usercss-meta v0.8.4
usercss-meta installed via npm - source repo:
-https://unpkg.com/usercss-meta@0.8.3/dist/usercss-meta.min.js
+https://unpkg.com/usercss-meta@0.8.4/dist/usercss-meta.min.js
diff --git a/vendor/usercss-meta/usercss-meta.min.js b/vendor/usercss-meta/usercss-meta.min.js
index 16a90dfd..54f804bc 100644
--- a/vendor/usercss-meta/usercss-meta.min.js
+++ b/vendor/usercss-meta/usercss-meta.min.js
@@ -1,2 +1,2 @@
-var usercssMeta=function(e){"use strict";class n extends Error{constructor(e){super(e.message),delete e.message,this.name="ParseError",Object.assign(this,e)}}class t extends n{constructor(e,n){super({code:"missingChar",args:e,message:`Missing character: ${e.map(e=>`'${e}'`).join(", ")}`,index:n})}}class a extends n{constructor(e){super({code:"EOF",message:"Unexpected end of file",index:e})}}const s=/<<e[1]===n?n:JSON.parse(`"${e}"`))}function m(e){l.lastIndex=e.lastIndex,l.exec(e.text),e.lastIndex=l.lastIndex}function g(e){r.lastIndex=e.lastIndex,e.lastIndex+=r.exec(e.text)[0].length}function y(e){if(e.lastIndex>=e.text.length)throw new a(e.lastIndex);e.index=e.lastIndex,e.value=e.text[e.lastIndex],e.lastIndex++,g(e)}function h(e){const t=e.lastIndex;u.lastIndex=t;const a=u.exec(e.text);if(!a)throw new n({code:"invalidWord",message:"Invalid word",index:t});e.index=t,e.value=a[1],e.lastIndex+=a[0].length}function w(e){const a=e.lastIndex;try{!function e(a){const{text:s}=a;if("{"===s[a.lastIndex]){const n={};for(a.lastIndex++,g(a);"}"!==s[a.lastIndex];){O(a);const l=a.value;if(":"!==s[a.lastIndex])throw new t([":"],a.lastIndex);if(a.lastIndex++,g(a),e(a),n[l]=a.value,","===s[a.lastIndex])a.lastIndex++,g(a);else if("}"!==s[a.lastIndex])throw new t([",","}"],a.lastIndex)}a.lastIndex++,g(a),a.value=n}else if("["===s[a.lastIndex]){const n=[];for(a.lastIndex++,g(a);"]"!==s[a.lastIndex];)if(e(a),n.push(a.value),","===s[a.lastIndex])a.lastIndex++,g(a);else if("]"!==s[a.lastIndex])throw new t([",","]"],a.lastIndex);a.lastIndex++,g(a),a.value=n}else if('"'===s[a.lastIndex]||"'"===s[a.lastIndex]||"`"===s[a.lastIndex])O(a);else if(/[-\d.]/.test(s[a.lastIndex]))S(a);else{if(h(a),!(a.value in p))throw new n({code:"unknownJSONLiteral",args:[a.value],message:`Unknown literal '${a.value}'`,index:a.index});a.value=p[a.value]}}(e)}catch(e){throw e.message=`Invalid JSON: ${e.message}`,e}e.index=a}function I(e){const t=e.lastIndex;s.lastIndex=t;const a=e.text.match(s);if(!a)throw new n({code:"missingEOT",message:"Missing EOT",index:t});e.index=t,e.lastIndex+=a[0].length,e.value=f(a[1].trim()),g(e)}function b(e){x.lastIndex=e.lastIndex;const n=x.exec(e.text);e.index=e.lastIndex,e.lastIndex=x.lastIndex,e.value=n[0].trim().replace(/\s+/g,"-")}function O(e,t=!1){const a=e.lastIndex,s="`"===e.text[a]?d:c;s.lastIndex=a;const l=s.exec(e.text);if(!l)throw new n({code:"invalidString",message:"Invalid string",index:a});e.index=a,e.lastIndex+=l[0].length,e.value=v(l[1]),t?function(e){o.lastIndex=e.lastIndex,e.lastIndex+=o.exec(e.text)[0].length}(e):g(e)}function S(e){const t=e.lastIndex;i.lastIndex=t;const a=i.exec(e.text);if(!a)throw new n({code:"invalidNumber",message:"Invalid number",index:t});e.index=t,e.value=Number(a[0].trim()),e.lastIndex+=a[0].length}function $(e){l.lastIndex=e.lastIndex;const n=l.exec(e.text);e.index=e.lastIndex,e.value=v(n[0].trim()),e.lastIndex=l.lastIndex}var k={eatLine:m,eatWhitespace:g,parseChar:y,parseEOT:I,parseJSON:w,parseNumber:S,parseString:O,parseStringToEnd:$,parseStringUnquoted:b,parseWord:h,unquote:v};const R=self.URL,E=new Set(["em","ex","cap","ch","ic","rem","lh","rlh","vw","vh","vi","vb","vmin","vmax","cm","mm","Q","in","pt","pc","px","deg","grad","rad","turn","s","ms","Hz","kHz","dpi","dpcm","dppx","%"]),j={name:$,version:$,namespace:$,author:$,description:$,homepageURL:$,supportURL:$,updateURL:$,license:$,preprocessor:$},U={version:function(e){const t=e.value.match(/\bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?\b/gi);if(!t||t[0]!==e.value)throw new n({code:"invalidVersion",args:[e.value],message:`Invalid version: ${e.value}`,index:e.valueIndex});var a;e.value="v"===(a=e.value)[0]||"="===a[0]?a.slice(1):a},homepageURL:z,supportURL:z,updateURL:z},N={text:$,color:$,checkbox:y,select:L,dropdown:{advanced:V},image:{var:L,advanced:V},number:J,range:J},T={checkbox:function(e){if("1"!==e.value&&"0"!==e.value)throw new n({code:"invalidCheckboxDefault",message:"value must be 0 or 1",index:e.valueIndex})},number:K,range:K},M=["name","namespace","version"],D=["default","min","max","step"];function J(e){w(e);const t={min:null,max:null,step:null,units:null};if("number"==typeof e.value)t.default=e.value;else{if(!Array.isArray(e.value))throw new n({code:"invalidRange",message:"the default value must be an array or a number",index:e.valueIndex,args:[e.type]});{let a=0;for(const s of e.value)if("string"==typeof s){if(null!=t.units)throw new n({code:"invalidRangeMultipleUnits",message:"units is alredy defined",args:[e.type],index:e.valueIndex});t.units=s}else{if("number"!=typeof s&&null!==s)throw new n({code:"invalidRangeValue",message:"value must be number, string, or null",args:[e.type],index:e.valueIndex});if(a>=D.length)throw new n({code:"invalidRangeTooManyValues",message:"the array contains too many values",args:[e.type],index:e.valueIndex});t[D[a++]]=s}}}e.value=t.default,Object.assign(e.varResult,t)}function L(e){if(w(e),"object"!=typeof e.value||!e.value)throw new n({code:"invalidSelect",message:"The value must be an array or object"});const t=Array.isArray(e.value)?e.value.map(e=>A(e)):Object.entries(e.value).map(([e,n])=>A(e,n));if(new Set(t.map(e=>e.name)).sizee.isDefault);if(a.length>1)throw new n({code:"invalidSelectMultipleDefaults",message:"multiple default values"});t.forEach(e=>{delete e.isDefault}),e.varResult.options=t,e.value=(a.length>0?a[0]:t[0]).name}function V(e){const a=e.lastIndex;if("{"!==e.text[e.lastIndex])throw new t(["{"],a);const s=[];for(e.lastIndex++;"}"!==e.text[e.lastIndex];){const n={};b(e),n.name=e.value,O(e),n.label=e.value,"dropdown"===e.type?I(e):O(e),n.value=e.value,s.push(n)}if(e.lastIndex++,g(e),0===s.length)throw new n({code:"invalidSelectEmptyOptions",message:"Option list is empty",index:a});"dropdown"===e.type&&(e.varResult.type="select",e.type="select"),e.varResult.options=s,e.value=s[0].name}function A(e,t){if("string"!=typeof e||t&&"string"!=typeof t)throw new n({code:"invalidSelectValue",message:"Values in the object/array must be strings"});let a,s=!1;e.endsWith("*")&&(s=!0,e=e.slice(0,-1));const l=e.match(/^(\w+):(.*)/);if(l&&([,a,e]=l),a||(a=e),!e)throw new n({code:"invalidSelectLabel",message:"Option label is empty"});return null==t&&(t=a),{name:a,label:e,value:t,isDefault:s}}function _(e,n){if(n)try{e()}catch(e){n.push(e)}else e()}function z(e){let t;try{t=new R(e.value)}catch(n){throw n.args=[e.value],n.index=e.valueIndex,n}if(!/^https?:/.test(t.protocol))throw new n({code:"invalidURLProtocol",args:[t.protocol],message:`Invalid protocol: ${t.protocol}`,index:e.valueIndex})}function K(e){const t=e.value;if("number"!=typeof t)throw new n({code:"invalidRangeDefault",message:`the default value of @var ${e.type} must be a number`,index:e.valueIndex,args:[e.type]});const a=e.varResult;if(null!=a.min&&ta.max)throw new n({code:"invalidRangeMax",message:"the value is larger than the maximum",index:e.valueIndex,args:[e.type]});if(null!=a.step&&[t,a.min,a.max].some(e=>null!=e&&!function(e,n){const t=n.toString().split(".")[1],a=t?10**t.length:1;return e*a%(n*a)==0}(e,a.step)))throw new n({code:"invalidRangeStep",message:"the value is not a multiple of the step",index:e.valueIndex,args:[e.type]});if(a.units&&!E.has(a.units))throw new n({code:"invalidRangeUnits",message:`Invalid CSS unit: ${a.units}`,index:e.valueIndex,args:[e.type,a.units]})}function P({unknownKey:e="ignore",mandatoryKeys:t=M,parseKey:a,parseVar:s,validateKey:l,validateVar:i,allowErrors:r=!1}={}){if(!["ignore","assign","throw"].includes(e))throw new TypeError("unknownKey must be 'ignore', 'assign', or 'throw'");const o=Object.assign({__proto__:null},j,a),u=Object.assign({},N,s),d=Object.assign({},U,l),c=Object.assign({},T,i);return{parse:function(e){if(e.includes("\r"))throw new TypeError("metadata includes invalid character: '\\r'");const a={},s=[],l=/@(\w+)[^\S\r\n]*/gm,i={index:0,lastIndex:0,text:e,usercssData:a,warn:e=>s.push(e)};let o;for(;o=l.exec(e);)i.index=o.index,i.lastIndex=l.lastIndex,i.key=o[1],i.shouldIgnore=!1,_(()=>{try{"var"===i.key||"advanced"===i.key?p(i):f(i)}catch(e){throw void 0===e.index&&(e.index=i.index),e}"var"===i.key||"advanced"===i.key||i.shouldIgnore||(a[i.key]=i.value)},r&&s),l.lastIndex=i.lastIndex;return i.maybeUSO&&!a.preprocessor&&(a.preprocessor="uso"),_(()=>{const e=t.filter(e=>!Object.prototype.hasOwnProperty.call(a,e));if(e.length>0)throw new n({code:"missingMandatory",args:e,message:`Missing metadata: ${e.map(e=>`@${e}`).join(", ")}`})},r&&s),{metadata:a,errors:s}},validateVar:function(e){x({key:"var",type:e.type,value:e.value,varResult:e})}};function x(e){const n="object"==typeof c[e.type]?c[e.type][e.key]:c[e.type];n&&n(e)}function p(e){const t={type:null,label:null,name:null,value:null,default:null,options:null};e.varResult=t,h(e),e.type=e.value,t.type=e.type;const a="object"==typeof u[e.type]?u[e.type][e.key]:u[e.type];if(!a)throw new n({code:"unknownVarType",message:`Unknown @${e.key} type: ${e.type}`,args:[e.key,e.type],index:e.index});h(e),t.name=e.value,O(e,!0),t.label=e.value,e.valueIndex=e.lastIndex,a(e),x(e),t.default=e.value,e.usercssData.vars||(e.usercssData.vars={}),e.usercssData.vars[t.name]=t,"advanced"===e.key&&(e.maybeUSO=!0)}function f(t){let a=o[t.key];if(!a){if("assign"!==e){if(m(t),"ignore"===e)return void(t.shouldIgnore=!0);throw new n({code:"unknownMeta",args:[t.key],message:`Unknown metadata: @${t.key}`,index:t.index})}a=$}t.valueIndex=t.lastIndex,a(t),d[t.key]&&d[t.key](t)}}function C({alignKeys:e=!1,space:n=2,format:t="stylus",stringifyKey:a={},stringifyVar:s={}}={}){return{stringify:function(l){let i;if("stylus"===t)i="var";else{if("xstyle"!==t)throw new TypeError("options.format must be 'stylus' or 'xstyle'");i="advanced"}const r=[];for(const[e,o]of Object.entries(l))if(Object.prototype.hasOwnProperty.call(a,e)){const n=a[e](o);Array.isArray(n)?r.push(...n.map(n=>[e,n])):r.push([e,n])}else if("vars"===e)for(const e of Object.values(o))r.push([i,W(e,t,s,n)]);else if(Array.isArray(o))for(const n of o)r.push([e,q(n)]);else r.push([e,q(o)]);const o=e?Math.max(...r.map(e=>e[0].length)):0;return`/* ==UserStyle==\n${u=r.map(([e,n])=>`@${e.padEnd(o)} ${n}`).join("\n"),u.replace(/\*\//g,"*\\/")}\n==/UserStyle== */`;var u}}}function W(e,n,t,a){return`${"xstyle"===n&&"select"===e.type?"dropdown":e.type} ${e.name} ${JSON.stringify(e.label)} ${function(){if(Object.prototype.hasOwnProperty.call(t,e.type))return t[e.type](e,n,a);if(e.options)return"stylus"===n?JSON.stringify(e.options.reduce((n,t)=>{const a=t.name===e.default?"*":"";return n[`${t.name}:${t.label}${a}`]=t.value,n},{}),null,a):function(e,n=!1,t=0){const a="string"==typeof t?t:" ".repeat(t);return`{\n${e.map(e=>`${a}${e.name} ${JSON.stringify(e.label)} ${function(e){return n?JSON.stringify(e):`<<`'${e}'`).join(", ")}`,index:n})}}class a extends n{constructor(e){super({code:"EOF",message:"Unexpected end of file",index:e})}}const s=/<<e[1]===n?n:JSON.parse(`"${e}"`))}function m(e){l.lastIndex=e.lastIndex,l.exec(e.text),e.lastIndex=l.lastIndex}function y(e){r.lastIndex=e.lastIndex,e.lastIndex+=r.exec(e.text)[0].length}function g(e){if(e.lastIndex>=e.text.length)throw new a(e.lastIndex);e.index=e.lastIndex,e.value=e.text[e.lastIndex],e.lastIndex++,y(e)}function h(e){const t=e.lastIndex;u.lastIndex=t;const a=u.exec(e.text);if(!a)throw new n({code:"invalidWord",message:"Invalid word",index:t});e.index=t,e.value=a[1],e.lastIndex+=a[0].length}function w(e){const a=e.lastIndex;try{!function e(a){const{text:s}=a;if("{"===s[a.lastIndex]){const n={};for(a.lastIndex++,y(a);"}"!==s[a.lastIndex];){O(a);const l=a.value;if(":"!==s[a.lastIndex])throw new t([":"],a.lastIndex);if(a.lastIndex++,y(a),e(a),n[l]=a.value,","===s[a.lastIndex])a.lastIndex++,y(a);else if("}"!==s[a.lastIndex])throw new t([",","}"],a.lastIndex)}a.lastIndex++,y(a),a.value=n}else if("["===s[a.lastIndex]){const n=[];for(a.lastIndex++,y(a);"]"!==s[a.lastIndex];)if(e(a),n.push(a.value),","===s[a.lastIndex])a.lastIndex++,y(a);else if("]"!==s[a.lastIndex])throw new t([",","]"],a.lastIndex);a.lastIndex++,y(a),a.value=n}else if('"'===s[a.lastIndex]||"'"===s[a.lastIndex]||"`"===s[a.lastIndex])O(a);else if(/[-\d.]/.test(s[a.lastIndex]))S(a);else{if(h(a),!(a.value in p))throw new n({code:"unknownJSONLiteral",args:[a.value],message:`Unknown literal '${a.value}'`,index:a.index});a.value=p[a.value]}}(e)}catch(e){throw e.message=`Invalid JSON: ${e.message}`,e}e.index=a}function I(e){const t=e.lastIndex;s.lastIndex=t;const a=s.exec(e.text);if(!a)throw new n({code:"missingEOT",message:"Missing EOT",index:t});e.index=t,e.lastIndex+=a[0].length,e.value=f(a[1].trim()),y(e)}function b(e){x.lastIndex=e.lastIndex;const n=x.exec(e.text);e.index=e.lastIndex,e.lastIndex=x.lastIndex,e.value=n[0].trim().replace(/\s+/g,"-")}function O(e,t=!1){const a=e.lastIndex,s="`"===e.text[a]?d:c;s.lastIndex=a;const l=s.exec(e.text);if(!l)throw new n({code:"invalidString",message:"Invalid string",index:a});e.index=a,e.lastIndex+=l[0].length,e.value=v(l[1]),t?function(e){o.lastIndex=e.lastIndex,e.lastIndex+=o.exec(e.text)[0].length}(e):y(e)}function S(e){const t=e.lastIndex;i.lastIndex=t;const a=i.exec(e.text);if(!a)throw new n({code:"invalidNumber",message:"Invalid number",index:t});e.index=t,e.value=Number(a[0].trim()),e.lastIndex+=a[0].length}function k(e){l.lastIndex=e.lastIndex;const n=l.exec(e.text);e.index=e.lastIndex,e.value=v(n[0].trim()),e.lastIndex=l.lastIndex}var $={eatLine:m,eatWhitespace:y,parseChar:g,parseEOT:I,parseJSON:w,parseNumber:S,parseString:O,parseStringToEnd:k,parseStringUnquoted:b,parseWord:h,unquote:v};const R=self.URL,E=new Set(["em","ex","cap","ch","ic","rem","lh","rlh","vw","vh","vi","vb","vmin","vmax","cm","mm","Q","in","pt","pc","px","deg","grad","rad","turn","s","ms","Hz","kHz","dpi","dpcm","dppx","%"]),j={name:k,version:k,namespace:k,author:k,description:k,homepageURL:k,supportURL:k,updateURL:k,license:k,preprocessor:k},U={version:function(e){const t=e.value.match(/\bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?\b/gi);if(!t||t[0]!==e.value)throw new n({code:"invalidVersion",args:[e.value],message:`Invalid version: ${e.value}`,index:e.valueIndex});var a;e.value="v"===(a=e.value)[0]||"="===a[0]?a.slice(1):a},homepageURL:z,supportURL:z,updateURL:z},N={text:k,color:k,checkbox:g,select:L,dropdown:{advanced:V},image:{var:L,advanced:V},number:J,range:J},T={checkbox:function(e){if("1"!==e.value&&"0"!==e.value)throw new n({code:"invalidCheckboxDefault",message:"value must be 0 or 1",index:e.valueIndex})},number:K,range:K},M=["name","namespace","version"],D=["default","min","max","step"];function J(e){w(e);const t={min:null,max:null,step:null,units:null};if("number"==typeof e.value)t.default=e.value;else{if(!Array.isArray(e.value))throw new n({code:"invalidRange",message:"the default value must be an array or a number",index:e.valueIndex,args:[e.type]});{let a=0;for(const s of e.value)if("string"==typeof s){if(null!=t.units)throw new n({code:"invalidRangeMultipleUnits",message:"units is alredy defined",args:[e.type],index:e.valueIndex});t.units=s}else{if("number"!=typeof s&&null!==s)throw new n({code:"invalidRangeValue",message:"value must be number, string, or null",args:[e.type],index:e.valueIndex});if(a>=D.length)throw new n({code:"invalidRangeTooManyValues",message:"the array contains too many values",args:[e.type],index:e.valueIndex});t[D[a++]]=s}}}e.value=t.default,Object.assign(e.varResult,t)}function L(e){if(w(e),"object"!=typeof e.value||!e.value)throw new n({code:"invalidSelect",message:"The value must be an array or object"});const t=Array.isArray(e.value)?e.value.map(e=>A(e)):Object.keys(e.value).map(n=>A(n,e.value[n]));if(new Set(t.map(e=>e.name)).sizee.isDefault);if(a.length>1)throw new n({code:"invalidSelectMultipleDefaults",message:"multiple default values"});t.forEach(e=>{delete e.isDefault}),e.varResult.options=t,e.value=(a.length>0?a[0]:t[0]).name}function V(e){const a=e.lastIndex;if("{"!==e.text[e.lastIndex])throw new t(["{"],a);const s=[];for(e.lastIndex++;"}"!==e.text[e.lastIndex];){const n={};b(e),n.name=e.value,O(e),n.label=e.value,"dropdown"===e.type?I(e):O(e),n.value=e.value,s.push(n)}if(e.lastIndex++,y(e),0===s.length)throw new n({code:"invalidSelectEmptyOptions",message:"Option list is empty",index:a});"dropdown"===e.type&&(e.varResult.type="select",e.type="select"),e.varResult.options=s,e.value=s[0].name}function A(e,t){if("string"!=typeof e||t&&"string"!=typeof t)throw new n({code:"invalidSelectValue",message:"Values in the object/array must be strings"});let a,s=!1;e.endsWith("*")&&(s=!0,e=e.slice(0,-1));const l=e.match(/^(\w+):(.*)/);if(l&&([,a,e]=l),a||(a=e),!e)throw new n({code:"invalidSelectLabel",message:"Option label is empty"});return null==t&&(t=a),{name:a,label:e,value:t,isDefault:s}}function _(e,n){if(n)try{e()}catch(e){n.push(e)}else e()}function z(e){let t;try{t=new R(e.value)}catch(n){throw n.args=[e.value],n.index=e.valueIndex,n}if(!/^https?:/.test(t.protocol))throw new n({code:"invalidURLProtocol",args:[t.protocol],message:`Invalid protocol: ${t.protocol}`,index:e.valueIndex})}function K(e){const t=e.value;if("number"!=typeof t)throw new n({code:"invalidRangeDefault",message:`the default value of @var ${e.type} must be a number`,index:e.valueIndex,args:[e.type]});const a=e.varResult;if(null!=a.min&&ta.max)throw new n({code:"invalidRangeMax",message:"the value is larger than the maximum",index:e.valueIndex,args:[e.type]});if(null!=a.step&&[t,a.min,a.max].some(e=>null!=e&&!function(e,n){const t=n.toString().split(".")[1],a=t?Math.pow(10,t.length):1;return e*a%(n*a)==0}(e,a.step)))throw new n({code:"invalidRangeStep",message:"the value is not a multiple of the step",index:e.valueIndex,args:[e.type]});if(a.units&&!E.has(a.units))throw new n({code:"invalidRangeUnits",message:`Invalid CSS unit: ${a.units}`,index:e.valueIndex,args:[e.type,a.units]})}function P({unknownKey:e="ignore",mandatoryKeys:t=M,parseKey:a,parseVar:s,validateKey:l,validateVar:i,allowErrors:r=!1}={}){if(!["ignore","assign","throw"].includes(e))throw new TypeError("unknownKey must be 'ignore', 'assign', or 'throw'");const o=Object.assign({__proto__:null},j,a),u=Object.assign({},N,s),d=Object.assign({},U,l),c=Object.assign({},T,i);return{parse:function(e){if(e.includes("\r"))throw new TypeError("metadata includes invalid character: '\\r'");const a={},s=[],l=/@(\w+)[^\S\r\n]*/gm,i={index:0,lastIndex:0,text:e,usercssData:a,warn:e=>s.push(e)};let o;for(;o=l.exec(e);)i.index=o.index,i.lastIndex=l.lastIndex,i.key=o[1],i.shouldIgnore=!1,_(()=>{try{"var"===i.key||"advanced"===i.key?p(i):f(i)}catch(e){throw void 0===e.index&&(e.index=i.index),e}"var"===i.key||"advanced"===i.key||i.shouldIgnore||(a[i.key]=i.value)},r&&s),l.lastIndex=i.lastIndex;return i.maybeUSO&&!a.preprocessor&&(a.preprocessor="uso"),_(()=>{const e=t.filter(e=>!Object.prototype.hasOwnProperty.call(a,e));if(e.length>0)throw new n({code:"missingMandatory",args:e,message:`Missing metadata: ${e.map(e=>`@${e}`).join(", ")}`})},r&&s),{metadata:a,errors:s}},validateVar:function(e){x({key:"var",type:e.type,value:e.value,varResult:e})}};function x(e){const n="object"==typeof c[e.type]?c[e.type][e.key]:c[e.type];n&&n(e)}function p(e){const t={type:null,label:null,name:null,value:null,default:null,options:null};e.varResult=t,h(e),e.type=e.value,t.type=e.type;const a="object"==typeof u[e.type]?u[e.type][e.key]:u[e.type];if(!a)throw new n({code:"unknownVarType",message:`Unknown @${e.key} type: ${e.type}`,args:[e.key,e.type],index:e.index});h(e),t.name=e.value,O(e,!0),t.label=e.value,e.valueIndex=e.lastIndex,a(e),x(e),t.default=e.value,e.usercssData.vars||(e.usercssData.vars={}),e.usercssData.vars[t.name]=t,"advanced"===e.key&&(e.maybeUSO=!0)}function f(t){let a=o[t.key];if(!a){if("assign"!==e){if(m(t),"ignore"===e)return void(t.shouldIgnore=!0);throw new n({code:"unknownMeta",args:[t.key],message:`Unknown metadata: @${t.key}`,index:t.index})}a=k}t.valueIndex=t.lastIndex,a(t),d[t.key]&&d[t.key](t)}}function C({alignKeys:e=!1,space:n=2,format:t="stylus",stringifyKey:a={},stringifyVar:s={}}={}){return{stringify:function(l){let i;if("stylus"===t)i="var";else{if("xstyle"!==t)throw new TypeError("options.format must be 'stylus' or 'xstyle'");i="advanced"}const r=[];for(const e of Object.keys(l)){const o=l[e];if(Object.prototype.hasOwnProperty.call(a,e)){const n=a[e](o);Array.isArray(n)?r.push(...n.map(n=>[e,n])):r.push([e,n])}else if("vars"===e)for(const e of Object.values(o))r.push([i,W(e,t,s,n)]);else if(Array.isArray(o))for(const n of o)r.push([e,q(n)]);else r.push([e,q(o)])}const o=e?Math.max(...r.map(e=>e[0].length)):0;return`/* ==UserStyle==\n${u=r.map(([e,n])=>`@${e.padEnd(o)} ${n}`).join("\n"),u.replace(/\*\//g,"*\\/")}\n==/UserStyle== */`;var u}}}function W(e,n,t,a){return`${"xstyle"===n&&"select"===e.type?"dropdown":e.type} ${e.name} ${JSON.stringify(e.label)} ${function(){if(Object.prototype.hasOwnProperty.call(t,e.type))return t[e.type](e,n,a);if(e.options)return"stylus"===n?JSON.stringify(e.options.reduce((n,t)=>{const a=t.name===e.default?"*":"";return n[`${t.name}:${t.label}${a}`]=t.value,n},{}),null,a):function(e,n=!1,t=0){const a="string"==typeof t?t:" ".repeat(t);return`{\n${e.map(e=>`${a}${e.name} ${JSON.stringify(e.label)} ${function(e){return n?JSON.stringify(e):`<<