@stylexjs/stylex 0.2.0-beta.21 → 0.2.0-beta.22

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/stylex.d.ts CHANGED
@@ -10,33 +10,43 @@
10
10
  import type {
11
11
  Keyframes,
12
12
  Stylex$Create,
13
- StyleX$CreateVars,
14
- StyleX$OverrideVars,
13
+ StyleX$DefineVars,
14
+ StyleX$CreateTheme,
15
15
  StyleXArray,
16
- MapNamespace,
17
16
  CompiledStyles,
17
+ InlineStyles,
18
+ StyleXClassNameFor,
18
19
  } from './StyleXTypes';
19
20
  export type { Theme, Variant } from './StyleXTypes';
20
21
  import injectStyle from './stylex-inject';
21
- export declare function spread(
22
+ export declare function props(
22
23
  styles: StyleXArray<
23
24
  | (null | undefined | CompiledStyles)
24
25
  | boolean
25
- | Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>
26
+ | Readonly<[CompiledStyles, InlineStyles]>
26
27
  >,
27
28
  _options?: {},
28
29
  ): Readonly<{
29
- className: string;
30
- style: Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>;
30
+ className?: string;
31
+ style?: Readonly<{ [$$Key$$: string]: string | number }>;
31
32
  }>;
32
33
  type Stylex$Include = <
33
- TStyles extends { readonly [$$Key$$: string]: string | number },
34
+ TStyles extends {
35
+ readonly [$$Key$$: string]: StyleXClassNameFor<string, unknown>;
36
+ },
34
37
  >(
35
- _styles: MapNamespace<TStyles>,
36
- ) => TStyles;
38
+ styles: TStyles,
39
+ ) => {
40
+ readonly [Key in keyof TStyles]: TStyles[Key] extends StyleXClassNameFor<
41
+ unknown,
42
+ infer V
43
+ >
44
+ ? V
45
+ : string;
46
+ };
37
47
  export declare const create: Stylex$Create;
38
- export declare const unstable_createVars: StyleX$CreateVars;
39
- export declare const unstable_overrideVars: StyleX$OverrideVars;
48
+ export declare const defineVars: StyleX$DefineVars;
49
+ export declare const createTheme: StyleX$CreateTheme;
40
50
  export declare const include: Stylex$Include;
41
51
  type ValueWithDefault<T> =
42
52
  | T
@@ -90,32 +100,31 @@ export declare const types: {
90
100
  _v: ValueWithDefault<T>,
91
101
  ) => ICSSType<T>;
92
102
  };
93
- export declare const keyframes: (_keyframes: Keyframes) => string;
103
+ export declare const keyframes: (keyframes: Keyframes) => string;
94
104
  export declare const firstThatWorks: <T extends string | number>(
95
- ..._styles: ReadonlyArray<T>
105
+ ...styles: ReadonlyArray<T>
96
106
  ) => ReadonlyArray<T>;
97
107
  export declare const inject: typeof injectStyle;
