From b6cc6a09b932933e3135cc654a63175f7b5863c7 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 1 Aug 2021 19:00:42 +0300 Subject: [PATCH] detect typo in metadata when linting makes use of https://github.com/openstyles/usercss-meta/pull/78 --- _locales/en/messages.json | 12 ++++++++++++ edit/source-editor.js | 18 +++++++++++------- package-lock.json | 14 +++++++------- package.json | 2 +- vendor/usercss-meta/README.md | 2 +- vendor/usercss-meta/usercss-meta.min.js | 2 +- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index d464ac9b..2552b60b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -970,6 +970,18 @@ }, "description": "Error displayed when unknown metadata is parsed" }, + "meta_unknownMetaTypo": { + "message": "Maybe @$keyOk$? Unknown metadata: @$keyErr$", + "placeholders": { + "keyErr": { + "content": "$1" + }, + "keyOk": { + "content": "$2" + } + }, + "description": "Try translating it so that at least the first placeholder is visible in our narrow panel. This is the error displayed when an unknown metadata key was sufficiently similar to a known one to consider it a typo." + }, "meta_unknownPreprocessor": { "message": "Unknown @preprocessor: $preprocessor$", "placeholders": { diff --git a/edit/source-editor.js b/edit/source-editor.js index 1fb348dd..e931f02c 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -326,13 +326,17 @@ function SourceEditor() { if (errors.every(err => err.code === 'unknownMeta')) { onUpdated(metadata); } - cache = errors.map(err => ({ - from: cm.posFromIndex((err.index || 0) + match.index), - to: cm.posFromIndex((err.index || 0) + match.index), - message: err.code && t(`meta_${err.code}`, err.args, false) || err.message, - severity: err.code === 'unknownMeta' ? 'warning' : 'error', - rule: err.code, - })); + cache = errors.map(({code, index, args, message}) => { + const isUnknownMeta = code === 'unknownMeta'; + const typo = isUnknownMeta && args.length === 2 ? 'Typo' : ''; + return ({ + from: cm.posFromIndex((index || 0) + match.index), + to: cm.posFromIndex((index || 0) + match.index), + message: code && t(`meta_${code}${typo}`, args, false) || message, + severity: isUnknownMeta ? 'warning' : 'error', + rule: code, + }); + }); meta = match[0]; metaIndex = match.index; return cache; diff --git a/package-lock.json b/package-lock.json index 781b9337..15d0a79f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "lz-string-unsafe": "^1.4.4-fork-1", "stylelint-bundle": "^13.8.0", "stylus-lang-bundle": "github:openstyles/stylus-lang-bundle#v0.54.7", - "usercss-meta": "^0.11.0", + "usercss-meta": "^0.12.0", "webext-launch-web-auth-flow": "^0.1.1" }, "devDependencies": { @@ -11125,9 +11125,9 @@ } }, "node_modules/usercss-meta": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/usercss-meta/-/usercss-meta-0.11.0.tgz", - "integrity": "sha512-I6yJacP9zxr2Urww7loqJOzHfrrxxelziRiZZn4zKLj2117/MXt6Q4ix7Y1IWm4FrrL4JAo3LPpB4ggHeNWtMw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/usercss-meta/-/usercss-meta-0.12.0.tgz", + "integrity": "sha512-zKrXCKdpeIwtVe87omxGo9URf+7mbozduMZEg79dmT4KB3XJwfIkEi/Uk0PcTwR/nZLtAK1+k7isgbGB/g6E7Q==", "engines": { "node": ">=8.3" } @@ -21126,9 +21126,9 @@ "optional": true }, "usercss-meta": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/usercss-meta/-/usercss-meta-0.11.0.tgz", - "integrity": "sha512-I6yJacP9zxr2Urww7loqJOzHfrrxxelziRiZZn4zKLj2117/MXt6Q4ix7Y1IWm4FrrL4JAo3LPpB4ggHeNWtMw==" + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/usercss-meta/-/usercss-meta-0.12.0.tgz", + "integrity": "sha512-zKrXCKdpeIwtVe87omxGo9URf+7mbozduMZEg79dmT4KB3XJwfIkEi/Uk0PcTwR/nZLtAK1+k7isgbGB/g6E7Q==" }, "util-deprecate": { "version": "1.0.2", diff --git a/package.json b/package.json index 14f06dca..c66ed1ff 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lz-string-unsafe": "^1.4.4-fork-1", "stylelint-bundle": "^13.8.0", "stylus-lang-bundle": "github:openstyles/stylus-lang-bundle#v0.54.7", - "usercss-meta": "^0.11.0", + "usercss-meta": "^0.12.0", "webext-launch-web-auth-flow": "^0.1.1" }, "devDependencies": { diff --git a/vendor/usercss-meta/README.md b/vendor/usercss-meta/README.md index a7b65d38..d5bb5fc5 100644 --- a/vendor/usercss-meta/README.md +++ b/vendor/usercss-meta/README.md @@ -1,4 +1,4 @@ -## usercss-meta v0.11.0 +## usercss-meta v0.12.0 Following files are copied from npm (node_modules): diff --git a/vendor/usercss-meta/usercss-meta.min.js b/vendor/usercss-meta/usercss-meta.min.js index 9f6f936d..4ad053b3 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 h(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 w(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 I(e){const n=e.lastIndex;try{$(e)}catch(e){throw e.message=`Invalid JSON: ${e.message}`,e}e.index=n}function b(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=v(a[1].trim()),g(e)}function O(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 S(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=y(l[1]),t?function(e){o.lastIndex=e.lastIndex,e.lastIndex+=o.exec(e.text)[0].length}(e):g(e)}function $(e){const{text:a}=e;if("{"===a[e.lastIndex]){const n={};for(e.lastIndex++,g(e);"}"!==a[e.lastIndex];){S(e);const s=e.value;if(":"!==a[e.lastIndex])throw new t([":"],e.lastIndex);if(e.lastIndex++,g(e),$(e),n[s]=e.value,","===a[e.lastIndex])e.lastIndex++,g(e);else if("}"!==a[e.lastIndex])throw new t([",","}"],e.lastIndex)}e.lastIndex++,g(e),e.value=n}else if("["===a[e.lastIndex]){const n=[];for(e.lastIndex++,g(e);"]"!==a[e.lastIndex];)if($(e),n.push(e.value),","===a[e.lastIndex])e.lastIndex++,g(e);else if("]"!==a[e.lastIndex])throw new t([",","]"],e.lastIndex);e.lastIndex++,g(e),e.value=n}else if('"'===a[e.lastIndex]||"'"===a[e.lastIndex]||"`"===a[e.lastIndex])S(e);else if(/[-\d.]/.test(a[e.lastIndex]))k(e);else{if(w(e),!(e.value in f))throw new n({code:"unknownJSONLiteral",args:[e.value],message:`Unknown literal '${e.value}'`,index:e.index});e.value=f[e.value]}}function k(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 R(e){l.lastIndex=e.lastIndex;const t=l.exec(e.text)[0].trim();if(!t)throw new n({code:"missingValue",message:"Missing value",index:l.lastIndex});e.index=e.lastIndex,e.value=y(t),e.lastIndex=l.lastIndex}function j(e){return p.test(e)}var E={__proto__:null,eatLine:m,eatWhitespace:g,parseChar:h,parseEOT:b,parseJSON:I,parseNumber:k,parseString:S,parseStringToEnd:R,parseStringUnquoted:O,parseWord:w,unquote:y,isValidVersion:j};const U=self.URL,M=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","%"]),N={name:R,version:R,namespace:R,author:R,description:R,homepageURL:R,supportURL:R,updateURL:R,license:R,preprocessor:R},T={version:function(e){if(!j(e.value))throw new n({code:"invalidVersion",args:[e.value],message:`Invalid version: ${e.value}`,index:e.valueIndex});var t;e.value="v"===(t=e.value)[0]||"="===t[0]?t.slice(1):t},homepageURL:W,supportURL:W,updateURL:W},V={text:R,color:R,checkbox:h,select:A,dropdown:{advanced:P},image:{var:A,advanced:P},number:_,range:_},D={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:z,range:z},J=["name","namespace","version"],L=["default","min","max","step"];function _(e){I(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>=L.length)throw new n({code:"invalidRangeTooManyValues",message:"the array contains too many values",args:[e.type],index:e.valueIndex});t[L[a++]]=s}}}e.value=t.default,Object.assign(e.varResult,t)}function A(e){if(I(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=>K(e))):Object.keys(e.value).map((n=>K(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 P(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={};O(e),n.name=e.value,S(e),n.label=e.value,"dropdown"===e.type?b(e):S(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 K(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 C(e,n){if(n)try{e()}catch(e){n.push(e)}else e()}function W(e){let t;try{t=new U(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 z(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=Math.abs(e/n),a=Math.round(t);return Math.abs(t-a)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,C((()=>{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"),C((()=>{const e=t.filter((e=>!Object.prototype.hasOwnProperty.call(a,e)||!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,w(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});w(e),t.name=e.value,S(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=R}t.valueIndex=t.lastIndex,a(t),d[t.key]&&d[t.key](t)}}function F({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.apply(r,n.map((n=>[e,n]))):r.push([e,n])}else if("vars"===e)for(const e of Object.values(o))r.push([i,H(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.apply(null,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 H(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=>{return`${a}${e.name} ${JSON.stringify(e.label)} ${t=e.value,n?JSON.stringify(t):`<<`'${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 g(e){l.lastIndex=e.lastIndex,l.exec(e.text),e.lastIndex=l.lastIndex}function m(e){i.lastIndex=e.lastIndex,e.lastIndex+=i.exec(e.text)[0].length}function h(e){if(e.lastIndex>=e.text.length)throw new a(e.lastIndex);e.index=e.lastIndex,e.value=e.text[e.lastIndex],e.lastIndex++,m(e)}function w(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 I(e){const n=e.lastIndex;try{$(e)}catch(e){throw e.message=`Invalid JSON: ${e.message}`,e}e.index=n}function b(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=v(a[1].trim()),m(e)}function O(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 S(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=y(l[1]),t?function(e){o.lastIndex=e.lastIndex,e.lastIndex+=o.exec(e.text)[0].length}(e):m(e)}function $(e){const{text:a}=e;if("{"===a[e.lastIndex]){const n={};for(e.lastIndex++,m(e);"}"!==a[e.lastIndex];){S(e);const s=e.value;if(":"!==a[e.lastIndex])throw new t([":"],e.lastIndex);if(e.lastIndex++,m(e),$(e),n[s]=e.value,","===a[e.lastIndex])e.lastIndex++,m(e);else if("}"!==a[e.lastIndex])throw new t([",","}"],e.lastIndex)}e.lastIndex++,m(e),e.value=n}else if("["===a[e.lastIndex]){const n=[];for(e.lastIndex++,m(e);"]"!==a[e.lastIndex];)if($(e),n.push(e.value),","===a[e.lastIndex])e.lastIndex++,m(e);else if("]"!==a[e.lastIndex])throw new t([",","]"],e.lastIndex);e.lastIndex++,m(e),e.value=n}else if('"'===a[e.lastIndex]||"'"===a[e.lastIndex]||"`"===a[e.lastIndex])S(e);else if(/[-\d.]/.test(a[e.lastIndex]))k(e);else{if(w(e),!(e.value in f))throw new n({code:"unknownJSONLiteral",args:[e.value],message:`Unknown literal '${e.value}'`,index:e.index});e.value=f[e.value]}}function k(e){const t=e.lastIndex;r.lastIndex=t;const a=r.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 R(e){l.lastIndex=e.lastIndex;const t=l.exec(e.text)[0].trim();if(!t)throw new n({code:"missingValue",message:"Missing value",index:l.lastIndex});e.index=e.lastIndex,e.value=y(t),e.lastIndex=l.lastIndex}function j(e){return p.test(e)}var E={__proto__:null,eatLine:g,eatWhitespace:m,parseChar:h,parseEOT:b,parseJSON:I,parseNumber:k,parseString:S,parseStringToEnd:R,parseStringUnquoted:O,parseWord:w,unquote:y,isValidVersion:j};const M=self.URL,U=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","%"]),N={name:R,version:R,namespace:R,author:R,description:R,homepageURL:R,supportURL:R,updateURL:R,license:R,preprocessor:R},T={version:function(e){if(!j(e.value))throw new n({code:"invalidVersion",args:[e.value],message:`Invalid version: ${e.value}`,index:e.valueIndex});var t;e.value="v"===(t=e.value)[0]||"="===t[0]?t.slice(1):t},homepageURL:W,supportURL:W,updateURL:W},V={text:R,color:R,checkbox:h,select:_,dropdown:{advanced:P},image:{var:_,advanced:P},number:L,range:L},A={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:z,range:z},D=["name","namespace","version"],J=["default","min","max","step"];function L(e){I(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>=J.length)throw new n({code:"invalidRangeTooManyValues",message:"the array contains too many values",args:[e.type],index:e.valueIndex});t[J[a++]]=s}}}e.value=t.default,Object.assign(e.varResult,t)}function _(e){if(I(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=>K(e))):Object.keys(e.value).map((n=>K(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 P(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={};O(e),n.name=e.value,S(e),n.label=e.value,"dropdown"===e.type?b(e):S(e),n.value=e.value,s.push(n)}if(e.lastIndex++,m(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 K(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 C(e,n){if(n)try{e()}catch(e){n.push(e)}else e()}function W(e){let t;try{t=new M(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 z(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=Math.abs(e/n),a=Math.round(t);return Math.abs(t-a)s.push(e)};let o;for(;o=l.exec(e);)r.index=o.index,r.lastIndex=l.lastIndex,r.key=o[1],r.shouldIgnore=!1,C((()=>{try{"var"===r.key||"advanced"===r.key?f(r):v(r)}catch(e){throw void 0===e.index&&(e.index=r.index),e}"var"===r.key||"advanced"===r.key||r.shouldIgnore||(a[r.key]=r.value)}),i&&s),l.lastIndex=r.lastIndex;return r.maybeUSO&&!a.preprocessor&&(a.preprocessor="uso"),C((()=>{const e=t.filter((e=>!Object.prototype.hasOwnProperty.call(a,e)||!a[e]));if(e.length>0)throw new n({code:"missingMandatory",args:e,message:`Missing metadata: ${e.map((e=>`@${e}`)).join(", ")}`})}),i&&s),{metadata:a,errors:s}},validateVar:function(e){p({key:"var",type:e.type,value:e.value,varResult:e})}};function p(e){const n="object"==typeof x[e.type]?x[e.type][e.key]:x[e.type];n&&n(e)}function f(e){const t={type:null,label:null,name:null,value:null,default:null,options:null};e.varResult=t,w(e),e.type=e.value,t.type=e.type;const a="object"==typeof d[e.type]?d[e.type][e.key]:d[e.type];if(!a)throw new n({code:"unknownVarType",message:`Unknown @${e.key} type: ${e.type}`,args:[e.key,e.type],index:e.index});w(e),t.name=e.value,S(e,!0),t.label=e.value,e.valueIndex=e.lastIndex,a(e),p(e),t.default=e.value,e.usercssData.vars||(e.usercssData.vars={}),e.usercssData.vars[t.name]=t,"advanced"===e.key&&(e.maybeUSO=!0)}function v(t){let a=o[t.key];if(!a){if("assign"!==e){if(g(t),"ignore"===e)return void(t.shouldIgnore=!0);const a=Math.log2(t.key.length),s=u.find((e=>function(e,n,t){const a=e.length,s=n.length;if(Math.abs(a-s)>t)return!1;let l=function(e){const n=Array(e);for(let t=0;tt)return!1;const o=r;r=l,l=o}return l[a]<=t}(e,t.key,a)));throw new n({code:"unknownMeta",args:[t.key,s],message:`Unknown metadata: @${t.key}${s?`, did you mean @${s}?`:""}`,index:t.index})}a=R}t.valueIndex=t.lastIndex,a(t),c[t.key]&&c[t.key](t)}}function F({alignKeys:e=!1,space:n=2,format:t="stylus",stringifyKey:a={},stringifyVar:s={}}={}){return{stringify:function(l){let r;if("stylus"===t)r="var";else{if("xstyle"!==t)throw new TypeError("options.format must be 'stylus' or 'xstyle'");r="advanced"}const i=[];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)?i.push.apply(i,n.map((n=>[e,n]))):i.push([e,n])}else if("vars"===e)for(const e of Object.values(o))i.push([r,H(e,t,s,n)]);else if(Array.isArray(o))for(const n of o)i.push([e,Q(n)]);else i.push([e,Q(o)])}const o=e?Math.max.apply(null,i.map((e=>e[0].length))):0;return`/* ==UserStyle==\n${u=i.map((([e,n])=>`@${e.padEnd(o)} ${n}`)).join("\n"),u.replace(/\*\//g,"*\\/")}\n==/UserStyle== */`;var u}}}function H(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=>{return`${a}${e.name} ${JSON.stringify(e.label)} ${t=e.value,n?JSON.stringify(t):`<<