ocrmnav
Version:
DevStack - The Complete Developer Toolkit - Virtual file system, workflow automation, and more than 65+ other development tools / features in one seamless extension. Cutting down dev times never before seen.
313 lines (239 loc) • 10.2 kB
JavaScript
exports.id = 89;
exports.ids = [89];
exports.modules = {
/***/ 1522:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ getDeclarationValue)
/* harmony export */ });
/**
* @param {import('postcss').Declaration} decl
* @returns {string}
*/
function getDeclarationValue(decl) {
const raws = decl.raws;
return (raws.value && raws.value.raw) || decl.value;
}
/***/ }),
/***/ 1623:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ isNonNegativeInteger)
/* harmony export */ });
/**
* @param {unknown} value
*/
function isNonNegativeInteger(value) {
return Number.isInteger(value) && typeof value === 'number' && value >= 0;
}
/***/ }),
/***/ 1624:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ validateObjectWithProps)
/* harmony export */ });
/* harmony import */ var _validateTypes_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(579);
/**
* Check whether the variable is an object and all its properties agree with the provided validator.
*
* @example
* config = {
* value1: 1,
* value2: 2,
* value3: 3,
* };
* validateObjectWithProps(isNumber)(config);
* //=> true
*
* @param {(value: unknown) => boolean} validator
* @returns {(value: unknown) => boolean}
*/
function validateObjectWithProps(validator) {
return (value) => {
if (!(0,_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_0__.isPlainObject)(value)) {
return false;
}
return Object.values(value).every((item) => {
return validator(item);
});
};
}
/***/ }),
/***/ 1751:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(889);
/* harmony import */ var _csstools_css_parser_algorithms__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1647);
/* harmony import */ var _utils_nodeFieldIndices_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1519);
/* harmony import */ var _utils_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(579);
/* harmony import */ var _utils_getAtRuleParams_mjs__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1520);
/* harmony import */ var _utils_getDeclarationValue_mjs__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1522);
/* harmony import */ var _utils_isNonNegativeInteger_mjs__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1623);
/* harmony import */ var _utils_matchesStringOrRegExp_mjs__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(870);
/* harmony import */ var _utils_optionsMatches_mjs__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(869);
/* harmony import */ var _utils_report_mjs__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(945);
/* harmony import */ var _utils_ruleMessages_mjs__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(950);
/* harmony import */ var _utils_validateObjectWithProps_mjs__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(1624);
/* harmony import */ var _utils_validateOptions_mjs__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(873);
const ruleName = 'number-max-precision';
const messages = (0,_utils_ruleMessages_mjs__WEBPACK_IMPORTED_MODULE_10__["default"])(ruleName, {
expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
});
const meta = {
url: 'https://stylelint.io/user-guide/rules/number-max-precision',
};
/** @type {import('stylelint').CoreRules[ruleName]} */
const rule = (primary, secondaryOptions) => {
return (root, result) => {
const validOptions = (0,_utils_validateOptions_mjs__WEBPACK_IMPORTED_MODULE_12__["default"])(
result,
ruleName,
{
actual: primary,
possible: [_utils_isNonNegativeInteger_mjs__WEBPACK_IMPORTED_MODULE_6__["default"]],
},
{
optional: true,
actual: secondaryOptions,
possible: {
ignoreProperties: [_utils_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_3__.isString, _utils_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_3__.isRegExp],
ignoreUnits: [_utils_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_3__.isString, _utils_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_3__.isRegExp],
insideFunctions: [(0,_utils_validateObjectWithProps_mjs__WEBPACK_IMPORTED_MODULE_11__["default"])(_utils_isNonNegativeInteger_mjs__WEBPACK_IMPORTED_MODULE_6__["default"])],
},
},
);
if (!validOptions) {
return;
}
/** @type {Map<string, number>} */
const insideFunctions = new Map(Object.entries(secondaryOptions?.insideFunctions ?? {}));
root.walkAtRules((atRule) => {
if (atRule.name.toLowerCase() === 'import') {
return;
}
check(atRule, _utils_nodeFieldIndices_mjs__WEBPACK_IMPORTED_MODULE_2__.atRuleParamIndex, (0,_utils_getAtRuleParams_mjs__WEBPACK_IMPORTED_MODULE_4__["default"])(atRule));
});
root.walkDecls((decl) => {
check(decl, _utils_nodeFieldIndices_mjs__WEBPACK_IMPORTED_MODULE_2__.declarationValueIndex, (0,_utils_getDeclarationValue_mjs__WEBPACK_IMPORTED_MODULE_5__["default"])(decl));
});
/**
* @template {import('postcss').AtRule | import('postcss').Declaration} T
* @param {T} node
* @param {(node: T) => number} getIndex
* @param {string} value
*/
function check(node, getIndex, value) {
// Get out quickly if there are no periods
if (!value.includes('.')) return;
const prop = 'prop' in node ? node.prop : undefined;
if ((0,_utils_optionsMatches_mjs__WEBPACK_IMPORTED_MODULE_8__["default"])(secondaryOptions, 'ignoreProperties', prop)) {
return;
}
const initialState = {
ignored: false,
precision: primary,
};
(0,_csstools_css_parser_algorithms__WEBPACK_IMPORTED_MODULE_1__.walk)(
(0,_csstools_css_parser_algorithms__WEBPACK_IMPORTED_MODULE_1__.parseListOfComponentValues)((0,_csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__.tokenize)({ css: value })),
({ node: mediaNode, state }) => {
if (!state) return;
if (state.ignored) return;
walker(node, getIndex, mediaNode, state);
},
initialState,
);
}
/**
* @template {import('postcss').AtRule | import('postcss').Declaration} T
* @param {T} node
* @param {(node: T) => number} getIndex
* @param {import('@csstools/css-parser-algorithms').ComponentValue} componentValue
* @param {{ ignored: boolean, precision: number }} state
*/
function walker(node, getIndex, componentValue, state) {
if ((0,_csstools_css_parser_algorithms__WEBPACK_IMPORTED_MODULE_1__.isFunctionNode)(componentValue)) {
const name = componentValue.getName().toLowerCase();
if (name === 'url') {
// postcss-value-parser exposed url token contents as "word" tokens, these were indistinguishable from numeric values in any other function.
// With @csstools/css-tokenizer this is no longer relevant, but we preserve the old condition to avoid breaking changes.
state.ignored = true;
return;
}
state.precision = precisionInsideFunction(name, state.precision);
return;
}
if (!(0,_csstools_css_parser_algorithms__WEBPACK_IMPORTED_MODULE_1__.isTokenNode)(componentValue)) {
return;
}
const [tokenType, raw, startIndex, endIndex, parsedValue] = componentValue.value;
if (
tokenType !== _csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__.TokenType.Number &&
tokenType !== _csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__.TokenType.Dimension &&
tokenType !== _csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__.TokenType.Percentage
) {
return;
}
let unitStringLength = 0;
if (tokenType === _csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__.TokenType.Dimension) {
const unit = parsedValue.unit;
unitStringLength = unit.length;
if ((0,_utils_optionsMatches_mjs__WEBPACK_IMPORTED_MODULE_8__["default"])(secondaryOptions, 'ignoreUnits', unit)) {
return;
}
} else if (tokenType === _csstools_css_tokenizer__WEBPACK_IMPORTED_MODULE_0__.TokenType.Percentage) {
unitStringLength = 1;
if ((0,_utils_optionsMatches_mjs__WEBPACK_IMPORTED_MODULE_8__["default"])(secondaryOptions, 'ignoreUnits', '%')) {
return;
}
}
const match = /\d*\.(\d+)/.exec(raw);
if (match == null || match[0] == null || match[1] == null) {
return;
}
if (match[1].length <= state.precision) {
return;
}
const nodeIndex = getIndex(node);
(0,_utils_report_mjs__WEBPACK_IMPORTED_MODULE_9__["default"])({
result,
ruleName,
node,
index: nodeIndex + startIndex,
endIndex: nodeIndex + (endIndex + 1) - unitStringLength,
message: messages.expected,
messageArgs: [parsedValue.value, parsedValue.value.toFixed(state.precision)],
});
}
/**
* @param {string} functionName
* @param {number} currentPrecision
* @returns {number}
*/
function precisionInsideFunction(functionName, currentPrecision) {
const precisionForFunction = insideFunctions.get(functionName);
const hasPrecision = typeof precisionForFunction !== 'undefined';
if (hasPrecision) return precisionForFunction;
for (const [name, precision] of insideFunctions) {
if ((0,_utils_matchesStringOrRegExp_mjs__WEBPACK_IMPORTED_MODULE_7__["default"])(functionName, name)) {
return precision;
}
}
return currentPrecision;
}
};
};
rule.ruleName = ruleName;
rule.messages = messages;
rule.meta = meta;
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (rule);
/***/ })
};
;
//# sourceMappingURL=89.extension.js.map
;