@stylix/core 6.2.1 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -280
- package/dist/index.d.ts +83 -59
- package/dist/index.js +276 -195
- package/dist/index.js.map +1 -1
- package/docs/CLAUDE_CONTEXT.md +156 -0
- package/docs/cheatsheet.md +354 -0
- package/docs/patterns.md +754 -0
- package/docs/performance.md +291 -0
- package/docs/philosophy.md +168 -0
- package/package.json +23 -20
- package/tsconfig.json +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,15 @@ type IntrinsicElements = (typeof htmlTags)[number];
|
|
|
9
9
|
*/
|
|
10
10
|
type HTMLProps<TTag extends keyof React.JSX.IntrinsicElements> = React.JSX.IntrinsicElements[TTag];
|
|
11
11
|
|
|
12
|
+
type OpaqueMediaStyles = {
|
|
13
|
+
__opaqueMediaStyles: true;
|
|
14
|
+
};
|
|
15
|
+
type StylixMediaValue = {
|
|
16
|
+
[key: string]: OpaqueMediaStyles | StylixMediaValue;
|
|
17
|
+
};
|
|
18
|
+
type StylixMediaFunc = (styles: OpaqueMediaStyles) => StylixMediaValue;
|
|
19
|
+
type StylixMediaDefinition = Record<string, StylixMediaFunc>;
|
|
20
|
+
|
|
12
21
|
type CSSProperties = CSS.StandardPropertiesHyphen<number | string> & CSS.VendorPropertiesHyphen<number | string> & CSS.StandardProperties<number | string> & CSS.VendorProperties<number | string>;
|
|
13
22
|
type Override<T, U> = Omit<T, keyof U> & U;
|
|
14
23
|
/**
|
|
@@ -27,7 +36,10 @@ type StylixStyles = StylixObject | null | undefined | false | StylixStyles[];
|
|
|
27
36
|
* Represents a value for a CSS prop in a Stylix object.
|
|
28
37
|
* The value can be a single value or an object with keys for different media queries.
|
|
29
38
|
*/
|
|
30
|
-
type StylixValue<T> = T |
|
|
39
|
+
type StylixValue<T> = T | {
|
|
40
|
+
default?: T | undefined;
|
|
41
|
+
[key: string]: T | undefined;
|
|
42
|
+
};
|
|
31
43
|
/**
|
|
32
44
|
* Used to indicate that a component can accept all Stylix properties, including
|
|
33
45
|
* all standard CSS properties, additional user-defined custom style props, and the $css prop.
|
|
@@ -90,60 +102,19 @@ type StylixHTMLProps<TTag extends IntrinsicElements> = Extends<HTMLProps<TTag>,
|
|
|
90
102
|
interface StylixPropsExtensions {
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
declare const customProps: (customProps: Record<string, any>) => StylixPlugin[];
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Stylix plugin function context object
|
|
97
|
-
*/
|
|
98
|
-
type StylixPluginFunctionContext = StylixPublicContext & {
|
|
99
|
-
className: string | null;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Stylix plugin interface
|
|
103
|
-
*/
|
|
104
|
-
type StylixPlugin = {
|
|
105
|
-
name: string;
|
|
106
|
-
before?: string;
|
|
107
|
-
after?: string;
|
|
108
|
-
atIndex?: number;
|
|
109
|
-
} & ({
|
|
110
|
-
name: string;
|
|
111
|
-
type: 'initialize';
|
|
112
|
-
plugin(ctx: StylixPluginFunctionContext): void;
|
|
113
|
-
} | {
|
|
114
|
-
type: 'processStyles' | 'preprocessStyles';
|
|
115
|
-
plugin(ctx: StylixPluginFunctionContext, styles: StylixStyles): StylixStyles;
|
|
116
|
-
});
|
|
117
|
-
declare const defaultPlugins: StylixPlugin[];
|
|
118
|
-
|
|
119
|
-
type OpaqueMediaStyles = {
|
|
120
|
-
__opaqueMediaStyles: true;
|
|
121
|
-
};
|
|
122
|
-
type StylixMediaValue = {
|
|
123
|
-
[key: string]: OpaqueMediaStyles | StylixMediaValue;
|
|
124
|
-
};
|
|
125
|
-
type StylixMediaFunc = (styles: OpaqueMediaStyles) => StylixMediaValue;
|
|
126
|
-
type StylixMediaDefinition = Record<string, StylixMediaFunc>;
|
|
127
|
-
|
|
128
105
|
/**
|
|
129
106
|
* Stylix context
|
|
130
107
|
*
|
|
131
|
-
*
|
|
132
|
-
* the <style> element where css is output.
|
|
133
|
-
* Stylix instance's configuration.
|
|
108
|
+
* A Stylix context represents an "instance" of Stylix - a configuration, set of plugins, and reference to
|
|
109
|
+
* the <style> element where css is output.
|
|
134
110
|
*
|
|
135
|
-
*
|
|
111
|
+
* A <StylixProvider> creates a context instance and provides it via React context to its descendent elements.
|
|
112
|
+
* All nodes contained within a <StylixProvider> element will share this context.
|
|
136
113
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
styleElement?: HTMLStyleElement;
|
|
142
|
-
media?: StylixMediaDefinition;
|
|
143
|
-
ssr?: boolean;
|
|
144
|
-
children: any;
|
|
145
|
-
};
|
|
146
|
-
type StylixContext$1 = {
|
|
114
|
+
/**
|
|
115
|
+
* The Stylix context object.
|
|
116
|
+
*/
|
|
117
|
+
type StylixContext = {
|
|
147
118
|
id: string;
|
|
148
119
|
devMode: boolean;
|
|
149
120
|
media: StylixMediaDefinition | undefined;
|
|
@@ -164,20 +135,75 @@ type StylixContext$1 = {
|
|
|
164
135
|
cleanupRequest?: number;
|
|
165
136
|
requestApply: boolean;
|
|
166
137
|
classifyProps(props: Record<string, unknown>): [Record<string, unknown>, Record<string, unknown>];
|
|
138
|
+
styles(styles: StylixStyles, config?: {
|
|
139
|
+
global: boolean;
|
|
140
|
+
}): string;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* React hook that gets the current Stylix context.
|
|
144
|
+
*/
|
|
145
|
+
declare function useStylixContext(): StylixContext;
|
|
146
|
+
/**
|
|
147
|
+
* Props for StylixProvider when passing an existing context.
|
|
148
|
+
*/
|
|
149
|
+
type StylixProviderPropsWithContext = {
|
|
150
|
+
context: StylixContext;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Props for StylixProvider when creating a new context.
|
|
154
|
+
*/
|
|
155
|
+
type StylixProviderPropsWithConfig = {
|
|
156
|
+
id?: string;
|
|
157
|
+
devMode?: boolean;
|
|
158
|
+
plugins?: StylixPlugin[] | StylixPlugin[][];
|
|
159
|
+
styleElement?: HTMLStyleElement;
|
|
160
|
+
media?: StylixMediaDefinition;
|
|
161
|
+
ssr?: boolean;
|
|
162
|
+
children: any;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Props for the StylixProvider component.
|
|
166
|
+
*/
|
|
167
|
+
type StylixProviderProps = StylixProviderPropsWithContext | StylixProviderPropsWithConfig;
|
|
168
|
+
/**
|
|
169
|
+
* StylixProvider component. Provides a Stylix context to its descendent elements.
|
|
170
|
+
* Can either accept an existing context via the `context` prop, or create a new context
|
|
171
|
+
* using the other configuration props.
|
|
172
|
+
*/
|
|
173
|
+
declare function StylixProvider(props: StylixProviderProps): React.ReactElement;
|
|
174
|
+
|
|
175
|
+
declare const customProps: (customProps: Record<string, any>) => StylixPlugin[];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Stylix plugin function context object
|
|
179
|
+
*/
|
|
180
|
+
type StylixPluginFunctionContext = Pick<StylixContext, 'id' | 'devMode' | 'media' | 'stylesheet' | 'styleElement' | 'styleProps'> & {
|
|
181
|
+
className: string | null;
|
|
167
182
|
};
|
|
168
|
-
type StylixPublicContext = Pick<StylixContext$1, 'id' | 'devMode' | 'media' | 'stylesheet' | 'styleElement' | 'styleProps'>;
|
|
169
183
|
/**
|
|
170
|
-
*
|
|
184
|
+
* Stylix plugin interface
|
|
171
185
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
type StylixPlugin = {
|
|
187
|
+
name: string;
|
|
188
|
+
before?: string;
|
|
189
|
+
after?: string;
|
|
190
|
+
atIndex?: number;
|
|
191
|
+
} & ({
|
|
192
|
+
name: string;
|
|
193
|
+
type: 'initialize';
|
|
194
|
+
plugin(ctx: StylixPluginFunctionContext): void;
|
|
195
|
+
} | {
|
|
196
|
+
type: 'processStyles' | 'preprocessStyles';
|
|
197
|
+
plugin(ctx: StylixPluginFunctionContext, styles: StylixStyles): StylixStyles;
|
|
198
|
+
});
|
|
199
|
+
declare const defaultPlugins: StylixPlugin[];
|
|
200
|
+
|
|
201
|
+
declare function RenderServerStyles(props: Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
174
202
|
|
|
175
203
|
declare function StyleElement(props: {
|
|
176
204
|
styles: string[];
|
|
177
205
|
} & Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
178
206
|
|
|
179
|
-
declare function RenderServerStyles(props: Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
180
|
-
|
|
181
207
|
/**
|
|
182
208
|
* Additional properties on the Stylix ($) component and its html component properties (`<$.div>`, etc).
|
|
183
209
|
*/
|
|
@@ -257,7 +283,7 @@ type ClassName = ClassNamePrimitive | ClassName[] | {
|
|
|
257
283
|
*/
|
|
258
284
|
declare function cx(...args: ClassName[]): string;
|
|
259
285
|
|
|
260
|
-
type ObjectOrArray = Record<string
|
|
286
|
+
type ObjectOrArray = (unknown[] & Record<string, unknown>);
|
|
261
287
|
type MapObjectFunction<TContext extends object = object> = (key: string | number, value: unknown, target: ObjectOrArray, context: TContext, mapRecursive: (value: unknown) => ObjectOrArray) => void;
|
|
262
288
|
/**
|
|
263
289
|
* Returns a new object or array, generated by invoking `map` on each key-value pair in `source` and merging the returned value into
|
|
@@ -318,7 +344,5 @@ type MapObjectFunction<TContext extends object = object> = (key: string | number
|
|
|
318
344
|
*/
|
|
319
345
|
declare function mapObject<TSource, TContext extends object>(source: TSource, mapFn: MapObjectFunction<TContext>, context?: TContext): TSource;
|
|
320
346
|
|
|
321
|
-
type StylixContext = StylixPublicContext;
|
|
322
|
-
|
|
323
347
|
export { RenderServerStyles, StyleElement, StylixProvider, createStyleCollector, customProps, cx, Stylix as default, defaultPlugins, mapObject, styleCollectorContext, useGlobalStyles, useKeyframes, useStyles, useStylixContext };
|
|
324
348
|
export type { Extends, HTMLProps, IntrinsicElements, StyleCollector, Stylix$Component, StylixContext, StylixHTMLProps, StylixObject, StylixPlugin, StylixPluginFunctionContext, StylixProps, StylixPropsExtensions, StylixStyles, StylixValue };
|