MCPcopy Create free account
hub / github.com/alibaba/lowcode-engine / cssToRuntime

Function cssToRuntime

packages/utils/src/css-helper.ts:141–191  ·  view source on GitHub ↗
(css: string)

Source from the content-addressed store, hash-verified

139}
140
141function cssToRuntime(css: string) {
142 if (!css) {
143 return {};
144 }
145 const runtime: {
146 extra?: string[];
147 default?: Record<string, string>;
148 } = {};
149 const groups = groupingCss(css);
150 groups.forEach((cssItem) => {
151 if (!cssItem.startsWith(':root')) {
152 runtime.extra = runtime.extra || [];
153 runtime.extra.push(cssItem.trim());
154 } else {
155 const res = /:root:?(.*)?{(.*)/ig.exec(cssItem.replace(/[\r\n]+/ig, '').trim());
156 if (res) {
157 let pseudo: string | undefined;
158
159 if (res[1] && res[1].trim() && some(pseudoMap, pse => res[1].indexOf(pse) === 0)) {
160 pseudo = res[1].trim();
161 } else if (res[1] && res[1].trim()) {
162 pseudo = res[1];
163 }
164
165 const s: Record<string, string> = {};
166 res[2].split(';').reduce<string[]>((prev, next) => {
167 if (next.indexOf('base64') > -1) {
168 prev[prev.length - 1] += `;${next}`;
169 } else {
170 prev.push(next);
171 }
172 return prev;
173 }, []).forEach((item) => {
174 if (item) {
175 if (PROPS_REG.test(item)) {
176 const props = item.match(PROPS_REG);
177 const key = props?.[1];
178 const value = props?.[2];
179 if (key && value) {
180 s[key.trim()] = value.trim();
181 }
182 }
183 }
184 });
185
186 runtime[pseudo || 'default'] = s;
187 }
188 }
189 });
190 return runtime;
191}
192
193function cssToStyle(css) {
194 try {

Callers 1

cssToStyleFunction · 0.85

Calls 7

groupingCssFunction · 0.85
pushMethod · 0.80
replaceMethod · 0.80
matchMethod · 0.80
forEachMethod · 0.65
indexOfMethod · 0.65
reduceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…