@stylexjs/shared 0.11.1 → 0.17.0

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.
Files changed (131) hide show
  1. package/lib/index.d.ts +10 -36
  2. package/lib/index.js +8 -25
  3. package/lib/index.js.flow +10 -43
  4. package/lib/utils/property-priorities.d.ts +4 -0
  5. package/lib/utils/property-priorities.js +54 -8
  6. package/lib/utils/property-priorities.js.flow +8 -0
  7. package/package.json +9 -22
  8. package/README.md +0 -81
  9. package/lib/common-types.d.ts +0 -47
  10. package/lib/common-types.js +0 -1
  11. package/lib/common-types.js.flow +0 -60
  12. package/lib/convert-to-className.d.ts +0 -20
  13. package/lib/convert-to-className.js +0 -66
  14. package/lib/convert-to-className.js.flow +0 -27
  15. package/lib/generate-css-rule.d.ts +0 -17
  16. package/lib/generate-css-rule.js +0 -25
  17. package/lib/generate-css-rule.js.flow +0 -17
  18. package/lib/hash.d.ts +0 -11
  19. package/lib/hash.js +0 -37
  20. package/lib/hash.js.flow +0 -10
  21. package/lib/messages.d.ts +0 -41
  22. package/lib/messages.js +0 -38
  23. package/lib/messages.js.flow +0 -44
  24. package/lib/physical-rtl/generate-ltr.d.ts +0 -13
  25. package/lib/physical-rtl/generate-ltr.js +0 -103
  26. package/lib/physical-rtl/generate-ltr.js.flow +0 -12
  27. package/lib/physical-rtl/generate-rtl.d.ts +0 -13
  28. package/lib/physical-rtl/generate-rtl.js +0 -177
  29. package/lib/physical-rtl/generate-rtl.js.flow +0 -12
  30. package/lib/preprocess-rules/PreRule.d.ts +0 -50
  31. package/lib/preprocess-rules/PreRule.js +0 -76
  32. package/lib/preprocess-rules/PreRule.js.flow +0 -62
  33. package/lib/preprocess-rules/application-order.d.ts +0 -183
  34. package/lib/preprocess-rules/application-order.js +0 -186
  35. package/lib/preprocess-rules/application-order.js.flow +0 -134
  36. package/lib/preprocess-rules/basic-validation.d.ts +0 -13
  37. package/lib/preprocess-rules/basic-validation.js +0 -73
  38. package/lib/preprocess-rules/basic-validation.js.flow +0 -13
  39. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +0 -20
  40. package/lib/preprocess-rules/flatten-raw-style-obj.js +0 -98
  41. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +0 -23
  42. package/lib/preprocess-rules/index.d.ts +0 -18
  43. package/lib/preprocess-rules/index.js +0 -33
  44. package/lib/preprocess-rules/index.js.flow +0 -22
  45. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +0 -165
  46. package/lib/preprocess-rules/legacy-expand-shorthands.js +0 -147
  47. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +0 -144
  48. package/lib/preprocess-rules/property-specificity.d.ts +0 -78
  49. package/lib/preprocess-rules/property-specificity.js +0 -107
  50. package/lib/preprocess-rules/property-specificity.js.flow +0 -87
  51. package/lib/stylex-create-theme.d.ts +0 -26
  52. package/lib/stylex-create-theme.js +0 -58
  53. package/lib/stylex-create-theme.js.flow +0 -19
  54. package/lib/stylex-create.d.ts +0 -27
  55. package/lib/stylex-create.js +0 -57
  56. package/lib/stylex-create.js.flow +0 -38
  57. package/lib/stylex-define-vars.d.ts +0 -28
  58. package/lib/stylex-define-vars.js +0 -94
  59. package/lib/stylex-define-vars.js.flow +0 -27
  60. package/lib/stylex-first-that-works.d.ts +0 -13
  61. package/lib/stylex-first-that-works.js +0 -26
  62. package/lib/stylex-first-that-works.js.flow +0 -12
  63. package/lib/stylex-include.d.ts +0 -18
  64. package/lib/stylex-include.js +0 -28
  65. package/lib/stylex-include.js.flow +0 -20
  66. package/lib/stylex-keyframes.d.ts +0 -17
  67. package/lib/stylex-keyframes.js +0 -55
  68. package/lib/stylex-keyframes.js.flow +0 -20
  69. package/lib/stylex-vars-utils.d.ts +0 -27
  70. package/lib/stylex-vars-utils.js +0 -69
  71. package/lib/stylex-vars-utils.js.flow +0 -31
  72. package/lib/transform-value.d.ts +0 -22
  73. package/lib/transform-value.js +0 -50
  74. package/lib/transform-value.js.flow +0 -25
  75. package/lib/types/index.d.ts +0 -240
  76. package/lib/types/index.js +0 -147
  77. package/lib/types/index.js.flow +0 -280
  78. package/lib/utils/Rule.d.ts +0 -58
  79. package/lib/utils/Rule.js +0 -50
  80. package/lib/utils/Rule.js.flow +0 -64
  81. package/lib/utils/dashify.d.ts +0 -11
  82. package/lib/utils/dashify.js +0 -9
  83. package/lib/utils/dashify.js.flow +0 -10
  84. package/lib/utils/default-options.d.ts +0 -11
  85. package/lib/utils/default-options.js +0 -15
  86. package/lib/utils/default-options.js.flow +0 -12
  87. package/lib/utils/file-based-identifier.d.ts +0 -15
  88. package/lib/utils/file-based-identifier.js +0 -14
  89. package/lib/utils/file-based-identifier.js.flow +0 -14
  90. package/lib/utils/genCSSRule.d.ts +0 -15
  91. package/lib/utils/genCSSRule.js +0 -15
  92. package/lib/utils/genCSSRule.js.flow +0 -15
  93. package/lib/utils/normalize-value.d.ts +0 -16
  94. package/lib/utils/normalize-value.js +0 -28
  95. package/lib/utils/normalize-value.js.flow +0 -16
  96. package/lib/utils/normalizers/convert-camel-case-values.d.ts +0 -14
  97. package/lib/utils/normalizers/convert-camel-case-values.js +0 -23
  98. package/lib/utils/normalizers/convert-camel-case-values.js.flow +0 -13
  99. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +0 -17
  100. package/lib/utils/normalizers/detect-unclosed-fns.js +0 -17
  101. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +0 -16
  102. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +0 -19
  103. package/lib/utils/normalizers/font-size-px-to-rem.js +0 -24
  104. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +0 -18
  105. package/lib/utils/normalizers/leading-zero.d.ts +0 -17
  106. package/lib/utils/normalizers/leading-zero.js +0 -24
  107. package/lib/utils/normalizers/leading-zero.js.flow +0 -16
  108. package/lib/utils/normalizers/quotes.d.ts +0 -18
  109. package/lib/utils/normalizers/quotes.js +0 -17
  110. package/lib/utils/normalizers/quotes.js.flow +0 -17
  111. package/lib/utils/normalizers/timings.d.ts +0 -18
  112. package/lib/utils/normalizers/timings.js +0 -25
  113. package/lib/utils/normalizers/timings.js.flow +0 -17
  114. package/lib/utils/normalizers/whitespace.d.ts +0 -19
  115. package/lib/utils/normalizers/whitespace.js +0 -54
  116. package/lib/utils/normalizers/whitespace.js.flow +0 -18
  117. package/lib/utils/normalizers/zero-dimensions.d.ts +0 -19
  118. package/lib/utils/normalizers/zero-dimensions.js +0 -42
  119. package/lib/utils/normalizers/zero-dimensions.js.flow +0 -18
  120. package/lib/utils/object-utils.d.ts +0 -66
  121. package/lib/utils/object-utils.js +0 -99
  122. package/lib/utils/object-utils.js.flow +0 -78
  123. package/lib/utils/rule-utils.d.ts +0 -15
  124. package/lib/utils/rule-utils.js +0 -41
  125. package/lib/utils/rule-utils.js.flow +0 -16
  126. package/lib/utils/split-css-value.d.ts +0 -14
  127. package/lib/utils/split-css-value.js +0 -33
  128. package/lib/utils/split-css-value.js.flow +0 -15
  129. package/lib/validate.d.ts +0 -12
  130. package/lib/validate.js +0 -21
  131. package/lib/validate.js.flow +0 -12
