UNPKG

@wix/css-property-parser

Version:

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

66 lines (65 loc) 2.37 kB
"use strict"; // CSS overflow property evaluator // Handles CSS overflow property values according to MDN specification // https://developer.mozilla.org/en-US/docs/Web/CSS/overflow 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'); const types_1 = require('../types.cjs'); /** * Parses a CSS overflow property value according to MDN specification * * Supports: * - visible: Content is not clipped and may overflow the container * - hidden: Content is clipped to the container with no scrolling mechanism * - scroll: Content is clipped with scrollbars always visible * - auto: Content is clipped with scrollbars shown only when needed * - clip: Content is clipped with no scrolling mechanism (newer value) * - Global keywords: inherit, initial, unset, revert, revert-layer * - CSS variables: var(--custom-overflow) * * @param value - The CSS value to parse * @returns Parsed OverflowValue or null if invalid */ 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); } // Global keywords if ((0, shared_utils_1.isGlobalKeyword)(trimmed)) { return { type: 'keyword', keyword: trimmed.toLowerCase() }; } // Overflow-specific keywords const overflowKeyword = (0, shared_utils_1.getValidKeyword)(trimmed, types_1.OVERFLOW_KEYWORDS); if (overflowKeyword) { return { type: 'keyword', keyword: overflowKeyword }; } return null; } /** * Converts a parsed OverflowValue back to CSS string representation * * @param parsed - The parsed overflow value * @returns CSS value string or null if invalid */ function toCSSValue(parsed) { if (!parsed) return null; // Handle CSS variables if (parsed.type === 'variable') { return (0, css_variable_1.toCSSValue)(parsed); } // Handle keyword values (both overflow-specific and global) if (parsed.type === 'keyword') { return parsed.keyword; } return null; }