postcss-convert-values 9.0.5 → 9.0.7
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/package.json +3 -3
- package/src/lib/convert.js +193 -22
- package/src/lib/findReplacements.js +42 -13
- package/src/lib/transform.js +94 -26
- package/types/lib/convert.d.ts +18 -2
- package/types/lib/convert.d.ts.map +1 -1
- package/types/lib/findReplacements.d.ts.map +1 -1
- package/types/lib/transform.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-convert-values",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.7",
|
|
4
4
|
"description": "Convert values with PostCSS (e.g. ms -> s)",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"url": "git+https://github.com/cssnano/cssnano.git"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"browserslist": "^4.29.
|
|
44
|
-
"cssnano-utils": "^8.0.
|
|
43
|
+
"browserslist": "^4.29.3",
|
|
44
|
+
"cssnano-utils": "^8.0.2"
|
|
45
45
|
},
|
|
46
46
|
"bugs": {
|
|
47
47
|
"url": "https://github.com/cssnano/cssnano/issues"
|
package/src/lib/convert.js
CHANGED
|
@@ -53,6 +53,49 @@ export function roundToPrecision(value, precision) {
|
|
|
53
53
|
return Number(rounded + 'e-' + p);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Compute the shortest exact scientific notation for a number if one exists.
|
|
58
|
+
*
|
|
59
|
+
* @param {number} num
|
|
60
|
+
* @return {string | undefined}
|
|
61
|
+
*/
|
|
62
|
+
export function toCompactExponent(num) {
|
|
63
|
+
if (num === 0 || !Number.isFinite(num)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const abs = Math.abs(num);
|
|
67
|
+
if (Number.isInteger(num) && abs > Number.MAX_SAFE_INTEGER) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const sign = num < 0 ? '-' : '';
|
|
72
|
+
const expStr = abs.toExponential();
|
|
73
|
+
const eIndex = expStr.indexOf('e');
|
|
74
|
+
const mantissaStr = expStr.slice(0, eIndex);
|
|
75
|
+
const baseExp = Number(expStr.slice(eIndex + 1));
|
|
76
|
+
const dotIndex = mantissaStr.indexOf('.');
|
|
77
|
+
|
|
78
|
+
if (dotIndex === -1) {
|
|
79
|
+
const candidate = sign + mantissaStr + 'e' + baseExp;
|
|
80
|
+
return Number(candidate) === num ? candidate : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const digits =
|
|
84
|
+
mantissaStr.slice(0, dotIndex) + mantissaStr.slice(dotIndex + 1);
|
|
85
|
+
const decPlaces = mantissaStr.length - dotIndex - 1;
|
|
86
|
+
const candidate1 = sign + digits + 'e' + (baseExp - decPlaces);
|
|
87
|
+
if (Number(candidate1) === num) {
|
|
88
|
+
return candidate1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const candidate2 = sign + mantissaStr + 'e' + baseExp;
|
|
92
|
+
if (Number(candidate2) === num) {
|
|
93
|
+
return candidate2;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
56
99
|
/**
|
|
57
100
|
* @param {number} number
|
|
58
101
|
* @return {string}
|
|
@@ -73,13 +116,45 @@ export function dropLeadingZero(number) {
|
|
|
73
116
|
return value;
|
|
74
117
|
}
|
|
75
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Format a number using standard decimal or compact exponent notation.
|
|
121
|
+
*
|
|
122
|
+
* @param {number} number
|
|
123
|
+
* @param {boolean} [allowExponent=true]
|
|
124
|
+
* @return {string}
|
|
125
|
+
*/
|
|
126
|
+
export function formatNumber(number, allowExponent = true) {
|
|
127
|
+
const decimal = dropLeadingZero(number);
|
|
128
|
+
if (!allowExponent) {
|
|
129
|
+
return decimal;
|
|
130
|
+
}
|
|
131
|
+
const abs = Math.abs(number);
|
|
132
|
+
if (abs >= 0.001 && abs < 1000) {
|
|
133
|
+
return decimal;
|
|
134
|
+
}
|
|
135
|
+
if (Number.isInteger(number) && number % 1000 !== 0) {
|
|
136
|
+
return decimal;
|
|
137
|
+
}
|
|
138
|
+
const exp = toCompactExponent(number);
|
|
139
|
+
if (exp && exp.length < decimal.length) {
|
|
140
|
+
return exp;
|
|
141
|
+
}
|
|
142
|
+
return decimal;
|
|
143
|
+
}
|
|
144
|
+
|
|
76
145
|
/**
|
|
77
146
|
* @param {number} number
|
|
78
147
|
* @param {string} originalUnit
|
|
79
148
|
* @param {typeof lengthConv | typeof timeConv | typeof angleConv | typeof freqConv | typeof metricConv} conversions
|
|
149
|
+
* @param {boolean} [allowExponent=true]
|
|
80
150
|
* @return {string}
|
|
81
151
|
*/
|
|
82
|
-
function findShortestConversion(
|
|
152
|
+
function findShortestConversion(
|
|
153
|
+
number,
|
|
154
|
+
originalUnit,
|
|
155
|
+
conversions,
|
|
156
|
+
allowExponent = true
|
|
157
|
+
) {
|
|
83
158
|
const base = number * /** @type {number} */ (conversions.get(originalUnit));
|
|
84
159
|
|
|
85
160
|
let shortest = '';
|
|
@@ -88,7 +163,7 @@ function findShortestConversion(number, originalUnit, conversions) {
|
|
|
88
163
|
continue;
|
|
89
164
|
}
|
|
90
165
|
const convertedNumber = Number((base / factor).toPrecision(15));
|
|
91
|
-
const value =
|
|
166
|
+
const value = formatNumber(convertedNumber, allowExponent) + u;
|
|
92
167
|
|
|
93
168
|
if (!shortest || value.length < shortest.length) {
|
|
94
169
|
shortest = value;
|
|
@@ -114,38 +189,134 @@ function convertAngle(number, unit) {
|
|
|
114
189
|
}
|
|
115
190
|
|
|
116
191
|
/**
|
|
117
|
-
* @param {number} number
|
|
118
192
|
* @param {string} unit
|
|
119
193
|
* @param {ConvertOptions} options
|
|
120
|
-
* @return {
|
|
194
|
+
* @return {boolean}
|
|
121
195
|
*/
|
|
122
|
-
|
|
196
|
+
function isConversionDisabled(unit, options) {
|
|
123
197
|
const { time, length, angle, frequency } = options;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (length !== false && lengthConv.has(lowerCaseUnit)) {
|
|
127
|
-
converted = findShortestConversion(number, lowerCaseUnit, lengthConv);
|
|
128
|
-
} else if (length !== false && metricConv.has(lowerCaseUnit)) {
|
|
129
|
-
converted = findShortestConversion(number, lowerCaseUnit, metricConv);
|
|
130
|
-
} else if (time !== false && timeConv.has(lowerCaseUnit)) {
|
|
131
|
-
converted = findShortestConversion(number, lowerCaseUnit, timeConv);
|
|
198
|
+
if (length === false && (lengthConv.has(unit) || metricConv.has(unit))) {
|
|
199
|
+
return true;
|
|
132
200
|
}
|
|
201
|
+
if (time === false && timeConv.has(unit)) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
if (angle === false && (angleConv.has(unit) || unit === 'rad')) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
if (frequency === false && freqConv.has(unit)) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
133
212
|
|
|
134
|
-
|
|
135
|
-
|
|
213
|
+
/**
|
|
214
|
+
* @param {number} number
|
|
215
|
+
* @param {string} lowerCaseUnit
|
|
216
|
+
* @param {ConvertOptions} options
|
|
217
|
+
* @param {boolean} allowExponent
|
|
218
|
+
* @return {string | undefined}
|
|
219
|
+
*/
|
|
220
|
+
function findConverted(number, lowerCaseUnit, options, allowExponent) {
|
|
221
|
+
const { time, length, angle, frequency } = options;
|
|
222
|
+
if (length !== false) {
|
|
223
|
+
if (lengthConv.has(lowerCaseUnit)) {
|
|
224
|
+
return findShortestConversion(
|
|
225
|
+
number,
|
|
226
|
+
lowerCaseUnit,
|
|
227
|
+
lengthConv,
|
|
228
|
+
allowExponent
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
if (metricConv.has(lowerCaseUnit)) {
|
|
232
|
+
return findShortestConversion(
|
|
233
|
+
number,
|
|
234
|
+
lowerCaseUnit,
|
|
235
|
+
metricConv,
|
|
236
|
+
allowExponent
|
|
237
|
+
);
|
|
238
|
+
}
|
|
136
239
|
}
|
|
137
|
-
if (
|
|
138
|
-
|
|
240
|
+
if (time !== false && timeConv.has(lowerCaseUnit)) {
|
|
241
|
+
return findShortestConversion(
|
|
242
|
+
number,
|
|
243
|
+
lowerCaseUnit,
|
|
244
|
+
timeConv,
|
|
245
|
+
allowExponent
|
|
246
|
+
);
|
|
139
247
|
}
|
|
248
|
+
if (angle !== false) {
|
|
249
|
+
const convertedAngle = convertAngle(number, lowerCaseUnit);
|
|
250
|
+
if (convertedAngle) {
|
|
251
|
+
return convertedAngle;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (frequency !== false && freqConv.has(lowerCaseUnit)) {
|
|
255
|
+
return findShortestConversion(
|
|
256
|
+
number,
|
|
257
|
+
lowerCaseUnit,
|
|
258
|
+
freqConv,
|
|
259
|
+
allowExponent
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
140
264
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
265
|
+
/**
|
|
266
|
+
* @param {string} converted
|
|
267
|
+
* @param {string} value
|
|
268
|
+
* @param {string} decimalValue
|
|
269
|
+
* @param {string} lowerCaseUnit
|
|
270
|
+
* @return {boolean}
|
|
271
|
+
*/
|
|
272
|
+
function shouldUseConverted(converted, value, decimalValue, lowerCaseUnit) {
|
|
273
|
+
if (converted.length < value.length) {
|
|
274
|
+
return true;
|
|
144
275
|
}
|
|
276
|
+
if (lowerCaseUnit === 'rad' && converted.length <= value.length) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
return (
|
|
280
|
+
converted.length === value.length &&
|
|
281
|
+
!converted.includes('e') &&
|
|
282
|
+
value.includes('e') &&
|
|
283
|
+
converted.length < decimalValue.length
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @param {number} number
|
|
289
|
+
* @param {string} unit
|
|
290
|
+
* @param {ConvertOptions} [options]
|
|
291
|
+
* @param {boolean} [allowExponent=true] false where only an `<integer>` is valid
|
|
292
|
+
* @return {string}
|
|
293
|
+
*/
|
|
294
|
+
const convert = function (number, unit, options = {}, allowExponent = true) {
|
|
295
|
+
const lowerCaseUnit = unit.toLowerCase();
|
|
296
|
+
if (isConversionDisabled(lowerCaseUnit, options)) {
|
|
297
|
+
// Disabling unit conversion must not disable number formatting of
|
|
298
|
+
// <length> dimensions such as 1e-6px.
|
|
299
|
+
const isLength =
|
|
300
|
+
lengthConv.has(lowerCaseUnit) || metricConv.has(lowerCaseUnit);
|
|
301
|
+
return (
|
|
302
|
+
(isLength
|
|
303
|
+
? formatNumber(number, allowExponent)
|
|
304
|
+
: dropLeadingZero(number)) + (unit ? unit : '')
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const converted = findConverted(
|
|
309
|
+
number,
|
|
310
|
+
lowerCaseUnit,
|
|
311
|
+
options,
|
|
312
|
+
allowExponent
|
|
313
|
+
);
|
|
314
|
+
const decimalValue = dropLeadingZero(number) + (unit ? unit : '');
|
|
315
|
+
const value = formatNumber(number, allowExponent) + (unit ? unit : '');
|
|
145
316
|
|
|
146
317
|
if (
|
|
147
|
-
converted
|
|
148
|
-
(
|
|
318
|
+
converted &&
|
|
319
|
+
shouldUseConverted(converted, value, decimalValue, lowerCaseUnit)
|
|
149
320
|
) {
|
|
150
321
|
return converted;
|
|
151
322
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cssnanoUtils from 'cssnano-utils';
|
|
2
2
|
import convert, {
|
|
3
|
-
|
|
3
|
+
formatNumber,
|
|
4
4
|
roundToPrecision,
|
|
5
5
|
timeConv,
|
|
6
6
|
angleConv,
|
|
@@ -59,6 +59,33 @@ const convertibleUnits = new Set([
|
|
|
59
59
|
/** @typedef {{precision?: false | number, transformCustomProperties?: boolean} & ConvertOptions & { overrideBrowserslist?: string | string[] } & import('browserslist').Options} Options */
|
|
60
60
|
/** @typedef {{keepZeroPercent: boolean, keepZeroLength: boolean, clampAlpha: boolean, isAlpha: boolean, isFont: boolean}} ReplacementFlags */
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @param {string} unit
|
|
64
|
+
* @param {string} lowerCasedUnit
|
|
65
|
+
* @param {Options} opts
|
|
66
|
+
* @param {boolean} keepZeroPercent
|
|
67
|
+
* @param {boolean} keepZeroLength
|
|
68
|
+
* @return {string}
|
|
69
|
+
*/
|
|
70
|
+
function formatZero(
|
|
71
|
+
unit,
|
|
72
|
+
lowerCasedUnit,
|
|
73
|
+
opts,
|
|
74
|
+
keepZeroPercent,
|
|
75
|
+
keepZeroLength
|
|
76
|
+
) {
|
|
77
|
+
if (convertibleUnits.has(lowerCasedUnit)) {
|
|
78
|
+
return convert(0, unit, opts);
|
|
79
|
+
}
|
|
80
|
+
if (unit === '%') {
|
|
81
|
+
return keepZeroPercent ? '0%' : '0';
|
|
82
|
+
}
|
|
83
|
+
if (lengthUnits.has(lowerCasedUnit)) {
|
|
84
|
+
return keepZeroLength ? '0' + unit : '0';
|
|
85
|
+
}
|
|
86
|
+
return '0';
|
|
87
|
+
}
|
|
88
|
+
|
|
62
89
|
/** @param {number} number @param {string} unit @param {string} raw @param {Options} opts @param {boolean} keepZeroPercent @param {boolean} keepZeroLength @param {boolean} hasDecimal @return {string} */
|
|
63
90
|
function parseNumber(
|
|
64
91
|
number,
|
|
@@ -87,18 +114,20 @@ function parseNumber(
|
|
|
87
114
|
num = roundToPrecision(num, opts.precision);
|
|
88
115
|
}
|
|
89
116
|
if (num === 0) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return keepZeroLength ? '0' + unit : '0';
|
|
98
|
-
}
|
|
99
|
-
return '0';
|
|
117
|
+
return formatZero(
|
|
118
|
+
unit,
|
|
119
|
+
lowerCasedUnit,
|
|
120
|
+
opts,
|
|
121
|
+
keepZeroPercent,
|
|
122
|
+
keepZeroLength
|
|
123
|
+
);
|
|
100
124
|
}
|
|
101
|
-
|
|
125
|
+
// An exponent is never a valid <integer>, so a bare number written as an
|
|
126
|
+
// integer may sit where only <integer> is allowed. Dimensions and numbers
|
|
127
|
+
// already written as non-integers cannot.
|
|
128
|
+
const writtenAsInteger =
|
|
129
|
+
unit === '' && !raw.includes('.') && !raw.toLowerCase().includes('e');
|
|
130
|
+
return convert(num, unit, opts, !writtenAsInteger);
|
|
102
131
|
}
|
|
103
132
|
|
|
104
133
|
/** @param {string} value @param {number} number @param {string} unit @param {Options} opts @param {boolean} [clamp] @return {string} */
|
|
@@ -112,7 +141,7 @@ function clampOpacity(value, number, unit, opts, clamp = true) {
|
|
|
112
141
|
if (typeof opts.precision === 'number' && opts.precision >= 0) {
|
|
113
142
|
decimalNumber = roundToPrecision(decimalNumber, opts.precision);
|
|
114
143
|
}
|
|
115
|
-
const decimal =
|
|
144
|
+
const decimal = formatNumber(decimalNumber);
|
|
116
145
|
return decimal.length < value.length ? decimal : value;
|
|
117
146
|
}
|
|
118
147
|
if (clamp) {
|
package/src/lib/transform.js
CHANGED
|
@@ -92,6 +92,78 @@ function skipsTransformation(property, opts) {
|
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/** @param {boolean | string[]} supportsIE @return {boolean} */
|
|
96
|
+
function hasIESupportTarget(supportsIE) {
|
|
97
|
+
if (typeof supportsIE === 'boolean') {
|
|
98
|
+
return supportsIE;
|
|
99
|
+
}
|
|
100
|
+
return supportsIE.some((b) => b.startsWith('ie '));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** @param {import('postcss').Declaration} decl @param {string} lowerCasedProp @return {boolean} */
|
|
104
|
+
function isAtPropertyInitialValue(decl, lowerCasedProp) {
|
|
105
|
+
if (lowerCasedProp !== 'initial-value') return false;
|
|
106
|
+
const parent = decl.parent;
|
|
107
|
+
return (
|
|
108
|
+
parent?.type === 'atrule' &&
|
|
109
|
+
/** @type {import('postcss').AtRule} */ (parent).name.toLowerCase() ===
|
|
110
|
+
'property'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {string} strippedProp
|
|
116
|
+
* @param {boolean} isLineHeight
|
|
117
|
+
* @param {boolean} isFlexBasis
|
|
118
|
+
* @param {boolean} hasIESupport
|
|
119
|
+
* @param {boolean} inKeyframes
|
|
120
|
+
* @param {boolean} isKeyframeProp
|
|
121
|
+
* @param {boolean} allowsAtPropertyPercentage
|
|
122
|
+
* @return {boolean}
|
|
123
|
+
*/
|
|
124
|
+
function shouldKeepZeroPercent(
|
|
125
|
+
strippedProp,
|
|
126
|
+
isLineHeight,
|
|
127
|
+
isFlexBasis,
|
|
128
|
+
hasIESupport,
|
|
129
|
+
inKeyframes,
|
|
130
|
+
isKeyframeProp,
|
|
131
|
+
allowsAtPropertyPercentage
|
|
132
|
+
) {
|
|
133
|
+
if (isLineHeight || isFlexBasis || zeroPercentRetention.has(strippedProp)) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (hasIESupport && zeroUnitRetention.ie11Percent.has(strippedProp)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if (inKeyframes && isKeyframeProp) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return allowsAtPropertyPercentage;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {string} strippedProp
|
|
147
|
+
* @param {boolean} isLineHeight
|
|
148
|
+
* @param {boolean} isFlexBasis
|
|
149
|
+
* @param {boolean} isAtProperty
|
|
150
|
+
* @return {boolean}
|
|
151
|
+
*/
|
|
152
|
+
function shouldKeepZeroLength(
|
|
153
|
+
strippedProp,
|
|
154
|
+
isLineHeight,
|
|
155
|
+
isFlexBasis,
|
|
156
|
+
isAtProperty
|
|
157
|
+
) {
|
|
158
|
+
return (
|
|
159
|
+
isLineHeight ||
|
|
160
|
+
isFlexBasis ||
|
|
161
|
+
strippedProp === 'columns' ||
|
|
162
|
+
strippedProp === 'flex-order' ||
|
|
163
|
+
isAtProperty
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
95
167
|
/**
|
|
96
168
|
* @param {import('postcss').Declaration} decl
|
|
97
169
|
* @param {string} lowerCasedProp
|
|
@@ -102,38 +174,34 @@ function skipsTransformation(property, opts) {
|
|
|
102
174
|
function getDeclarationFlags(decl, lowerCasedProp, strippedProp, supportsIE) {
|
|
103
175
|
const isLineHeight = strippedProp === 'line-height';
|
|
104
176
|
const isFlexBasis = flexBasisProperties.has(strippedProp);
|
|
105
|
-
const isAtProperty =
|
|
106
|
-
lowerCasedProp === 'initial-value' &&
|
|
107
|
-
decl.parent?.type === 'atrule' &&
|
|
108
|
-
/** @type {import('postcss').AtRule} */ (decl.parent).name.toLowerCase() ===
|
|
109
|
-
'property';
|
|
177
|
+
const isAtProperty = isAtPropertyInitialValue(decl, lowerCasedProp);
|
|
110
178
|
const isAlpha = alphaProperties.has(strippedProp);
|
|
111
179
|
const isKeyframeProp = zeroUnitRetention.keyframePercent.has(strippedProp);
|
|
112
180
|
const inKeyframes = (isKeyframeProp || isAlpha) && isInsideKeyframes(decl);
|
|
113
181
|
const hasParentContext = lowerCasedProp === 'initial-value' || inKeyframes;
|
|
114
182
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
183
|
+
const allowsAtPropertyPercentage =
|
|
184
|
+
isAtProperty &&
|
|
185
|
+
atPropertyAllowsPercentage(
|
|
186
|
+
/** @type {import('postcss').AtRule} */ (decl.parent)
|
|
187
|
+
);
|
|
119
188
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
isLineHeight
|
|
133
|
-
isFlexBasis
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
isAtProperty;
|
|
189
|
+
const hasIESupport = hasIESupportTarget(supportsIE);
|
|
190
|
+
const keepZeroPercent = shouldKeepZeroPercent(
|
|
191
|
+
strippedProp,
|
|
192
|
+
isLineHeight,
|
|
193
|
+
isFlexBasis,
|
|
194
|
+
hasIESupport,
|
|
195
|
+
inKeyframes,
|
|
196
|
+
isKeyframeProp,
|
|
197
|
+
allowsAtPropertyPercentage
|
|
198
|
+
);
|
|
199
|
+
const keepZeroLength = shouldKeepZeroLength(
|
|
200
|
+
strippedProp,
|
|
201
|
+
isLineHeight,
|
|
202
|
+
isFlexBasis,
|
|
203
|
+
isAtProperty
|
|
204
|
+
);
|
|
137
205
|
|
|
138
206
|
const clampAlpha = !inKeyframes;
|
|
139
207
|
const isFont = strippedProp === 'font';
|
package/types/lib/convert.d.ts
CHANGED
|
@@ -17,17 +17,33 @@ export type ConvertOptions = {
|
|
|
17
17
|
* @return {number}
|
|
18
18
|
*/
|
|
19
19
|
export declare function roundToPrecision(value: number, precision: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Compute the shortest exact scientific notation for a number if one exists.
|
|
22
|
+
*
|
|
23
|
+
* @param {number} num
|
|
24
|
+
* @return {string | undefined}
|
|
25
|
+
*/
|
|
26
|
+
export declare function toCompactExponent(num: number): string | undefined;
|
|
20
27
|
/**
|
|
21
28
|
* @param {number} number
|
|
22
29
|
* @return {string}
|
|
23
30
|
*/
|
|
24
31
|
export declare function dropLeadingZero(number: number): string;
|
|
32
|
+
/**
|
|
33
|
+
* Format a number using standard decimal or compact exponent notation.
|
|
34
|
+
*
|
|
35
|
+
* @param {number} number
|
|
36
|
+
* @param {boolean} [allowExponent=true]
|
|
37
|
+
* @return {string}
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatNumber(number: number, allowExponent?: boolean): string;
|
|
25
40
|
/**
|
|
26
41
|
* @param {number} number
|
|
27
42
|
* @param {string} unit
|
|
28
|
-
* @param {ConvertOptions} options
|
|
43
|
+
* @param {ConvertOptions} [options]
|
|
44
|
+
* @param {boolean} [allowExponent=true] false where only an `<integer>` is valid
|
|
29
45
|
* @return {string}
|
|
30
46
|
*/
|
|
31
|
-
declare const convert: (number: number, unit: string, options
|
|
47
|
+
declare const convert: (number: number, unit: string, options?: ConvertOptions, allowExponent?: boolean) => string;
|
|
32
48
|
export default convert;
|
|
33
49
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/lib/convert.js"],"names":[],"mappings":"AAaA,eAAO,MAAM,QAAQ,qBAGnB,CAAC;AAEH,eAAO,MAAM,SAAS,qBAIpB,CAAC;AAEH,eAAO,MAAM,QAAQ,qBAGnB,CAAC;AAEC,YAAoF,cAAc,GAAxF;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAC,CAAgB;AAAtG,yGAAyG;AAEzG;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAJ3B,MAI2B,EAAE,SAAS,EAHtC,MAGsC,GAFrC,MAAM,CAgBjB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAH3B,MAG2B,GAF1B,MAAM,CAgBjB;
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/lib/convert.js"],"names":[],"mappings":"AAaA,eAAO,MAAM,QAAQ,qBAGnB,CAAC;AAEH,eAAO,MAAM,SAAS,qBAIpB,CAAC;AAEH,eAAO,MAAM,QAAQ,qBAGnB,CAAC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AI,EAHxC,OAGwC,GAFvC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,EAAE,CAqDvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.js"],"names":[],"mappings":"AAiDI,YAAmD,OAAO,GAAhD,OAAO,uBAAuB,EAAE,OAAO,CAAS;
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.js"],"names":[],"mappings":"AAiDI,YAAmD,OAAO,GAAhD,OAAO,uBAAuB,EAAE,OAAO,CAAS;AAwM9D,mKAAmK;AACnK,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,IAAI,EAD1B,OAC0B,EAAE,UAAU,EADhB,OAAO,GAAG,MAAM,EACA,EAAE,IAAI,EADiB,OAAO,SAAS,EAAE,WACnC,EAAE,KAAK,AAD8C,CAAqC,EAA7B,GAAG,CAAC,MAAM,EAAE,MAAM,CACxE,GAD4F,IAAI,CA8B9J"}
|