@stylexjs/shared 0.17.5 → 0.18.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 (145) hide show
  1. package/lib/common-types.d.ts +61 -0
  2. package/lib/common-types.js +1 -0
  3. package/lib/common-types.js.flow +85 -0
  4. package/lib/hash.d.ts +15 -0
  5. package/lib/hash.js +49 -0
  6. package/lib/hash.js.flow +12 -0
  7. package/lib/messages.d.ts +70 -0
  8. package/lib/messages.js +38 -0
  9. package/lib/messages.js.flow +44 -0
  10. package/lib/physical-rtl/generate-ltr.d.ts +15 -0
  11. package/lib/physical-rtl/generate-ltr.js +75 -0
  12. package/lib/physical-rtl/generate-ltr.js.flow +14 -0
  13. package/lib/physical-rtl/generate-rtl.d.ts +15 -0
  14. package/lib/physical-rtl/generate-rtl.js +157 -0
  15. package/lib/physical-rtl/generate-rtl.js.flow +14 -0
  16. package/lib/preprocess-rules/PreRule.d.ts +51 -0
  17. package/lib/preprocess-rules/PreRule.js +79 -0
  18. package/lib/preprocess-rules/PreRule.js.flow +63 -0
  19. package/lib/preprocess-rules/__tests__/PreRule-test.js +33 -0
  20. package/lib/preprocess-rules/__tests__/flatten-raw-style-obj-test.js +196 -0
  21. package/lib/preprocess-rules/application-order.d.ts +186 -0
  22. package/lib/preprocess-rules/application-order.js +195 -0
  23. package/lib/preprocess-rules/application-order.js.flow +141 -0
  24. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  25. package/lib/preprocess-rules/basic-validation.js +70 -0
  26. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  27. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +20 -0
  28. package/lib/preprocess-rules/flatten-raw-style-obj.js +100 -0
  29. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +23 -0
  30. package/lib/preprocess-rules/index.d.ts +21 -0
  31. package/lib/preprocess-rules/index.js +45 -0
  32. package/lib/preprocess-rules/index.js.flow +23 -0
  33. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +170 -0
  34. package/lib/preprocess-rules/legacy-expand-shorthands.js +222 -0
  35. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +142 -0
  36. package/lib/preprocess-rules/property-specificity.d.ts +79 -0
  37. package/lib/preprocess-rules/property-specificity.js +107 -0
  38. package/lib/preprocess-rules/property-specificity.js.flow +93 -0
  39. package/lib/stylex-consts-utils.d.ts +11 -0
  40. package/lib/stylex-consts-utils.js +1 -0
  41. package/lib/stylex-consts-utils.js.flow +14 -0
  42. package/lib/stylex-create-theme.d.ts +26 -0
  43. package/lib/stylex-create-theme.js +53 -0
  44. package/lib/stylex-create-theme.js.flow +19 -0
  45. package/lib/stylex-create.d.ts +27 -0
  46. package/lib/stylex-create.js +60 -0
  47. package/lib/stylex-create.js.flow +37 -0
  48. package/lib/stylex-defaultMarker.d.ts +14 -0
  49. package/lib/stylex-defaultMarker.js +14 -0
  50. package/lib/stylex-defaultMarker.js.flow +13 -0
  51. package/lib/stylex-define-consts.d.ts +23 -0
  52. package/lib/stylex-define-consts.js +40 -0
  53. package/lib/stylex-define-consts.js.flow +19 -0
  54. package/lib/stylex-define-vars.d.ts +28 -0
  55. package/lib/stylex-define-vars.js +90 -0
  56. package/lib/stylex-define-vars.js.flow +26 -0
  57. package/lib/stylex-first-that-works.d.ts +13 -0
  58. package/lib/stylex-first-that-works.js +23 -0
  59. package/lib/stylex-first-that-works.js.flow +12 -0
  60. package/lib/stylex-keyframes.d.ts +17 -0
  61. package/lib/stylex-keyframes.js +46 -0
  62. package/lib/stylex-keyframes.js.flow +20 -0
  63. package/lib/stylex-position-try.d.ts +15 -0
  64. package/lib/stylex-position-try.js +47 -0
  65. package/lib/stylex-position-try.js.flow +18 -0
  66. package/lib/stylex-vars-utils.d.ts +27 -0
  67. package/lib/stylex-vars-utils.js +66 -0
  68. package/lib/stylex-vars-utils.js.flow +31 -0
  69. package/lib/stylex-view-transition-class.d.ts +22 -0
  70. package/lib/stylex-view-transition-class.js +42 -0
  71. package/lib/stylex-view-transition-class.js.flow +23 -0
  72. package/lib/types/__tests__/stylex-types-test.js +178 -0
  73. package/lib/types/index.d.ts +254 -0
  74. package/lib/types/index.js +147 -0
  75. package/lib/types/index.js.flow +280 -0
  76. package/lib/utils/Rule.d.ts +58 -0
  77. package/lib/utils/Rule.js +50 -0
  78. package/lib/utils/Rule.js.flow +64 -0
  79. package/lib/utils/__tests__/convert-to-className-test.js +85 -0
  80. package/lib/utils/__tests__/property-priorities-test.js +33 -0
  81. package/lib/utils/__tests__/split-css-value-test.js +26 -0
  82. package/lib/utils/__tests__/transform-value-test.js +36 -0
  83. package/lib/utils/convert-to-className.d.ts +21 -0
  84. package/lib/utils/convert-to-className.js +61 -0
  85. package/lib/utils/convert-to-className.js.flow +29 -0
  86. package/lib/utils/css-properties.js.flow +155 -0
  87. package/lib/utils/dashify.d.ts +11 -0
  88. package/lib/utils/dashify.js +9 -0
  89. package/lib/utils/dashify.js.flow +10 -0
  90. package/lib/utils/default-options.d.ts +12 -0
  91. package/lib/utils/default-options.js +26 -0
  92. package/lib/utils/default-options.js.flow +12 -0
  93. package/lib/utils/file-based-identifier.d.ts +15 -0
  94. package/lib/utils/file-based-identifier.js +13 -0
  95. package/lib/utils/file-based-identifier.js.flow +14 -0
  96. package/lib/utils/generate-css-rule.d.ts +19 -0
  97. package/lib/utils/generate-css-rule.js +37 -0
  98. package/lib/utils/generate-css-rule.js.flow +19 -0
  99. package/lib/utils/normalize-value.d.ts +16 -0
  100. package/lib/utils/normalize-value.js +27 -0
  101. package/lib/utils/normalize-value.js.flow +16 -0
  102. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  103. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  104. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  105. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  106. package/lib/utils/normalizers/detect-unclosed-fns.js +16 -0
  107. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  108. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  109. package/lib/utils/normalizers/font-size-px-to-rem.js +24 -0
  110. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  111. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  112. package/lib/utils/normalizers/leading-zero.js +24 -0
  113. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  114. package/lib/utils/normalizers/quotes.d.ts +18 -0
  115. package/lib/utils/normalizers/quotes.js +17 -0
  116. package/lib/utils/normalizers/quotes.js.flow +17 -0
  117. package/lib/utils/normalizers/timings.d.ts +18 -0
  118. package/lib/utils/normalizers/timings.js +25 -0
  119. package/lib/utils/normalizers/timings.js.flow +17 -0
  120. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  121. package/lib/utils/normalizers/whitespace.js +54 -0
  122. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  123. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  124. package/lib/utils/normalizers/zero-dimensions.js +45 -0
  125. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  126. package/lib/utils/object-utils.d.ts +68 -0
  127. package/lib/utils/object-utils.js +89 -0
  128. package/lib/utils/object-utils.js.flow +78 -0
  129. package/lib/utils/property-priorities.js +13 -1
  130. package/lib/utils/rule-utils.d.ts +17 -0
  131. package/lib/utils/rule-utils.js +41 -0
  132. package/lib/utils/rule-utils.js.flow +16 -0
  133. package/lib/utils/split-css-value.d.ts +14 -0
  134. package/lib/utils/split-css-value.js +41 -0
  135. package/lib/utils/split-css-value.js.flow +15 -0
  136. package/lib/utils/transform-value.d.ts +24 -0
  137. package/lib/utils/transform-value.js +50 -0
  138. package/lib/utils/transform-value.js.flow +25 -0
  139. package/lib/validate.d.ts +12 -0
  140. package/lib/validate.js +19 -0
  141. package/lib/validate.js.flow +14 -0
  142. package/lib/when/when.d.ts +67 -0
  143. package/lib/when/when.js +71 -0
  144. package/lib/when/when.js.flow +73 -0
  145. package/package.json +1 -1
