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

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