UNPKG

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.

802 lines (620 loc) 22.7 kB
"use strict"; exports.id = 22; exports.ids = [22]; exports.modules = { /***/ 1519: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ atRuleAfterIndex: () => (/* binding */ atRuleAfterIndex), /* harmony export */ atRuleAfterNameIndex: () => (/* binding */ atRuleAfterNameIndex), /* harmony export */ atRuleBetweenIndex: () => (/* binding */ atRuleBetweenIndex), /* harmony export */ atRuleParamIndex: () => (/* binding */ atRuleParamIndex), /* harmony export */ declarationBetweenIndex: () => (/* binding */ declarationBetweenIndex), /* harmony export */ declarationValueIndex: () => (/* binding */ declarationValueIndex), /* harmony export */ ruleAfterIndex: () => (/* binding */ ruleAfterIndex), /* harmony export */ ruleBetweenIndex: () => (/* binding */ ruleBetweenIndex) /* harmony export */ }); /* harmony import */ var _getAtRuleParams_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1520); /* harmony import */ var _getRuleSelector_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1521); /* harmony import */ var _validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(579); /** @import {AtRule, Declaration, Rule} from 'postcss' */ /** * @param {AtRule} atRule * @returns {number} */ function atRuleParamIndex(atRule) { const index = atRuleAfterNameIndex(atRule); return index + (atRule.raws.afterName?.length ?? 0); } /** * @param {AtRule} atRule * @returns {number} */ function atRuleAfterIndex(atRule) { // subtract 1 for `}` const endOffset = atRule.source?.end?.offset; if (!endOffset) return atRule.toString().length - 1; const afterLength = atRule.raws?.after?.length; if (!afterLength) return endOffset - 1; return endOffset - (afterLength + 1); } /** * @param {AtRule} atRule * @returns {number} */ function atRuleAfterNameIndex(atRule) { // Initial 1 is for the `@` return 1 + atRule.name.length; } /** * @param {AtRule} atRule * @returns {number} */ function atRuleBetweenIndex(atRule) { return atRuleParamIndex(atRule) + (0,_getAtRuleParams_mjs__WEBPACK_IMPORTED_MODULE_0__["default"])(atRule).length; } /** * @param {Declaration} decl * @returns {number} */ function declarationBetweenIndex(decl) { const { prop } = decl.raws; const propIsObject = (0,_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__.isObject)(prop); return countChars([ propIsObject && 'prefix' in prop && prop.prefix, (propIsObject && 'raw' in prop && prop.raw) || decl.prop, propIsObject && 'suffix' in prop && prop.suffix, ]); } /** * Get the index of a declaration's value * * @param {Declaration} decl * @returns {number} */ function declarationValueIndex(decl) { const { between, value } = decl.raws; return ( declarationBetweenIndex(decl) + countChars([between || ':', value && 'prefix' in value && value.prefix]) ); } /** * @param {Rule} rule * @returns {number} */ function ruleBetweenIndex(rule) { return (0,_getRuleSelector_mjs__WEBPACK_IMPORTED_MODULE_1__["default"])(rule).length; } /** * @param {Rule} rule * @returns {number} */ function ruleAfterIndex(rule) { // subtract 1 for `}` const endOffset = rule.source?.end?.offset; if (!endOffset) return rule.toString().length - 1; const afterLength = rule.raws?.after?.length; if (!afterLength) return endOffset - 1; return endOffset - (afterLength + 1); } /** * @param {unknown[]} values * @returns {number} */ function countChars(values) { return values.reduce((/** @type {number} */ count, value) => { if ((0,_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__.isString)(value)) return count + value.length; return count; }, 0); } /***/ }), /***/ 1520: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ getAtRuleParams) /* harmony export */ }); /** * @param {import('postcss').AtRule} atRule * @returns {string} */ function getAtRuleParams(atRule) { return atRule.raws.params?.raw ?? atRule.params; } /***/ }), /***/ 1521: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ getRuleSelector) /* harmony export */ }); /** * @param {import('postcss').Rule} ruleNode * @returns {string} */ function getRuleSelector(ruleNode) { const raws = ruleNode.raws; return (raws.selector && raws.selector.raw) || ruleNode.selector; } /***/ }), /***/ 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; } /***/ }), /***/ 1525: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ hasLessInterpolation) /* harmony export */ }); const HAS_LESS_INTERPOLATION = /@\{.+?\}/; /** * Check whether a string has less interpolation * * @param {string} string * @returns {boolean} If `true`, a string has less interpolation */ function hasLessInterpolation(string) { return HAS_LESS_INTERPOLATION.test(string); } /***/ }), /***/ 1526: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ hasPsvInterpolation) /* harmony export */ }); const HAS_PSV_INTERPOLATION = /\$\(.+?\)/; /** * Check whether a string has postcss-simple-vars interpolation * * @param {string} string * @returns {boolean} */ function hasPsvInterpolation(string) { return HAS_PSV_INTERPOLATION.test(string); } /***/ }), /***/ 1527: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ hasScssInterpolation) /* harmony export */ }); const HAS_SCSS_INTERPOLATION = /#\{.+?\}/s; /** * Check whether a string has scss interpolation * * @param {string} string * @returns {boolean} */ function hasScssInterpolation(string) { return HAS_SCSS_INTERPOLATION.test(string); } /***/ }), /***/ 1528: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ hasTplInterpolation) /* harmony export */ }); const HAS_TPL_INTERPOLATION = /\{.+?\}/s; /** * Check whether a string has JS template literal interpolation or HTML-like template * * @param {string} string * @returns {boolean} If `true`, a string has template literal interpolation */ function hasTplInterpolation(string) { return HAS_TPL_INTERPOLATION.test(string); } /***/ }), /***/ 1539: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ isStandardSyntaxDeclaration) /* harmony export */ }); /* harmony import */ var _typeGuards_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(886); /* harmony import */ var _isScssVariable_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1540); /** * Check whether a declaration is standard * * @param {import('postcss').Declaration | import('postcss-less').Declaration} decl * @returns {boolean} */ function isStandardSyntaxDeclaration(decl) { const prop = decl.prop; const parent = decl.parent; // SCSS var; covers map and list declarations if ((0,_isScssVariable_mjs__WEBPACK_IMPORTED_MODULE_1__["default"])(prop)) { return false; } // Less var (e.g. @var: x), but exclude variable interpolation (e.g. @{var}) if (prop[0] === '@' && prop[1] !== '{') { return false; } // Less map declaration if (parent && parent.type === 'atrule' && parent.raws.afterName === ':') { return false; } // Less map (e.g. #my-map() { myprop: red; }) if ( parent && (0,_typeGuards_mjs__WEBPACK_IMPORTED_MODULE_0__.isRule)(parent) && parent.selector && parent.selector.startsWith('#') && parent.selector.endsWith('()') ) { return false; } // Sass nested properties (e.g. border: { style: solid; color: red; }) if ( parent && (0,_typeGuards_mjs__WEBPACK_IMPORTED_MODULE_0__.isRule)(parent) && parent.selector && parent.selector[parent.selector.length - 1] === ':' && parent.selector.substring(0, 2) !== '--' ) { return false; } // Less &:extend if ('extend' in decl && decl.extend) { return false; } return true; } /***/ }), /***/ 1540: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ isScssVariable) /* harmony export */ }); /** * Check whether a property is SCSS variable * * @param {string} property * @returns {boolean} */ function isScssVariable(property) { // SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value)) if (property.startsWith('$')) { return true; } // SCSS var within a namespace (e.g. namespace.$var: x) if (property.includes('.$')) { return true; } return false; } /***/ }), /***/ 1650: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ functionArgumentsSearch) /* harmony export */ }); /* harmony import */ var balanced_match__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1651); /* harmony import */ var postcss_value_parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1514); /* harmony import */ var _validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(579); /** @typedef {(expression: string, expressionIndex: number, funcNode: valueParser.FunctionNode, parsedValue: valueParser.ParsedValue) => void} Callback */ /** * Search a CSS string for functions by name. * For every match, invoke the callback, passing the function's * "argument(s) string" (whatever is inside the parentheses) * as an argument. * * Callback will be called once for every matching function found, * with the function's "argument(s) string" and its starting index * as the arguments. * * @param {string} source * @param {string | RegExp} functionName * @param {Callback} callback * @returns {valueParser.ParsedValue} */ function functionArgumentsSearch(source, functionName, callback) { const parsedValue = postcss_value_parser__WEBPACK_IMPORTED_MODULE_1__(source); return parsedValue.walk((node) => { if (node.type !== 'function') return; const { value } = node; if ((0,_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__.isString)(functionName) && value !== functionName) return; if ((0,_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__.isRegExp)(functionName) && !functionName.test(node.value)) return; const parensMatch = balanced_match__WEBPACK_IMPORTED_MODULE_0__('(', ')', source.slice(node.sourceIndex)); (0,_validateTypes_mjs__WEBPACK_IMPORTED_MODULE_2__.assert)(parensMatch); const expression = parensMatch.body; const parenLength = 1; // == '(' const expressionIndex = node.sourceIndex + value.length + parenLength; callback(expression, expressionIndex, node, parsedValue); }); } /***/ }), /***/ 1651: /***/ ((module) => { module.exports = balanced function balanced (a, b, str) { if (a instanceof RegExp) a = maybeMatch(a, str) if (b instanceof RegExp) b = maybeMatch(b, str) const r = range(a, b, str) return ( r && { start: r[0], end: r[1], pre: str.slice(0, r[0]), body: str.slice(r[0] + a.length, r[1]), post: str.slice(r[1] + b.length) } ) } function maybeMatch (reg, str) { const m = str.match(reg) return m ? m[0] : null } balanced.range = range function range (a, b, str) { let begs, beg, left, right, result let ai = str.indexOf(a) let bi = str.indexOf(b, ai + 1) let i = ai if (ai >= 0 && bi > 0) { if (a === b) { return [ai, bi] } begs = [] left = str.length while (i >= 0 && !result) { if (i === ai) { begs.push(i) ai = str.indexOf(a, i + 1) } else if (begs.length === 1) { result = [begs.pop(), bi] } else { beg = begs.pop() if (beg < left) { left = beg right = bi } bi = str.indexOf(b, i + 1) } i = ai < bi && ai >= 0 ? ai : bi } if (begs.length) { result = [left, right] } } return result } /***/ }), /***/ 1656: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ isStandardSyntaxUrl) /* harmony export */ }); /* harmony import */ var _hasLessInterpolation_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1525); /* harmony import */ var _hasPsvInterpolation_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1526); /* harmony import */ var _hasScssInterpolation_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1527); /* harmony import */ var _hasTplInterpolation_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1528); const IS_LESS_VARIABLE_IN_URL = /^@@?[\w-]+$/; const IS_SCSS_VARIABLE_IN_URL = /^[$\s\w+\-,./*'"@#?]+$/; /** * Check whether a URL is standard * * @param {string} url * @returns {boolean} */ function isStandardSyntaxUrl(url) { if (url.length === 0) { return true; } // Sass interpolation works anywhere if ((0,_hasScssInterpolation_mjs__WEBPACK_IMPORTED_MODULE_2__["default"])(url) || (0,_hasTplInterpolation_mjs__WEBPACK_IMPORTED_MODULE_3__["default"])(url) || (0,_hasPsvInterpolation_mjs__WEBPACK_IMPORTED_MODULE_1__["default"])(url)) { return false; } // Inside `'` and `"` work only LESS interpolation if ((url.startsWith(`'`) && url.endsWith(`'`)) || (url.startsWith(`"`) && url.endsWith(`"`))) { if ((0,_hasLessInterpolation_mjs__WEBPACK_IMPORTED_MODULE_0__["default"])(url)) { return false; } return true; } // Less variable works only at the beginning // Check is less variable, allow use '@url/some/path' // https://github.com/less/less.js/blob/3.x/lib/less/parser/parser.js#L547 if (url.startsWith('@') && IS_LESS_VARIABLE_IN_URL.test(url)) { return false; } // In url without quotes scss variable can be everywhere // But in this case it is allowed to use only specific characters // Also forbidden "/" at the end of url if (url.includes('$') && IS_SCSS_VARIABLE_IN_URL.test(url) && !url.endsWith('/')) { return false; } return true; } /***/ }), /***/ 1657: /***/ ((__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 _utils_nodeFieldIndices_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1519); /* harmony import */ var _utils_functionArgumentsSearch_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1650); /* harmony import */ var _utils_getAtRuleParams_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1520); /* harmony import */ var _utils_getDeclarationValue_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1522); /* harmony import */ var _utils_isStandardSyntaxDeclaration_mjs__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1539); /* harmony import */ var _utils_isStandardSyntaxUrl_mjs__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1656); /* harmony import */ var _utils_optionsMatches_mjs__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(869); /* harmony import */ var _utils_report_mjs__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(945); /* harmony import */ var _utils_ruleMessages_mjs__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(950); /* harmony import */ var _utils_validateOptions_mjs__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(873); const ruleName = 'function-url-quotes'; const messages = (0,_utils_ruleMessages_mjs__WEBPACK_IMPORTED_MODULE_8__["default"])(ruleName, { expected: (functionName) => `Expected quotes around "${functionName}" function argument`, rejected: (functionName) => `Unexpected quotes around "${functionName}" function argument`, }); const meta = { url: 'https://stylelint.io/user-guide/rules/function-url-quotes', fixable: true, }; const URL_FUNC_REGEX = /url\(/i; /** @import { Problem, CoreRules } from 'stylelint' */ /** @import { FunctionNode, ParsedValue } from 'postcss-value-parser' */ /** @import { AtRule, Declaration } from 'postcss' */ /** @type {CoreRules[ruleName]} */ const rule = (primary, secondaryOptions) => { return (root, result) => { const validOptions = (0,_utils_validateOptions_mjs__WEBPACK_IMPORTED_MODULE_9__["default"])( result, ruleName, { actual: primary, possible: ['always', 'never'], }, { actual: secondaryOptions, possible: { except: ['empty'], }, optional: true, }, ); if (!validOptions) { return; } const exceptEmpty = (0,_utils_optionsMatches_mjs__WEBPACK_IMPORTED_MODULE_6__["default"])(secondaryOptions, 'except', 'empty'); const emptyArgumentPatterns = new Set(['', "''", '""']); root.walkAtRules(checkAtRuleParams); root.walkDecls(checkDeclParams); /** * @param {Declaration|AtRule} node * @param {FunctionNode} fn * @param {keyof messages} messageType * @param {ParsedValue} parsedValue */ function getFix(node, fn, messageType, parsedValue) { return () => { switch (messageType) { case 'expected': addQuotes(fn); break; case 'rejected': removeQuotes(fn); break; } switch (node.type) { case 'decl': node.value = parsedValue.toString(); break; case 'atrule': node.params = parsedValue.toString(); break; } }; } /** * @param {AtRule|Declaration} node * @param {string} source * @param {number} startIndex */ function complain(node, source, startIndex) { (0,_utils_functionArgumentsSearch_mjs__WEBPACK_IMPORTED_MODULE_1__["default"])(source, /^url$/i, (args, index, funcNode, parsedValue) => { const object = checkArgs(args, startIndex + index); if (object) { const { messageType, ...rest } = object; const message = messages[messageType]; const messageArgs = [funcNode.value.toLowerCase()]; const fix = getFix(node, funcNode, messageType, parsedValue); (0,_utils_report_mjs__WEBPACK_IMPORTED_MODULE_7__["default"])({ ...rest, node, fix: { apply: fix, node }, message, messageArgs, result, ruleName, }); } }); } /** @param {Declaration} decl */ function checkDeclParams(decl) { if (!URL_FUNC_REGEX.test(decl.value)) return; if (!(0,_utils_isStandardSyntaxDeclaration_mjs__WEBPACK_IMPORTED_MODULE_4__["default"])(decl)) return; const value = (0,_utils_getDeclarationValue_mjs__WEBPACK_IMPORTED_MODULE_3__["default"])(decl); const startIndex = (0,_utils_nodeFieldIndices_mjs__WEBPACK_IMPORTED_MODULE_0__.declarationValueIndex)(decl); complain(decl, value, startIndex); } /** @param {AtRule} atRule */ function checkAtRuleParams(atRule) { const params = (0,_utils_getAtRuleParams_mjs__WEBPACK_IMPORTED_MODULE_2__["default"])(atRule); const startIndex = (0,_utils_nodeFieldIndices_mjs__WEBPACK_IMPORTED_MODULE_0__.atRuleParamIndex)(atRule); complain(atRule, params, startIndex); } /** @param {FunctionNode} funcNode */ function addQuotes(funcNode) { for (const argNode of funcNode.nodes) { if (argNode.type === 'word') { argNode.value = `"${argNode.value}"`; } } } /** @param {FunctionNode} funcNode */ function removeQuotes(funcNode) { for (const argNode of funcNode.nodes) { if (argNode.type === 'string') { // NOTE: We can ignore this error because the test passes. // @ts-expect-error -- TS2322: Type '"word"' is not assignable to type '"string"'. argNode.type = 'word'; } } } /** * @param {string} args * @param {number} index * @returns {Pick<Problem, 'index' | 'endIndex'> & { messageType: keyof messages } | undefined} */ function checkArgs(args, index) { const leftTrimmedArgs = args.trimStart(); if (!(0,_utils_isStandardSyntaxUrl_mjs__WEBPACK_IMPORTED_MODULE_5__["default"])(leftTrimmedArgs)) return; let expectQuotes = primary === 'always'; if (exceptEmpty && emptyArgumentPatterns.has(args.trim())) { expectQuotes = !expectQuotes; } const hasQuotes = leftTrimmedArgs.startsWith("'") || leftTrimmedArgs.startsWith('"'); if (expectQuotes && hasQuotes) return; if (!expectQuotes && !hasQuotes) return; const messageType = expectQuotes ? 'expected' : 'rejected'; const reportIndex = index + args.length - leftTrimmedArgs.length; const reportEndIndex = index + args.length; return { messageType, index: reportIndex, endIndex: reportEndIndex, }; } }; }; rule.ruleName = ruleName; rule.messages = messages; rule.meta = meta; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (rule); /***/ }) }; ; //# sourceMappingURL=22.extension.js.map