@@ -522,6 +522,16 @@ const RELATIONAL_SELECTORS = {
522
522
  SIBLING_AFTER: /^:where\(:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/,
523
523
  ANY_SIBLING: /^:where\(\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\s+~\s+\*,\s+:has\(~\s\.[0-9a-zA-Z_-]+(:[a-zA-Z-]+)\)\)$/
524
524
  };
525
+ const PSEUDO_PART_REGEX = /::[a-zA-Z-]+|:[a-zA-Z-]+(?:\([^)]*\))?/g;
526
+ function getCompoundPseudoPriority(key) {
527
+ const parts = key.match(PSEUDO_PART_REGEX);
528
+ if (!parts || parts.length <= 1 || parts.some(p => p.includes('('))) return;
529
+ let total = 0;
530
+ for (const part of parts) {
531
+ total += part.startsWith('::') ? PSEUDO_ELEMENT_PRIORITY : PSEUDO_CLASS_PRIORITIES[part] ?? 40;
532
+ }
533
+ return total;
534
+ }
525
535
  function getAtRulePriority(key) {
526
536
  if (key.startsWith('--')) {
527
537
  return 1;
@@ -562,7 +572,7 @@ function getPseudoClassPriority(key) {
562
572
  return 40 + pseudoBase(siblingAfterMatch[1]);
563
573
  }
564
574
  if (key.startsWith(':')) {
565
- const prop = key.startsWith(':') && key.includes('(') ? key.slice(0, key.indexOf('(')) : key;
575
+ const prop = key.split('(')[0];
566
576
  return PSEUDO_CLASS_PRIORITIES[prop] ?? 40;
567
577
  }
568
578
  }
@@ -583,6 +593,8 @@ function getDefaultPriority(key) {
583
593
  function getPriority(key) {
584
594
  const atRulePriority = getAtRulePriority(key);
585
595
  if (atRulePriority) return atRulePriority;
596
+ const compoundPriority = getCompoundPseudoPriority(key);
597
+ if (compoundPriority != null) return compoundPriority;
586
598
  const pseudoElementPriority = getPseudoElementPriority(key);
587
599
  if (pseudoElementPriority) return pseudoElementPriority;
588
600
  const pseudoClassPriority = getPseudoClassPriority(key);
@@ -0,0 +1,17 @@
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 declare const sortPseudos: (
11
+ pseudos: ReadonlyArray<string>,
12
+ ) => ReadonlyArray<string>;
13
+ export declare type sortPseudos = typeof sortPseudos;
14
+ export declare const sortAtRules: (
15
+ atRules: ReadonlyArray<string>,
16
+ ) => ReadonlyArray<string>;
17
+ export declare type sortAtRules = typeof sortAtRules;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortPseudos = exports.sortAtRules = void 0;
7
+ var _objectUtils = require("./object-utils");
8
+ const sortPseudos = pseudos => {
9
+ if (pseudos.length < 2) {
10
+ return pseudos;
11
+ }
12
+ return pseudos.reduce((acc, pseudo) => {
13
+ if (pseudo.startsWith('::')) {
14
+ return [...acc, pseudo];
15
+ }
16
+ const lastElement = acc[acc.length - 1];
17
+ const allButLast = acc.slice(0, acc.length - 1);
18
+ if (Array.isArray(lastElement)) {
19
+ return [...allButLast, [...lastElement, pseudo]];
20
+ } else {
21
+ return [...allButLast, lastElement, [pseudo]].filter(Boolean);
22
+ }
23
+ }, []).flatMap(pseudo => {
24
+ if (Array.isArray(pseudo)) {
25
+ return (0, _objectUtils.arraySort)(pseudo, stringComparator);
26
+ }
27
+ return [pseudo];
28
+ });
29
+ };
30
+ exports.sortPseudos = sortPseudos;
31
+ const sortAtRules = atRules => (0, _objectUtils.arraySort)(atRules);
32
+ exports.sortAtRules = sortAtRules;
33
+ const stringComparator = (a, b) => {
34
+ if (a === 'default') {
35
+ return -1;
36
+ }
37
+ if (b === 'default') {
38
+ return 1;
39
+ }
40
+ return a.localeCompare(b);
41
+ };
@@ -0,0 +1,16 @@
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
+ declare export const sortPseudos: (
11
+ pseudos: $ReadOnlyArray<string>,
12
+ ) => $ReadOnlyArray<string>;
13
+
14
+ declare export const sortAtRules: (
15
+ atRules: $ReadOnlyArray<string>,
16
+ ) => $ReadOnlyArray<string>;
@@ -0,0 +1,14 @@
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 { TStyleValue } from '../common-types';
11
+ declare function splitValue(
12
+ str: TStyleValue,
13
+ ): ReadonlyArray<number | string | null>;
14
+ export default splitValue;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = splitValue;
7
+ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function printNode(node) {
10
+ return ($$gen$m0 => {
11
+ if ((typeof $$gen$m0 === "object" && $$gen$m0 !== null || typeof $$gen$m0 === "function") && $$gen$m0.type === 'word' && "value" in $$gen$m0) {
12
+ const value = $$gen$m0.value;
13
+ return value;
14
+ }
15
+ if ((typeof $$gen$m0 === "object" && $$gen$m0 !== null || typeof $$gen$m0 === "function") && $$gen$m0.type === 'string' && "value" in $$gen$m0 && "quote" in $$gen$m0) {
16
+ const value = $$gen$m0.value;
17
+ const quote = $$gen$m0.quote;
18
+ return `${quote}${value}${quote}`;
19
+ }
20
+ if ((typeof $$gen$m0 === "object" && $$gen$m0 !== null || typeof $$gen$m0 === "function") && $$gen$m0.type === 'function' && "value" in $$gen$m0 && "nodes" in $$gen$m0) {
21
+ const value = $$gen$m0.value;
22
+ const nodes = $$gen$m0.nodes;
23
+ return `${value}(${nodes.map(printNode).join('')})`;
24
+ }
25
+ return node.value;
26
+ })(node);
27
+ }
28
+ function splitValue(str) {
29
+ if (str == null || typeof str === 'number') {
30
+ return [str];
31
+ }
32
+ if (Array.isArray(str)) {
33
+ return str;
34
+ }
35
+ const parsed = (0, _postcssValueParser.default)(str.trim());
36
+ const nodes = parsed.nodes.filter(node => node.type !== 'space' && node.type !== 'div').map(printNode);
37
+ if (nodes.length > 1 && nodes[nodes.length - 1].toLowerCase() === '!important') {
38
+ return nodes.slice(0, nodes.length - 1).map(node => node + ' !important');
39
+ }
40
+ return nodes;
41
+ }
@@ -0,0 +1,15 @@
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 { TStyleValue } from '../common-types';
11
+
12
+ // Using split(' ') Isn't enough because of values like calc.
13
+ declare export default function splitValue(
14
+ str: TStyleValue,
15
+ ): $ReadOnlyArray<number | string | null>;
@@ -0,0 +1,24 @@
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 { StyleXOptions } from '../common-types';
11
+ /**
12
+ * Convert a CSS value in JS to the final CSS string value
13
+ */
14
+ declare function transformValue(
15
+ key: string,
16
+ rawValue: string | number,
17
+ options: StyleXOptions,
18
+ ): string;
19
+ export default transformValue;
20
+ export declare function getNumberSuffix(key: string): string;
21
+ export declare const timeUnits: Set<string>;
22
+ export declare type timeUnits = typeof timeUnits;
23
+ export declare const lengthUnits: Set<string>;
24
+ export declare type lengthUnits = typeof lengthUnits;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = transformValue;
7
+ exports.getNumberSuffix = getNumberSuffix;
8
+ exports.timeUnits = exports.lengthUnits = void 0;
9
+ var _normalizeValue = _interopRequireDefault(require("./normalize-value"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function transformValue(key, rawValue, options) {
12
+ const value = typeof rawValue === 'number' ? String(Math.round(rawValue * 10000) / 10000) + getNumberSuffix(key) : rawValue;
13
+ if ((key === 'content' || key === 'hyphenateCharacter' || key === 'hyphenate-character') && typeof value === 'string') {
14
+ const val = value.trim();
15
+ const cssContentFunctions = ['attr(', 'counter(', 'counters(', 'url(', 'linear-gradient(', 'image-set(', 'var(--'];
16
+ const cssContentKeywords = new Set(['normal', 'none', 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', 'inherit', 'initial', 'revert', 'revert-layer', 'unset']);
17
+ const isCssFunction = cssContentFunctions.some(func => val.includes(func));
18
+ const isKeyword = cssContentKeywords.has(val);
19
+ const hasMatchingQuotes = (val.match(/"/g)?.length ?? 0) >= 2 || (val.match(/'/g)?.length ?? 0) >= 2;
20
+ if (isCssFunction || isKeyword || hasMatchingQuotes) {
21
+ return val;
22
+ }
23
+ return `"${val}"`;
24
+ }
25
+ return (0, _normalizeValue.default)(value, key, options);
26
+ }
27
+ function getNumberSuffix(key) {
28
+ if (unitlessNumberProperties.has(key) || key.startsWith('--')) {
29
+ return '';
30
+ }
31
+ if (!(key in numberPropertySuffixes)) {
32
+ return 'px';
33
+ }
34
+ const suffix = numberPropertySuffixes[key];
35
+ if (suffix == null) {
36
+ return 'px';
37
+ } else {
38
+ return suffix;
39
+ }
40
+ }
41
+ const unitlessNumberProperties = new Set(['WebkitLineClamp', 'animationIterationCount', 'aspectRatio', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'counterSet', 'counterReset', 'columnCount', 'flex', 'flexGrow', 'flexShrink', 'flexOrder', 'gridRow', 'gridRowStart', 'gridRowEnd', 'gridColumn', 'gridColumnStart', 'gridColumnEnd', 'gridArea', 'fontWeight', 'hyphenateLimitChars', 'lineClamp', 'lineHeight', 'maskBorderOutset', 'maskBorderSlice', 'maskBorderWidth', 'opacity', 'order', 'orphans', 'tabSize', 'widows', 'zIndex', 'fillOpacity', 'floodOpacity', 'rotate', 'scale', 'shapeImageThreshold', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'scale', 'mathDepth', 'zoom']);
42
+ const numberPropertySuffixes = {
43
+ animationDelay: 'ms',
44
+ animationDuration: 'ms',
45
+ transitionDelay: 'ms',
46
+ transitionDuration: 'ms',
47
+ voiceDuration: 'ms'
48
+ };
49
+ const timeUnits = exports.timeUnits = new Set(Object.keys(numberPropertySuffixes));
50
+ const lengthUnits = exports.lengthUnits = new Set(['backgroundPositionX', 'backgroundPositionY', 'blockSize', 'borderBlockEndWidth', 'borderBlockStartWidth', 'borderBlockWidth', 'borderVerticalWidth', 'borderVerticalWidth', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomWidth', 'borderEndEndRadius', 'borderEndStartRadius', 'borderInlineEndWidth', 'borderEndWidth', 'borderInlineStartWidth', 'borderStartWidth', 'borderInlineWidth', 'borderHorizontalWidth', 'borderLeftWidth', 'borderRightWidth', 'borderSpacing', 'borderStartEndRadius', 'borderStartStartRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopWidth', 'bottom', 'columnGap', 'columnRuleWidth', 'columnWidth', 'containIntrinsicBlockSize', 'containIntrinsicHeight', 'containIntrinsicInlineSize', 'containIntrinsicWidth', 'flexBasis', 'fontSize', 'fontSmooth', 'height', 'inlineSize', 'insetBlockEnd', 'insetBlockStart', 'insetInlineEnd', 'insetInlineStart', 'left', 'letterSpacing', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginInlineEnd', 'marginEnd', 'marginInlineStart', 'marginStart', 'marginLeft', 'marginRight', 'marginTop', 'maxBlockSize', 'maxHeight', 'maxInlineSize', 'maxWidth', 'minBlockSize', 'minHeight', 'minInlineSize', 'minWidth', 'offsetDistance', 'outlineOffset', 'outlineWidth', 'overflowClipMargin', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingInlineEnd', 'paddingEnd', 'paddingInlineStart', 'paddingStart', 'paddingLeft', 'paddingRight', 'paddingTop', 'perspective', 'right', 'rowGap', 'scrollMarginBlockEnd', 'scrollMarginBlockStart', 'scrollMarginBottom', 'scrollMarginInlineEnd', 'scrollMarginInlineStart', 'scrollMarginLeft', 'scrollMarginRight', 'scrollMarginTop', 'scrollPaddingBlockEnd', 'scrollPaddingBlockStart', 'scrollPaddingBottom', 'scrollPaddingInlineEnd', 'scrollPaddingInlineStart', 'scrollPaddingLeft', 'scrollPaddingRight', 'scrollPaddingTop', 'scrollSnapMarginBottom', 'scrollSnapMarginLeft', 'scrollSnapMarginRight', 'scrollSnapMarginTop', 'shapeMargin', 'tabSize', 'textDecorationThickness', 'textIndent', 'textUnderlineOffset', 'top', 'transformOrigin', 'translate', 'verticalAlign', 'width', 'wordSpacing', 'border', 'borderBlock', 'borderBlockEnd', 'borderBlockStart', 'borderBottom', 'borderLeft', 'borderRadius', 'borderRight', 'borderTop', 'borderWidth', 'columnRule', 'containIntrinsicSize', 'gap', 'inset', 'insetBlock', 'insetInline', 'margin', 'marginBlock', 'marginVertical', 'marginInline', 'marginHorizontal', 'offset', 'outline', 'padding', 'paddingBlock', 'paddingVertical', 'paddingInline', 'paddingHorizontal', 'scrollMargin', 'scrollMarginBlock', 'scrollMarginInline', 'scrollPadding', 'scrollPaddingBlock', 'scrollPaddingInline', 'scrollSnapMargin']);
@@ -0,0 +1,25 @@
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 { StyleXOptions } from '../common-types';
11
+
12
+ /**
13
+ * Convert a CSS value in JS to the final CSS string value
14
+ */
15
+ declare export default function transformValue(
16
+ key: string,
17
+ rawValue: string | number,
18
+ options: StyleXOptions,
19
+ ): string;
20
+
21
+ declare export function getNumberSuffix(key: string): string;
22
+
23
+ declare export const timeUnits: Set<string>;
24
+
25
+ declare export const lengthUnits: Set<string>;
@@ -0,0 +1,12 @@
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 } from './common-types';
11
+ declare function validateEntry($$PARAM_0$$: [string, TRawValue]): void;
12
+ export default validateEntry;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = validateEntry;
7
+ function validateEntry([key, value]) {
8
+ if (Array.isArray(value)) {
9
+ value.forEach(val => validateSimplyEntry([key, val]));
10
+ } else {
11
+ validateSimplyEntry([key, value]);
12
+ }
13
+ }
14
+ function validateSimplyEntry([key, _value]) {
15
+ if (BANNED_KEYS.has(key)) {
16
+ throw new Error('Banned key: ' + key);
17
+ }
18
+ }
19
+ const BANNED_KEYS = new Set(['background', 'transition', 'grid']);
@@ -0,0 +1,14 @@
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 } from './common-types';
11
+
12
+ declare export default function validateEntry(
13
+ $$PARAM_0$$: [string, TRawValue],
14
+ ): void;
@@ -0,0 +1,67 @@
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 { StyleXOptions } from '../common-types';
11
+ type WhenSelector = `:${string}` | `[${string}`;
12
+ /**
13
+ * Creates selector that observes if the given pseudo-class is
14
+ * active on an ancestor with the "defaultMarker"
15
+ *
16
+ *
17
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
18
+ * @returns A :where() clause for the ancestor observer
19
+ */
20
+ export declare function ancestor(
21
+ pseudo: WhenSelector,
22
+ options?: string | StyleXOptions,
23
+ ): string;
24
+ /**
25
+ * Creates selector that observes if the given pseudo-class is
26
+ * active on a descendant with the "defaultMarker"
27
+ *
28
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
29
+ * @returns A :has() clause for the descendant observer
30
+ */
31
+ export declare function descendant(
32
+ pseudo: WhenSelector,
33
+ options?: string | StyleXOptions,
34
+ ): string;
35
+ /**
36
+ * Creates selector that observes if the given pseudo-class is
37
+ * active on a previous sibling with the "defaultMarker"
38
+ *
39
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
40
+ * @returns A :where() clause for the previous sibling observer
41
+ */
42
+ export declare function siblingBefore(
43
+ pseudo: WhenSelector,
44
+ options?: string | StyleXOptions,
45
+ ): string;
46
+ /**
47
+ * Creates selector that observes if the given pseudo-class is
48
+ * active on a next sibling with the "defaultMarker"
49
+ *
50
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
51
+ * @returns A :has() clause for the next sibling observer
52
+ */
53
+ export declare function siblingAfter(
54
+ pseudo: WhenSelector,
55
+ options?: string | StyleXOptions,
56
+ ): string;
57
+ /**
58
+ * Creates selector that observes if the given pseudo-class is
59
+ * active on any sibling with the "defaultMarker"
60
+ *
61
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
62
+ * @returns A :where() clause for the any sibling observer
63
+ */
64
+ export declare function anySibling(
65
+ pseudo: WhenSelector,
66
+ options?: string | StyleXOptions,
67
+ ): string;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ancestor = ancestor;
7
+ exports.anySibling = anySibling;
8
+ exports.descendant = descendant;
9
+ exports.siblingAfter = siblingAfter;
10
+ exports.siblingBefore = siblingBefore;
11
+ var _defaultOptions = require("../utils/default-options");
12
+ function fromProxy(value) {
13
+ if (typeof value === 'object' && value != null && value.__IS_PROXY === true && typeof value.toString === 'function') {
14
+ return value.toString();
15
+ }
16
+ return null;
17
+ }
18
+ function fromStyleXStyle(value) {
19
+ if (typeof value === 'object' && value != null && value.$$css === true) {
20
+ return Object.keys(value).find(key => key !== '$$css');
21
+ }
22
+ return null;
23
+ }
24
+ function getDefaultMarkerClassName(options = _defaultOptions.defaultOptions) {
25
+ const valueFromProxy = fromProxy(options);
26
+ if (valueFromProxy != null) {
27
+ return valueFromProxy;
28
+ }
29
+ const valueFromStyleXStyle = fromStyleXStyle(options);
30
+ if (valueFromStyleXStyle != null) {
31
+ return valueFromStyleXStyle;
32
+ }
33
+ const prefix = options.classNamePrefix != null ? `${options.classNamePrefix}-` : '';
34
+ return `${prefix}default-marker`;
35
+ }
36
+ function validatePseudoSelector(pseudo) {
37
+ if (!(pseudo.startsWith(':') || pseudo.startsWith('['))) {
38
+ throw new Error('Pseudo selector must start with ":" or "["');
39
+ }
40
+ if (pseudo.startsWith('::')) {
41
+ throw new Error('Pseudo selector cannot start with "::" (pseudo-elements are not supported)');
42
+ }
43
+ if (pseudo.startsWith('[') && !pseudo.endsWith(']')) {
44
+ throw new Error('Attribute selector must end with "]"');
45
+ }
46
+ }
47
+ function ancestor(pseudo, options = _defaultOptions.defaultOptions) {
48
+ validatePseudoSelector(pseudo);
49
+ const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
50
+ return `:where(.${defaultMarker}${pseudo} *)`;
51
+ }
52
+ function descendant(pseudo, options = _defaultOptions.defaultOptions) {
53
+ validatePseudoSelector(pseudo);
54
+ const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
55
+ return `:where(:has(.${defaultMarker}${pseudo}))`;
56
+ }
57
+ function siblingBefore(pseudo, options = _defaultOptions.defaultOptions) {
58
+ validatePseudoSelector(pseudo);
59
+ const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
60
+ return `:where(.${defaultMarker}${pseudo} ~ *)`;
61
+ }
62
+ function siblingAfter(pseudo, options = _defaultOptions.defaultOptions) {
63
+ validatePseudoSelector(pseudo);
64
+ const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
65
+ return `:where(:has(~ .${defaultMarker}${pseudo}))`;
66
+ }
67
+ function anySibling(pseudo, options = _defaultOptions.defaultOptions) {
68
+ validatePseudoSelector(pseudo);
69
+ const defaultMarker = typeof options === 'string' ? options : getDefaultMarkerClassName(options);
70
+ return `:where(.${defaultMarker}${pseudo} ~ *, :has(~ .${defaultMarker}${pseudo}))`;
71
+ }
@@ -0,0 +1,73 @@
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 { StyleXOptions } from '../common-types';
11
+
12
+ type WhenSelector = StringPrefix<':'> | StringPrefix<'['>;
13
+
14
+ /**
15
+ * Creates selector that observes if the given pseudo-class is
16
+ * active on an ancestor with the "defaultMarker"
17
+ *
18
+ *
19
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
20
+ * @returns A :where() clause for the ancestor observer
21
+ */
22
+ declare export function ancestor(
23
+ pseudo: WhenSelector,
24
+ options?: string | StyleXOptions,
25
+ ): string;
26
+
27
+ /**
28
+ * Creates selector that observes if the given pseudo-class is
29
+ * active on a descendant with the "defaultMarker"
30
+ *
31
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
32
+ * @returns A :has() clause for the descendant observer
33
+ */
34
+ declare export function descendant(
35
+ pseudo: WhenSelector,
36
+ options?: string | StyleXOptions,
37
+ ): string;
38
+
39
+ /**
40
+ * Creates selector that observes if the given pseudo-class is
41
+ * active on a previous sibling with the "defaultMarker"
42
+ *
43
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
44
+ * @returns A :where() clause for the previous sibling observer
45
+ */
46
+ declare export function siblingBefore(
47
+ pseudo: WhenSelector,
48
+ options?: string | StyleXOptions,
49
+ ): string;
50
+
51
+ /**
52
+ * Creates selector that observes if the given pseudo-class is
53
+ * active on a next sibling with the "defaultMarker"
54
+ *
55
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
56
+ * @returns A :has() clause for the next sibling observer
57
+ */
58
+ declare export function siblingAfter(
59
+ pseudo: WhenSelector,
60
+ options?: string | StyleXOptions,
61
+ ): string;
62
+
63
+ /**
64
+ * Creates selector that observes if the given pseudo-class is
65
+ * active on any sibling with the "defaultMarker"
66
+ *
67
+ * @param pseudo - The pseudo selector (e.g., ':hover', ':focus')
68
+ * @returns A :where() clause for the any sibling observer
69
+ */
70
+ declare export function anySibling(
71
+ pseudo: WhenSelector,
72
+ options?: string | StyleXOptions,
73
+ ): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/shared",
3
- "version": "0.17.5",
3
+ "version": "0.18.0",
4
4
  "main": "lib/index.js",
5
5
  "repository": {
6
6
  "type": "git",