@stylexjs/shared 0.3.0 → 0.4.1

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 CHANGED
@@ -4,8 +4,8 @@ This package contains most of the core JavaScript logic for stylex.
4
4
 
5
5
  It exports two primary functions `create` and `keyframes`.
6
6
 
7
- 1. `create` - takes a map of style rules. The return value include: a) the map with each style value replaced by a unique, reproducible, hashed className string, and b) a list of the CSS styles to be inserted into the document.
8
- 2. `keyframes` - takes a `@keyframes` animation as JS object. Returns a hashed string and the style ot be injected.
7
+ 1. `create` - takes a map of style rules. The return value includes: a) the map with each style value replaced by a unique, reproducible, hashed `className` string, and b) a list of the CSS styles to be inserted into the document.
8
+ 2. `keyframes` - takes a `@keyframes` animation as JS object. Returns a hashed string and the style to be injected.
9
9
 
10
10
  #### ⭐️ `create`
11
11
 
@@ -29,7 +29,7 @@ The first step here is expanding all [shorthands](#shorthands) into their indivi
29
29
 
30
30
  **Step 2**
31
31
 
32
- We hash each style `[key, value]` pair and generate a className and an associated CSS rule. Thie is done in the `convertToClassName(...)` function defined within [`convert-to-className.js`](#convert-to-classname-shared-package). (Explained below)
32
+ We hash each style `[key, value]` pair and generate a className and an associated CSS rule. This is done in the `convertToClassName(...)` function defined within [`convert-to-className.js`](#convert-to-classname-shared-package). (Explained below)
33
33
 
34
34
  **Step 3**
35
35
 
@@ -34,17 +34,16 @@ export type FlatCompiledStyles = Readonly<{
34
34
  [$$Key$$: string]: string | IncludedStyles | null;
35
35
  $$css: true;
36
36
  }>;
37
- export type StyleXOptions = {
37
+ export type StyleXOptions = Readonly<{
38
38
  dev: boolean;
39
39
  test: boolean;
40
40
  useRemForFontSize: boolean;
41
- runtimeInjection: boolean;
42
41
  classNamePrefix: string;
43
42
  definedStylexCSSVariables?: { [key: string]: unknown };
44
43
  styleResolution:
45
44
  | 'application-order'
46
45
  | 'property-specificity'
47
46
  | 'legacy-expand-shorthands';
48
- };
47
+ }>;
49
48
  export type MutableCompiledNamespaces = { [key: string]: FlatCompiledStyles };
50
49
  export type CompiledNamespaces = Readonly<MutableCompiledNamespaces>;
@@ -41,11 +41,10 @@ export type FlatCompiledStyles = $ReadOnly<{
41
41
  $$css: true,
42
42
  }>;
43
43
 
44
- export type StyleXOptions = {
44
+ export type StyleXOptions = $ReadOnly<{
45
45
  dev: boolean,
46
46
  test: boolean,
47
47
  useRemForFontSize: boolean,
48
- runtimeInjection: boolean,
49
48
  classNamePrefix: string,
50
49
  definedStylexCSSVariables?: { [key: string]: mixed },
51
50
  styleResolution:
@@ -56,7 +55,7 @@ export type StyleXOptions = {
56
55
  // This is not recommended, and will be removed in a future version.
57
56
  | 'legacy-expand-shorthands',
58
57
  ...
59
- };
58
+ }>;
60
59
 
61
60
  export type MutableCompiledNamespaces = {
62
61
  [key: string]: FlatCompiledStyles,
package/lib/index.js CHANGED
@@ -15,8 +15,8 @@ var _fileBasedIdentifier = _interopRequireDefault(require("./utils/file-based-id
15
15
  var m = _interopRequireWildcard(require("./messages"));
16
16
  var _types = _interopRequireWildcard(require("./types"));
17
17
  exports.types = _types;
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
  const create = exports.create = _stylexCreate.default;
22
22
  const defineVars = exports.defineVars = _stylexDefineVars.default;
package/lib/messages.d.ts CHANGED
@@ -7,12 +7,15 @@
7
7
  *
8
8
  */
9
9
 
10
- export declare const ILLEGAL_ARGUMENT_LENGTH: 'stylex() should have 1 argument.';
10
+ export declare const ILLEGAL_ARGUMENT_LENGTH: 'stylex.create() should have 1 argument.';
11
+ export declare const ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES: 'stylex.keyframes() should have 1 argument.';
11
12
  export declare const NON_STATIC_VALUE: 'Only static values are allowed inside of a stylex.create() call.';
13
+ export declare const NON_STATIC_KEYFRAME_VALUE: 'Only static values are allowed inside of a stylex.keyframes() call.';
12
14
  export declare const ESCAPED_STYLEX_VALUE: 'Escaping a stylex.create() value is not allowed.';
13
15
  export declare const UNBOUND_STYLEX_CALL_VALUE: 'stylex.create calls must be bound to a bare variable.';
14
16
  export declare const ONLY_TOP_LEVEL: 'stylex.create() is only allowed at the root of a program.';
15
17
  export declare const NON_OBJECT_FOR_STYLEX_CALL: 'stylex.create() can only accept a style object.';
18
+ export declare const NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL: 'stylex.keyframes() can only accept an object.';
16
19
  export declare const UNKNOWN_PROP_KEY: 'Unknown property key';
17
20
  export declare const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.';
18
21
  export declare const INVALID_PSEUDO_OR_AT_RULE: 'Invalid pseudo or at-rule.';
@@ -23,14 +26,16 @@ export declare const ILLEGAL_NESTED_PSEUDO: "Pseudo objects can't be nested more
23
26
  export declare const ILLEGAL_PROP_VALUE: 'A style value can only contain an array, string or number.';
24
27
  export declare const ILLEGAL_PROP_ARRAY_VALUE: 'A style array value can only contain strings or numbers.';
25
28
  export declare const ILLEGAL_NAMESPACE_VALUE: 'A stylex namespace must be an object.';
29
+ export declare const NON_OBJECT_KEYFRAME: 'Every frame within a stylex.keyframes() call must be an object.';
26
30
  export declare const INVALID_SPREAD: 'Imported styles spread with a stylex.create call must be type cast as `XStyle` to verify their type.';
27
31
  export declare const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function';
28
32
  export declare const LOCAL_ONLY: 'The return value of stylex.create() should not be exported.';
29
33
  export declare const UNEXPECTED_ARGUMENT: 'Unexpected argument passed to the stylex() function.';
30
34
  export declare const EXPECTED_FUNCTION_CALL: 'Expected a simple function call but found something else.';
31
35
  export declare const NO_PARENT_PATH: 'Unexpected AST node without a parent path.';
32
- export declare const ONLY_TOP_LEVEL_INLCUDES: 'stylex.include() is only at the top level of a style definition object.';
36
+ export declare const ONLY_TOP_LEVEL_INCLUDES: 'stylex.include() is only at the top level of a style definition object.';
33
37
  export declare const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
34
38
  export declare const NO_PROJECT_ROOT_DIRECTORY: 'The project root directory `rootDir` is not configured.';
35
39
  export declare const NON_EXPORT_NAMED_DECLARATION: 'The return value of stylex.defineVars() must be bound to a named export.';
36
40
  export declare const ANONYMOUS_THEME: 'stylex.createTheme() must be bound to a named constant.';
41
+ export declare const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
package/lib/messages.js CHANGED
@@ -3,13 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL_INLCUDES = exports.ONLY_TOP_LEVEL = exports.NO_PROJECT_ROOT_DIRECTORY = exports.NO_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.NON_EXPORT_NAMED_DECLARATION = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = exports.DUPLICATE_CONDITIONAL = exports.ANONYMOUS_THEME = void 0;
7
- const ILLEGAL_ARGUMENT_LENGTH = exports.ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.';
6
+ exports.UNKNOWN_PROP_KEY = exports.UNKNOWN_NAMESPACE = exports.UNEXPECTED_ARGUMENT = exports.UNBOUND_STYLEX_CALL_VALUE = exports.ONLY_TOP_LEVEL_INCLUDES = exports.ONLY_TOP_LEVEL = exports.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = exports.NO_PROJECT_ROOT_DIRECTORY = exports.NO_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_STATIC_KEYFRAME_VALUE = exports.NON_OBJECT_KEYFRAME = exports.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = exports.NON_OBJECT_FOR_STYLEX_CALL = exports.NON_EXPORT_NAMED_DECLARATION = exports.LOCAL_ONLY = exports.LINT_UNCLOSED_FUNCTION = exports.INVALID_SPREAD = exports.INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO = exports.ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_TYPE = exports.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = exports.ILLEGAL_ARGUMENT_LENGTH = exports.EXPECTED_FUNCTION_CALL = exports.ESCAPED_STYLEX_VALUE = exports.DUPLICATE_CONDITIONAL = exports.ANONYMOUS_THEME = void 0;
7
+ const ILLEGAL_ARGUMENT_LENGTH = exports.ILLEGAL_ARGUMENT_LENGTH = 'stylex.create() should have 1 argument.';
8
+ const ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = exports.ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES = 'stylex.keyframes() should have 1 argument.';
8
9
  const NON_STATIC_VALUE = exports.NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
10
+ const NON_STATIC_KEYFRAME_VALUE = exports.NON_STATIC_KEYFRAME_VALUE = 'Only static values are allowed inside of a stylex.keyframes() call.';
9
11
  const ESCAPED_STYLEX_VALUE = exports.ESCAPED_STYLEX_VALUE = 'Escaping a stylex.create() value is not allowed.';
10
12
  const UNBOUND_STYLEX_CALL_VALUE = exports.UNBOUND_STYLEX_CALL_VALUE = 'stylex.create calls must be bound to a bare variable.';
11
13
  const ONLY_TOP_LEVEL = exports.ONLY_TOP_LEVEL = 'stylex.create() is only allowed at the root of a program.';
12
14
  const NON_OBJECT_FOR_STYLEX_CALL = exports.NON_OBJECT_FOR_STYLEX_CALL = 'stylex.create() can only accept a style object.';
15
+ const NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = exports.NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL = 'stylex.keyframes() can only accept an object.';
13
16
  const UNKNOWN_PROP_KEY = exports.UNKNOWN_PROP_KEY = 'Unknown property key';
14
17
  const INVALID_PSEUDO = exports.INVALID_PSEUDO = 'Invalid pseudo selector, not on the whitelist.';
15
18
  const INVALID_PSEUDO_OR_AT_RULE = exports.INVALID_PSEUDO_OR_AT_RULE = 'Invalid pseudo or at-rule.';
@@ -20,14 +23,16 @@ const ILLEGAL_NESTED_PSEUDO = exports.ILLEGAL_NESTED_PSEUDO = "Pseudo objects ca
20
23
  const ILLEGAL_PROP_VALUE = exports.ILLEGAL_PROP_VALUE = 'A style value can only contain an array, string or number.';
21
24
  const ILLEGAL_PROP_ARRAY_VALUE = exports.ILLEGAL_PROP_ARRAY_VALUE = 'A style array value can only contain strings or numbers.';
22
25
  const ILLEGAL_NAMESPACE_VALUE = exports.ILLEGAL_NAMESPACE_VALUE = 'A stylex namespace must be an object.';
26
+ const NON_OBJECT_KEYFRAME = exports.NON_OBJECT_KEYFRAME = 'Every frame within a stylex.keyframes() call must be an object.';
23
27
  const INVALID_SPREAD = exports.INVALID_SPREAD = 'Imported styles spread with a stylex.create call must be type cast as `XStyle<>` to verify their type.';
24
28
  const LINT_UNCLOSED_FUNCTION = exports.LINT_UNCLOSED_FUNCTION = 'Rule contains an unclosed function';
25
29
  const LOCAL_ONLY = exports.LOCAL_ONLY = 'The return value of stylex.create() should not be exported.';
26
30
  const UNEXPECTED_ARGUMENT = exports.UNEXPECTED_ARGUMENT = 'Unexpected argument passed to the stylex() function.';
27
31
  const EXPECTED_FUNCTION_CALL = exports.EXPECTED_FUNCTION_CALL = 'Expected a simple function call but found something else.';
28
32
  const NO_PARENT_PATH = exports.NO_PARENT_PATH = 'Unexpected AST node without a parent path.';
29
- const ONLY_TOP_LEVEL_INLCUDES = exports.ONLY_TOP_LEVEL_INLCUDES = 'stylex.include() is only at the top level of a style definition object.';
33
+ const ONLY_TOP_LEVEL_INCLUDES = exports.ONLY_TOP_LEVEL_INCLUDES = 'stylex.include() is only at the top level of a style definition object.';
30
34
  const DUPLICATE_CONDITIONAL = exports.DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
31
35
  const NO_PROJECT_ROOT_DIRECTORY = exports.NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
32
36
  const NON_EXPORT_NAMED_DECLARATION = exports.NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.defineVars() must be bound to a named export.';
33
- const ANONYMOUS_THEME = exports.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.';
37
+ const ANONYMOUS_THEME = exports.ANONYMOUS_THEME = 'stylex.createTheme() must be bound to a named constant.';
38
+ const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = exports.ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS = 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
@@ -8,14 +8,17 @@
8
8
  */
9
9
 
10
10
  // This file contains constants to be used within Error messages.
11
- // The URLs within will eventually be replaced by links to the documenation website for Stylex.
11
+ // The URLs within will eventually be replaced by links to the documentation website for Stylex.
12
12
 
13
- declare export const ILLEGAL_ARGUMENT_LENGTH: 'stylex() should have 1 argument.';
13
+ declare export const ILLEGAL_ARGUMENT_LENGTH: 'stylex.create() should have 1 argument.';
14
+ declare export const ILLEGAL_ARG_LENGTH_FOR_KEYFRAMES: 'stylex.keyframes() should have 1 argument.';
14
15
  declare export const NON_STATIC_VALUE: 'Only static values are allowed inside of a stylex.create() call.';
16
+ declare export const NON_STATIC_KEYFRAME_VALUE: 'Only static values are allowed inside of a stylex.keyframes() call.';
15
17
  declare export const ESCAPED_STYLEX_VALUE: 'Escaping a stylex.create() value is not allowed.';
16
18
  declare export const UNBOUND_STYLEX_CALL_VALUE: 'stylex.create calls must be bound to a bare variable.';
17
19
  declare export const ONLY_TOP_LEVEL: 'stylex.create() is only allowed at the root of a program.';
18
20
  declare export const NON_OBJECT_FOR_STYLEX_CALL: 'stylex.create() can only accept a style object.';
21
+ declare export const NON_OBJECT_FOR_STYLEX_KEYFRAMES_CALL: 'stylex.keyframes() can only accept an object.';
19
22
  declare export const UNKNOWN_PROP_KEY: 'Unknown property key';
20
23
  declare export const INVALID_PSEUDO: 'Invalid pseudo selector, not on the whitelist.';
21
24
  declare export const INVALID_PSEUDO_OR_AT_RULE: 'Invalid pseudo or at-rule.';
@@ -26,14 +29,16 @@ declare export const ILLEGAL_NESTED_PSEUDO: "Pseudo objects can't be nested more
26
29
  declare export const ILLEGAL_PROP_VALUE: 'A style value can only contain an array, string or number.';
27
30
  declare export const ILLEGAL_PROP_ARRAY_VALUE: 'A style array value can only contain strings or numbers.';
28
31
  declare export const ILLEGAL_NAMESPACE_VALUE: 'A stylex namespace must be an object.';
32
+ declare export const NON_OBJECT_KEYFRAME: 'Every frame within a stylex.keyframes() call must be an object.';
29
33
  declare export const INVALID_SPREAD: 'Imported styles spread with a stylex.create call must be type cast as `XStyle<>` to verify their type.';
30
34
  declare export const LINT_UNCLOSED_FUNCTION: 'Rule contains an unclosed function';
31
35
  declare export const LOCAL_ONLY: 'The return value of stylex.create() should not be exported.';
32
36
  declare export const UNEXPECTED_ARGUMENT: 'Unexpected argument passed to the stylex() function.';
33
37
  declare export const EXPECTED_FUNCTION_CALL: 'Expected a simple function call but found something else.';
34
38
  declare export const NO_PARENT_PATH: 'Unexpected AST node without a parent path.';
35
- declare export const ONLY_TOP_LEVEL_INLCUDES: 'stylex.include() is only at the top level of a style definition object.';
39
+ declare export const ONLY_TOP_LEVEL_INCLUDES: 'stylex.include() is only at the top level of a style definition object.';
36
40
  declare export const DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
37
41
  declare export const NO_PROJECT_ROOT_DIRECTORY: 'The project root directory `rootDir` is not configured.';
38
42
  declare export const NON_EXPORT_NAMED_DECLARATION: 'The return value of stylex.defineVars() must be bound to a named export.';
39
43
  declare export const ANONYMOUS_THEME: 'stylex.createTheme() must be bound to a named constant.';
44
+ declare export const ONLY_NAMED_PARAMETERS_IN_DYNAMIC_STYLE_FUNCTIONS: 'Only named parameters are allowed in Dynamic Style functions. Destructuring, spreading or default values are not allowed.';
@@ -124,8 +124,8 @@ declare const shorthands: {
124
124
  borderInlineEnd: (rawValue: TStyleValue) => TReturn;
125
125
  borderRight: (rawValue: TStyleValue) => TReturn;
126
126
  borderBottom: (rawValue: TStyleValue) => TReturn;
127
- borderInlineStart: (_rawValue: TStyleValue) => TReturn;
128
- borderLeft: (_rawValue: TStyleValue) => TReturn;
127
+ borderInlineStart: (rawValue: TStyleValue) => TReturn;
128
+ borderLeft: (rawValue: TStyleValue) => TReturn;
129
129
  borderInlineWidth: (rawValue: TStyleValue) => TReturn;
130
130
  borderInlineStyle: (rawValue: TStyleValue) => TReturn;
131
131
  borderInlineColor: (rawValue: TStyleValue) => TReturn;
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _splitCssValue = _interopRequireDefault(require("../utils/split-css-value"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
7
  const shorthands = {
10
8
  all: _ => {
11
9
  throw new Error('all is not supported');
@@ -21,8 +19,8 @@ const shorthands = {
21
19
  borderInlineEnd: rawValue => [['borderInlineEnd', rawValue], ...shorthands.borderInlineEndWidth(null), ...shorthands.borderInlineEndStyle(null), ...shorthands.borderInlineEndColor(null)],
22
20
  borderRight: rawValue => [['borderRight', rawValue], ...shorthands.borderRightWidth(null), ...shorthands.borderRightStyle(null), ...shorthands.borderRightColor(null)],
23
21
  borderBottom: rawValue => [['borderBottom', rawValue], ['borderBottomWidth', null], ['borderBottomStyle', null], ['borderBottomColor', null]],
24
- borderInlineStart: _rawValue => [['borderInlineStart', null], ...shorthands.borderInlineStartWidth(null), ...shorthands.borderInlineStartStyle(null), ...shorthands.borderInlineStartColor(null)],
25
- borderLeft: _rawValue => [['borderLeft', null], ...shorthands.borderLeftWidth(null), ...shorthands.borderLeftStyle(null), ...shorthands.borderLeftColor(null)],
22
+ borderInlineStart: rawValue => [['borderInlineStart', rawValue], ...shorthands.borderInlineStartWidth(null), ...shorthands.borderInlineStartStyle(null), ...shorthands.borderInlineStartColor(null)],
23
+ borderLeft: rawValue => [['borderLeft', rawValue], ...shorthands.borderLeftWidth(null), ...shorthands.borderLeftStyle(null), ...shorthands.borderLeftColor(null)],
26
24
  borderInlineWidth: rawValue => [['borderInlineWidth', rawValue], ['borderInlineStartWidth', null], ['borderLeftWidth', null], ['borderInlineEndWidth', null], ['borderRightWidth', null]],
27
25
  borderInlineStyle: rawValue => [['borderInlineStyle', rawValue], ['borderInlineStartStyle', null], ['borderLeftStyle', null], ['borderInlineEndStyle', null], ['borderRightStyle', null]],
28
26
  borderInlineColor: rawValue => [['borderInlineColor', rawValue], ['borderInlineStartColor', null], ['borderLeftColor', null], ['borderInlineEndColor', null], ['borderRightColor', null]],
@@ -89,12 +87,7 @@ const shorthands = {
89
87
  outline: value => [['outline', value], ['outlineColor', null], ['outlineOffset', null], ['outlineStyle', null], ['outlineWidth', null]],
90
88
  overflow: value => [['overflow', value], ['overflowX', null], ['overflowY', null]],
91
89
  padding: rawValue => {
92
- const values = typeof rawValue === 'number' ? [rawValue] : (0, _splitCssValue.default)(rawValue);
93
- if (values.length === 1) {
94
- return [['padding', values[0]], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null], ['paddingTop', null], ['paddingBottom', null]];
95
- }
96
- const [top, right = top, bottom = top, left = right] = values;
97
- return [['paddingTop', top], ['paddingEnd', right], ['paddingBottom', bottom], ['paddingStart', left]];
90
+ return [['padding', rawValue], ...shorthands.paddingInline(null), ...shorthands.paddingBlock(null)];
98
91
  },
99
92
  paddingInline: rawValue => [['paddingInline', rawValue], ['paddingStart', null], ['paddingLeft', null], ['paddingEnd', null], ['paddingRight', null]],
100
93
  paddingBlock: rawValue => [['paddingBlock', rawValue], ['paddingTop', null], ['paddingBottom', null]],
@@ -75,8 +75,8 @@ declare const shorthands: {
75
75
  borderInlineEnd: (rawValue: TStyleValue) => TReturn,
76
76
  borderRight: (rawValue: TStyleValue) => TReturn,
77
77
  borderBottom: (rawValue: TStyleValue) => TReturn,
78
- borderInlineStart: (_rawValue: TStyleValue) => TReturn,
79
- borderLeft: (_rawValue: TStyleValue) => TReturn,
78
+ borderInlineStart: (rawValue: TStyleValue) => TReturn,
79
+ borderLeft: (rawValue: TStyleValue) => TReturn,
80
80
  borderInlineWidth: (rawValue: TStyleValue) => TReturn,
81
81
  borderInlineStyle: (rawValue: TStyleValue) => TReturn,
82
82
  borderInlineColor: (rawValue: TStyleValue) => TReturn,
@@ -7,8 +7,8 @@ exports.validateNamespace = validateNamespace;
7
7
  var _stylexInclude = require("../stylex-include");
8
8
  var messages = _interopRequireWildcard(require("../messages"));
9
9
  var _objectUtils = require("../utils/object-utils");
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
12
  function validateNamespace(namespace) {
13
13
  let conditions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
14
14
  if (!(0, _objectUtils.isPlainObject)(namespace)) {
@@ -33,7 +33,7 @@ function validateNamespace(namespace) {
33
33
  if (conditions.length === 0) {
34
34
  continue;
35
35
  }
36
- throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES);
36
+ throw new Error(messages.ONLY_TOP_LEVEL_INCLUDES);
37
37
  }
38
38
  if ((0, _objectUtils.isPlainObject)(val)) {
39
39
  if (key.startsWith('@') || key.startsWith(':')) {
@@ -72,7 +72,7 @@ function validateConditionalStyles(val) {
72
72
  continue;
73
73
  }
74
74
  if (v instanceof _stylexInclude.IncludedStyles) {
75
- throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES);
75
+ throw new Error(messages.ONLY_TOP_LEVEL_INCLUDES);
76
76
  }
77
77
  if ((0, _objectUtils.isPlainObject)(v)) {
78
78
  validateConditionalStyles(v, [...conditions, key]);
@@ -46,17 +46,22 @@ function styleXCreateTheme(themeVars, variables, options) {
46
46
  return `${atRule}{${atRules[atRule].sort().join('')}}`;
47
47
  }).join('');
48
48
  const overrideClassName = classNamePrefix + (0, _hash.default)(cssVariablesOverrideString + atRulesStringForHash);
49
- const atRulesCss = sortedAtRules.map(atRule => {
50
- return `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`;
51
- }).join('');
52
- return [{
53
- $$css: true,
54
- [themeVars.__themeName__]: overrideClassName
55
- }, {
49
+ const stylesToInject = {
56
50
  [overrideClassName]: {
57
- ltr: `.${overrideClassName}{${cssVariablesOverrideString}}${atRulesCss}`,
58
- priority: 0.99,
51
+ ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`,
52
+ priority: 0.8,
59
53
  rtl: undefined
60
54
  }
61
- }];
55
+ };
56
+ for (const atRule of sortedAtRules) {
57
+ stylesToInject[overrideClassName + '-' + (0, _hash.default)(atRule)] = {
58
+ ltr: `${atRule}{.${overrideClassName}{${atRules[atRule].join('')}}}`,
59
+ priority: 0.9,
60
+ rtl: null
61
+ };
62
+ }
63
+ return [{
64
+ $$css: true,
65
+ [themeVars.__themeName__]: overrideClassName
66
+ }, stylesToInject];
62
67
  }
@@ -7,30 +7,23 @@
7
7
  *
8
8
  */
9
9
 
10
- import type { StyleXOptions } from './common-types';
11
- type VarsObject<
12
- Vars extends {
13
- readonly [$$Key$$: string]:
14
- | string
15
- | { readonly default: string; readonly [$$Key$$: string]: string };
16
- },
17
- > = Readonly</**
18
- * > 15 | ...$ObjMapConst<Vars, string>,
10
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+ type VarsConfig = Readonly<{
12
+ [$$Key$$: string]:
13
+ | string
14
+ | Readonly<{ default: string; [$$Key$$: string]: string }>;
15
+ }>;
16
+ type VarsObject<Vars extends VarsConfig> = Readonly</**
17
+ * > 17 | ...$ObjMapConst<Vars, string>,
19
18
  * | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unsupported feature: Translating "object types with complex spreads" is currently not supported.
20
19
  **/
21
20
  any>;
22
- declare function styleXDefineVars<
23
- Vars extends {
24
- readonly [$$Key$$: string]:
25
- | string
26
- | { readonly default: string; readonly [$$Key$$: string]: string };
27
- },
28
- >(
21
+ declare function styleXDefineVars<Vars extends VarsConfig>(
29
22
  variables: Vars,
30
23
  options: Readonly<
31
24
  Omit<Partial<StyleXOptions>, keyof ({ themeName: string })> & {
32
25
  themeName: string;
33
26
  }
34
27
  >,
35
- ): [VarsObject<Vars>, { css: string }];
28
+ ): [VarsObject<Vars>, { [$$Key$$: string]: InjectableStyle }];
36
29
  export default styleXDefineVars;
@@ -30,43 +30,44 @@ function styleXDefineVars(variables, options) {
30
30
  } = _ref;
31
31
  return `var(--${nameHash})`;
32
32
  });
33
- const cssVariablesString = constructCssVariablesString(variablesMap);
33
+ const injectableStyles = constructCssVariablesString(variablesMap, themeNameHash);
34
34
  return [{
35
35
  ...themeVariablesObject,
36
36
  __themeName__: themeNameHash
37
- }, {
38
- css: cssVariablesString
39
- }];
37
+ }, injectableStyles];
40
38
  }
41
- function constructCssVariablesString(variables) {
42
- const atRules = {};
43
- const varsString = (0, _objectUtils.objEntries)(variables).map(_ref2 => {
44
- let [key, {
45
- nameHash,
46
- value
47
- }] = _ref2;
39
+ function constructCssVariablesString(variables, themeNameHash) {
40
+ const ruleByAtRule = {};
41
+ for (const [key, {
42
+ nameHash,
43
+ value
44
+ }] of (0, _objectUtils.objEntries)(variables)) {
48
45
  if (value !== null && typeof value === 'object') {
49
46
  if (value.default === undefined) {
50
47
  throw new Error('Default value is not defined for ' + key + ' variable.');
51
48
  }
52
- const definedVarString = `--${nameHash}:${value.default};`;
53
- Object.keys(value).forEach(key => {
54
- if (key.startsWith('@')) {
55
- const definedVarStringForAtRule = `--${nameHash}:${value[key]};`;
56
- if (atRules[key] == null) {
57
- atRules[key] = [definedVarStringForAtRule];
58
- } else {
59
- atRules[key].push(definedVarStringForAtRule);
60
- }
61
- }
62
- });
63
- return definedVarString;
49
+ const v = value;
50
+ for (const [key, value] of (0, _objectUtils.objEntries)(v)) {
51
+ ruleByAtRule[key] ??= [];
52
+ ruleByAtRule[key].push(`--${nameHash}:${value};`);
53
+ }
54
+ } else {
55
+ ruleByAtRule.default ??= [];
56
+ ruleByAtRule.default.push(`--${nameHash}:${value};`);
64
57
  }
65
- return `--${nameHash}:${value};`;
66
- }).join('');
67
- const atRulesString = (0, _objectUtils.objEntries)(atRules).map(_ref3 => {
68
- let [atRule, varsArr] = _ref3;
69
- return `${atRule}{:root{${varsArr.join('')}}}`;
70
- }).join('');
71
- return `:root{${varsString}}${atRulesString || ''}`;
58
+ }
59
+ const result = {};
60
+ for (const [key, value] of (0, _objectUtils.objEntries)(ruleByAtRule)) {
61
+ const suffix = key === 'default' ? '' : `-${(0, _hash.default)(key)}`;
62
+ let ltr = `:root{${value.join('')}}`;
63
+ if (key !== 'default') {
64
+ ltr = `${key}{${ltr}}`;
65
+ }
66
+ result[themeNameHash + suffix] = {
67
+ ltr,
68
+ rtl: null,
69
+ priority: key === 'default' ? 0 : 0.1
70
+ };
71
+ }
72
+ return result;
72
73
  }
@@ -7,22 +7,20 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type { StyleXOptions } from './common-types';
10
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
11
 
12
- type VarsObject<
13
- Vars: { +[string]: string | { +default: string, +[string]: string } },
14
- > = $ReadOnly<{
12
+ type VarsConfig = $ReadOnly<{
13
+ [string]: string | $ReadOnly<{ default: string, [string]: string }>,
14
+ }>;
15
+
16
+ type VarsObject<Vars: VarsConfig> = $ReadOnly<{
15
17
  ...$ObjMapConst<Vars, string>,
16
18
  __themeName__: string,
17
19
  }>;
18
20
 
19
21
  // Similar to `stylex.create` it takes an object of variables with their values
20
22
  // and returns a string after hashing it.
21
- declare export default function styleXDefineVars<
22
- Vars: {
23
- +[string]: string | { +default: string, +[string]: string },
24
- },
25
- >(
23
+ declare export default function styleXDefineVars<Vars: VarsConfig>(
26
24
  variables: Vars,
27
25
  options: $ReadOnly<{ ...Partial<StyleXOptions>, themeName: string, ... }>,
28
- ): [VarsObject<Vars>, { css: string }];
26
+ ): [VarsObject<Vars>, { [string]: InjectableStyle }];
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.IncludedStyles = void 0;
7
7
  exports.default = stylexInclude;
8
8
  var messages = _interopRequireWildcard(require("./messages"));
9
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  let number = 0;
12
12
  function uuid() {
13
13
  return `__included_${++number}__`;
@@ -10,7 +10,7 @@
10
10
  // import type { Color as ColorType } from './stylex-types-color';
11
11
 
12
12
  // We want all in one file?
13
- // option 1, creat interface an implement it in the class
13
+ // option 1, create interface an implement it in the class
14
14
  // why? All the types have a single base definition of props
15
15
  // We want on type that defines CSS Types
16
16
  // Option 2: Do a union type and make
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.defaultOptions = void 0;
7
7
  const defaultOptions = exports.defaultOptions = {
8
8
  dev: false,
9
- runtimeInjection: false,
10
9
  useRemForFontSize: true,
11
10
  test: false,
12
11
  classNamePrefix: 'x',
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = detectUnclosedFns;
7
7
  var messages = _interopRequireWildcard(require("../../messages"));
8
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
10
  function detectUnclosedFns(ast, _) {
11
11
  ast.walk(node => {
12
12
  if (node.type === 'function' && node.unclosed) {
@@ -9,7 +9,7 @@
9
9
 
10
10
  /**
11
11
  * Use single spaces and remove spaces when not needed: around functions,
12
- * commas. But preserve spece around + and - as they are required in calc()
12
+ * commas. But preserve space around + and - as they are required in calc()
13
13
  */
14
14
 
15
15
  declare function normalizeWhitespace(
@@ -9,7 +9,7 @@
9
9
 
10
10
  /**
11
11
  * Use single spaces and remove spaces when not needed: around functions,
12
- * commas. But preserve spece around + and - as they are required in calc()
12
+ * commas. But preserve space around + and - as they are required in calc()
13
13
  */
14
14
 
15
15
  declare export default function normalizeWhitespace(
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { TStyleValue } from '../common-types';
11
11
 
12
- // Using split(' ') Isn't enough bcause of values like calc.
12
+ // Using split(' ') Isn't enough because of values like calc.
13
13
  declare export default function splitValue(
14
14
  str: TStyleValue,
15
15
  ): $ReadOnlyArray<number | string | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "main": "lib/index.js",
5
5
  "repository": "https://www.github.com/facebook/stylex",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "postcss-value-parser": "^4.1.0"
14
14
  },
15
15
  "devDependencies": {
16
- "@stylexjs/scripts": "0.3.0"
16
+ "@stylexjs/scripts": "0.4.1"
17
17
  },
18
18
  "jest": {
19
19
  "snapshotFormat": {