UNPKG

@wix/css-property-parser

Version:

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

45 lines (44 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = parse; exports.toCSSValue = toCSSValue; const position_1 = require('./position.cjs'); /** * Parses CSS object-position property values * * Object-position uses the same syntax as background-position: * - Keywords: left, right, top, bottom, center * - Length/percentage values: 50px, 25%, etc. * - Combinations: "left top", "50% 25%", "center", etc. * - Offset syntax: "left 10px top 20px" * * Syntax: <position> | inherit | initial | unset | revert * * @param value - The CSS object-position value to parse * @returns Parsed PositionValue or null if invalid * * @example * ```typescript * parse('center') // { type: 'position', x: 'center', y: 'center' } * parse('left top') // { type: 'position', x: 'left', y: 'top' } * parse('50% 25%') // { type: 'position', x: '50%', y: '25%' } * parse('left 10px top 20px') // { type: 'position', x: 'left', y: 'top', xOffset: '10px', yOffset: '20px' } * parse('var(--obj-pos)') // { type: 'variable', variable: 'obj-pos' } * ``` */ function parse(value) { // Handle non-string inputs gracefully if (!value || typeof value !== 'string') { return null; } return (0, position_1.parse)(value); } /** * Converts a parsed PositionValue back to its CSS string representation * * @param value - The parsed object-position value * @returns CSS string representation or null if invalid */ function toCSSValue(value) { return (0, position_1.toCSSValue)(value); }