function cssToRuntime()

in packages/utils/src/css-helper.ts [141:191]


function cssToRuntime(css: string) {
  if (!css) {
    return {};
  }
  const runtime: {
    extra?: string[];
    default?: Record<string, string>;
  } = {};
  const groups = groupingCss(css);
  groups.forEach((cssItem) => {
    if (!cssItem.startsWith(':root')) {
      runtime.extra = runtime.extra || [];
      runtime.extra.push(cssItem.trim());
    } else {
      const res = /:root:?(.*)?{(.*)/ig.exec(cssItem.replace(/[\r\n]+/ig, '').trim());
      if (res) {
        let pseudo: string | undefined;

        if (res[1] && res[1].trim() && some(pseudoMap, pse => res[1].indexOf(pse) === 0)) {
          pseudo = res[1].trim();
        } else if (res[1] && res[1].trim()) {
          pseudo = res[1];
        }

        const s: Record<string, string> = {};
        res[2].split(';').reduce<string[]>((prev, next) => {
          if (next.indexOf('base64') > -1) {
            prev[prev.length - 1] += `;${next}`;
          } else {
            prev.push(next);
          }
          return prev;
        }, []).forEach((item) => {
          if (item) {
            if (PROPS_REG.test(item)) {
              const props = item.match(PROPS_REG);
              const key = props?.[1];
              const value = props?.[2];
              if (key && value) {
                s[key.trim()] = value.trim();
              }
            }
          }
        });

        runtime[pseudo || 'default'] = s;
      }
    }
  });
  return runtime;
}