@wix/css-property-parser
Version:
A comprehensive TypeScript library for parsing and serializing CSS property values with full MDN specification compliance
67 lines (66 loc) • 2.22 kB
JavaScript
;
// Shared border style evaluator
// Provides parsing and serialization for individual border style properties
// Used by border-top-style, border-right-style, border-bottom-style, border-left-style
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBorderStyleProperty = parseBorderStyleProperty;
exports.borderStyleToCSSValue = borderStyleToCSSValue;
const shared_utils_1 = require('../utils/shared-utils.cjs');
const css_variable_1 = require('./css-variable.cjs');
// Import centralized types
const types_1 = require('../types.cjs');
/**
* Check if value is a border style keyword
*/
function isBorderStyleKeyword(value) {
return types_1.BORDER_STYLE_KEYWORDS.includes(value.toLowerCase());
}
/**
* Parse a border style property value (keyword only)
* Accepts border style keywords: none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset
*
* @param value - CSS border style value string
* @returns Parsed border style value or null if invalid
*/
function parseBorderStyleProperty(value) {
if (!value || typeof value !== 'string') {
return null;
}
const trimmed = value.trim();
if (trimmed === '') {
return null;
}
// CSS variables - return proper CSSVariable object
if ((0, shared_utils_1.isCssVariable)(trimmed)) {
return (0, css_variable_1.parse)(trimmed);
}
// Global keywords
if ((0, shared_utils_1.isGlobalKeyword)(trimmed)) {
return { type: 'keyword', keyword: trimmed.toLowerCase() };
}
// Border style keywords
if (isBorderStyleKeyword(trimmed)) {
return { type: 'keyword', keyword: trimmed.toLowerCase() };
}
return null;
}
/**
* Convert a border style property value back to CSS string
*
* @param parsed - Parsed border style value
* @returns CSS string representation or null if invalid
*/
function borderStyleToCSSValue(parsed) {
if (!parsed) {
return null;
}
// Handle CSS variables
if ('CSSvariable' in parsed) {
return (0, css_variable_1.toCSSValue)(parsed);
}
// All border style values are keywords
if ('keyword' in parsed) {
return parsed.keyword;
}
return null;
}