@stylexjs/shared 0.2.0-beta.10 → 0.2.0-beta.11

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.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateNamespace = validateNamespace;
7
- var _ = require("..");
7
+ var _stylexInclude = require("../stylex-include");
8
8
  var messages = _interopRequireWildcard(require("../messages"));
9
9
  var _objectUtils = require("../utils/object-utils");
10
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); }
@@ -38,7 +38,7 @@ function validateNamespace(namespace) {
38
38
  }
39
39
  continue;
40
40
  }
41
- if (val instanceof _.IncludedStyles) {
41
+ if (val instanceof _stylexInclude.IncludedStyles) {
42
42
  if (conditions.length === 0) {
43
43
  continue;
44
44
  }
@@ -80,7 +80,7 @@ function validateConditionalStyles(val) {
80
80
  }
81
81
  continue;
82
82
  }
83
- if (v instanceof _.IncludedStyles) {
83
+ if (v instanceof _stylexInclude.IncludedStyles) {
84
84
  throw new Error(messages.ONLY_TOP_LEVEL_INLCUDES);
85
85
  }
86
86
  if ((0, _objectUtils.isPlainObject)(v)) {
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports._flattenRawStyleObject = _flattenRawStyleObject;
7
7
  exports.flattenRawStyleObject = flattenRawStyleObject;
8
- var _ = _interopRequireDefault(require("."));
8
+ var _index = _interopRequireDefault(require("./index"));
9
9
  var _PreRule = require("./PreRule");
10
- var _2 = require("..");
10
+ var _stylexInclude = require("../stylex-include");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  /**
13
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -27,14 +27,14 @@ function _flattenRawStyleObject(style, pseudos, atRules, options) {
27
27
  const value = style[key];
28
28
 
29
29
  // Included Styles
30
- if (typeof value === 'object' && value instanceof _2.IncludedStyles) {
30
+ if (typeof value === 'object' && value instanceof _stylexInclude.IncludedStyles) {
31
31
  flattened.push([key, new _PreRule.PreIncludedStylesRule(value)]);
32
32
  continue;
33
33
  }
34
34
 
35
35
  // Default styles
36
36
  if (value === null || typeof value === 'string' || typeof value === 'number') {
37
- const pairs = (0, _.default)([key, value], options);
37
+ const pairs = (0, _index.default)([key, value], options);
38
38
  for (const [property, value] of pairs) {
39
39
  if (value === null) {
40
40
  flattened.push([property, new _PreRule.NullPreRule()]);
@@ -49,7 +49,7 @@ function _flattenRawStyleObject(style, pseudos, atRules, options) {
49
49
  if (Array.isArray(value)) {
50
50
  const equivalentPairs = {};
51
51
  for (const eachVal of value) {
52
- const pairs = (0, _.default)([key, eachVal], options);
52
+ const pairs = (0, _index.default)([key, eachVal], options);
53
53
  for (const [property, val] of pairs) {
54
54
  if (Array.isArray(val)) {
55
55
  if (equivalentPairs[property] == null) {
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXCreateVars;
7
+ var _hash = _interopRequireDefault(require("./hash"));
8
+ var _objectUtils = require("./utils/object-utils");
9
+ var _defaultOptions = require("./utils/default-options");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ */
19
+
20
+ // Similar to `stylex.create` it takes an object of variables with their values
21
+ // and returns a string after hashing it.
22
+ function styleXCreateVars(variables, options) {
23
+ const {
24
+ classNamePrefix,
25
+ themeName
26
+ } = {
27
+ ..._defaultOptions.defaultOptions,
28
+ ...options
29
+ };
30
+ const themeNameHash = classNamePrefix + (0, _hash.default)(themeName);
31
+ const variablesMap = (0, _objectUtils.objMap)(variables, (value, key) => {
32
+ // Created hashed variable names with fileName//themeName//key
33
+ const nameHash = classNamePrefix + (0, _hash.default)(`${themeName}.${key}`);
34
+ return {
35
+ nameHash,
36
+ value
37
+ };
38
+ });
39
+ const themeVariablesObject = (0, _objectUtils.objMap)(variablesMap, _ref => {
40
+ let {
41
+ nameHash
42
+ } = _ref;
43
+ return `var(--${nameHash})`;
44
+ });
45
+ const cssVariablesString = constructCssVariablesString(variablesMap);
46
+ return [{
47
+ ...themeVariablesObject,
48
+ __themeName__: themeNameHash
49
+ }, {
50
+ css: cssVariablesString
51
+ }];
52
+ }
53
+ function constructCssVariablesString(variables) {
54
+ const vars = (0, _objectUtils.objEntries)(variables).map(_ref2 => {
55
+ let [_, value] = _ref2;
56
+ return `--${value.nameHash}:${value.value};`;
57
+ }).join('');
58
+ return `:root{${vars}}`;
59
+ }
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.2.0-beta.10",
4
- "description": "Shared Code for Stylex compile and runtime.",
3
+ "version": "0.2.0-beta.11",
5
4
  "main": "lib/index.js",
6
- "repository": "https://www.github.com/facebookexternal/stylex",
7
- "author": "Naman Goel <nmn@fb.com>",
5
+ "repository": "https://www.github.com/facebook/stylex",
8
6
  "license": "MIT",
9
7
  "scripts": {
10
8
  "build": "babel src/ --out-dir lib/ --copy-files",