@react-pdf/stylesheet 5.1.0 → 5.2.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.
package/README.md CHANGED
@@ -15,7 +15,7 @@ yarn add @react-pdf/stylesheet
15
15
  ## How it works
16
16
 
17
17
  ```js
18
- const stylesheet = require('@react-pdf/stylesheet');
18
+ import stylesheet from '@react-pdf/stylesheet';
19
19
 
20
20
  const container = {
21
21
  width: 400,
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+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/;
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 dpi = 72; // Removed: container.dpi || 72
443
- const mmFactor = 1 / 25.4 * dpi;
444
- const cmFactor = 1 / 2.54 * dpi;
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 * dpi;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf/stylesheet",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "license": "MIT",
5
5
  "description": "A styles engine for Node and the browser",
6
6
  "author": "Diego Muracciole <diegomuracciole@gmail.com>",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@babel/runtime": "^7.20.13",
22
22
  "@react-pdf/fns": "3.0.0",
23
- "@react-pdf/types": "^2.7.0",
23
+ "@react-pdf/types": "^2.7.1",
24
24
  "color-string": "^1.9.1",
25
25
  "hsl-to-hex": "^1.0.0",
26
26
  "media-engine": "^1.0.3",