@stylexjs/stylex 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +18 -43
  2. package/lib/StyleXCSSTypes.d.ts +3 -1
  3. package/lib/StyleXCSSTypes.js.flow +4 -2
  4. package/lib/StyleXSheet.js +17 -3
  5. package/lib/StyleXTypes.d.ts +10 -4
  6. package/lib/StyleXTypes.js.flow +9 -6
  7. package/lib/stylex.d.ts +0 -7
  8. package/lib/stylex.js +1 -5
  9. package/lib/stylex.js.flow +0 -4
  10. package/package.json +2 -2
  11. package/lib/native/CSSCustomPropertyValue.d.ts +0 -26
  12. package/lib/native/CSSCustomPropertyValue.js +0 -27
  13. package/lib/native/CSSCustomPropertyValue.js.flow +0 -27
  14. package/lib/native/CSSLengthUnitValue.d.ts +0 -18
  15. package/lib/native/CSSLengthUnitValue.js +0 -73
  16. package/lib/native/CSSLengthUnitValue.js.flow +0 -21
  17. package/lib/native/CSSMediaQuery.d.ts +0 -25
  18. package/lib/native/CSSMediaQuery.js +0 -55
  19. package/lib/native/CSSMediaQuery.js.flow +0 -26
  20. package/lib/native/SpreadOptions.d.ts +0 -19
  21. package/lib/native/SpreadOptions.js +0 -1
  22. package/lib/native/SpreadOptions.js.flow +0 -19
  23. package/lib/native/__tests__/__snapshots__/stylex-css-var-test.js.snap +0 -48
  24. package/lib/native/__tests__/__snapshots__/stylex-test.js.snap +0 -1046
  25. package/lib/native/__tests__/parseTimeValue-test.js +0 -11
  26. package/lib/native/__tests__/stylex-css-var-test.js +0 -148
  27. package/lib/native/__tests__/stylex-test.js +0 -924
  28. package/lib/native/errorMsg.d.ts +0 -11
  29. package/lib/native/errorMsg.js +0 -13
  30. package/lib/native/errorMsg.js.flow +0 -12
  31. package/lib/native/fixContentBox.d.ts +0 -11
  32. package/lib/native/fixContentBox.js +0 -59
  33. package/lib/native/fixContentBox.js.flow +0 -11
  34. package/lib/native/flattenStyle.d.ts +0 -15
  35. package/lib/native/flattenStyle.js +0 -20
  36. package/lib/native/flattenStyle.js.flow +0 -20
  37. package/lib/native/parseShadow.d.ts +0 -18
  38. package/lib/native/parseShadow.js +0 -36
  39. package/lib/native/parseShadow.js.flow +0 -19
  40. package/lib/native/parseTimeValue.d.ts +0 -11
  41. package/lib/native/parseTimeValue.js +0 -18
  42. package/lib/native/parseTimeValue.js.flow +0 -12
  43. package/lib/native/stylex.d.ts +0 -50
  44. package/lib/native/stylex.js +0 -393
  45. package/lib/native/stylex.js.flow +0 -60
