|
1 | 1 | import type { ReturnStyleType, ClassesObjectType } from '../../_internal'; |
2 | | -import { cssCodeGenSheet, isInDevelopment, injectCSS } from '../../_internal'; |
| 2 | +import { cssCodeGenSheet, isInDevelopment, injectCSS, genBase62Hash } from '../../_internal'; |
3 | 3 | import styles from '../styles/style.module.css'; |
4 | 4 | import { createGlobalStyleSheetPromise, globalStyleSheetPromise, resolveGlobalStyleSheet } from './sheet-build-in-helper'; |
5 | 5 |
|
6 | 6 | 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); |
8 | 9 | if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise(); |
9 | 10 | resolveGlobalStyleSheet(styleSheet); |
10 | 11 |
|
11 | 12 | return new Proxy<T & ClassesObjectType>(object, { |
12 | 13 | get: function (target, prop: string) { |
13 | 14 | if (typeof prop === 'string' && prop in target) { |
14 | 15 | 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 | + |
19 | 18 | return isInDevelopment ? className : styles[className]; |
20 | 19 | } |
21 | 20 | }, |
|
0 commit comments