fdbfb23547
* parserlib: fast section extraction, tweaks and speedups
* csslint: "simple-not" rule
* csslint: enable and fix "selector-newline" rule
* simplify db: resolve with result
* simplify download()
* remove noCode param as it wastes more time/memory on copying
* styleManager: switch style<->data names to reflect their actual contents
* inline method bodies to avoid indirection and enable better autocomplete/hint/jump support in IDE
* upgrade getEventKeyName to handle mouse clicks
* don't trust location.href as it hides text fragment
* getAllKeys is implemented since Chrome48, FF44
* allow recoverable css errors + async'ify usercss.js
* openManage: unminimize windows
* remove the obsolete Chrome pre-65 workaround
* fix temporal dead zone in apply.js
* ff bug workaround for simple editor window
* consistent window scrolling in scrollToEditor and jumpToPos
* rework waitForSelector and collapsible <details>
* blank paint frame workaround for new Chrome
* extract stuff from edit.js and load on demand
* simplify regexpTester::isShown
* move MozDocMapper to sections-util.js
* extract fitSelectBox()
* initialize router earlier
* use helpPopup.close()
* fix autofocus in popups, follow-up to 5bb1b5ef
* clone objects in prefs.get() + cosmetics
* reuse getAll result for INC
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
/* exported metaParser */
|
|
const metaParser = (() => {
|
|
require(['/vendor/usercss-meta/usercss-meta.min']); /* global usercssMeta */
|
|
const {createParser, ParseError} = usercssMeta;
|
|
const PREPROCESSORS = new Set(['default', 'uso', 'stylus', 'less']);
|
|
const options = {
|
|
validateKey: {
|
|
preprocessor: state => {
|
|
if (!PREPROCESSORS.has(state.value)) {
|
|
throw new ParseError({
|
|
code: 'unknownPreprocessor',
|
|
args: [state.value],
|
|
index: state.valueIndex,
|
|
});
|
|
}
|
|
},
|
|
},
|
|
validateVar: {
|
|
select: state => {
|
|
if (state.varResult.options.every(o => o.name !== state.value)) {
|
|
throw new ParseError({
|
|
code: 'invalidSelectValueMismatch',
|
|
index: state.valueIndex,
|
|
});
|
|
}
|
|
},
|
|
color: state => {
|
|
require(['/js/color/color-converter']); /* global colorConverter */
|
|
const color = colorConverter.parse(state.value);
|
|
if (!color) {
|
|
throw new ParseError({
|
|
code: 'invalidColor',
|
|
args: [state.value],
|
|
index: state.valueIndex,
|
|
});
|
|
}
|
|
state.value = colorConverter.format(color, 'rgb');
|
|
},
|
|
},
|
|
};
|
|
const parser = createParser(options);
|
|
const looseParser = createParser(Object.assign({}, options, {
|
|
allowErrors: true,
|
|
unknownKey: 'throw',
|
|
}));
|
|
|
|
return {
|
|
|
|
lint: looseParser.parse,
|
|
parse: parser.parse,
|
|
|
|
nullifyInvalidVars(vars) {
|
|
for (const va of Object.values(vars)) {
|
|
if (va.value !== null) {
|
|
try {
|
|
parser.validateVar(va);
|
|
} catch (err) {
|
|
va.value = null;
|
|
}
|
|
}
|
|
}
|
|
return vars;
|
|
},
|
|
};
|
|
})();
|