Bump
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
// MIT License. Copyright (c) 2017 Brice BERNARD
|
||||
// https://github.com/brikou/CSS-in-JS-generator/commit/2a887d0d96f1d5044039d0e0457001f0fde0def0
|
||||
import JSON5 from "json5";
|
||||
import { camelCase } from "lodash-es";
|
||||
import {
|
||||
type AtRule,
|
||||
type Builder,
|
||||
@ -8,11 +10,9 @@ import {
|
||||
type Rule,
|
||||
parse,
|
||||
} from "postcss";
|
||||
import JSON5 from "json5";
|
||||
import parseSelector from "postcss-selector-parser";
|
||||
import Stringifier from "postcss/lib/stringifier";
|
||||
import parseSelector from "postcss-selector-parser";
|
||||
import { type Element, compile } from "stylis";
|
||||
import { camelCase } from "lodash";
|
||||
|
||||
function getSelectorScope(selector: string): string {
|
||||
let selectorScope = "root";
|
||||
@ -129,7 +129,8 @@ const convertScopeToModuleName = (scope: string) =>
|
||||
"_$1"
|
||||
);
|
||||
|
||||
export function convertCssToJS(
|
||||
/** @internal */
|
||||
export function toJSCode(
|
||||
css: string,
|
||||
mapClassNames: (className: string) => string = convertScopeToModuleName
|
||||
): string {
|
||||
@ -211,7 +212,7 @@ export function convertCssToJS(
|
||||
? `injectGlobal\`${style}\n\`;\n`
|
||||
: `\nexport const ${mapClassNames(
|
||||
scope
|
||||
)} = ${JSON5.stringify(asJSObject(style), null, 2)};\n`;
|
||||
)} = ${JSON5.stringify(cssToJS(style), null, 2)};\n`;
|
||||
}
|
||||
|
||||
return res.trim();
|
||||
@ -299,7 +300,7 @@ function simplifyValue(propName: string, value: string) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function asJSObject(inputCssText: string) {
|
||||
export function cssToJS(inputCssText: string): Record<string, any> {
|
||||
const css = compile(inputCssText);
|
||||
const result: Record<string, string> = {};
|
||||
|
||||
@ -338,5 +339,5 @@ function asJSObject(inputCssText: string) {
|
||||
for (const node of css) {
|
||||
walk(result, node);
|
||||
}
|
||||
return result as React.CSSProperties;
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user