package/lib/index.d.ts CHANGED
@@ -7,47 +7,21 @@
7
7
  *
8
8
  */
9
9
 
10
- export type {
11
- RawStyles,
12
- StyleRule,
13
- TNestableStyleValue,
14
- TRawValue,
15
- TStyleValue,
16
- } from './common-types';
17
- import styleXCreateSet from './stylex-create';
18
- import styleXDefineVars from './stylex-define-vars';
19
- import styleXCreateTheme from './stylex-create-theme';
20
- import stylexKeyframes from './stylex-keyframes';
21
- import stylexFirstThatWorks from './stylex-first-that-works';
22
- import hash from './hash';
23
- import genFileBasedIdentifier from './utils/file-based-identifier';
24
- import * as m from './messages';
25
- export * as types from './types';
26
10
  import {
11
+ default as _getPriority,
12
+ getAtRulePriority as _getAtRulePriority,
13
+ getPseudoElementPriority as _getPseudoElementPriority,
14
+ getPseudoClassPriority as _getPseudoClassPriority,
15
+ getDefaultPriority as _getDefaultPriority,
27
16
  PSEUDO_CLASS_PRIORITIES as _PSEUDO_CLASS_PRIORITIES,
28
17
  AT_RULE_PRIORITIES as _AT_RULE_PRIORITIES,
29
18
  PSEUDO_ELEMENT_PRIORITY as _PSEUDO_ELEMENT_PRIORITY,
30
19
  } from './utils/property-priorities';
