unnestcss
Version:
A library for un-nesting CSS
1 lines • 1.75 kB
Source Map (JSON)
{"mappings":"AAAA,cAEO,eASA;AAIP,OAAO,cAAM,OAAQ,SAAS;AAyC9B,eAAe","names":[],"sources":["../../../src/lib/host.ts"],"sourcesContent":["import {\n COLON,\n type Element,\n GREATER_THAN,\n LEFT_SQUARE_BRACKET,\n PLUS,\n RIGHT_SQUARE_BRACKET,\n RULESET,\n SPACE,\n TILDE,\n Tokenizer,\n} from \"./stylis.ts\";\n\nconst _host = \"host\";\n\nexport const host = (element: Element): void => {\n if (element.type === RULESET && element.parent?.value.startsWith(COLON + _host)) {\n element.props = (element.props as string[]).map((item) => {\n const tokens = new Tokenizer(item).tokenize();\n let start: number | undefined,\n end = tokens.length,\n hasHost = false;\n for (let index = 0; index < tokens.length; index++) {\n const token = tokens[index];\n switch (token) {\n case COLON:\n if (tokens.length > index + 2 && tokens[index + 1] === _host) {\n const afterHostToken = tokens[index + 2];\n if (\n afterHostToken === COLON ||\n (afterHostToken.startsWith(LEFT_SQUARE_BRACKET) &&\n afterHostToken.endsWith(RIGHT_SQUARE_BRACKET))\n ) {\n start = index + 2;\n hasHost = true;\n }\n }\n break;\n case SPACE:\n case GREATER_THAN:\n case TILDE:\n case PLUS:\n if (hasHost) {\n end = index;\n }\n break;\n }\n }\n if (hasHost) {\n return `:${_host}(${tokens.slice(start, end).join(\"\")})${tokens.slice(end).join(\"\")}`;\n }\n return item;\n });\n }\n};\n\nexport default host;\n"],"version":3,"file":"host.d.ts"}