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

Commit 2b6a9ad

Browse files
committed
feat(*): base62Hash 5 characters to base36Hash 6 and 8 characters
1 parent 7f16a95 commit 2b6a9ad

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

src/_internal/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from './types';
22
export * from './utils/extends';
33
export * from './utils/helper';
4-
export { genBase62Hash } from './utils/hash';
4+
export { genBase36Hash } from './utils/hash';
55
export { injectClientCSS } from './utils/inject-client-css';
66
export { injectClientGlobalCSS } from './utils/inject-client-global-css';
77
export { injectServerCSS, getServerCSS } from './utils/inject-server-css';

src/_internal/utils/sheet-compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { pseudo, camelToKebabCase, isClassesObjectType, applyCssValue } from '..';
22
import type { PropertyType, ClassesObjectType, CustomCSSProperties, CustomHTMLType } from '..';
33

4-
export function sheetCompiler(object: ClassesObjectType | CustomHTMLType, base62Hash?: string, core?: string) {
4+
export function sheetCompiler(object: ClassesObjectType | CustomHTMLType, base36Hash?: string, core?: string) {
55
let styleSheet = '';
66
let bigIndent = false;
77
const mediaQueries: { media: string; css: string }[] = [];
88

99
const classNameType = (property: string) => {
1010
if (core === '--global') return property;
11-
else return '.' + property + '_' + base62Hash;
11+
else return '.' + property + '_' + base36Hash;
1212
};
1313

1414
const rules = (indent: string, rulesValue: unknown, property: unknown) => {

src/_internal/utils/style-compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { camelToKebabCase, pseudo, applyCssValue } from '..';
22
import type { CustomCSSProperties, PropertyType, PropertyValue } from '..';
33

4-
export function styleCompiler<T extends CustomCSSProperties>(object: T, base62Hash?: string, root?: string) {
4+
export function styleCompiler<T extends CustomCSSProperties>(object: T, base36Hash?: string, root?: string) {
55
const classNameType = () => {
66
if (root === '--root') return ':root';
7-
else return '._' + base62Hash;
7+
else return '.' + base36Hash;
88
};
99
let bigIndent = false;
1010

src/core/method/create.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import type { ReturnStyleType, ClassesObjectType, ExactClassesObjectType } from '../../_internal';
2-
import { isDevelopment, isDevAndTest, isServer, injectServerCSS, injectClientCSS, sheetCompiler, genBase62Hash } from '../../_internal';
3-
import styles from '../styles/style.module.css';
2+
import { isDevAndTest, sheetCompiler, isDevelopment, injectServerCSS, genBase36Hash, isServer, injectClientCSS } from '../../_internal';
43
import { createGlobalStyleSheetPromise, globalStyleSheetPromise, resolveGlobalStyleSheet } from './create-build-in-helper';
4+
import styles from '../styles/style.module.css';
55

66
export function create<T extends ClassesObjectType>(object: ExactClassesObjectType<T> | ClassesObjectType): ReturnStyleType<T> {
7-
const base62Hash = genBase62Hash(object, 5);
8-
const { styleSheet } = sheetCompiler(object, base62Hash);
7+
const base36Hash = genBase36Hash(object, 6);
8+
const { styleSheet } = sheetCompiler(object, base36Hash);
99
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
1010
resolveGlobalStyleSheet(styleSheet);
1111

1212
return new Proxy(object, {
13-
get: function (target, prop: string) {
14-
if (typeof prop === 'string' && prop in target) {
15-
const className = prop + '_' + base62Hash;
16-
if (isDevelopment) isServer ? injectServerCSS(base62Hash, styleSheet, 'create') : injectClientCSS(base62Hash, styleSheet, 'create');
13+
get: function (target, key: string) {
14+
if (typeof key === 'string' && key in target) {
15+
const className = key + '_' + base36Hash;
16+
if (isDevelopment) isServer ? injectServerCSS(base36Hash, styleSheet, 'create') : injectClientCSS(base36Hash, styleSheet, 'create');
1717
return isDevAndTest ? className : styles[className];
1818
}
1919
},

src/core/method/global.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { CustomHTMLType } from '../../_internal';
2-
import { isDevAndTest, isServer, injectServerCSS, injectClientGlobalCSS, sheetCompiler, genBase62Hash } from '../../_internal';
2+
import { isDevAndTest, isServer, injectServerCSS, injectClientGlobalCSS, sheetCompiler, genBase36Hash } from '../../_internal';
33
import { resolveGlobalStyleSheet, globalStyleSheetPromise, createGlobalStyleSheetPromise } from './global-build-in-helper';
4+
import '../styles/global.css';
45

56
export function global(object: CustomHTMLType): void {
6-
const base62Hash = genBase62Hash(object, 5);
7+
const base36Hash = genBase36Hash(object, 8);
78
const { styleSheet } = sheetCompiler(object, undefined, '--global');
89
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
910
resolveGlobalStyleSheet([styleSheet, '--global']);
1011

11-
if (isDevAndTest) isServer ? injectServerCSS(base62Hash, styleSheet, 'global') : injectClientGlobalCSS(styleSheet, 'global');
12+
if (isDevAndTest) isServer ? injectServerCSS(base36Hash, styleSheet, 'global') : injectClientGlobalCSS(styleSheet, 'global');
1213
}

src/core/method/root.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { ExtendedCSSProperties } from '../../_internal';
2-
import { isDevAndTest, isServer, injectServerCSS, injectClientGlobalCSS, styleCompiler, genBase62Hash } from '../../_internal';
2+
import { isDevAndTest, isServer, injectServerCSS, injectClientGlobalCSS, styleCompiler, genBase36Hash } from '../../_internal';
33
import { resolveGlobalStyleSheet, globalStyleSheetPromise, createGlobalStyleSheetPromise } from './root-build-in-helper';
4+
import '../styles/global.css';
45

56
export function root(object: ExtendedCSSProperties): void {
6-
const base62Hash = genBase62Hash(object, 5);
7+
const base36Hash = genBase36Hash(object, 8);
78
const { styleSheet } = styleCompiler(object, undefined, '--root');
89
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
910
resolveGlobalStyleSheet([styleSheet, '--global']); // global.css
1011

11-
if (isDevAndTest) isServer ? injectServerCSS(base62Hash, styleSheet, 'root') : injectClientGlobalCSS(styleSheet, 'root');
12+
if (isDevAndTest) isServer ? injectServerCSS(base36Hash, styleSheet, 'root') : injectClientGlobalCSS(styleSheet, 'root');
1213
}

src/core/method/set.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import type { ExtendedCSSProperties } from '../../_internal';
2-
import { isDevelopment, isDevAndTest, isServer, injectServerCSS, injectClientCSS, styleCompiler, genBase62Hash } from '../../_internal';
3-
import styles from '../styles/style.module.css';
2+
import { isDevAndTest, isDevelopment, injectClientCSS, styleCompiler, genBase36Hash, injectServerCSS, isServer } from '../../_internal';
43
import { createGlobalStyleSheetPromise, globalStyleSheetPromise, resolveGlobalStyleSheet } from './set-build-in-helper';
4+
import styles from '../styles/style.module.css';
55

66
export function set(object: ExtendedCSSProperties): string {
7-
const base62Hash = genBase62Hash(object, 5);
8-
const { styleSheet } = styleCompiler(object, base62Hash);
9-
const classHash = '_' + base62Hash;
7+
const base36Hash = genBase36Hash(object, 8);
8+
const { styleSheet } = styleCompiler(object, base36Hash);
109
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
1110
resolveGlobalStyleSheet(styleSheet);
1211

13-
if (isDevelopment) isServer ? injectServerCSS(base62Hash, styleSheet, 'set') : injectClientCSS(base62Hash, styleSheet, 'set');
14-
return isDevAndTest ? classHash : styles[classHash];
12+
if (isDevelopment) isServer ? injectServerCSS(base36Hash, styleSheet, 'set') : injectClientCSS(base36Hash, styleSheet, 'set');
13+
return isDevAndTest ? base36Hash : styles[base36Hash];
1514
}

0 commit comments

Comments
 (0)