98
- export declare const UNSUPPORTED_PROPERTY: <T>(_props: T) => T;
99
108
  type IStyleX = {
100
109
  (
101
110
  ...styles: ReadonlyArray<
102
111
  StyleXArray<(null | undefined | CompiledStyles) | boolean>
103
112
  >
104
113
  ): string;
105
- spread: (
114
+ props: (
106
115
  styles: StyleXArray<
107
116
  | (null | undefined | CompiledStyles)
108
117
  | boolean
109
- | Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>
118
+ | Readonly<[CompiledStyles, InlineStyles]>
110
119
  >,
111
120
  _options?: {},
112
121
  ) => Readonly<{
113
- className: string;
114
- style: Readonly<{ $$css?: void; [$$Key$$: string]: string | number }>;
122
+ className?: string;
123
+ style?: Readonly<{ [$$Key$$: string]: string | number }>;
115
124
  }>;
116
125
  create: Stylex$Create;
117
- unstable_createVars: StyleX$CreateVars;
118
- unstable_overrideVars: StyleX$OverrideVars;
126
+ defineVars: StyleX$DefineVars;
127
+ createTheme: StyleX$CreateTheme;
119
128
  include: Stylex$Include;
120
129
  types: typeof types;
121
130
  firstThatWorks: <T extends string | number>(
@@ -127,7 +136,7 @@ type IStyleX = {
127
136
  rtlRule: null | undefined | string,
128
137
  ) => void;
129
138
  keyframes: (keyframes: Keyframes) => string;
130
- UNSUPPORTED_PROPERTY: <T>(props: T) => T;
139
+ __customProperties?: { [$$Key$$: string]: unknown };
131
140
  };
132
141
  export declare const stylex: IStyleX;
133
142
  declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
package/lib/stylex.js CHANGED
@@ -1,98 +1,115 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.keyframes = exports.inject = exports.include = exports.firstThatWorks = exports.default = exports.create = exports.UNSUPPORTED_PROPERTY = void 0;
7
- exports.spread = spread;
8
- exports.unstable_overrideVars = exports.unstable_createVars = exports.types = exports.stylex = void 0;
6
+ exports.__monkey_patch__ = __monkey_patch__;
7
+ exports.keyframes = exports.inject = exports.include = exports.firstThatWorks = exports.defineVars = exports.default = exports.createTheme = exports.create = void 0;
8
+ exports.props = props;
9
+ exports.types = exports.stylex = void 0;
9
10
  var _stylexInject = _interopRequireDefault(require("./stylex-inject"));
10
11
  var _styleq = require("styleq");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function spread(styles, _options) {
13
+ function props(styles, _options) {
14
+ if (__implementations.props) {
15
+ return __implementations.props(styles, _options);
16
+ }
13
17
  const [className, style] = (0, _styleq.styleq)(styles);
14
- return {
15
- className,
16
- style
17
- };
18
- }
19
- function stylexCreate(_styles) {
20
- throw new Error("stylex.create should never be called. It should be compiled away.");
21
- }
22
- function stylexCreateVars(_styles) {
23
- throw new Error("stylex.createVars should never be called. It should be compiled away.");
18
+ const result = {};
19
+ if (className != null && className !== '') {
20
+ result.className = className;
21
+ }
22
+ if (style != null && Object.keys(style).length > 0) {
23
+ result.style = style;
24
+ }
25
+ return result;
24
26
  }
25
- function stylexOverrideVars(_styles) {
26
- throw new Error("stylex.overrideVars should never be called. It should be compiled away.");
27
+ function stylexCreate(styles) {
28
+ if (__implementations.create != null) {
29
+ const create = __implementations.create;
30
+ return create(styles);
31
+ }
32
+ throw new Error('stylex.create should never be called. It should be compiled away.');
27
33
  }
28
- function stylexIncludes(_styles) {
29
- throw new Error("stylex.extends should never be called. It should be compiled away.");
34
+ function stylexDefineVars(styles) {
35
+ if (__implementations.defineVars) {
36
+ return __implementations.defineVars(styles);
37
+ }
38
+ throw new Error('stylex.defineVars should never be called. It should be compiled away.');
30
39
  }
31
- const create = stylexCreate;
32
- exports.create = create;
33
- const unstable_createVars = stylexCreateVars;
34
- exports.unstable_createVars = unstable_createVars;
35
- const unstable_overrideVars = stylexOverrideVars;
36
- exports.unstable_overrideVars = unstable_overrideVars;
37
- const include = stylexIncludes;
38
- exports.include = include;
39
- const types = {
40
+ const stylexCreateTheme = (baseTokens, overrides) => {
41
+ if (__implementations.createTheme) {
42
+ return __implementations.createTheme(baseTokens, overrides);
43
+ }
44
+ throw new Error('stylex.createTheme should never be called. It should be compiled away.');
45
+ };
46
+ const stylexInclude = styles => {
47
+ if (__implementations.include) {
48
+ return __implementations.include(styles);
49
+ }
50
+ throw new Error('stylex.extends should never be called. It should be compiled away.');
51
+ };
52
+ const create = exports.create = stylexCreate;
53
+ const defineVars = exports.defineVars = stylexDefineVars;
54
+ const createTheme = exports.createTheme = stylexCreateTheme;
55
+ const include = exports.include = stylexInclude;
56
+ const types = exports.types = {
40
57
  angle: _v => {
41
- throw new Error(errorForType("angle"));
58
+ throw new Error(errorForType('angle'));
42
59
  },
43
60
  color: _v => {
44
- throw new Error(errorForType("color"));
61
+ throw new Error(errorForType('color'));
45
62
  },
46
63
  url: _v => {
47
- throw new Error(errorForType("url"));
64
+ throw new Error(errorForType('url'));
48
65
  },
49
66
  image: _v => {
50
- throw new Error(errorForType("image"));
67
+ throw new Error(errorForType('image'));
51
68
  },
52
69
  integer: _v => {
53
- throw new Error(errorForType("integer"));
70
+ throw new Error(errorForType('integer'));
54
71
  },
55
72
  lengthPercentage: _v => {
56
- throw new Error(errorForType("lengthPercentage"));
73
+ throw new Error(errorForType('lengthPercentage'));
57
74
  },
58
75
  length: _v => {
59
- throw new Error(errorForType("length"));
76
+ throw new Error(errorForType('length'));
60
77
  },
61
78
  percentage: _v => {
62
- throw new Error(errorForType("percentage"));
79
+ throw new Error(errorForType('percentage'));
63
80
  },
64
81
  number: _v => {
65
- throw new Error(errorForType("number"));
82
+ throw new Error(errorForType('number'));
66
83
  },
67
84
  resolution: _v => {
68
- throw new Error(errorForType("resolution"));
85
+ throw new Error(errorForType('resolution'));
69
86
  },
70
87
  time: _v => {
71
- throw new Error(errorForType("time"));
88
+ throw new Error(errorForType('time'));
72
89
  },
73
90
  transformFunction: _v => {
74
- throw new Error(errorForType("transformFunction"));
91
+ throw new Error(errorForType('transformFunction'));
75
92
  },
76
93
  transformList: _v => {
77
- throw new Error(errorForType("transformList"));
94
+ throw new Error(errorForType('transformList'));
78
95
  }
79
96
  };
80
- exports.types = types;
81
97
  const errorForType = type => `stylex.types.${type} should be compiled away by @stylexjs/babel-plugin`;
82
- const keyframes = _keyframes => {
83
- throw new Error("stylex.keyframes should never be called");
98
+ const keyframes = keyframes => {
99
+ if (__implementations.keyframes) {
100
+ return __implementations.keyframes(keyframes);
101
+ }
102
+ throw new Error('stylex.keyframes should never be called');
84
103
  };
85
104
  exports.keyframes = keyframes;
86
105
  const firstThatWorks = function () {
87
- throw new Error("stylex.firstThatWorks should never be called.");
106
+ if (__implementations.firstThatWorks) {
107
+ return __implementations.firstThatWorks(...arguments);
108
+ }
109
+ throw new Error('stylex.firstThatWorks should never be called.');
88
110
  };
89
111
  exports.firstThatWorks = firstThatWorks;
90
- const inject = _stylexInject.default;
91
- exports.inject = inject;
92
- const UNSUPPORTED_PROPERTY = _props => {
93
- throw new Error("stylex.UNSUPPORTED_PROPERTY should never be called. It should be compiled away.");
94
- };
95
- exports.UNSUPPORTED_PROPERTY = UNSUPPORTED_PROPERTY;
112
+ const inject = exports.inject = _stylexInject.default;
96
113
  function _stylex() {
97
114
  for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
98
115
  styles[_key] = arguments[_key];
@@ -100,17 +117,22 @@ function _stylex() {
100
117
  const [className] = (0, _styleq.styleq)(styles);
101
118
  return className;
102
119
  }
103
- _stylex.spread = spread;
120
+ _stylex.props = props;
104
121
  _stylex.create = create;
105
- _stylex.unstable_createVars = unstable_createVars;
106
- _stylex.unstable_overrideVars = unstable_overrideVars;
122
+ _stylex.defineVars = defineVars;
123
+ _stylex.createTheme = createTheme;
107
124
  _stylex.include = include;
108
125
  _stylex.keyframes = keyframes;
109
126
  _stylex.firstThatWorks = firstThatWorks;
110
127
  _stylex.inject = inject;
111
- _stylex.UNSUPPORTED_PROPERTY = UNSUPPORTED_PROPERTY;
112
128
  _stylex.types = types;
113
- const stylex = _stylex;
114
- exports.stylex = stylex;
115
- var _default = _stylex;
116
- exports.default = _default;
129
+ const __implementations = {};
130
+ function __monkey_patch__(key, implementation) {
131
+ if (key === 'types') {
132
+ Object.assign(types, implementation);
133
+ } else {
134
+ __implementations[key] = implementation;
135
+ }
136
+ }
137
+ const stylex = exports.stylex = _stylex;
138
+ var _default = exports.default = _stylex;
@@ -10,37 +10,45 @@
10
10
  import type {
11
11
  Keyframes,
12
12
  Stylex$Create,
13
- StyleX$CreateVars,
14
- StyleX$OverrideVars,
13
+ StyleX$DefineVars,
14
+ StyleX$CreateTheme,
15
15
  StyleXArray,
16
- MapNamespace,
17
16
  CompiledStyles,
17
+ InlineStyles,
18
+ StyleXClassNameFor,
18
19
  } from './StyleXTypes';
19
20
 
20
21
  export type { Theme, Variant } from './StyleXTypes';
21
22
 
22
23
  import injectStyle from './stylex-inject';
23
- declare export function spread(
24
+ declare export function props(
24
25
  styles: StyleXArray<
25
- | ?CompiledStyles
26
- | boolean
27
- | $ReadOnly<{ $$css?: void, [string]: string | number }>,
26
+ ?CompiledStyles | boolean | $ReadOnly<[CompiledStyles, InlineStyles]>,
28
27
  >,
29
28
  _options?: { ... },
30
29
  ): $ReadOnly<{
31
- className: string,
32
- style: $ReadOnly<{ $$css?: void, [string]: string | number }>,
30
+ className?: string,
31
+ style?: $ReadOnly<{ [string]: string | number }>,
33
32
  }>;
34
33
 
35
- type Stylex$Include = <TStyles: { +[string]: string | number }>(
36
- _styles: MapNamespace<TStyles>,
37
- ) => TStyles;
34
+ type Stylex$Include = <
35
+ TStyles: { +[string]: StyleXClassNameFor<string, mixed> },
36
+ >(
37
+ styles: TStyles,
38
+ ) => {
39
+ +[Key in keyof TStyles]: TStyles[Key] extends StyleXClassNameFor<
40
+ mixed,
41
+ infer V,
42
+ >
43
+ ? V
44
+ : string,
45
+ };
38
46
 
39
47
  declare export const create: Stylex$Create;
40
48
 
41
- declare export const unstable_createVars: StyleX$CreateVars;
49
+ declare export const defineVars: StyleX$DefineVars;
42
50
 
43
- declare export const unstable_overrideVars: StyleX$OverrideVars;
51
+ declare export const createTheme: StyleX$CreateTheme;
44
52
 
45
53
  declare export const include: Stylex$Include;
46
54
 
@@ -94,32 +102,28 @@ declare export const types: {
94
102
  ) => ICSSType<T>,
95
103
  transformList: <T: number | string>(_v: ValueWithDefault<T>) => ICSSType<T>,
96
104
  };
97
- declare export const keyframes: (_keyframes: Keyframes) => string;
105
+ declare export const keyframes: (keyframes: Keyframes) => string;
98
106
 
99
107
  declare export const firstThatWorks: <T: string | number>(
100
- ..._styles: $ReadOnlyArray<T>
108
+ ...styles: $ReadOnlyArray<T>
101
109
  ) => $ReadOnlyArray<T>;
102
110
 
103
111
  declare export const inject: typeof injectStyle;
104
112
 
105
- declare export const UNSUPPORTED_PROPERTY: <T>(_props: T) => T;
106
-
107
113
  type IStyleX = {
108
114
  (...styles: $ReadOnlyArray<StyleXArray<?CompiledStyles | boolean>>): string,
109
- spread: (
115
+ props: (
110
116
  styles: StyleXArray<
111
- | ?CompiledStyles
112
- | boolean
113
- | $ReadOnly<{ $$css?: void, [string]: string | number }>,
117
+ ?CompiledStyles | boolean | $ReadOnly<[CompiledStyles, InlineStyles]>,
114
118
  >,
115
119
  _options?: { ... },
116
120
  ) => $ReadOnly<{
117
- className: string,
118
- style: $ReadOnly<{ $$css?: void, [string]: string | number }>,
121
+ className?: string,
122
+ style?: $ReadOnly<{ [string]: string | number }>,
119
123
  }>,
120
124
  create: Stylex$Create,
121
- unstable_createVars: StyleX$CreateVars,
122
- unstable_overrideVars: StyleX$OverrideVars,
125
+ defineVars: StyleX$DefineVars,
126
+ createTheme: StyleX$CreateTheme,
123
127
  include: Stylex$Include,
124
128
  types: typeof types,
125
129
  firstThatWorks: <T: string | number>(
@@ -127,9 +131,10 @@ type IStyleX = {
127
131
  ) => $ReadOnlyArray<T>,
128
132
  inject: (ltrRule: string, priority: number, rtlRule: ?string) => void,
129
133
  keyframes: (keyframes: Keyframes) => string,
130
- UNSUPPORTED_PROPERTY: <T>(props: T) => T,
134
+ __customProperties?: { [string]: mixed },
131
135
  ...
132
136
  };
133
137
 
138
+
134
139
  declare export const stylex: IStyleX;
135
140
  declare export default IStyleX;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/stylex",
3
- "version": "0.2.0-beta.21",
3
+ "version": "0.2.0-beta.22",
4
4
  "description": "A library for defining styles for optimized user interfaces.",
5
5
  "main": "lib/stylex.js",
6
6
  "react-native": "lib/native/stylex.js",
@@ -20,7 +20,7 @@
20
20
  "utility-types": "^3.10.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@stylexjs/scripts": "0.2.0-beta.21"
23
+ "@stylexjs/scripts": "0.2.0-beta.22"
24
24
  },
25
25
  "jest": {},
26
26
  "files": [