UNPKG

@wix/css-property-parser

Version:

A comprehensive TypeScript library for parsing and serializing CSS property values with full MDN specification compliance

54 lines (53 loc) 1.61 kB
"use strict"; // Font Style property parser // Handles parsing of CSS font-style property values // https://developer.mozilla.org/en-US/docs/Web/CSS/font-style Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = parse; exports.toCSSValue = toCSSValue; 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'); /** * Parse a CSS font-style property string */ function parse(value) { if (!value || typeof value !== 'string') { return null; } const trimmed = value.trim(); if (trimmed === '') { return null; } // CSS variables - parse and return directly if ((0, shared_utils_1.isCssVariable)(trimmed)) { return (0, css_variable_1.parse)(trimmed); } // Handle global keywords if ((0, shared_utils_1.isGlobalKeyword)(trimmed)) { return { type: 'keyword', keyword: trimmed.toLowerCase() }; } // Handle font-style keywords const fontStyleKeyword = (0, shared_utils_1.getValidKeyword)(trimmed, types_1.FONT_STYLE_KEYWORDS); if (fontStyleKeyword) { return { type: 'keyword', keyword: fontStyleKeyword }; } return null; } /** * Convert FontStyleValue back to CSS string */ function toCSSValue(parsed) { if (!parsed) { return null; } // Handle CSS variables if ('CSSvariable' in parsed) { return (0, css_variable_1.toCSSValue)(parsed); } if ('keyword' in parsed) { return parsed.keyword; } return null; }