31
- import type {
32
- InjectableStyle as _InjectableStyle,
33
- CompiledNamespaces as _CompiledNamespaces,
34
- MutableCompiledNamespaces as _MutableCompiledNamespaces,
35
- StyleXOptions as _StyleXOptions,
36
- } from './common-types';
37
- export declare const create: typeof styleXCreateSet;
38
- export declare const defineVars: typeof styleXDefineVars;
39
- export declare const createTheme: typeof styleXCreateTheme;
40
- export declare const keyframes: typeof stylexKeyframes;
41
- export declare const utils: {
42
- hash: typeof hash;
43
- genFileBasedIdentifier: typeof genFileBasedIdentifier;
44
- };
45
- export declare const messages: typeof m;
46
- export declare const firstThatWorks: typeof stylexFirstThatWorks;
20
+ export declare const getAtRulePriority: typeof _getAtRulePriority;
21
+ export declare const getPseudoElementPriority: typeof _getPseudoElementPriority;
22
+ export declare const getPseudoClassPriority: typeof _getPseudoClassPriority;
23
+ export declare const getDefaultPriority: typeof _getDefaultPriority;
24
+ export declare const getPriority: typeof _getPriority;
47
25
  export declare const PSEUDO_CLASS_PRIORITIES: typeof _PSEUDO_CLASS_PRIORITIES;
48
26
  export declare const AT_RULE_PRIORITIES: typeof _AT_RULE_PRIORITIES;
49
27
  export declare const PSEUDO_ELEMENT_PRIORITY: typeof _PSEUDO_ELEMENT_PRIORITY;
50
- export type InjectableStyle = _InjectableStyle;
51
- export type CompiledNamespaces = _CompiledNamespaces;
52
- export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
53
- export type StyleXOptions = _StyleXOptions;
package/lib/index.js CHANGED
@@ -3,31 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.utils = exports.types = exports.messages = exports.keyframes = exports.firstThatWorks = exports.defineVars = exports.createTheme = exports.create = exports.PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_CLASS_PRIORITIES = exports.AT_RULE_PRIORITIES = void 0;
7
- var _stylexCreate = _interopRequireDefault(require("./stylex-create"));
8
- var _stylexDefineVars = _interopRequireDefault(require("./stylex-define-vars"));
9
- var _stylexCreateTheme = _interopRequireDefault(require("./stylex-create-theme"));
10
- var _stylexKeyframes = _interopRequireDefault(require("./stylex-keyframes"));
11
- var _stylexFirstThatWorks = _interopRequireDefault(require("./stylex-first-that-works"));
12
- var _hash = _interopRequireDefault(require("./hash"));
13
- var _fileBasedIdentifier = _interopRequireDefault(require("./utils/file-based-identifier"));
14
- var m = _interopRequireWildcard(require("./messages"));
15
- var _types = _interopRequireWildcard(require("./types"));
16
- exports.types = _types;
17
- var _propertyPriorities = require("./utils/property-priorities");
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 && {}.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
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
- const create = exports.create = _stylexCreate.default;
22
- const defineVars = exports.defineVars = _stylexDefineVars.default;
23
- const createTheme = exports.createTheme = _stylexCreateTheme.default;
24
- const keyframes = exports.keyframes = _stylexKeyframes.default;
25
- const utils = exports.utils = {
26
- hash: _hash.default,
27
- genFileBasedIdentifier: _fileBasedIdentifier.default
28
- };
29
- const messages = exports.messages = m;
30
- const firstThatWorks = exports.firstThatWorks = _stylexFirstThatWorks.default;
6
+ exports.getPseudoElementPriority = exports.getPseudoClassPriority = exports.getPriority = exports.getDefaultPriority = exports.getAtRulePriority = exports.PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_CLASS_PRIORITIES = exports.AT_RULE_PRIORITIES = void 0;
7
+ var _propertyPriorities = _interopRequireWildcard(require("./utils/property-priorities"));
8
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
9
+ const getAtRulePriority = exports.getAtRulePriority = _propertyPriorities.getAtRulePriority;
10
+ const getPseudoElementPriority = exports.getPseudoElementPriority = _propertyPriorities.getPseudoElementPriority;
11
+ const getPseudoClassPriority = exports.getPseudoClassPriority = _propertyPriorities.getPseudoClassPriority;
12
+ const getDefaultPriority = exports.getDefaultPriority = _propertyPriorities.getDefaultPriority;
13
+ const getPriority = exports.getPriority = _propertyPriorities.default;
31
14
  const PSEUDO_CLASS_PRIORITIES = exports.PSEUDO_CLASS_PRIORITIES = _propertyPriorities.PSEUDO_CLASS_PRIORITIES;
32
15
  const AT_RULE_PRIORITIES = exports.AT_RULE_PRIORITIES = _propertyPriorities.AT_RULE_PRIORITIES;
33
16
  const PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_ELEMENT_PRIORITY = _propertyPriorities.PSEUDO_ELEMENT_PRIORITY;
