1 | import type * as CSS from 'csstype';
|
2 | import React from 'react';
|
3 | import ComponentStyle from './models/ComponentStyle';
|
4 | import { DefaultTheme } from './models/ThemeProvider';
|
5 | import createWarnTooManyClasses from './utils/createWarnTooManyClasses';
|
6 | import type { SupportedHTMLElements } from './utils/domElements';
|
7 | export { CSS, DefaultTheme, SupportedHTMLElements };
|
8 | interface ExoticComponentWithDisplayName<P extends object = {}> extends React.ExoticComponent<P> {
|
9 | defaultProps?: Partial<P> | undefined;
|
10 | displayName?: string | undefined;
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export type StyledComponentBrand = {
|
17 | readonly _sc: symbol;
|
18 | };
|
19 | export type BaseObject = {};
|
20 | export type OmitNever<T> = {
|
21 | [K in keyof T as T[K] extends never ? never : K]: T[K];
|
22 | };
|
23 | export type FastOmit<T extends object, U extends string | number | symbol> = {
|
24 | [K in keyof T as K extends U ? never : K]: T[K];
|
25 | };
|
26 | export type Runtime = 'web' | 'native';
|
27 | export type AnyComponent<P extends object = any> = ExoticComponentWithDisplayName<P> | React.ComponentType<P>;
|
28 | export type KnownTarget = SupportedHTMLElements | AnyComponent;
|
29 | export type WebTarget = string | KnownTarget;
|
30 | export type NativeTarget = AnyComponent;
|
31 | export type StyledTarget<R extends Runtime> = R extends 'web' ? WebTarget : NativeTarget;
|
32 | export interface StyledOptions<R extends Runtime, Props extends object> {
|
33 | attrs?: Attrs<Props>[] | undefined;
|
34 | componentId?: (R extends 'web' ? string : never) | undefined;
|
35 | displayName?: string | undefined;
|
36 | parentComponentId?: (R extends 'web' ? string : never) | undefined;
|
37 | shouldForwardProp?: ShouldForwardProp<R> | undefined;
|
38 | }
|
39 | export type Dict<T = any> = {
|
40 | [key: string]: T;
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | export type DataAttributes = {
|
56 | [key: `data-${string}`]: any;
|
57 | };
|
58 | export type ExecutionProps = {
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | as?: KnownTarget | undefined;
|
70 | forwardedAs?: KnownTarget | undefined;
|
71 | theme?: DefaultTheme | undefined;
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 | export interface ExecutionContext extends ExecutionProps {
|
77 | theme: DefaultTheme;
|
78 | }
|
79 | export interface StyleFunction<Props extends object> {
|
80 | (executionContext: ExecutionContext & Props): Interpolation<Props>;
|
81 | }
|
82 | export type Interpolation<Props extends object> = StyleFunction<Props> | StyledObject<Props> | TemplateStringsArray | string | number | false | undefined | null | Keyframes | StyledComponentBrand | RuleSet<Props> | Interpolation<Props>[];
|
83 | export type Attrs<Props extends object = BaseObject> = (ExecutionProps & Partial<Props>) | ((props: ExecutionContext & Props) => ExecutionProps & Partial<Props>);
|
84 | export type RuleSet<Props extends object = BaseObject> = Interpolation<Props>[];
|
85 | export type Styles<Props extends object> = TemplateStringsArray | StyledObject<Props> | StyleFunction<Props>;
|
86 | export type NameGenerator = (hash: number) => string;
|
87 | export interface StyleSheet {
|
88 | create: Function;
|
89 | }
|
90 | export interface Keyframes {
|
91 | id: string;
|
92 | name: string;
|
93 | rules: string;
|
94 | }
|
95 | export interface Flattener<Props extends object> {
|
96 | (chunks: Interpolation<Props>[], executionContext: object | null | undefined, styleSheet: StyleSheet | null | undefined): Interpolation<Props>[];
|
97 | }
|
98 | export interface Stringifier {
|
99 | (css: string, selector?: string | undefined, prefix?: string | undefined, componentId?: string | undefined): string[];
|
100 | hash: string;
|
101 | }
|
102 | export interface ShouldForwardProp<R extends Runtime> {
|
103 | (prop: string, elementToBeCreated: StyledTarget<R>): boolean;
|
104 | }
|
105 | export interface CommonStatics<R extends Runtime, Props extends object> {
|
106 | attrs: Attrs<Props>[];
|
107 | target: StyledTarget<R>;
|
108 | shouldForwardProp?: ShouldForwardProp<R> | undefined;
|
109 | }
|
110 | export interface IStyledStatics<R extends Runtime, OuterProps extends object> extends CommonStatics<R, OuterProps> {
|
111 | componentStyle: R extends 'web' ? ComponentStyle : never;
|
112 | foldedComponentIds: R extends 'web' ? string : never;
|
113 | inlineStyle: R extends 'native' ? InstanceType<IInlineStyleConstructor<OuterProps>> : never;
|
114 | target: StyledTarget<R>;
|
115 | styledComponentId: R extends 'web' ? string : never;
|
116 | warnTooManyClasses?: (R extends 'web' ? ReturnType<typeof createWarnTooManyClasses> : never) | undefined;
|
117 | }
|
118 |
|
119 |
|
120 |
|
121 | export type PolymorphicComponentProps<R extends Runtime, BaseProps extends object, AsTarget extends StyledTarget<R> | void, ForwardedAsTarget extends StyledTarget<R> | void, AsTargetProps extends object = AsTarget extends KnownTarget ? React.ComponentPropsWithRef<AsTarget> : {}, ForwardedAsTargetProps extends object = ForwardedAsTarget extends KnownTarget ? React.ComponentPropsWithRef<ForwardedAsTarget> : {}> = NoInfer<FastOmit<Substitute<BaseProps, Substitute<ForwardedAsTargetProps, AsTargetProps>>, keyof ExecutionProps>> & FastOmit<ExecutionProps, 'as' | 'forwardedAs'> & {
|
122 | as?: AsTarget;
|
123 | forwardedAs?: ForwardedAsTarget;
|
124 | };
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | export interface PolymorphicComponent<R extends Runtime, BaseProps extends object> extends React.ForwardRefExoticComponent<BaseProps> {
|
133 | <AsTarget extends StyledTarget<R> | void = void, ForwardedAsTarget extends StyledTarget<R> | void = void>(props: PolymorphicComponentProps<R, BaseProps, AsTarget, ForwardedAsTarget>): React.JSX.Element;
|
134 | }
|
135 | export interface IStyledComponentBase<R extends Runtime, Props extends object = BaseObject> extends PolymorphicComponent<R, Props>, IStyledStatics<R, Props>, StyledComponentBrand {
|
136 | defaultProps?: (ExecutionProps & Partial<Props>) | undefined;
|
137 | toString: () => string;
|
138 | }
|
139 | export type IStyledComponent<R extends Runtime, Props extends object = BaseObject> = IStyledComponentBase<R, Props> &
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | (R extends 'web' ? string : {});
|
159 | export interface IStyledComponentFactory<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object, OuterStatics extends object = BaseObject> {
|
160 | <Props extends object = BaseObject, Statics extends object = BaseObject>(target: Target, options: StyledOptions<R, OuterProps & Props>, rules: RuleSet<OuterProps & Props>): IStyledComponent<R, Substitute<OuterProps, Props>> & OuterStatics & Statics;
|
161 | }
|
162 | export interface IInlineStyleConstructor<Props extends object> {
|
163 | new (rules: RuleSet<Props>): IInlineStyle<Props>;
|
164 | }
|
165 | export interface IInlineStyle<Props extends object> {
|
166 | rules: RuleSet<Props>;
|
167 | generateStyleObject(executionContext: ExecutionContext & Props): object;
|
168 | }
|
169 | export type CSSProperties = CSS.Properties<number | (string & {})>;
|
170 | export type CSSPseudos = {
|
171 | [K in CSS.Pseudos]?: CSSObject;
|
172 | };
|
173 | export type CSSKeyframes = object & {
|
174 | [key: string]: CSSObject;
|
175 | };
|
176 | export type CSSObject<Props extends object = BaseObject> = StyledObject<Props>;
|
177 | export interface StyledObject<Props extends object = BaseObject> extends CSSProperties, CSSPseudos {
|
178 | [key: string]: StyledObject<Props> | string | number | StyleFunction<Props> | RuleSet<any> | undefined;
|
179 | }
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 | export type CSSProp = Interpolation<any>;
|
202 | export type NoInfer<T> = [T][T extends any ? 0 : never];
|
203 | export type Substitute<A extends object, B extends object> = FastOmit<A, keyof B> & B;
|
204 | export type InsertionTarget = HTMLElement | ShadowRoot;
|