@stylexjs/stylex 0.18.1 → 0.18.2
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/lib/cjs/stylex.d.ts +23 -2
- package/lib/cjs/stylex.js +21 -0
- package/lib/cjs/stylex.js.flow +28 -2
- package/lib/cjs/types/StyleXTypes.d.ts +6 -0
- package/lib/cjs/types/StyleXTypes.js.flow +2 -0
- package/lib/es/stylex.d.ts +23 -2
- package/lib/es/stylex.js.flow +28 -2
- package/lib/es/stylex.mjs +21 -1
- package/lib/es/types/StyleXTypes.d.ts +6 -0
- package/lib/es/types/StyleXTypes.js.flow +2 -0
- package/package.json +2 -2
package/lib/cjs/stylex.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type {
|
|
|
30
30
|
StyleX$When,
|
|
31
31
|
MapNamespace,
|
|
32
32
|
StyleX$DefineMarker,
|
|
33
|
+
StyleX$Env,
|
|
33
34
|
} from './types/StyleXTypes';
|
|
34
35
|
import type { ValueWithDefault } from './types/StyleXUtils';
|
|
35
36
|
import * as Types from './types/VarTypes';
|
|
@@ -82,6 +83,16 @@ export declare function props(
|
|
|
82
83
|
'data-style-src'?: string;
|
|
83
84
|
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
84
85
|
}>;
|
|
86
|
+
export declare function attrs(
|
|
87
|
+
this: null | undefined | unknown,
|
|
88
|
+
...styles: ReadonlyArray<
|
|
89
|
+
StyleXArray<
|
|
90
|
+
| (null | undefined | CompiledStyles)
|
|
91
|
+
| boolean
|
|
92
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
93
|
+
>
|
|
94
|
+
>
|
|
95
|
+
): Readonly<{ class?: string; 'data-style-src'?: string; style?: string }>;
|
|
85
96
|
export declare const viewTransitionClass: (
|
|
86
97
|
_viewTransitionClass: ViewTransitionClass,
|
|
87
98
|
) => string;
|
|
@@ -92,7 +103,7 @@ export declare const defaultMarker: () => MapNamespace<
|
|
|
92
103
|
export declare type defaultMarker = typeof defaultMarker;
|
|
93
104
|
export declare const when: StyleX$When;
|
|
94
105
|
export declare type when = typeof when;
|
|
95
|
-
export declare const env:
|
|
106
|
+
export declare const env: StyleX$Env;
|
|
96
107
|
export declare type env = typeof env;
|
|
97
108
|
export declare const types: {
|
|
98
109
|
angle: <T extends string | 0 = string | 0>(
|
|
@@ -146,7 +157,7 @@ type IStyleX = {
|
|
|
146
157
|
createTheme: StyleX$CreateTheme;
|
|
147
158
|
defineConsts: StyleX$DefineConsts;
|
|
148
159
|
defineVars: StyleX$DefineVars;
|
|
149
|
-
env:
|
|
160
|
+
env: StyleX$Env;
|
|
150
161
|
defaultMarker: () => MapNamespace<Readonly<{ marker: 'default-marker' }>>;
|
|
151
162
|
defineMarker: StyleX$DefineMarker;
|
|
152
163
|
firstThatWorks: <T extends string | number>(
|
|
@@ -168,6 +179,16 @@ type IStyleX = {
|
|
|
168
179
|
'data-style-src'?: string;
|
|
169
180
|
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
170
181
|
}>;
|
|
182
|
+
attrs: (
|
|
183
|
+
this: null | undefined | unknown,
|
|
184
|
+
...styles: ReadonlyArray<
|
|
185
|
+
StyleXArray<
|
|
186
|
+
| (null | undefined | CompiledStyles)
|
|
187
|
+
| boolean
|
|
188
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
189
|
+
>
|
|
190
|
+
>
|
|
191
|
+
) => Readonly<{ class?: string; 'data-style-src'?: string; style?: string }>;
|
|
171
192
|
viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string;
|
|
172
193
|
types: typeof types;
|
|
173
194
|
when: typeof when;
|
package/lib/cjs/stylex.js
CHANGED
|
@@ -172,6 +172,25 @@ function props(...styles) {
|
|
|
172
172
|
}
|
|
173
173
|
return result;
|
|
174
174
|
}
|
|
175
|
+
const toKebabCase = str => str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
176
|
+
function attrs(...styles) {
|
|
177
|
+
const {
|
|
178
|
+
className,
|
|
179
|
+
style,
|
|
180
|
+
'data-style-src': dataStyleSrc
|
|
181
|
+
} = props.apply(this, styles);
|
|
182
|
+
const result = {};
|
|
183
|
+
if (className != null) {
|
|
184
|
+
result.class = className;
|
|
185
|
+
}
|
|
186
|
+
if (style != null) {
|
|
187
|
+
result.style = Object.entries(style).map(([key, value]) => `${toKebabCase(key)}:${value}`).join(';');
|
|
188
|
+
}
|
|
189
|
+
if (dataStyleSrc != null) {
|
|
190
|
+
result['data-style-src'] = dataStyleSrc;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
175
194
|
const viewTransitionClass = _viewTransitionClass => {
|
|
176
195
|
throw errorForFn('viewTransitionClass');
|
|
177
196
|
};
|
|
@@ -251,12 +270,14 @@ _legacyMerge.firstThatWorks = firstThatWorks;
|
|
|
251
270
|
_legacyMerge.keyframes = keyframes;
|
|
252
271
|
_legacyMerge.positionTry = positionTry;
|
|
253
272
|
_legacyMerge.props = props;
|
|
273
|
+
_legacyMerge.attrs = attrs;
|
|
254
274
|
_legacyMerge.types = types;
|
|
255
275
|
_legacyMerge.when = when;
|
|
256
276
|
_legacyMerge.viewTransitionClass = viewTransitionClass;
|
|
257
277
|
_legacyMerge.env = env;
|
|
258
278
|
const legacyMerge = _legacyMerge;
|
|
259
279
|
|
|
280
|
+
exports.attrs = attrs;
|
|
260
281
|
exports.create = create;
|
|
261
282
|
exports.createTheme = createTheme;
|
|
262
283
|
exports.defaultMarker = defaultMarker;
|
package/lib/cjs/stylex.js.flow
CHANGED
|
@@ -30,6 +30,7 @@ import type {
|
|
|
30
30
|
StyleX$When,
|
|
31
31
|
MapNamespace,
|
|
32
32
|
StyleX$DefineMarker,
|
|
33
|
+
StyleX$Env,
|
|
33
34
|
} from './types/StyleXTypes';
|
|
34
35
|
import type { ValueWithDefault } from './types/StyleXUtils';
|
|
35
36
|
import * as Types from './types/VarTypes';
|
|
@@ -83,6 +84,19 @@ declare export function props(
|
|
|
83
84
|
style?: Readonly<{ [string]: string | number }>,
|
|
84
85
|
}>;
|
|
85
86
|
|
|
87
|
+
declare export function attrs(
|
|
88
|
+
this: ?unknown,
|
|
89
|
+
...styles: ReadonlyArray<
|
|
90
|
+
StyleXArray<
|
|
91
|
+
?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
|
|
92
|
+
>,
|
|
93
|
+
>
|
|
94
|
+
): Readonly<{
|
|
95
|
+
class?: string,
|
|
96
|
+
'data-style-src'?: string,
|
|
97
|
+
style?: string,
|
|
98
|
+
}>;
|
|
99
|
+
|
|
86
100
|
declare export const viewTransitionClass: (
|
|
87
101
|
_viewTransitionClass: ViewTransitionClass,
|
|
88
102
|
) => string;
|
|
@@ -95,7 +109,7 @@ declare export const defaultMarker: () => MapNamespace<
|
|
|
95
109
|
|
|
96
110
|
declare export const when: StyleX$When;
|
|
97
111
|
|
|
98
|
-
declare export const env: $
|
|
112
|
+
declare export const env: StyleX$Env;
|
|
99
113
|
|
|
100
114
|
declare export const types: {
|
|
101
115
|
angle: <T: string | 0 = string | 0>(
|
|
@@ -137,7 +151,7 @@ type IStyleX = {
|
|
|
137
151
|
createTheme: StyleX$CreateTheme,
|
|
138
152
|
defineConsts: StyleX$DefineConsts,
|
|
139
153
|
defineVars: StyleX$DefineVars,
|
|
140
|
-
env: $
|
|
154
|
+
env: StyleX$Env,
|
|
141
155
|
defaultMarker: () => MapNamespace<
|
|
142
156
|
Readonly<{
|
|
143
157
|
marker: 'default-marker',
|
|
@@ -161,6 +175,18 @@ type IStyleX = {
|
|
|
161
175
|
'data-style-src'?: string,
|
|
162
176
|
style?: Readonly<{ [string]: string | number }>,
|
|
163
177
|
}>,
|
|
178
|
+
attrs: (
|
|
179
|
+
this: ?unknown,
|
|
180
|
+
...styles: ReadonlyArray<
|
|
181
|
+
StyleXArray<
|
|
182
|
+
?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
|
|
183
|
+
>,
|
|
184
|
+
>
|
|
185
|
+
) => Readonly<{
|
|
186
|
+
class?: string,
|
|
187
|
+
'data-style-src'?: string,
|
|
188
|
+
style?: string,
|
|
189
|
+
}>,
|
|
164
190
|
viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string,
|
|
165
191
|
types: typeof types,
|
|
166
192
|
when: typeof when,
|
|
@@ -354,3 +354,9 @@ export type StyleX$When = {
|
|
|
354
354
|
// @ts-expect-error - Trying to use a symbol in a string is not normally allowed
|
|
355
355
|
) => `:where-any-sibling(${Pseudo}, ${MarkerSymbol})`;
|
|
356
356
|
};
|
|
357
|
+
|
|
358
|
+
export interface Register {}
|
|
359
|
+
|
|
360
|
+
export type StyleX$Env = Register extends { env: infer TEnv }
|
|
361
|
+
? TEnv
|
|
362
|
+
: Readonly<{ [key: string]: unknown }>;
|
package/lib/es/stylex.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type {
|
|
|
30
30
|
StyleX$When,
|
|
31
31
|
MapNamespace,
|
|
32
32
|
StyleX$DefineMarker,
|
|
33
|
+
StyleX$Env,
|
|
33
34
|
} from './types/StyleXTypes';
|
|
34
35
|
import type { ValueWithDefault } from './types/StyleXUtils';
|
|
35
36
|
import * as Types from './types/VarTypes';
|
|
@@ -82,6 +83,16 @@ export declare function props(
|
|
|
82
83
|
'data-style-src'?: string;
|
|
83
84
|
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
84
85
|
}>;
|
|
86
|
+
export declare function attrs(
|
|
87
|
+
this: null | undefined | unknown,
|
|
88
|
+
...styles: ReadonlyArray<
|
|
89
|
+
StyleXArray<
|
|
90
|
+
| (null | undefined | CompiledStyles)
|
|
91
|
+
| boolean
|
|
92
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
93
|
+
>
|
|
94
|
+
>
|
|
95
|
+
): Readonly<{ class?: string; 'data-style-src'?: string; style?: string }>;
|
|
85
96
|
export declare const viewTransitionClass: (
|
|
86
97
|
_viewTransitionClass: ViewTransitionClass,
|
|
87
98
|
) => string;
|
|
@@ -92,7 +103,7 @@ export declare const defaultMarker: () => MapNamespace<
|
|
|
92
103
|
export declare type defaultMarker = typeof defaultMarker;
|
|
93
104
|
export declare const when: StyleX$When;
|
|
94
105
|
export declare type when = typeof when;
|
|
95
|
-
export declare const env:
|
|
106
|
+
export declare const env: StyleX$Env;
|
|
96
107
|
export declare type env = typeof env;
|
|
97
108
|
export declare const types: {
|
|
98
109
|
angle: <T extends string | 0 = string | 0>(
|
|
@@ -146,7 +157,7 @@ type IStyleX = {
|
|
|
146
157
|
createTheme: StyleX$CreateTheme;
|
|
147
158
|
defineConsts: StyleX$DefineConsts;
|
|
148
159
|
defineVars: StyleX$DefineVars;
|
|
149
|
-
env:
|
|
160
|
+
env: StyleX$Env;
|
|
150
161
|
defaultMarker: () => MapNamespace<Readonly<{ marker: 'default-marker' }>>;
|
|
151
162
|
defineMarker: StyleX$DefineMarker;
|
|
152
163
|
firstThatWorks: <T extends string | number>(
|
|
@@ -168,6 +179,16 @@ type IStyleX = {
|
|
|
168
179
|
'data-style-src'?: string;
|
|
169
180
|
style?: Readonly<{ [$$Key$$: string]: string | number }>;
|
|
170
181
|
}>;
|
|
182
|
+
attrs: (
|
|
183
|
+
this: null | undefined | unknown,
|
|
184
|
+
...styles: ReadonlyArray<
|
|
185
|
+
StyleXArray<
|
|
186
|
+
| (null | undefined | CompiledStyles)
|
|
187
|
+
| boolean
|
|
188
|
+
| Readonly<[CompiledStyles, InlineStyles]>
|
|
189
|
+
>
|
|
190
|
+
>
|
|
191
|
+
) => Readonly<{ class?: string; 'data-style-src'?: string; style?: string }>;
|
|
171
192
|
viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string;
|
|
172
193
|
types: typeof types;
|
|
173
194
|
when: typeof when;
|
package/lib/es/stylex.js.flow
CHANGED
|
@@ -30,6 +30,7 @@ import type {
|
|
|
30
30
|
StyleX$When,
|
|
31
31
|
MapNamespace,
|
|
32
32
|
StyleX$DefineMarker,
|
|
33
|
+
StyleX$Env,
|
|
33
34
|
} from './types/StyleXTypes';
|
|
34
35
|
import type { ValueWithDefault } from './types/StyleXUtils';
|
|
35
36
|
import * as Types from './types/VarTypes';
|
|
@@ -83,6 +84,19 @@ declare export function props(
|
|
|
83
84
|
style?: Readonly<{ [string]: string | number }>,
|
|
84
85
|
}>;
|
|
85
86
|
|
|
87
|
+
declare export function attrs(
|
|
88
|
+
this: ?unknown,
|
|
89
|
+
...styles: ReadonlyArray<
|
|
90
|
+
StyleXArray<
|
|
91
|
+
?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
|
|
92
|
+
>,
|
|
93
|
+
>
|
|
94
|
+
): Readonly<{
|
|
95
|
+
class?: string,
|
|
96
|
+
'data-style-src'?: string,
|
|
97
|
+
style?: string,
|
|
98
|
+
}>;
|
|
99
|
+
|
|
86
100
|
declare export const viewTransitionClass: (
|
|
87
101
|
_viewTransitionClass: ViewTransitionClass,
|
|
88
102
|
) => string;
|
|
@@ -95,7 +109,7 @@ declare export const defaultMarker: () => MapNamespace<
|
|
|
95
109
|
|
|
96
110
|
declare export const when: StyleX$When;
|
|
97
111
|
|
|
98
|
-
declare export const env: $
|
|
112
|
+
declare export const env: StyleX$Env;
|
|
99
113
|
|
|
100
114
|
declare export const types: {
|
|
101
115
|
angle: <T: string | 0 = string | 0>(
|
|
@@ -137,7 +151,7 @@ type IStyleX = {
|
|
|
137
151
|
createTheme: StyleX$CreateTheme,
|
|
138
152
|
defineConsts: StyleX$DefineConsts,
|
|
139
153
|
defineVars: StyleX$DefineVars,
|
|
140
|
-
env: $
|
|
154
|
+
env: StyleX$Env,
|
|
141
155
|
defaultMarker: () => MapNamespace<
|
|
142
156
|
Readonly<{
|
|
143
157
|
marker: 'default-marker',
|
|
@@ -161,6 +175,18 @@ type IStyleX = {
|
|
|
161
175
|
'data-style-src'?: string,
|
|
162
176
|
style?: Readonly<{ [string]: string | number }>,
|
|
163
177
|
}>,
|
|
178
|
+
attrs: (
|
|
179
|
+
this: ?unknown,
|
|
180
|
+
...styles: ReadonlyArray<
|
|
181
|
+
StyleXArray<
|
|
182
|
+
?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
|
|
183
|
+
>,
|
|
184
|
+
>
|
|
185
|
+
) => Readonly<{
|
|
186
|
+
class?: string,
|
|
187
|
+
'data-style-src'?: string,
|
|
188
|
+
style?: string,
|
|
189
|
+
}>,
|
|
164
190
|
viewTransitionClass: (viewTransitionClass: ViewTransitionClass) => string,
|
|
165
191
|
types: typeof types,
|
|
166
192
|
when: typeof when,
|
package/lib/es/stylex.mjs
CHANGED
|
@@ -170,6 +170,25 @@ function props(...styles) {
|
|
|
170
170
|
}
|
|
171
171
|
return result;
|
|
172
172
|
}
|
|
173
|
+
const toKebabCase = str => str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
174
|
+
function attrs(...styles) {
|
|
175
|
+
const {
|
|
176
|
+
className,
|
|
177
|
+
style,
|
|
178
|
+
'data-style-src': dataStyleSrc
|
|
179
|
+
} = props.apply(this, styles);
|
|
180
|
+
const result = {};
|
|
181
|
+
if (className != null) {
|
|
182
|
+
result.class = className;
|
|
183
|
+
}
|
|
184
|
+
if (style != null) {
|
|
185
|
+
result.style = Object.entries(style).map(([key, value]) => `${toKebabCase(key)}:${value}`).join(';');
|
|
186
|
+
}
|
|
187
|
+
if (dataStyleSrc != null) {
|
|
188
|
+
result['data-style-src'] = dataStyleSrc;
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
173
192
|
const viewTransitionClass = _viewTransitionClass => {
|
|
174
193
|
throw errorForFn('viewTransitionClass');
|
|
175
194
|
};
|
|
@@ -249,10 +268,11 @@ _legacyMerge.firstThatWorks = firstThatWorks;
|
|
|
249
268
|
_legacyMerge.keyframes = keyframes;
|
|
250
269
|
_legacyMerge.positionTry = positionTry;
|
|
251
270
|
_legacyMerge.props = props;
|
|
271
|
+
_legacyMerge.attrs = attrs;
|
|
252
272
|
_legacyMerge.types = types;
|
|
253
273
|
_legacyMerge.when = when;
|
|
254
274
|
_legacyMerge.viewTransitionClass = viewTransitionClass;
|
|
255
275
|
_legacyMerge.env = env;
|
|
256
276
|
const legacyMerge = _legacyMerge;
|
|
257
277
|
|
|
258
|
-
export { create, createTheme, defaultMarker, defineConsts, defineMarker, defineVars, env, firstThatWorks, keyframes, legacyMerge, positionTry, props, types, viewTransitionClass, when };
|
|
278
|
+
export { attrs, create, createTheme, defaultMarker, defineConsts, defineMarker, defineVars, env, firstThatWorks, keyframes, legacyMerge, positionTry, props, types, viewTransitionClass, when };
|
|
@@ -354,3 +354,9 @@ export type StyleX$When = {
|
|
|
354
354
|
// @ts-expect-error - Trying to use a symbol in a string is not normally allowed
|
|
355
355
|
) => `:where-any-sibling(${Pseudo}, ${MarkerSymbol})`;
|
|
356
356
|
};
|
|
357
|
+
|
|
358
|
+
export interface Register {}
|
|
359
|
+
|
|
360
|
+
export type StyleX$Env = Register extends { env: infer TEnv }
|
|
361
|
+
? TEnv
|
|
362
|
+
: Readonly<{ [key: string]: unknown }>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/stylex",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "A library for defining styles for optimized user interfaces.",
|
|
5
5
|
"main": "./lib/cjs/stylex.js",
|
|
6
6
|
"module": "./lib/es/stylex.mjs",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"babel-plugin-syntax-hermes-parser": "^0.32.1",
|
|
61
61
|
"cross-env": "^10.1.0",
|
|
62
62
|
"rollup": "^4.59.0",
|
|
63
|
-
"scripts": "0.18.
|
|
63
|
+
"scripts": "0.18.2"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"lib/*"
|