@@ -1,11 +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 declare function errorMsg(msg: string): void;
11
- export declare function warnMsg(msg: string): void;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.errorMsg = errorMsg;
7
- exports.warnMsg = warnMsg;
8
- function errorMsg(msg) {
9
- console.error(`stylex: ${msg}`);
10
- }
11
- function warnMsg(msg) {
12
- console.warn(`stylex: ${msg}`);
13
- }
@@ -1,12 +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
- declare export function errorMsg(msg: string): void;
11
-
12
- declare export function warnMsg(msg: string): void;
@@ -1,11 +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
- type FlatStyle = { [key: string]: unknown };
11
- export declare function fixContentBox(flatStyle: FlatStyle): FlatStyle;
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fixContentBox = fixContentBox;
7
- var _errorMsg = require("./errorMsg");
8
- const TOP = 0;
9
- const RIGHT = 1;
10
- const BOTTOM = 2;
11
- const LEFT = 3;
12
- const START = LEFT;
13
- const END = RIGHT;
14
- const borderMapping = [['borderWidth', [TOP, RIGHT, BOTTOM, LEFT]], ['borderTopWidth', [TOP]], ['borderRightWidth', [RIGHT]], ['borderBottomWidth', [BOTTOM]], ['borderLeftWidth', [LEFT]], ['borderStartWidth', [START]], ['borderEndWidth', [END]]];
15
- const paddingMapping = [['padding', [TOP, RIGHT, BOTTOM, LEFT]], ['paddingVertical', [TOP, BOTTOM]], ['paddingHorizontal', [LEFT, RIGHT]], ['paddingTop', [TOP]], ['paddingRight', [RIGHT]], ['paddingBottom', [BOTTOM]], ['paddingLeft', [LEFT]], ['paddingStart', [START]], ['paddingEnd', [END]]];
16
- function fixContentBox(flatStyle) {
17
- const border = [0, 0, 0, 0];
18
- const padding = [0, 0, 0, 0];
19
- for (const [styleProp, directions] of borderMapping) {
20
- if (typeof flatStyle[styleProp] === 'number') {
21
- for (const direction of directions) {
22
- border[direction] = flatStyle[styleProp];
23
- }
24
- }
25
- }
26
- for (const [styleProp, directions] of paddingMapping) {
27
- if (typeof flatStyle[styleProp] === 'number') {
28
- for (const direction of directions) {
29
- padding[direction] = flatStyle[styleProp];
30
- }
31
- }
32
- }
33
- const correctionVertical = border[TOP] + padding[TOP] + padding[BOTTOM] + border[BOTTOM];
34
- const correctionHorizontal = border[LEFT] + padding[LEFT] + padding[RIGHT] + border[RIGHT];
35
- const correctionMapping = new Map([['width', correctionHorizontal], ['minWidth', correctionHorizontal], ['maxWidth', correctionHorizontal], ['height', correctionVertical], ['minHeight', correctionVertical], ['maxHeight', correctionVertical]]);
36
- const nextStyle = {};
37
- for (const styleProp of Object.keys(flatStyle)) {
38
- const correction = correctionMapping.get(styleProp);
39
- const styleValue = flatStyle[styleProp];
40
- if (correction != null) {
41
- if (styleValue == null) {
42
- nextStyle[styleProp] = null;
43
- continue;
44
- }
45
- if (styleValue === 'auto') {
46
- nextStyle[styleProp] = styleValue;
47
- continue;
48
- }
49
- if (typeof styleValue !== 'number') {
50
- (0, _errorMsg.warnMsg)(`"boxSizing:'content-box'" does not support value "${String(styleValue)}" for property "${styleProp}". Expected a value that resolves to a number. Percentage values can only be used with "boxSizing:'border-box'".`);
51
- return flatStyle;
52
- }
53
- nextStyle[styleProp] = styleValue + correction;
54
- } else {
55
- nextStyle[styleProp] = styleValue;
56
- }
57
- }
58
- return nextStyle;
59
- }
@@ -1,11 +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
- type FlatStyle = { [key: string]: mixed };
11
- declare export function fixContentBox(flatStyle: FlatStyle): FlatStyle;
@@ -1,15 +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
- type InlineStyle = { [key: string]: unknown };
11
- type StylesArray<T> = T | ReadonlyArray<StylesArray<T>>;
12
- type Styles = StylesArray<InlineStyle | false | void | null>;
13
- export declare function flattenStyle(...styles: Array<Styles>): {
14
- [key: string]: any;
15
- };
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.flattenStyle = flattenStyle;
7
- function flattenStyle() {
8
- for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
9
- styles[_key] = arguments[_key];
10
- }
11
- const flatArray = styles.flat(Infinity);
12
- const result = {};
13
- for (let i = 0; i < flatArray.length; i++) {
14
- const style = flatArray[i];
15
- if (style != null && typeof style === 'object') {
16
- Object.assign(result, style);
17
- }
18
- }
19
- return result;
20
- }
@@ -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
- * @flow
8
- */
9
-
10
- type InlineStyle = {
11
- [key: string]: mixed,
12
- };
13
-
14
- type StylesArray<+T> = T | $ReadOnlyArray<StylesArray<T>>;
15
-
16
- type Styles = StylesArray<InlineStyle | false | void | null>;
17
-
18
- declare export function flattenStyle(...styles: Array<Styles>): {
19
- [key: string]: any,
20
- };
@@ -1,18 +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
- type ParsedShadow = {
11
- inset: boolean;
12
- offsetX: number | string;
13
- offsetY: number | string;
14
- blurRadius: number | string;
15
- spreadRadius: number | string;
16
- color: string | null;
17
- };
18
- export declare function parseShadow(str: string): Array<ParsedShadow>;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseShadow = parseShadow;
7
- const VALUES_REG = /,(?![^(]*\))/;
8
- const PARTS_REG = /\s(?![^(]*\))/;
9
- const LENGTH_REG = /^[0-9]+[a-zA-Z%]+?$/;
10
- function isLength(v) {
11
- return v === '0' || LENGTH_REG.test(v);
12
- }
13
- function toMaybeNum(v) {
14
- if (!/px$/.test(v) && v !== '0') return v;
15
- const n = parseFloat(v);
16
- return !isNaN(n) ? n : v;
17
- }
18
- function parseValue(str) {
19
- const parts = str.split(PARTS_REG);
20
- const inset = parts.includes('inset');
21
- const last = parts.slice(-1)[0];
22
- const color = !isLength(last) ? last : null;
23
- const nums = parts.filter(n => n !== 'inset').filter(n => n !== color).map(toMaybeNum);
24
- const [offsetX, offsetY, blurRadius, spreadRadius] = nums;
25
- return {
26
- inset,
27
- offsetX,
28
- offsetY,
29
- blurRadius,
30
- spreadRadius,
31
- color
32
- };
33
- }
34
- function parseShadow(str) {
35
- return str.split(VALUES_REG).map(s => s.trim()).map(parseValue);
36
- }
@@ -1,19 +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
- type ParsedShadow = {
11
- inset: boolean,
12
- offsetX: number | string,
13
- offsetY: number | string,
14
- blurRadius: number | string,
15
- spreadRadius: number | string,
16
- color: string | null,
17
- };
18
-
19
- declare export function parseShadow(str: string): Array<ParsedShadow>;
@@ -1,11 +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
- type Milliseconds = number;
11
- export declare function parseTimeValue(timeValue: string): Milliseconds;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseTimeValue = parseTimeValue;
7
- function parseTimeValue(timeValue) {
8
- const trimmedTimeValue = timeValue.trim().toLowerCase();
9
- if (trimmedTimeValue.endsWith('ms')) {
10
- const msVal = parseFloat(trimmedTimeValue.replace(/ms$/, ''));
11
- return Number.isFinite(msVal) ? msVal : 0;
12
- }
13
- if (trimmedTimeValue.endsWith('s')) {
14
- const sVal = parseFloat(trimmedTimeValue.replace(/s$/, ''));
15
- return Number.isFinite(sVal) ? sVal * 1000 : 0;
16
- }
17
- return 0;
18
- }
@@ -1,12 +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
- type Milliseconds = number;
11
-
12
- declare export function parseTimeValue(timeValue: string): Milliseconds;
@@ -1,50 +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 SpreadOptions } from './SpreadOptions';
11
- import type { StyleX$CreateTheme, StyleX$DefineVars } from '../StyleXTypes';
12
- /**
13
- * The create method shim should do initial transforms like
14
- * renaming/expanding/validating properties, essentially all the steps
15
- * which can be done at initialization-time (could potentially be done at
16
- * compile-time in the future).
17
- */
18
- export declare function create<S extends { [$$Key$$: string]: {} }>(
19
- styles: S,
20
- ): { [$$Key$$: string]: {} };
21
- export declare const firstThatWorks: <T extends string | number>(
22
- ...values: ReadonlyArray<T>
23
- ) => T;
24
- type Keyframes = {
25
- readonly [key: string]: { readonly [k: string]: string | number };
26
- };
27
- export declare function keyframes(k: Keyframes): Keyframes;
28
- /**
29
- * The spread method shim
30
- */
31
-
32
- export declare function props(
33
- this: SpreadOptions,
34
- ...style: ReadonlyArray<null | undefined | { [key: string]: unknown }>
35
- ): { [$$Key$$: string]: {} };
36
- export declare const __customProperties: { [$$Key$$: string]: unknown };
37
- export declare const defineVars: StyleX$DefineVars;
38
- export declare const createTheme: any;
39
- export type IStyleX = Readonly<{
40
- create: typeof create;
41
- firstThatWorks: typeof firstThatWorks;
42
- keyframes: typeof keyframes;
43
- props: typeof props;
44
- defineVars: StyleX$DefineVars;
45
- createTheme: StyleX$CreateTheme;
46
- __customProperties?: { [$$Key$$: string]: unknown };
47
- }>;
48
- export declare const stylex: IStyleX;
49
- declare const $$EXPORT_DEFAULT_DECLARATION$$: IStyleX;
50
- export default $$EXPORT_DEFAULT_DECLARATION$$;