@stylexjs/shared 0.2.0-beta.13 → 0.2.0-beta.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,8 @@ export type FlatCompiledStyles = Readonly<{
37
37
  export type StyleXOptions = {
38
38
  dev: boolean;
39
39
  test: boolean;
40
+ moduleSystem?: 'haste' | 'commonjs';
41
+ rootDir?: string | void;
40
42
  stylexSheetName?: string | void;
41
43
  classNamePrefix: string;
42
44
  definedStylexCSSVariables?: { [key: string]: unknown };
@@ -44,6 +44,8 @@ export type FlatCompiledStyles = $ReadOnly<{
44
44
  export type StyleXOptions = {
45
45
  dev: boolean,
46
46
  test: boolean,
47
+ moduleSystem?: 'haste' | 'commonjs',
48
+ rootDir?: string | void,
47
49
  stylexSheetName?: string | void,
48
50
  classNamePrefix: string,
49
51
  definedStylexCSSVariables?: { [key: string]: mixed },
package/lib/hash.js CHANGED
@@ -28,7 +28,8 @@ exports.default = void 0;
28
28
  * @param {number} seed Positive integer only
29
29
  * @return {number} 32-bit positive integer hash
30
30
  */
31
- function murmurhash2_32_gc(str, seed) {
31
+ function murmurhash2_32_gc(str) {
32
+ let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
32
33
  let l = str.length,
33
34
  h = seed ^ l,
34
35
  i = 0,
package/lib/index.d.ts CHANGED
@@ -15,11 +15,15 @@ export type {
15
15
  TStyleValue,
16
16
  } from './common-types';
17
17
  import styleXCreateSet from './stylex-create';
18
+ import styleXCreateVars from './stylex-create-vars';
19
+ import styleXOverrideVars from './stylex-override-vars';
18
20
  import stylexKeyframes from './stylex-keyframes';
19
21
  import stylexInclude, {
20
22
  IncludedStyles as _IncludedStyles,
21
23
  } from './stylex-include';
22
24
  import stylexFirstThatWorks from './stylex-first-that-works';
25
+ import hash from './hash';
26
+ import genFileBasedIdentifier from './utils/file-based-identifier';
23
27
  import * as m from './messages';
24
28
  import type {
25
29
  InjectableStyle as _InjectableStyle,
@@ -28,8 +32,14 @@ import type {
28
32
  StyleXOptions as _StyleXOptions,
29
33
  } from './common-types';
30
34
  export declare var create: typeof styleXCreateSet;
35
+ export declare var createVars: typeof styleXCreateVars;
36
+ export declare var overrideVars: typeof styleXOverrideVars;
31
37
  export declare var keyframes: typeof stylexKeyframes;
32
38
  export declare var include: typeof stylexInclude;
39
+ export declare var utils: {
40
+ hash: typeof hash;
41
+ genFileBasedIdentifier: typeof genFileBasedIdentifier;
42
+ };
33
43
  export declare var messages: typeof m;
34
44
  export declare var IncludedStyles: typeof _IncludedStyles;
35
45
  export declare var firstThatWorks: typeof stylexFirstThatWorks;
package/lib/index.js CHANGED
@@ -3,11 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.create = exports.IncludedStyles = void 0;
6
+ exports.utils = exports.overrideVars = exports.messages = exports.keyframes = exports.include = exports.firstThatWorks = exports.createVars = exports.create = exports.IncludedStyles = void 0;
7
7
  var _stylexCreate = _interopRequireDefault(require("./stylex-create"));
8
+ var _stylexCreateVars = _interopRequireDefault(require("./stylex-create-vars"));
9
+ var _stylexOverrideVars = _interopRequireDefault(require("./stylex-override-vars"));
8
10
  var _stylexKeyframes = _interopRequireDefault(require("./stylex-keyframes"));
9
11
  var _stylexInclude = _interopRequireWildcard(require("./stylex-include"));
10
12
  var _stylexFirstThatWorks = _interopRequireDefault(require("./stylex-first-that-works"));
13
+ var _hash = _interopRequireDefault(require("./hash"));
14
+ var _fileBasedIdentifier = _interopRequireDefault(require("./utils/file-based-identifier"));
11
15
  var m = _interopRequireWildcard(require("./messages"));
12
16
  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); }
13
17
  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; }
@@ -28,10 +32,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
28
32
 
29
33
  const create = _stylexCreate.default;
30
34
  exports.create = create;
35
+ const createVars = _stylexCreateVars.default;
36
+ exports.createVars = createVars;
37
+ const overrideVars = _stylexOverrideVars.default;
38
+ exports.overrideVars = overrideVars;
31
39
  const keyframes = _stylexKeyframes.default;
32
40
  exports.keyframes = keyframes;
33
41
  const include = _stylexInclude.default;
34
42
  exports.include = include;
43
+ const utils = {
44
+ hash: _hash.default,
45
+ genFileBasedIdentifier: _fileBasedIdentifier.default
46
+ };
47
+ exports.utils = utils;
35
48
  const messages = m;
36
49
  exports.messages = messages;
37
50
  const IncludedStyles = _stylexInclude.IncludedStyles;
package/lib/index.js.flow CHANGED
@@ -21,11 +21,15 @@ export type {
21
21
  // These are the implementations of those functions.
22
22
 
23
23
  import styleXCreateSet from './stylex-create';
24
+ import styleXCreateVars from './stylex-create-vars';
25
+ import styleXOverrideVars from './stylex-override-vars';
24
26
  import stylexKeyframes from './stylex-keyframes';
25
27
  import stylexInclude, {
26
28
  IncludedStyles as _IncludedStyles,
27
29
  } from './stylex-include';
28
30
  import stylexFirstThatWorks from './stylex-first-that-works';
31
+ import hash from './hash';
32
+ import genFileBasedIdentifier from './utils/file-based-identifier';
29
33
  import * as m from './messages';
30
34
 
31
35
  import type {
@@ -36,8 +40,14 @@ import type {
36
40
  } from './common-types';
37
41
 
38
42
  declare export var create: typeof styleXCreateSet;
43
+ declare export var createVars: typeof styleXCreateVars;
44
+ declare export var overrideVars: typeof styleXOverrideVars;
39
45
  declare export var keyframes: typeof stylexKeyframes;
40
46
  declare export var include: typeof stylexInclude;
47
+ declare export var utils: {
48
+ hash: typeof hash,
49
+ genFileBasedIdentifier: typeof genFileBasedIdentifier,
50
+ };
41
51
  declare export var messages: typeof m;
42
52
  declare export var IncludedStyles: typeof _IncludedStyles;
43
53
  declare export var firstThatWorks: typeof stylexFirstThatWorks;
package/lib/messages.d.ts CHANGED
@@ -30,3 +30,5 @@ export declare var EXPECTED_FUNCTION_CALL: 'Expected a simple function call but
30
30
  export declare var NO_PARENT_PATH: 'Unexpected AST node without a parent path.';
31
31
  export declare var ONLY_TOP_LEVEL_INLCUDES: 'stylex.include() is only at the top level of a style definition object.';
32
32
  export declare var DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
33
+ export declare var NO_PROJECT_ROOT_DIRECTORY: 'The project root directory `rootDir` is not configured.';
34
+ export declare var NON_EXPORT_NAMED_DECLARATION: 'The return value of stylex.createVars() must be bound to a named export.';
package/lib/messages.js CHANGED
@@ -13,7 +13,7 @@
13
13
  Object.defineProperty(exports, "__esModule", {
14
14
  value: true
15
15
  });
16
- 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_PARENT_PATH = exports.NO_CONDITIONAL_SHORTHAND = exports.NON_STATIC_VALUE = exports.NON_OBJECT_FOR_STYLEX_CALL = 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 = void 0;
16
+ 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 = void 0;
17
17
  const ILLEGAL_ARGUMENT_LENGTH = 'stylex() should have 1 argument.';
18
18
  exports.ILLEGAL_ARGUMENT_LENGTH = ILLEGAL_ARGUMENT_LENGTH;
19
19
  const NON_STATIC_VALUE = 'Only static values are allowed inside of a stylex.create() call.';
@@ -61,4 +61,8 @@ exports.NO_PARENT_PATH = NO_PARENT_PATH;
61
61
  const ONLY_TOP_LEVEL_INLCUDES = 'stylex.include() is only at the top level of a style definition object.';
62
62
  exports.ONLY_TOP_LEVEL_INLCUDES = ONLY_TOP_LEVEL_INLCUDES;
63
63
  const DUPLICATE_CONDITIONAL = 'The same pseudo selector or at-rule cannot be used more than once.';
64
- exports.DUPLICATE_CONDITIONAL = DUPLICATE_CONDITIONAL;
64
+ exports.DUPLICATE_CONDITIONAL = DUPLICATE_CONDITIONAL;
65
+ const NO_PROJECT_ROOT_DIRECTORY = 'The project root directory `rootDir` is not configured.';
66
+ exports.NO_PROJECT_ROOT_DIRECTORY = NO_PROJECT_ROOT_DIRECTORY;
67
+ const NON_EXPORT_NAMED_DECLARATION = 'The return value of stylex.createVars() must be bound to a named export.';
68
+ exports.NON_EXPORT_NAMED_DECLARATION = NON_EXPORT_NAMED_DECLARATION;
@@ -33,3 +33,5 @@ declare export var EXPECTED_FUNCTION_CALL: 'Expected a simple function call but
33
33
  declare export var NO_PARENT_PATH: 'Unexpected AST node without a parent path.';
34
34
  declare export var ONLY_TOP_LEVEL_INLCUDES: 'stylex.include() is only at the top level of a style definition object.';
35
35
  declare export var DUPLICATE_CONDITIONAL: 'The same pseudo selector or at-rule cannot be used more than once.';
36
+ declare export var NO_PROJECT_ROOT_DIRECTORY: 'The project root directory `rootDir` is not configured.';
37
+ declare export var NON_EXPORT_NAMED_DECLARATION: 'The return value of stylex.createVars() must be bound to a named export.';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+ declare function styleXOverrideVars(
12
+ themeVars: { __themeName__: string; readonly [$$Key$$: string]: string },
13
+ variables: { readonly [$$Key$$: string]: string },
14
+ options?: StyleXOptions
15
+ ): [
16
+ { $$css: true; readonly [$$Key$$: string]: string },
17
+ { [$$Key$$: string]: InjectableStyle }
18
+ ];
19
+ export default styleXOverrideVars;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXOverrideVars;
7
+ var _hash = _interopRequireDefault(require("./hash"));
8
+ var _defaultOptions = require("./utils/default-options");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /**
11
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
12
+ *
13
+ * This source code is licensed under the MIT license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ *
17
+ */
18
+
19
+ // It takes an object of variables with their values and the original set of variables to override
20
+ // and returns a hashed className with variables overrides.
21
+ //
22
+ function styleXOverrideVars(themeVars, variables, options) {
23
+ if (typeof themeVars.__themeName__ !== 'string') {
24
+ throw new Error('Can only override variables theme created with stylex.unstable_createVars().');
25
+ }
26
+ const {
27
+ classNamePrefix
28
+ } = {
29
+ ..._defaultOptions.defaultOptions,
30
+ ...options
31
+ };
32
+ const sortedKeys = Object.keys(variables).sort();
33
+ const cssVariablesOverrideString = sortedKeys.map(key => {
34
+ const varNameHash = themeVars[key].slice(4, -1);
35
+ return varNameHash != null ? `${varNameHash}:${variables[key]};` : '';
36
+ }).join('');
37
+ const overrideClassName = classNamePrefix + (0, _hash.default)(cssVariablesOverrideString);
38
+ return [{
39
+ $$css: true,
40
+ [themeVars.__themeName__]: overrideClassName
41
+ }, {
42
+ [overrideClassName]: {
43
+ ltr: `.${overrideClassName}{${cssVariablesOverrideString}}`,
44
+ priority: 0.99,
45
+ rtl: undefined
46
+ }
47
+ }];
48
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+
12
+ // It takes an object of variables with their values and the original set of variables to override
13
+ // and returns a hashed className with variables overrides.
14
+ //
15
+ declare export default function styleXOverrideVars(
16
+ themeVars: { __themeName__: string, +[string]: string },
17
+ variables: { +[string]: string },
18
+ options?: StyleXOptions
19
+ ): [{ $$css: true, +[string]: string }, { [string]: InjectableStyle }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.2.0-beta.13",
3
+ "version": "0.2.0-beta.15",
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.2.0-beta.13",
16
+ "@stylexjs/scripts": "0.2.0-beta.15",
17
17
  "typescript": "^4.7.4"
18
18
  },
19
19
  "jest": {