@react-pdf/stylesheet 5.1.0 → 5.2.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.js +8 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -162,7 +162,7 @@ const processMarginSingle = expandBoxModel({
|
|
|
162
162
|
autoSupported: true
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
const BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(
|
|
165
|
+
const BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(in|mm|cm|pt|vw|vh|px|rem)?)\s(\S+)\s(.+)/;
|
|
166
166
|
const matchBorderShorthand = value => value.match(BORDER_SHORTHAND_REGEX) || [];
|
|
167
167
|
const expandBorders = (key, value) => {
|
|
168
168
|
const match = matchBorderShorthand(`${value}`);
|
|
@@ -439,14 +439,15 @@ const parseValue = value => {
|
|
|
439
439
|
*/
|
|
440
440
|
const transformUnit = (container, value) => {
|
|
441
441
|
const scalar = parseValue(value);
|
|
442
|
-
const
|
|
443
|
-
const
|
|
444
|
-
const
|
|
442
|
+
const outputDpi = 72;
|
|
443
|
+
const inputDpi = container.dpi || 72;
|
|
444
|
+
const mmFactor = 1 / 25.4 * outputDpi;
|
|
445
|
+
const cmFactor = 1 / 2.54 * outputDpi;
|
|
445
446
|
switch (scalar.unit) {
|
|
446
447
|
case 'rem':
|
|
447
448
|
return scalar.value * (container.remBase || 18);
|
|
448
449
|
case 'in':
|
|
449
|
-
return scalar.value *
|
|
450
|
+
return scalar.value * outputDpi;
|
|
450
451
|
case 'mm':
|
|
451
452
|
return scalar.value * mmFactor;
|
|
452
453
|
case 'cm':
|
|
@@ -455,6 +456,8 @@ const transformUnit = (container, value) => {
|
|
|
455
456
|
return scalar.value * (container.height / 100);
|
|
456
457
|
case 'vw':
|
|
457
458
|
return scalar.value * (container.width / 100);
|
|
459
|
+
case 'px':
|
|
460
|
+
return Math.round(scalar.value * (outputDpi / inputDpi));
|
|
458
461
|
default:
|
|
459
462
|
return scalar.value;
|
|
460
463
|
}
|