MCPcopy Create free account
hub / github.com/webstudio-is/webstudio / parseShadow

Function parseShadow

packages/css-data/src/parse-css-value.ts:480–523  ·  view source on GitHub ↗
(
  nodes: CssNode[],
  input: string
)

Source from the content-addressed store, hash-verified

478};
479
480const parseShadow = (
481 nodes: CssNode[],
482 input: string
483): ShadowValue | UnparsedValue => {
484 // https://drafts.csswg.org/css-borders-4/#box-shadow-position
485 let position: "inset" | "outset" = "outset";
486 let color: undefined | ColorValue | RgbValue | KeywordValue;
487 const units: UnitValue[] = [];
488 for (const node of nodes) {
489 const item = parseLiteral(node, ["inset"]);
490 if (item?.type === "keyword" && item.value === "inset") {
491 position = item.value;
492 } else if (item?.type === "keyword" && parseColor(item.value)) {
493 color = item;
494 } else if (item?.type === "color") {
495 color = item;
496 } else if (item?.type === "rgb") {
497 color = item;
498 } else if (item?.type === "unit") {
499 units.push(item);
500 } else {
501 return { type: "unparsed", value: input };
502 }
503 }
504 if (units.length < 2) {
505 return { type: "unparsed", value: input };
506 }
507 const shadowValue: ShadowValue = {
508 type: "shadow",
509 position,
510 offsetX: units[0],
511 offsetY: units[1],
512 };
513 if (units.length > 2) {
514 shadowValue.blur = units[2];
515 }
516 if (units.length > 3) {
517 shadowValue.spread = units[3];
518 }
519 if (color) {
520 shadowValue.color = color;
521 }
522 return shadowValue;
523};
524
525export const parseCssVar = (node: FunctionNode): undefined | VarValue => {
526 const [name, _comma, ...fallback] = node.children;

Callers 2

parseLiteralFunction · 0.85
parseCssValueFunction · 0.85

Calls 2

parseLiteralFunction · 0.85
parseColorFunction · 0.70

Tested by

no test coverage detected