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

Commit 0e12deb

Browse files
committed
feat(type*) add new ExtendedCSSProperties and Fix Pseudos.
1 parent 81ba82c commit 0e12deb

File tree

4 files changed

+64
-49
lines changed

4 files changed

+64
-49
lines changed

src/_internal/types/common/pseudo-selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export type ArgsPseudos =
8484
| LanguagesType
8585
| CustomNthArgsType;
8686

87-
type AndStrings = `&${string}`;
87+
export type AndStrings = `&${string}`;
8888
export type AndStringsType = {
8989
[key in AndStrings]: CustomCSSProperties;
9090
};

src/_internal/types/custom/custom-css-properties.ts

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import type {
88
CSSEdgeSizeValue,
99
CSSRadiusValues,
1010
} from '../common/css-values';
11-
import type { AndStringsType, ArgsPseudos } from '../common/pseudo-selectors';
11+
import type { AndStrings, AndStringsType, ArgsPseudos } from '../common/pseudo-selectors';
1212
import type { CSSColorValue, CSSVariableProperties, CSSVariableValue } from '../common/css-variables';
13-
import { MediaQueryType } from './custom-html-type';
13+
import { MediaQuery, MediaQueryType } from './custom-html-type';
14+
import { HtmlTags } from '../../utils/html-tags';
15+
import { LanguageCodes } from '../../utils/language-codes';
1416

1517
type CustomExtendProperties = {
1618
width?: CSSNumericValue | CSSLengthSubValue | 'auto';
@@ -33,7 +35,7 @@ type CustomExtendProperties = {
3335
wordSpacing?: CSSNumericValue | 'normal';
3436
borderWidth?: CSSNumericValue | 'thin' | 'medium' | 'thick';
3537
borderRadius?: CSSRadiusValues | number;
36-
top?: CSSNumericValue | 'auto';
38+
top?: CSSNumericValue | 'auto' | number;
3739
right?: CSSNumericValue | 'auto';
3840
bottom?: CSSNumericValue | 'auto';
3941
left?: CSSNumericValue | 'auto';
@@ -51,45 +53,51 @@ type CustomExtendProperties = {
5153
color?: CSSColorValue | CSSGlobalValue;
5254
background?: CSSColorValue | CSSGlobalValue | 'none';
5355
backgroundColor?: CSSColorValue | CSSGlobalValue;
54-
active?: CustomCSSProperties;
55-
hover?: CustomCSSProperties;
56-
link?: CustomCSSProperties;
57-
visited?: CustomCSSProperties;
58-
empty?: CustomCSSProperties;
59-
lang?: undefined;
60-
not?: undefined;
61-
notClass?: undefined;
62-
has?: undefined;
63-
hasChild?: undefined;
64-
hasPlus?: undefined;
65-
hasClass?: undefined;
66-
hasClassChild?: undefined;
67-
hasClassPlus?: undefined;
68-
firstChild?: CustomCSSProperties;
69-
lastChild?: CustomCSSProperties;
70-
nthChild?: undefined;
71-
nthLastChild?: undefined;
72-
nthLastOfType?: undefined;
73-
nthOfType?: undefined;
74-
checked?: CustomCSSProperties;
75-
disabled?: CustomCSSProperties;
76-
enabled?: CustomCSSProperties;
77-
focus?: CustomCSSProperties;
78-
inRange?: CustomCSSProperties;
79-
invalid?: CustomCSSProperties;
80-
valid?: CustomCSSProperties;
81-
optional?: CustomCSSProperties;
82-
outOfRange?: CustomCSSProperties;
83-
readOnly?: CustomCSSProperties;
84-
readWrite?: CustomCSSProperties;
85-
required?: CustomCSSProperties;
86-
target?: CustomCSSProperties;
87-
after?: CustomCSSProperties;
88-
before?: CustomCSSProperties;
89-
firstLetter?: CustomCSSProperties;
90-
firstLine?: CustomCSSProperties;
91-
marker?: CustomCSSProperties;
92-
selection?: CustomCSSProperties;
56+
};
57+
58+
type PseudoElementsAndClassKeys =
59+
| 'active'
60+
| 'hover'
61+
| 'link'
62+
| 'visited'
63+
| 'empty'
64+
| `lang${LanguageCodes}`
65+
| `not${HtmlTags}`
66+
| `notClass${string}`
67+
| `has${HtmlTags}`
68+
| `hasChild${HtmlTags}`
69+
| `hasPlus${HtmlTags}`
70+
| `hasClass${string}`
71+
| `hasClassChild${string}`
72+
| `hasClassPlus${string}`
73+
| 'firstChild'
74+
| 'lastChild'
75+
| `nthChild${number | 'Odd' | 'Even'}`
76+
| `nthLastChild${number | 'Odd' | 'Even'}`
77+
| `nthLastOfType${number | 'Odd' | 'Even'}`
78+
| `nthOfType${number | 'Odd' | 'Even'}`
79+
| 'checked'
80+
| 'disabled'
81+
| 'enabled'
82+
| 'focus'
83+
| 'inRange'
84+
| 'invalid'
85+
| 'valid'
86+
| 'optional'
87+
| 'outOfRange'
88+
| 'readOnly'
89+
| 'readWrite'
90+
| 'required'
91+
| 'target'
92+
| 'after'
93+
| 'before'
94+
| 'firstLetter'
95+
| 'firstLine'
96+
| 'marker'
97+
| 'selection';
98+
99+
type PseudoElementsAndClassType = {
100+
[K in PseudoElementsAndClassKeys]?: CustomCSSProperties;
93101
};
94102

95103
export type CustomCSSProperties =
@@ -99,4 +107,11 @@ export type CustomCSSProperties =
99107
[K in keyof React.CSSProperties]: React.CSSProperties[K] | CSSVariableValue;
100108
})
101109
| CSSVariableProperties
102-
| MediaQueryType;
110+
| MediaQueryType
111+
| PseudoElementsAndClassType;
112+
113+
export type ExtendedCSSProperties =
114+
| CustomCSSProperties
115+
| {
116+
[K in AndStrings | PseudoElementsAndClassKeys | MediaQuery]?: CustomCSSProperties;
117+
};