package/lib/index.js.flow CHANGED
@@ -7,56 +7,23 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- export type {
11
- RawStyles,
12
- StyleRule,
13
- TNestableStyleValue,
14
- TRawValue,
15
- TStyleValue,
16
- } from './common-types';
17
-
18
- // All functions exposed from `stylex` are defined in a way that can be run
19
- // entirely in the browser.
20
-
21
- // These are the implementations of those functions.
22
-
23
- import styleXCreateSet from './stylex-create';
24
- import styleXDefineVars from './stylex-define-vars';
25
- import styleXCreateTheme from './stylex-create-theme';
26
- import stylexKeyframes from './stylex-keyframes';
27
- import stylexFirstThatWorks from './stylex-first-that-works';
28
- import hash from './hash';
29
- import genFileBasedIdentifier from './utils/file-based-identifier';
30
- import * as m from './messages';
31
- export * as types from './types';
32
10
  import {
11
+ default as _getPriority,
12
+ getAtRulePriority as _getAtRulePriority,
13
+ getPseudoElementPriority as _getPseudoElementPriority,
14
+ getPseudoClassPriority as _getPseudoClassPriority,
15
+ getDefaultPriority as _getDefaultPriority,
33
16
  PSEUDO_CLASS_PRIORITIES as _PSEUDO_CLASS_PRIORITIES,
34
17
  AT_RULE_PRIORITIES as _AT_RULE_PRIORITIES,
35
18
  PSEUDO_ELEMENT_PRIORITY as _PSEUDO_ELEMENT_PRIORITY,
36
19
  } from './utils/property-priorities';
37
20
 
38
- import type {
39
- InjectableStyle as _InjectableStyle,
40
- CompiledNamespaces as _CompiledNamespaces,
41
- MutableCompiledNamespaces as _MutableCompiledNamespaces,
42
- StyleXOptions as _StyleXOptions,
43
- } from './common-types';
21
+ declare export const getAtRulePriority: typeof _getAtRulePriority;
22
+ declare export const getPseudoElementPriority: typeof _getPseudoElementPriority;
23
+ declare export const getPseudoClassPriority: typeof _getPseudoClassPriority;
24
+ declare export const getDefaultPriority: typeof _getDefaultPriority;
25
+ declare export const getPriority: typeof _getPriority;
44
26
 
45
- declare export const create: typeof styleXCreateSet;
46
- declare export const defineVars: typeof styleXDefineVars;
47
- declare export const createTheme: typeof styleXCreateTheme;
48
- declare export const keyframes: typeof stylexKeyframes;
49
- declare export const utils: {
50
- hash: typeof hash,
51
- genFileBasedIdentifier: typeof genFileBasedIdentifier,
52
- };
53
- declare export const messages: typeof m;
54
- declare export const firstThatWorks: typeof stylexFirstThatWorks;
55
27
  declare export const PSEUDO_CLASS_PRIORITIES: typeof _PSEUDO_CLASS_PRIORITIES;
56
28
  declare export const AT_RULE_PRIORITIES: typeof _AT_RULE_PRIORITIES;
57
29
  declare export const PSEUDO_ELEMENT_PRIORITY: typeof _PSEUDO_ELEMENT_PRIORITY;
