@stylexjs/shared 0.12.0 → 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.
- package/lib/index.d.ts +10 -36
- package/lib/index.js +8 -25
- package/lib/index.js.flow +10 -43
- package/lib/utils/property-priorities.d.ts +4 -0
- package/lib/utils/property-priorities.js +54 -8
- package/lib/utils/property-priorities.js.flow +8 -0
- package/package.json +5 -21
- package/README.md +0 -81
- package/lib/common-types.d.ts +0 -50
- package/lib/common-types.js +0 -1
- package/lib/common-types.js.flow +0 -63
- package/lib/convert-to-className.d.ts +0 -20
- package/lib/convert-to-className.js +0 -66
- package/lib/convert-to-className.js.flow +0 -27
- package/lib/generate-css-rule.d.ts +0 -17
- package/lib/generate-css-rule.js +0 -25
- package/lib/generate-css-rule.js.flow +0 -17
- package/lib/hash.d.ts +0 -12
- package/lib/hash.js +0 -50
- package/lib/hash.js.flow +0 -12
- package/lib/messages.d.ts +0 -42
- package/lib/messages.js +0 -39
- package/lib/messages.js.flow +0 -45
- package/lib/physical-rtl/generate-ltr.d.ts +0 -13
- package/lib/physical-rtl/generate-ltr.js +0 -103
- package/lib/physical-rtl/generate-ltr.js.flow +0 -12
- package/lib/physical-rtl/generate-rtl.d.ts +0 -13
- package/lib/physical-rtl/generate-rtl.js +0 -177
- package/lib/physical-rtl/generate-rtl.js.flow +0 -12
- package/lib/preprocess-rules/PreRule.d.ts +0 -50
- package/lib/preprocess-rules/PreRule.js +0 -76
- package/lib/preprocess-rules/PreRule.js.flow +0 -62
- package/lib/preprocess-rules/application-order.d.ts +0 -183
- package/lib/preprocess-rules/application-order.js +0 -186
- package/lib/preprocess-rules/application-order.js.flow +0 -134
- package/lib/preprocess-rules/basic-validation.d.ts +0 -13
- package/lib/preprocess-rules/basic-validation.js +0 -73
- package/lib/preprocess-rules/basic-validation.js.flow +0 -13
- package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +0 -20
- package/lib/preprocess-rules/flatten-raw-style-obj.js +0 -98
- package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +0 -23
- package/lib/preprocess-rules/index.d.ts +0 -18
- package/lib/preprocess-rules/index.js +0 -33
- package/lib/preprocess-rules/index.js.flow +0 -22
- package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +0 -165
- package/lib/preprocess-rules/legacy-expand-shorthands.js +0 -147
- package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +0 -144
- package/lib/preprocess-rules/property-specificity.d.ts +0 -78
- package/lib/preprocess-rules/property-specificity.js +0 -107
- package/lib/preprocess-rules/property-specificity.js.flow +0 -87
- package/lib/stylex-consts-utils.d.ts +0 -11
- package/lib/stylex-consts-utils.js +0 -1
- package/lib/stylex-consts-utils.js.flow +0 -14
- package/lib/stylex-create-theme.d.ts +0 -26
- package/lib/stylex-create-theme.js +0 -58
- package/lib/stylex-create-theme.js.flow +0 -19
- package/lib/stylex-create.d.ts +0 -27
- package/lib/stylex-create.js +0 -64
- package/lib/stylex-create.js.flow +0 -37
- package/lib/stylex-define-consts.d.ts +0 -23
- package/lib/stylex-define-consts.js +0 -42
- package/lib/stylex-define-consts.js.flow +0 -18
- package/lib/stylex-define-vars.d.ts +0 -28
- package/lib/stylex-define-vars.js +0 -96
- package/lib/stylex-define-vars.js.flow +0 -27
- package/lib/stylex-first-that-works.d.ts +0 -13
- package/lib/stylex-first-that-works.js +0 -26
- package/lib/stylex-first-that-works.js.flow +0 -12
- package/lib/stylex-include.d.ts +0 -18
- package/lib/stylex-include.js +0 -28
- package/lib/stylex-include.js.flow +0 -20
- package/lib/stylex-keyframes.d.ts +0 -17
- package/lib/stylex-keyframes.js +0 -55
- package/lib/stylex-keyframes.js.flow +0 -20
- package/lib/stylex-vars-utils.d.ts +0 -27
- package/lib/stylex-vars-utils.js +0 -69
- package/lib/stylex-vars-utils.js.flow +0 -31
- package/lib/transform-value.d.ts +0 -22
- package/lib/transform-value.js +0 -50
- package/lib/transform-value.js.flow +0 -25
- package/lib/types/index.d.ts +0 -240
- package/lib/types/index.js +0 -147
- package/lib/types/index.js.flow +0 -280
- package/lib/utils/Rule.d.ts +0 -58
- package/lib/utils/Rule.js +0 -50
- package/lib/utils/Rule.js.flow +0 -64
- package/lib/utils/dashify.d.ts +0 -11
- package/lib/utils/dashify.js +0 -9
- package/lib/utils/dashify.js.flow +0 -10
- package/lib/utils/default-options.d.ts +0 -11
- package/lib/utils/default-options.js +0 -17
- package/lib/utils/default-options.js.flow +0 -12
- package/lib/utils/file-based-identifier.d.ts +0 -15
- package/lib/utils/file-based-identifier.js +0 -14
- package/lib/utils/file-based-identifier.js.flow +0 -14
- package/lib/utils/genCSSRule.d.ts +0 -15
- package/lib/utils/genCSSRule.js +0 -15
- package/lib/utils/genCSSRule.js.flow +0 -15
- package/lib/utils/media-query-transform.d.ts +0 -16
- package/lib/utils/media-query-transform.js +0 -53
- package/lib/utils/media-query-transform.js.flow +0 -20
- package/lib/utils/normalize-value.d.ts +0 -16
- package/lib/utils/normalize-value.js +0 -28
- package/lib/utils/normalize-value.js.flow +0 -16
- package/lib/utils/normalizers/convert-camel-case-values.d.ts +0 -14
- package/lib/utils/normalizers/convert-camel-case-values.js +0 -23
- package/lib/utils/normalizers/convert-camel-case-values.js.flow +0 -13
- package/lib/utils/normalizers/detect-unclosed-fns.d.ts +0 -17
- package/lib/utils/normalizers/detect-unclosed-fns.js +0 -17
- package/lib/utils/normalizers/detect-unclosed-fns.js.flow +0 -16
- package/lib/utils/normalizers/font-size-px-to-rem.d.ts +0 -19
- package/lib/utils/normalizers/font-size-px-to-rem.js +0 -24
- package/lib/utils/normalizers/font-size-px-to-rem.js.flow +0 -18
- package/lib/utils/normalizers/leading-zero.d.ts +0 -17
- package/lib/utils/normalizers/leading-zero.js +0 -24
- package/lib/utils/normalizers/leading-zero.js.flow +0 -16
- package/lib/utils/normalizers/quotes.d.ts +0 -18
- package/lib/utils/normalizers/quotes.js +0 -17
- package/lib/utils/normalizers/quotes.js.flow +0 -17
- package/lib/utils/normalizers/timings.d.ts +0 -18
- package/lib/utils/normalizers/timings.js +0 -25
- package/lib/utils/normalizers/timings.js.flow +0 -17
- package/lib/utils/normalizers/whitespace.d.ts +0 -19
- package/lib/utils/normalizers/whitespace.js +0 -54
- package/lib/utils/normalizers/whitespace.js.flow +0 -18
- package/lib/utils/normalizers/zero-dimensions.d.ts +0 -19
- package/lib/utils/normalizers/zero-dimensions.js +0 -42
- package/lib/utils/normalizers/zero-dimensions.js.flow +0 -18
- package/lib/utils/object-utils.d.ts +0 -66
- package/lib/utils/object-utils.js +0 -99
- package/lib/utils/object-utils.js.flow +0 -78
- package/lib/utils/rule-utils.d.ts +0 -15
- package/lib/utils/rule-utils.js +0 -41
- package/lib/utils/rule-utils.js.flow +0 -16
- package/lib/utils/split-css-value.d.ts +0 -14
- package/lib/utils/split-css-value.js +0 -33
- package/lib/utils/split-css-value.js.flow +0 -15
- package/lib/validate.d.ts +0 -12
- package/lib/validate.js +0 -21
- package/lib/validate.js.flow +0 -12
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.applyLastMediaQueryWins = applyLastMediaQueryWins;
|
|
7
|
-
exports.transformMediaQueryStyles = transformMediaQueryStyles;
|
|
8
|
-
var _mediaQuery = require("@style-value-parser/src/at-queries-from-tokens/media-query");
|
|
9
|
-
function applyLastMediaQueryWins(mediaQuery) {
|
|
10
|
-
const queries = mediaQuery.queries.queries;
|
|
11
|
-
if (queries.length <= 1) {
|
|
12
|
-
return mediaQuery;
|
|
13
|
-
}
|
|
14
|
-
const transformedQueries = queries.slice(0, -1).map(query => new _mediaQuery.NotMediaRule(query instanceof _mediaQuery.MediaRule ? query.rules : query)).concat(queries.slice(-1));
|
|
15
|
-
const newOrSeparatedRules = new _mediaQuery.OrSeparatedMediaRules(transformedQueries);
|
|
16
|
-
return new _mediaQuery.MediaQuery(newOrSeparatedRules);
|
|
17
|
-
}
|
|
18
|
-
function transformMediaQueryStyles(styles) {
|
|
19
|
-
const transformedStyles = {};
|
|
20
|
-
for (const key in styles) {
|
|
21
|
-
if (typeof styles[key] === 'object' && styles[key] !== null) {
|
|
22
|
-
const mediaQueries = Object.keys(styles[key]).filter(k => k.startsWith('@media'));
|
|
23
|
-
const defaultValues = Object.keys(styles[key]).filter(k => !k.startsWith('@media'));
|
|
24
|
-
const transformedMediaQueries = {};
|
|
25
|
-
for (let i = 0; i < mediaQueries.length; i++) {
|
|
26
|
-
const currentQuery = mediaQueries[i];
|
|
27
|
-
const negations = mediaQueries.slice(i + 1).map(q => `not (${q.replace('@media ', '')})`).join(' and ');
|
|
28
|
-
const transformedQuery = negations ? `${currentQuery} and (${negations})` : currentQuery;
|
|
29
|
-
transformedMediaQueries[transformedQuery] = styles[key][currentQuery];
|
|
30
|
-
}
|
|
31
|
-
transformedStyles[key] = {
|
|
32
|
-
...defaultValues.reduce((acc, val) => {
|
|
33
|
-
acc[val] = styles[key][val];
|
|
34
|
-
return acc;
|
|
35
|
-
}, {}),
|
|
36
|
-
...transformedMediaQueries
|
|
37
|
-
};
|
|
38
|
-
} else {
|
|
39
|
-
transformedStyles[key] = styles[key];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return transformedStyles;
|
|
43
|
-
}
|
|
44
|
-
const originalStyles = {
|
|
45
|
-
gridColumn: {
|
|
46
|
-
default: '1 / 2',
|
|
47
|
-
'@media (max-width: 1440px)': '1 / 4',
|
|
48
|
-
'@media (max-width: 1024px)': '1 / 3',
|
|
49
|
-
'@media (max-width: 768px)': '1 / -1'
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const transformedStyles = transformMediaQueryStyles(originalStyles);
|
|
53
|
-
console.log(transformedStyles);
|
|
@@ -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 strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// Importing media query parser classes
|
|
11
|
-
import { MediaQuery } from '@style-value-parser/src/at-queries-from-tokens/media-query';
|
|
12
|
-
|
|
13
|
-
declare export function applyLastMediaQueryWins(
|
|
14
|
-
mediaQuery: MediaQuery,
|
|
15
|
-
): MediaQuery;
|
|
16
|
-
|
|
17
|
-
// Function to transform a style object so that the last media query always wins
|
|
18
|
-
declare export function transformMediaQueryStyles(
|
|
19
|
-
styles: Record<string, any>,
|
|
20
|
-
): Record<string, any>;
|
|
@@ -1,16 +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 { StyleXOptions } from '../common-types';
|
|
11
|
-
declare function normalizeValue(
|
|
12
|
-
value: string,
|
|
13
|
-
key: string,
|
|
14
|
-
$$PARAM_2$$: StyleXOptions,
|
|
15
|
-
): string;
|
|
16
|
-
export default normalizeValue;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeValue;
|
|
7
|
-
var _fontSizePxToRem = _interopRequireDefault(require("./normalizers/font-size-px-to-rem"));
|
|
8
|
-
var _leadingZero = _interopRequireDefault(require("./normalizers/leading-zero"));
|
|
9
|
-
var _quotes = _interopRequireDefault(require("./normalizers/quotes"));
|
|
10
|
-
var _timings = _interopRequireDefault(require("./normalizers/timings"));
|
|
11
|
-
var _whitespace = _interopRequireDefault(require("./normalizers/whitespace"));
|
|
12
|
-
var _zeroDimensions = _interopRequireDefault(require("./normalizers/zero-dimensions"));
|
|
13
|
-
var _detectUnclosedFns = _interopRequireDefault(require("./normalizers/detect-unclosed-fns"));
|
|
14
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
15
|
-
var _convertCamelCaseValues = _interopRequireDefault(require("./normalizers/convert-camel-case-values"));
|
|
16
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
const normalizers = [_detectUnclosedFns.default, _whitespace.default, _timings.default, _zeroDimensions.default, _leadingZero.default, _quotes.default, _convertCamelCaseValues.default];
|
|
18
|
-
function normalizeValue(value, key, _ref) {
|
|
19
|
-
let {
|
|
20
|
-
useRemForFontSize
|
|
21
|
-
} = _ref;
|
|
22
|
-
if (value == null) {
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
const parsedAST = (0, _postcssValueParser.default)(value);
|
|
26
|
-
const relevantNormalizers = useRemForFontSize ? [...normalizers, _fontSizePxToRem.default] : normalizers;
|
|
27
|
-
return relevantNormalizers.reduce((ast, fn) => fn(ast, key), parsedAST).toString();
|
|
28
|
-
}
|
|
@@ -1,16 +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 { StyleXOptions } from '../common-types';
|
|
11
|
-
|
|
12
|
-
declare export default function normalizeValue(
|
|
13
|
-
value: string,
|
|
14
|
-
key: string,
|
|
15
|
-
StyleXOptions,
|
|
16
|
-
): string;
|
|
@@ -1,14 +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
|
-
declare function convertCamelCasedValues(
|
|
11
|
-
ast: PostCSSValueAST,
|
|
12
|
-
key: string,
|
|
13
|
-
): PostCSSValueAST;
|
|
14
|
-
export default convertCamelCasedValues;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = convertCamelCasedValues;
|
|
7
|
-
var _dashify = _interopRequireDefault(require("../dashify"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
function convertCamelCasedValues(ast, key) {
|
|
10
|
-
if (key !== 'transitionProperty' && key !== 'willChange') {
|
|
11
|
-
return ast;
|
|
12
|
-
}
|
|
13
|
-
const nodes = ast.nodes;
|
|
14
|
-
if (!nodes) {
|
|
15
|
-
return ast;
|
|
16
|
-
}
|
|
17
|
-
nodes.forEach(node => {
|
|
18
|
-
if (node.type === 'word' && !node.value.startsWith('--')) {
|
|
19
|
-
node.value = (0, _dashify.default)(node.value);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return ast;
|
|
23
|
-
}
|
|
@@ -1,13 +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 default function convertCamelCasedValues(
|
|
11
|
-
ast: PostCSSValueAST,
|
|
12
|
-
key: string,
|
|
13
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
/**
|
|
11
|
-
* Remove leading zeros from numbers
|
|
12
|
-
*/
|
|
13
|
-
declare function detectUnclosedFns(
|
|
14
|
-
ast: PostCSSValueAST,
|
|
15
|
-
_: unknown,
|
|
16
|
-
): PostCSSValueAST;
|
|
17
|
-
export default detectUnclosedFns;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = detectUnclosedFns;
|
|
7
|
-
var messages = _interopRequireWildcard(require("../../messages"));
|
|
8
|
-
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); }
|
|
9
|
-
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; }
|
|
10
|
-
function detectUnclosedFns(ast, _) {
|
|
11
|
-
ast.walk(node => {
|
|
12
|
-
if (node.type === 'function' && node.unclosed) {
|
|
13
|
-
throw new Error(messages.LINT_UNCLOSED_FUNCTION);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return ast;
|
|
17
|
-
}
|
|
@@ -1,16 +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
|
-
/**
|
|
11
|
-
* Remove leading zeros from numbers
|
|
12
|
-
*/
|
|
13
|
-
declare export default function detectUnclosedFns(
|
|
14
|
-
ast: PostCSSValueAST,
|
|
15
|
-
_: mixed,
|
|
16
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Convert font sizes from absolute unit `px` to relative unit `rem`.
|
|
12
|
-
* This will allow developers to continue thinking and using what's familiar
|
|
13
|
-
* while we output font sizes that are adjustable
|
|
14
|
-
*/
|
|
15
|
-
declare function convertFontSizeToRem(
|
|
16
|
-
ast: PostCSSValueAST,
|
|
17
|
-
key: string,
|
|
18
|
-
): PostCSSValueAST;
|
|
19
|
-
export default convertFontSizeToRem;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = convertFontSizeToRem;
|
|
7
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const ROOT_FONT_SIZE = 16;
|
|
10
|
-
function convertFontSizeToRem(ast, key) {
|
|
11
|
-
if (key !== 'fontSize') {
|
|
12
|
-
return ast;
|
|
13
|
-
}
|
|
14
|
-
ast.walk(node => {
|
|
15
|
-
if (node.type !== 'word') {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const dimension = _postcssValueParser.default.unit(node.value);
|
|
19
|
-
if (dimension && dimension.unit === 'px') {
|
|
20
|
-
node.value = `${parseFloat(dimension.number) / ROOT_FONT_SIZE}rem`;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return ast;
|
|
24
|
-
}
|
|
@@ -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
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Convert font sizes from absolute unit `px` to relative unit `rem`.
|
|
12
|
-
* This will allow developers to continue thinking and using what's familiar
|
|
13
|
-
* while we output font sizes that are adjustable
|
|
14
|
-
*/
|
|
15
|
-
declare export default function convertFontSizeToRem(
|
|
16
|
-
ast: PostCSSValueAST,
|
|
17
|
-
key: string,
|
|
18
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
/**
|
|
11
|
-
* Remove leading zeros from numbers
|
|
12
|
-
*/
|
|
13
|
-
declare function normalizeLeadingZero(
|
|
14
|
-
ast: PostCSSValueAST,
|
|
15
|
-
_: unknown,
|
|
16
|
-
): PostCSSValueAST;
|
|
17
|
-
export default normalizeLeadingZero;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeLeadingZero;
|
|
7
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
function normalizeLeadingZero(ast, _) {
|
|
10
|
-
ast.walk(node => {
|
|
11
|
-
if (node.type !== 'word') {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const value = Number.parseFloat(node.value);
|
|
15
|
-
if (Number.isNaN(value)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const dimension = _postcssValueParser.default.unit(node.value);
|
|
19
|
-
if (value < 1 && value >= 0) {
|
|
20
|
-
node.value = value.toString().replace('0.', '.') + (dimension ? dimension.unit : '');
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return ast;
|
|
24
|
-
}
|
|
@@ -1,16 +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
|
-
/**
|
|
11
|
-
* Remove leading zeros from numbers
|
|
12
|
-
*/
|
|
13
|
-
declare export default function normalizeLeadingZero(
|
|
14
|
-
ast: PostCSSValueAST,
|
|
15
|
-
_: mixed,
|
|
16
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
/**
|
|
11
|
-
* Make empty strings use consistent double quotes
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
declare function normalizeQuotes(
|
|
15
|
-
ast: PostCSSValueAST,
|
|
16
|
-
_: unknown,
|
|
17
|
-
): PostCSSValueAST;
|
|
18
|
-
export default normalizeQuotes;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeQuotes;
|
|
7
|
-
function normalizeQuotes(ast, _) {
|
|
8
|
-
ast.walk(node => {
|
|
9
|
-
if (node.type !== 'string') {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (node.value === '') {
|
|
13
|
-
node.quote = '"';
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return ast;
|
|
17
|
-
}
|
|
@@ -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
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Make empty strings use consistent double quotes
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
declare export default function normalizeQuotes(
|
|
15
|
-
ast: PostCSSValueAST,
|
|
16
|
-
_: mixed,
|
|
17
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
/**
|
|
11
|
-
* Turn millisecond values to seconds (shorter), except when < 10ms
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
declare function normalizeTimings(
|
|
15
|
-
ast: PostCSSValueAST,
|
|
16
|
-
_: unknown,
|
|
17
|
-
): PostCSSValueAST;
|
|
18
|
-
export default normalizeTimings;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeTimings;
|
|
7
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
function normalizeTimings(ast, _) {
|
|
10
|
-
ast.walk(node => {
|
|
11
|
-
if (node.type !== 'word') {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const value = Number.parseFloat(node.value);
|
|
15
|
-
if (Number.isNaN(value)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const dimension = _postcssValueParser.default.unit(node.value);
|
|
19
|
-
if (!dimension || dimension.unit !== 'ms' || value < 10) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
node.value = value / 1000 + 's';
|
|
23
|
-
});
|
|
24
|
-
return ast;
|
|
25
|
-
}
|
|
@@ -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
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Turn millisecond values to seconds (shorter), except when < 10ms
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
declare export default function normalizeTimings(
|
|
15
|
-
ast: PostCSSValueAST,
|
|
16
|
-
_: mixed,
|
|
17
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Use single spaces and remove spaces when not needed: around functions,
|
|
12
|
-
* commas. But preserve space around + and - as they are required in calc()
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
declare function normalizeWhitespace(
|
|
16
|
-
ast: PostCSSValueAST,
|
|
17
|
-
_: unknown,
|
|
18
|
-
): PostCSSValueAST;
|
|
19
|
-
export default normalizeWhitespace;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeWhitespace;
|
|
7
|
-
function normalizeWhitespace(ast, _) {
|
|
8
|
-
if (ast.nodes[0].type === 'space') {
|
|
9
|
-
ast.nodes.shift();
|
|
10
|
-
}
|
|
11
|
-
if (ast.nodes[ast.nodes.length - 1].type === 'space') {
|
|
12
|
-
ast.nodes.pop();
|
|
13
|
-
}
|
|
14
|
-
ast.walk((node, idx) => {
|
|
15
|
-
switch (node.type) {
|
|
16
|
-
case 'space':
|
|
17
|
-
{
|
|
18
|
-
node.value = ' ';
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
case 'div':
|
|
22
|
-
{
|
|
23
|
-
if (node.value === ',') {
|
|
24
|
-
node.before = '';
|
|
25
|
-
node.after = '';
|
|
26
|
-
} else {
|
|
27
|
-
node.before = ' ';
|
|
28
|
-
node.after = ' ';
|
|
29
|
-
}
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
case 'function':
|
|
33
|
-
{
|
|
34
|
-
node.before = '';
|
|
35
|
-
node.after = '';
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'word':
|
|
39
|
-
{
|
|
40
|
-
if (node.value === '!important') {
|
|
41
|
-
if (ast.nodes[idx - 1] && ast.nodes[idx - 1].type === 'space') {
|
|
42
|
-
ast.nodes.splice(idx - 1, 1);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
default:
|
|
48
|
-
{
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
return ast;
|
|
54
|
-
}
|
|
@@ -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
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Use single spaces and remove spaces when not needed: around functions,
|
|
12
|
-
* commas. But preserve space around + and - as they are required in calc()
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
declare export default function normalizeWhitespace(
|
|
16
|
-
ast: PostCSSValueAST,
|
|
17
|
-
_: mixed,
|
|
18
|
-
): PostCSSValueAST;
|
|
@@ -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
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Remove units in zero values, except when required: in angles, timings, fractions, and percentages,
|
|
12
|
-
* in which case make them consistent 0deg, 0s, 0fr, and 0%.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
declare function normalizeZeroDimensions(
|
|
16
|
-
ast: PostCSSValueAST,
|
|
17
|
-
_: unknown,
|
|
18
|
-
): PostCSSValueAST;
|
|
19
|
-
export default normalizeZeroDimensions;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeZeroDimensions;
|
|
7
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const angles = ['deg', 'grad', 'turn', 'rad'];
|
|
10
|
-
const timings = ['ms', 's'];
|
|
11
|
-
const fraction = 'fr';
|
|
12
|
-
const percentage = '%';
|
|
13
|
-
function normalizeZeroDimensions(ast, _) {
|
|
14
|
-
let endFunction = 0;
|
|
15
|
-
ast.walk(node => {
|
|
16
|
-
if (node.type === 'function' && !endFunction) {
|
|
17
|
-
endFunction = node.sourceEndIndex ?? 0;
|
|
18
|
-
}
|
|
19
|
-
if (endFunction > 0 && node.sourceIndex > endFunction) {
|
|
20
|
-
endFunction = 0;
|
|
21
|
-
}
|
|
22
|
-
if (node.type !== 'word') {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const dimension = _postcssValueParser.default.unit(node.value);
|
|
26
|
-
if (!dimension || dimension.number !== '0') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (angles.indexOf(dimension.unit) !== -1) {
|
|
30
|
-
node.value = '0deg';
|
|
31
|
-
} else if (timings.indexOf(dimension.unit) !== -1) {
|
|
32
|
-
node.value = '0s';
|
|
33
|
-
} else if (dimension.unit === fraction) {
|
|
34
|
-
node.value = '0fr';
|
|
35
|
-
} else if (dimension.unit === percentage) {
|
|
36
|
-
node.value = '0%';
|
|
37
|
-
} else if (!endFunction) {
|
|
38
|
-
node.value = '0';
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return ast;
|
|
42
|
-
}
|
|
@@ -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
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Remove units in zero values, except when required: in angles, timings, fractions, and percentages,
|
|
12
|
-
* in which case make them consistent 0deg, 0s, 0fr, and 0%.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
declare export default function normalizeZeroDimensions(
|
|
16
|
-
ast: PostCSSValueAST,
|
|
17
|
-
_: mixed,
|
|
18
|
-
): PostCSSValueAST;
|