src/core/method/set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { CustomCSSProperties } from '../../_internal';
1+
import type { ExtendedCSSProperties } from '../../_internal';
22
import { isInDevelopment, injectCSS, styleCompiler, genBase62Hash } from '../../_internal';
33
import styles from '../styles/style.module.css';
44
import { createGlobalStyleSheetPromise, globalStyleSheetPromise, resolveGlobalStyleSheet } from './set-build-in-helper';
55

6-
export function set(object: CustomCSSProperties): string {
6+
export function set(object: ExtendedCSSProperties): string {
77
const base62Hash = genBase62Hash(object, 5);
88
const { styleSheet } = styleCompiler(object, base62Hash);
99
const classHash = '_' + base62Hash;

src/core/style.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ClassesObjectType, ReturnStyleType, CustomHTMLType, CustomCSSProperties, ExactClassesObjectType } from '../_internal';
1+
import type { ClassesObjectType, ExactClassesObjectType, ReturnStyleType, CustomHTMLType, ExtendedCSSProperties } from '../_internal';
22
import { create } from './method/create';
33
import { set } from './method/set';
44
import { global } from './method/global';
@@ -8,13 +8,13 @@ class Style {
88
static create<T extends ClassesObjectType>(object: ExactClassesObjectType<T> | ClassesObjectType): ReturnStyleType<T> {
99
return create(object);
1010
}
11-
static set(object: CustomCSSProperties): string {
11+
static set(object: ExtendedCSSProperties): string {
1212
return set(object);
1313
}
1414
static global(object: CustomHTMLType): void {
1515
return global(object);
1616
}
17-
static root(object: CustomCSSProperties): void {
17+
static root(object: ExtendedCSSProperties): void {
1818
return root(object);
1919
}
2020
}

0 commit comments

Comments
 (0)