58
-
59
- export type InjectableStyle = _InjectableStyle;
60
- export type CompiledNamespaces = _CompiledNamespaces;
61
- export type MutableCompiledNamespaces = _MutableCompiledNamespaces;
62
- export type StyleXOptions = _StyleXOptions;
@@ -13,5 +13,9 @@ export declare const PSEUDO_CLASS_PRIORITIES: Readonly<{
13
13
  type AtRulePriorities = { '@supports': 30; '@media': 200; '@container': 300 };
14
14
  export declare const AT_RULE_PRIORITIES: Readonly<AtRulePriorities>;
15
15
  export declare const PSEUDO_ELEMENT_PRIORITY: number;
16
+ export declare function getAtRulePriority(key: string): number | void;
17
+ export declare function getPseudoElementPriority(key: string): number | void;
18
+ export declare function getPseudoClassPriority(key: string): number | void;
19
+ export declare function getDefaultPriority(key: string): number | void;
16
20
  declare function getPriority(key: string): number;
17
21
  export default getPriority;
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_CLASS_PRIORITIES = exports.AT_RULE_PRIORITIES = void 0;
7
7
  exports.default = getPriority;
8
+ exports.getAtRulePriority = getAtRulePriority;
9
+ exports.getDefaultPriority = getDefaultPriority;
10
+ exports.getPseudoClassPriority = getPseudoClassPriority;
11
+ exports.getPseudoElementPriority = getPseudoElementPriority;
8
12
  const longHandPhysical = new Set();
9
13
  const longHandLogical = new Set();
10
14
  const shorthandsOfLonghands = new Set();
@@ -502,7 +506,14 @@ const AT_RULE_PRIORITIES = exports.AT_RULE_PRIORITIES = {
502
506
  '@container': 300
503
507
  };
504
508
  const PSEUDO_ELEMENT_PRIORITY = exports.PSEUDO_ELEMENT_PRIORITY = 5000;
505
- function getPriority(key) {
509
+ const RELATIONAL_SELECTORS = {
510
+ ANCESTOR: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+\*\)$/,
511
+ DESCENDANT: /^:where\(:has\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
512
+ SIBLING_BEFORE: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*\)$/,
513
+ SIBLING_AFTER: /^:where\(:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
514
+ ANY_SIBLING: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*,\s+:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/
515
+ };
516
+ function getAtRulePriority(key) {
506
517
  if (key.startsWith('--')) {
507
518
  return 1;
508
519
  }
@@ -515,24 +526,59 @@ function getPriority(key) {
515
526
  if (key.startsWith('@container')) {
516
527
  return AT_RULE_PRIORITIES['@container'];
517
528
  }
529
+ }
530
+ function getPseudoElementPriority(key) {
518
531
  if (key.startsWith('::')) {
519
532
  return PSEUDO_ELEMENT_PRIORITY;
520
533
  }
534
+ }
535
+ function getPseudoClassPriority(key) {
536
+ const pseudoBase = p => (PSEUDO_CLASS_PRIORITIES[p] ?? 40) / 100;
537
+ const ancestorMatch = RELATIONAL_SELECTORS.ANCESTOR.exec(key);
538
+ if (ancestorMatch) {
539
+ return 10 + pseudoBase(ancestorMatch[1]);
540
+ }
541
+ const descendantMatch = RELATIONAL_SELECTORS.DESCENDANT.exec(key);
542
+ if (descendantMatch) {
543
+ return 15 + pseudoBase(descendantMatch[1]);
544
+ }
545
+ const anySiblingMatch = RELATIONAL_SELECTORS.ANY_SIBLING.exec(key);
546
+ if (anySiblingMatch) return 20 + Math.max(pseudoBase(anySiblingMatch[1]), pseudoBase(anySiblingMatch[2]));
547
+ const siblingBeforeMatch = RELATIONAL_SELECTORS.SIBLING_BEFORE.exec(key);
548
+ if (siblingBeforeMatch) {
549
+ return 30 + pseudoBase(siblingBeforeMatch[1]);
550
+ }
551
+ const siblingAfterMatch = RELATIONAL_SELECTORS.SIBLING_AFTER.exec(key);
552
+ if (siblingAfterMatch) {
553
+ return 40 + pseudoBase(siblingAfterMatch[1]);
554
+ }
521
555
  if (key.startsWith(':')) {
522
556
  const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
523
557
  return PSEUDO_CLASS_PRIORITIES[prop] ?? 40;
524
558
  }
525
- if (longHandPhysical.has(key)) {
526
- return 4000;
527
- }
528
- if (longHandLogical.has(key)) {
529
- return 3000;
559
+ }
560
+ function getDefaultPriority(key) {
561
+ if (shorthandsOfShorthands.has(key)) {
562
+ return 1000;
530
563
  }
531
564
  if (shorthandsOfLonghands.has(key)) {
532
565
  return 2000;
533
566
  }
534
- if (shorthandsOfShorthands.has(key)) {
535
- return 1000;
567
+ if (longHandLogical.has(key)) {
568
+ return 3000;
536
569
  }
570
+ if (longHandPhysical.has(key)) {
571
+ return 4000;
572
+ }
573
+ }
574
+ function getPriority(key) {
575
+ const atRulePriority = getAtRulePriority(key);
576
+ if (atRulePriority) return atRulePriority;
577
+ const pseudoElementPriority = getPseudoElementPriority(key);
578
+ if (pseudoElementPriority) return pseudoElementPriority;
579
+ const pseudoClassPriority = getPseudoClassPriority(key);
580
+ if (pseudoClassPriority) return pseudoClassPriority;
581
+ const defaultPriority = getDefaultPriority(key);
582
+ if (defaultPriority) return defaultPriority;
537
583
  return 3000;
538
584
  }
@@ -75,4 +75,12 @@ declare export const AT_RULE_PRIORITIES: $ReadOnly<AtRulePriorities>;
75
75
 
76
76
  declare export const PSEUDO_ELEMENT_PRIORITY: number;
77
77
 
78
+ declare export function getAtRulePriority(key: string): number | void;
79
+
80
+ declare export function getPseudoElementPriority(key: string): number | void;
81
+
82
+ declare export function getPseudoClassPriority(key: string): number | void;
83
+
84
+ declare export function getDefaultPriority(key: string): number | void;
85
+
78
86
  declare export default function getPriority(key: string): number;
package/package.json CHANGED
@@ -1,33 +1,20 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.11.1",
3
+ "version": "0.17.0",
4
4
  "main": "lib/index.js",
5
- "repository": "https://www.github.com/facebook/stylex",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/facebook/stylex.git"
8
+ },
6
9
  "license": "MIT",
7
10
  "scripts": {
8
11
  "prebuild": "gen-types -i src/ -o lib/",
9
- "build": "babel src/ --out-dir lib/ --copy-files",
10
- "test": "jest"
11
- },
12
- "dependencies": {
13
- "postcss-value-parser": "^4.1.0"
12
+ "build": "babel src/ --out-dir lib/",
13
+ "test": "jest --coverage --passWithNoTests"
14
14
  },
15
15
  "devDependencies": {
16
- "@babel/cli": "^7.26.4",
17
- "@babel/core": "^7.26.8",
18
- "@babel/eslint-parser": "^7.26.8",
19
- "@babel/plugin-syntax-flow": "^7.26.0",
20
- "@babel/preset-env": "^7.26.8",
21
- "@babel/preset-flow": "^7.25.9",
22
- "@babel/preset-react": "^7.26.3",
23
- "@babel/preset-typescript": "^7.26.0",
24
- "@stylexjs/scripts": "0.11.1",
25
- "babel-plugin-syntax-hermes-parser": "^0.26.0"
26
- },
27
- "jest": {
28
- "snapshotFormat": {
29
- "printBasicPrototype": false
30
- }
16
+ "@babel/cli": "^7.23.9",
17
+ "@babel/core": "^7.23.9"
31
18
  },
32
19
  "files": [
33
20
  "lib/*"
package/README.md DELETED
@@ -1,81 +0,0 @@
1
- # @stylexjs/shared
2
-
3
- This package contains most of the core JavaScript logic for stylex.
4
-
5
- It exports two primary functions `create` and `keyframes`.
6
-
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
-
10
- #### ⭐️ `create`
11
-
12
- The `stylex.create` function is implemented here and can be found within `stylex-create.js` and is the default export of a function named `styleXCreateSet(...)`.
13
-
14
- ##### `styleXCreateSet(...)`
15
-
16
- > The function is called `styleXCreateSet` because `stylex.create` transforms a "set" or collection of multiple style [namespaces](#namespace)
17
-
18
- This function itself mostly just traverses over the objects to run each [namespaces](#namespace) through the `styleXCreateNamespace(...)` function. Other than that, it takes the styles to be injected from each namespace in a [Namespace Set](#namespace-set) and deduplicates them so the style isn't injected multiple times if it's used within multiple Namespaces in the same set.
19
-
20
- ##### `styleXCreateNamespace(...)`
21
-
22
- > This function has been kept separate in case we want to add a new function to the StyleX API in the future called `stylex.createOne` which transforms a single [namespace](#namespace) instead of a [Namespace Set](#namespace-set)
23
-
24
- This function is responsible to transforming a [namespace](#namespace) to a [Compiled Namespace](#compiled-namespace) by hashing each key value pair and returning an object where the values have been replaced by classNames.
25
-
26
- **Step 1**
27
-
28
- The first step here is expanding all [shorthands](#shorthands) into their individual properties. To do this we `.flatMap` over the object entries of the Namespace and use the `expandShorthands(...)` function defined within `expand-shorthands.js`
29
-
30
- **Step 2**
31
-
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
-
34
- **Step 3**
35
-
36
- Using the classNames generated in _step 2_ above, we collect all the individual style keys along with their associated classNames in the `resolvedNamespace` object.
37
-
38
- All the generated CSS rules from _step 2_ are collected in the `injectedStyles` object.
39
-
40
- The `[resolvedNamespace, injectedStyles]` is returned.
41
-
42
- ##### Back to `styleXCreateSet(...)`
43
-
44
- `styleXCreateSet(...)` takes all the `[resolvedNamespace, finalInjectedStyles]` tuples and returns a tuple of `[compiledNamespaceSet, allInjectedStyles]`
45
-
46
- ### Back to `create` with the `@stylexjs/babel-plugin` package
47
-
48
- The `create` function within the babel plugin package takes the `stylex.create(...)` function call and replaces it with the `compiledNamespaceSet`.
49
-
50
- It also takes each of the `injectedStyles` and:
51
-
52
- 1. Either injects it as a `stylex.inject` call (if in `dev` mode)
53
- 2. Or, adds it to the array of injected styles on [`babel.state.metadata`](#babel-metadata)
54
-
55
- #### ⭐️ `keyframes`
56
-
57
- This is the function backing `stylex.keyframes`. It works similarly to `create` but it's more simplified since it only defines a single CSS `@keyframes` rule and returns a single string.
58
-
59
- Here again, the source AST is converted to a JS object and passed to `stylex-keyframes.js` within the `shared` package.
60
-
61
- There, first the shorthands are expanded and then the whole objects is hashed. The resulting hash is used as the generated `animation name` for a `@keyframes` rule.
62
-
63
- The "name" and the CSS `@keyframes` rules are returned as a tuple.
64
-
65
- The `stylex.keyframes` call is replaced with the final string.
66
-
67
- The CSS `@keyframes` rule is either injected using `stylex.inject` in dev mode or set onto the `stylex` array on [`babel.state.metadata`](#babel-metadata).
68
-
69
- #### `convert-to-className` (`shared` package)
70
-
71
- This function is responsible for converting a single style key-value pair into a tuple of `[key, className, CSSRules]`
72
-
73
- It does so in the following steps:
74
-
75
- 1. Convert the camelCased keys that are used by end-users to define [Namespaces](#namespace) and convert them to the dash-separated keys used within CSS.
76
- 2. Hash `key` + (any `pseudo` or `at-rule`) + `value` to generate a className
77
- 3. Generate the CSS rule using the `generateCSSRule` function defined in [`generate-css-rule.js`](#generate-css-rulejs) in the `shared` package.
78
-
79
- #### `generate-css-rule.js`
80
-
81
- This function takes a CSS key value pair, checks if has an RTL counterpart and returns them along side a pre-configured priority based on the type of CSS rule it is.
@@ -1,47 +0,0 @@
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
- export type TRawValue = number | string | ReadonlyArray<number | string>;
11
- export type TStyleValue = null | TRawValue;
12
- export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
13
- export type RawStyles = Readonly<{ [$$Key$$: string]: TNestableStyleValue }>;
14
- export type PrimitiveRawStyles = Readonly<{
15
- [$$Key$$: string]: TNestableStyleValue;
16
- }>;
17
- export type InjectableStyle = {
18
- readonly priority: number;
19
- readonly ltr: string;
20
- readonly rtl: null | string;
21
- };
22
- export type StyleRule = [string, string, InjectableStyle];
23
- export type CompiledStyles = Readonly<{
24
- [$$Key$$: string]:
25
- | null
26
- | string
27
- | Readonly<{ [$$Key$$: string]: null | string }>;
28
- }>;
29
- export type FlatCompiledStyles = Readonly<{
30
- [$$Key$$: string]: string | null;
31
- $$css: true | string;
32
- }>;
33
- export type StyleXOptions = Readonly<{
34
- classNamePrefix: string;
35
- debug: null | undefined | boolean;
36
- enableDebugClassNames?: null | undefined | boolean;
37
- definedStylexCSSVariables?: { [key: string]: unknown };
38
- dev: boolean;
39
- styleResolution:
40
- | 'application-order'
41
- | 'property-specificity'
42
- | 'legacy-expand-shorthands';
43
- test: boolean;
44
- useRemForFontSize: boolean;
45
- }>;
46
- export type MutableCompiledNamespaces = { [key: string]: FlatCompiledStyles };
47
- export type CompiledNamespaces = Readonly<MutableCompiledNamespaces>;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,60 +0,0 @@
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
- export type TRawValue = number | string | $ReadOnlyArray<number | string>;
11
- export type TStyleValue = null | TRawValue;
12
- export type TNestableStyleValue = TStyleValue | PrimitiveRawStyles;
13
-
14
- export type RawStyles = $ReadOnly<{
15
- [string]: TNestableStyleValue,
16
- }>;
17
- export type PrimitiveRawStyles = $ReadOnly<{
18
- [string]: TNestableStyleValue,
19
- }>;
20
-
21
- export type InjectableStyle = {
22
- +priority: number,
23
- +ltr: string,
24
- +rtl: null | string,
25
- };
26
-
27
- export type StyleRule = [string, string, InjectableStyle];
28
-
29
- export type CompiledStyles = $ReadOnly<{
30
- [string]: null | string | $ReadOnly<{ [string]: null | string }>,
31
- }>;
32
-
33
- export type FlatCompiledStyles = $ReadOnly<{
34
- [string]: string | null,
35
- $$css: true | string,
36
- }>;
37
-
38
- export type StyleXOptions = $ReadOnly<{
39
- classNamePrefix: string,
40
- debug: ?boolean,
41
- enableDebugClassNames?: ?boolean,
42
- definedStylexCSSVariables?: { [key: string]: mixed },
43
- dev: boolean,
44
- styleResolution:
45
- | 'application-order' // The last style applied wins.
46
- // More specific styles will win over less specific styles. (margin-top wins over margin)
47
- | 'property-specificity'
48
- // Legacy behavior, that expands shorthand properties into their longhand counterparts at compile-time.
49
- // This is not recommended, and will be removed in a future version.
50
- | 'legacy-expand-shorthands',
51
- test: boolean,
52
- useRemForFontSize: boolean,
53
- ...
54
- }>;
55
-
56
- export type MutableCompiledNamespaces = {
57
- [key: string]: FlatCompiledStyles,
58
- };
59
-
60
- export type CompiledNamespaces = $ReadOnly<MutableCompiledNamespaces>;
@@ -1,20 +0,0 @@
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 { TRawValue, StyleRule, StyleXOptions } from './common-types';
11
- export declare function convertStyleToClassName(
12
- objEntry: Readonly<[string, TRawValue]>,
13
- pseudos: ReadonlyArray<string>,
14
- atRules: ReadonlyArray<string>,
15
- options: StyleXOptions,
16
- ): StyleRule;
17
- declare function variableFallbacks(
18
- values: ReadonlyArray<string>,
19
- ): ReadonlyArray<string>;
20
- export default variableFallbacks;
@@ -1,66 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.convertStyleToClassName = convertStyleToClassName;
7
- exports.default = variableFallbacks;
8
- var _hash = _interopRequireDefault(require("./hash"));
9
- var _dashify = _interopRequireDefault(require("./utils/dashify"));
10
- var _transformValue = _interopRequireDefault(require("./transform-value"));
11
- var _generateCssRule = require("./generate-css-rule");
12
- var _defaultOptions = require("./utils/default-options");
13
- var messages = _interopRequireWildcard(require("./messages"));
14
- var _ruleUtils = require("./utils/rule-utils");
15
- 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); }
16
- 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 && {}.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; }
17
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
- function convertStyleToClassName(objEntry, pseudos, atRules) {
19
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaultOptions.defaultOptions;
20
- const {
21
- classNamePrefix = 'x',
22
- debug = false,
23
- enableDebugClassNames = true
24
- } = options;
25
- const [key, rawValue] = objEntry;
26
- const dashedKey = key.startsWith('--') ? key : (0, _dashify.default)(key);
27
- let value = Array.isArray(rawValue) ? rawValue.map(eachValue => (0, _transformValue.default)(key, eachValue, options)) : (0, _transformValue.default)(key, rawValue, options);
28
- if (Array.isArray(value) && value.find(val => val.startsWith('var(') && val.endsWith(')'))) {
29
- value = variableFallbacks(value);
30
- }
31
- const sortedPseudos = (0, _ruleUtils.sortPseudos)(pseudos ?? []);
32
- const sortedAtRules = (0, _ruleUtils.sortAtRules)(atRules ?? []);
33
- const pseudoHashString = sortedPseudos.join('');
34
- const atRuleHashString = sortedAtRules.join('');
35
- const modifierHashString = pseudoHashString + atRuleHashString || 'null';
36
- const valueAsString = Array.isArray(value) ? value.join(', ') : value;
37
- const stringToHash = dashedKey + valueAsString + modifierHashString;
38
- const className = debug && enableDebugClassNames ? `${key}-${classNamePrefix}${(0, _hash.default)('<>' + stringToHash)}` : classNamePrefix + (0, _hash.default)('<>' + stringToHash);
39
- const cssRules = (0, _generateCssRule.generateRule)(className, dashedKey, value, pseudos, atRules);
40
- return [key, className, cssRules];
41
- }
42
- function variableFallbacks(values) {
43
- const firstVar = values.findIndex(val => val.startsWith('var(') && val.endsWith(')'));
44
- const lastVar = values.findLastIndex(val => val.startsWith('var(') && val.endsWith(')'));
45
- const valuesBeforeFirstVar = values.slice(0, firstVar);
46
- let varValues = values.slice(firstVar, lastVar + 1).reverse();
47
- const valuesAfterLastVar = values.slice(lastVar + 1);
48
- if (varValues.find(val => !val.startsWith('var(') || !val.endsWith(')'))) {
49
- throw new Error(messages.NON_CONTIGUOUS_VARS);
50
- }
51
- varValues = varValues.map(val => val.slice(4, -1));
52
- return [...(valuesBeforeFirstVar.length > 0 ? valuesBeforeFirstVar.map(val => composeVars(...varValues, val)) : composeVars(...varValues)), ...valuesAfterLastVar];
53
- }
54
- function composeVars() {
55
- for (var _len = arguments.length, vars = new Array(_len), _key = 0; _key < _len; _key++) {
56
- vars[_key] = arguments[_key];
57
- }
58
- const [first, ...rest] = vars;
59
- if (rest.length > 0) {
60
- return `var(${first},${composeVars(...rest)})`;
61
- } else if (first.startsWith('--')) {
62
- return `var(${first})`;
63
- } else {
64
- return first;
65
- }
66
- }
@@ -1,27 +0,0 @@
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 { TRawValue, StyleRule, StyleXOptions } from './common-types';
11
- // This function takes a single style rule and transforms it into a CSS rule.
12
- // [color: 'red'] => ['color', 'classname-for-color-red', CSSRULE{ltr, rtl, priority}]
13
- //
14
- // It converts the camelCased style key to a dash-separated key.
15
- // Handles RTL-flipping
16
- // Hashes to get a className
17
- // Returns the final key, className a CSS Rule
18
- declare export function convertStyleToClassName(
19
- objEntry: $ReadOnly<[string, TRawValue]>,
20
- pseudos: $ReadOnlyArray<string>,
21
- atRules: $ReadOnlyArray<string>,
22
- options: StyleXOptions,
23
- ): StyleRule;
24
-
25
- declare export default function variableFallbacks(
26
- values: $ReadOnlyArray<string>,
27
- ): $ReadOnlyArray<string>;
@@ -1,17 +0,0 @@
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 } from './common-types';
11
- export declare function generateRule(
12
- className: string,
13
- key: string,
14
- value: string | ReadonlyArray<string>,
15
- pseudos: ReadonlyArray<string>,
16
- atRules: ReadonlyArray<string>,
17
- ): InjectableStyle;