@stylexjs/stylex 0.2.0-beta.19 → 0.2.0-beta.21

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.
@@ -7,16 +7,12 @@
7
7
  *
8
8
  */
9
9
 
10
+ import type { SpreadOptions } from './SpreadOptions';
10
11
  type CSSLengthUnitType = 'em' | 'px' | 'rem' | 'vh' | 'vmax' | 'vmin' | 'vw';
11
12
  export declare class CSSLengthUnitValue {
12
- static parse(inp: string): CSSLengthUnitValue | null;
13
+ static parse(inp: string): [number, CSSLengthUnitType] | null;
13
14
  value: number;
14
15
  unit: CSSLengthUnitType;
15
16
  constructor(value: number, unit: CSSLengthUnitType);
16
- resolvePixelValue(
17
- viewportWidth: number,
18
- viewportHeight: number,
19
- fontScale: number,
20
- inheritedFontSize: null | undefined | number,
21
- ): number;
17
+ resolvePixelValue(options: SpreadOptions): number;
22
18
  }
@@ -13,13 +13,19 @@ class CSSLengthUnitValue {
13
13
  }
14
14
  const [, value, unit] = match;
15
15
  const parsedValue = parseFloat(value);
16
- return new CSSLengthUnitValue(parsedValue, unit);
16
+ return [parsedValue, unit];
17
17
  }
18
18
  constructor(value, unit) {
19
19
  this.value = value;
20
20
  this.unit = unit;
21
21
  }
22
- resolvePixelValue(viewportWidth, viewportHeight, fontScale, inheritedFontSize) {
22
+ resolvePixelValue(options) {
23
+ const {
24
+ viewportWidth,
25
+ viewportHeight,
26
+ fontScale = 1,
27
+ inheritedFontSize
28
+ } = options;
23
29
  const unit = this.unit;
24
30
  const value = this.value;
25
31
  const valuePercent = value / 100;
@@ -7,18 +7,15 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
+ import type { SpreadOptions } from './SpreadOptions';
11
+
10
12
  type CSSLengthUnitType = 'em' | 'px' | 'rem' | 'vh' | 'vmax' | 'vmin' | 'vw';
11
13
 
12
14
  // TODO: this only works on simple values
13
15
  declare export class CSSLengthUnitValue {
14
- static parse(inp: string): CSSLengthUnitValue | null;
16
+ static parse(inp: string): [number, CSSLengthUnitType] | null;
15
17
  value: number;
16
18
  unit: CSSLengthUnitType;
17
19
  constructor(value: number, unit: CSSLengthUnitType): void;
18
- resolvePixelValue(
19
- viewportWidth: number,
20
- viewportHeight: number,
21
- fontScale: number,
22
- inheritedFontSize: ?number,
23
- ): number;
20
+ resolvePixelValue(options: SpreadOptions): number;
24
21
  }
@@ -0,0 +1,18 @@
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 SpreadOptions = {
11
+ customProperties: {};
12
+ inheritedFontSize: null | undefined | number;
13
+ fontScale: number | void;
14
+ passthroughProperties: Array<string>;
15
+ viewportHeight: number;
16
+ viewportWidth: number;
17
+ writingDirection: 'ltr' | 'rtl';
18
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,18 @@
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 SpreadOptions = {|
11
+ customProperties: {},
12
+ inheritedFontSize: ?number,
13
+ fontScale: number | void,
14
+ passthroughProperties: Array<string>,
15
+ viewportHeight: number,
16
+ viewportWidth: number,
17
+ writingDirection: 'ltr' | 'rtl',
18
+ |};
@@ -0,0 +1,48 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`stylex CSSCustomProperty value test falls back to a default value with spaces 1`] = `
4
+ {
5
+ "style": {
6
+ "shadowColor": "0px 0px 0px black",
7
+ "shadowOffset": {
8
+ "height": undefined,
9
+ "width": undefined,
10
+ },
11
+ "shadowOpacity": 1,
12
+ },
13
+ }
14
+ `;
15
+
16
+ exports[`stylex CSSCustomProperty value test parses a variable with a default value with spaces 1`] = `
17
+ {
18
+ "style": {
19
+ "shadowColor": "5px 5px 5px black",
20
+ "shadowOffset": {
21
+ "height": undefined,
22
+ "width": undefined,
23
+ },
24
+ "shadowOpacity": 1,
25
+ },
26
+ }
27
+ `;
28
+
29
+ exports[`stylex CSSCustomProperty value test parses and falls back to a default value containing spaces and embedded variables 1`] = `
30
+ {
31
+ "style": {
32
+ "shadowColor": "var(--boxShadowVarNotFound",
33
+ "shadowOffset": {
34
+ "height": undefined,
35
+ "width": undefined,
36
+ },
37
+ "shadowOpacity": 1,
38
+ },
39
+ }
40
+ `;
41
+
42
+ exports[`stylex CSSCustomProperty value test parses and falls back to default value containing a variable 1`] = `
43
+ {
44
+ "style": {
45
+ "color": "blue",
46
+ },
47
+ }
48
+ `;