@salesforce-ux/eslint-plugin-slds
Version:
ESLint plugin provides custom linting rules specifically built for Salesforce Lightning Design System 2 (SLDS 2 beta)
160 lines (158 loc) • 5.4 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/property-matcher.ts
var property_matcher_exports = {};
__export(property_matcher_exports, {
colorProperties: () => colorProperties,
densificationProperties: () => densificationProperties,
fontProperties: () => fontProperties,
isBorderColorProperty: () => isBorderColorProperty,
isBorderRadius: () => isBorderRadius,
isBorderWidthProperty: () => isBorderWidthProperty,
isDimensionProperty: () => isDimensionProperty,
isInsetProperty: () => isInsetProperty,
isMarginProperty: () => isMarginProperty,
isPaddingProperty: () => isPaddingProperty,
matchesCssProperty: () => matchesCssProperty,
resolvePropertyToMatch: () => resolvePropertyToMatch,
toSelector: () => toSelector
});
module.exports = __toCommonJS(property_matcher_exports);
function matchesCssProperty(hookProperties, cssProperty) {
return hookProperties.some((propertyPattern) => {
const regexPattern = new RegExp(
"^" + propertyPattern.replace(/\*/g, ".*") + "$"
);
return regexPattern.test(cssProperty);
});
}
var DIRECTION_VALUES = "(?:top|right|bottom|left|inline|block|inline-start|inline-end|start|end|block-start|block-end)";
var CORNER_VALUES = "(?:top-left|top-right|bottom-right|bottom-left|start-start|start-end|end-start|end-end)";
var INSET_VALUES = "(?:inline|block|inline-start|inline-end|block-start|block-end)";
var BORDER_COLOR_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-color$`);
var BORDER_WIDTH_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-width$`);
var MARGIN_REGEX = new RegExp(`^margin(?:-${DIRECTION_VALUES})?$`);
var PADDING_REGEX = new RegExp(`^padding(?:-${DIRECTION_VALUES})?$`);
var BORDER_RADIUS_REGEX = new RegExp(`^border(?:-${CORNER_VALUES})?-radius$`);
var INSET_REGEX = new RegExp(`^inset(?:-${INSET_VALUES})?$`);
function isBorderColorProperty(cssProperty) {
return BORDER_COLOR_REGEX.test(cssProperty);
}
function isBorderWidthProperty(cssProperty) {
return BORDER_WIDTH_REGEX.test(cssProperty);
}
function isMarginProperty(cssProperty) {
return MARGIN_REGEX.test(cssProperty);
}
function isPaddingProperty(cssProperty) {
return PADDING_REGEX.test(cssProperty);
}
function isBorderRadius(cssProperty) {
return BORDER_RADIUS_REGEX.test(cssProperty);
}
function isDimensionProperty(cssProperty) {
return ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProperty);
}
function isInsetProperty(cssProperty) {
return INSET_REGEX.test(cssProperty);
}
var fontProperties = [
"font",
"font-size",
"font-weight"
];
var colorProperties = [
"color",
"fill",
"background",
"background-color",
"stroke",
"border",
"border*",
"border*-color",
"outline",
"outline-color"
];
var densificationProperties = [
"border*",
"margin*",
"padding*",
"width",
"height",
"min-width",
"max-width",
"min-height",
"max-height",
"inset",
"top",
"right",
"left",
"bottom",
"outline",
"outline-width",
"line-height"
];
function toSelector(properties) {
const selectorParts = properties.map((prop) => {
if (prop.includes("*")) {
const regexPattern = prop.replace(/\*/g, ".*");
return `Declaration[property=/^${regexPattern}$/]`;
} else {
return `Declaration[property='${prop}']`;
}
});
return selectorParts.join(", ");
}
function resolvePropertyToMatch(cssProperty) {
const propertyToMatch = cssProperty.toLowerCase();
if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
return "border-width";
} else if (isMarginProperty(propertyToMatch)) {
return "margin";
} else if (isPaddingProperty(propertyToMatch)) {
return "padding";
} else if (isBorderRadius(propertyToMatch)) {
return "border-radius";
} else if (isDimensionProperty(propertyToMatch)) {
return "width";
} else if (isInsetProperty(propertyToMatch)) {
return "top";
} else if (cssProperty === "background" || cssProperty === "background-color") {
return "background-color";
} else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
return "border-color";
}
return propertyToMatch;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
colorProperties,
densificationProperties,
fontProperties,
isBorderColorProperty,
isBorderRadius,
isBorderWidthProperty,
isDimensionProperty,
isInsetProperty,
isMarginProperty,
isPaddingProperty,
matchesCssProperty,
resolvePropertyToMatch,
toSelector
});
//# sourceMappingURL=property-matcher.js.map