Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 8826a64

Browse files
committed
perf(sheet.ts): Remove sheet regex and moved here genBase62Hash
1 parent 9a69c78 commit 8826a64

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/core/method/sheet.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import type { ReturnStyleType, ClassesObjectType } from '../../_internal';
2-
import { cssCodeGenSheet, isInDevelopment, injectCSS } from '../../_internal';
2+
import { cssCodeGenSheet, isInDevelopment, injectCSS, genBase62Hash } from '../../_internal';
33
import styles from '../styles/style.module.css';
44
import { createGlobalStyleSheetPromise, globalStyleSheetPromise, resolveGlobalStyleSheet } from './sheet-build-in-helper';
55

66
export function sheet<T extends ClassesObjectType>(object: T & ClassesObjectType): ReturnStyleType<T> {
7-
const { styleSheet, base62Hash } = cssCodeGenSheet(object);
7+
const base62Hash = genBase62Hash(object, 5);
8+
const { styleSheet } = cssCodeGenSheet(object, base62Hash);
89
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
910
resolveGlobalStyleSheet(styleSheet);
1011

1112
return new Proxy<T & ClassesObjectType>(object, {
1213
get: function (target, prop: string) {
1314
if (typeof prop === 'string' && prop in target) {
1415
const className = prop + '_' + base62Hash;
15-
if (isInDevelopment) {
16-
const sheet = (styleSheet.match(`\\\n.${className}\\s*{[^}]+}`) || '')[0];
17-
injectCSS(className, sheet, 'sheet');
18-
}
16+
if (isInDevelopment) injectCSS(className, styleSheet, 'sheet');
17+
1918
return isInDevelopment ? className : styles[className];
2019
}
2120
},

0 commit comments

Comments
 (0)