@react-pdf/stylesheet
Advanced tools
Comparing version 2.0.5 to 2.0.6
@@ -5,218 +5,42 @@ "use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
exports.__esModule = true; | ||
exports.default = exports.processObjectPosition = exports.processFontWeight = void 0; | ||
exports.default = void 0; | ||
var R = _interopRequireWildcard(require("ramda")); | ||
var _flex = _interopRequireDefault(require("./flex")); | ||
var _shorthands = _interopRequireDefault(require("./shorthands")); | ||
var _margins = _interopRequireDefault(require("./margins")); | ||
var BOX_MODEL_REGEX = /-?\d+(\.\d+)?(px|in|mm|cm|pt|%|vw|vh|px)?/g; | ||
var OBJECT_POSITION_REGEX = /-?\d+(\.\d+)?(px|in|mm|cm|pt|%|vw|vh|px)?/g; | ||
var BORDER_SHORTHAND_REGEX = /(-?\d+(\.\d+)?(px|in|mm|cm|pt|vw|vh|px)?)\s(\S+)\s(.+)/; | ||
var TRANSFORM_ORIGIN_REGEX = /(-?\d+(px|in|mm|cm|pt|%|vw|vh|px)?)|top|right|bottom|left|center/g; | ||
var FONT_WEIGHTS = { | ||
thin: 100, | ||
hairline: 100, | ||
ultralight: 200, | ||
extralight: 200, | ||
light: 300, | ||
normal: 400, | ||
medium: 500, | ||
semibold: 600, | ||
demibold: 600, | ||
bold: 700, | ||
ultrabold: 800, | ||
extrabold: 800, | ||
heavy: 900, | ||
black: 900 | ||
}; | ||
var matchBoxModel = R.match(BOX_MODEL_REGEX); | ||
var matchObjectPosition = R.match(OBJECT_POSITION_REGEX); | ||
var matchBorderShorthand = R.match(BORDER_SHORTHAND_REGEX); | ||
var matchTransformOrigin = R.match(TRANSFORM_ORIGIN_REGEX); | ||
var isNumber = R.is(Number); | ||
var FONT_WEIGHT_REGEX = /^fontWeight/; | ||
var _borders = _interopRequireDefault(require("./borders")); | ||
var isFontWeightStyle = function isFontWeightStyle(key) { | ||
return key.match(FONT_WEIGHT_REGEX); | ||
}; | ||
var _paddings = _interopRequireDefault(require("./paddings")); | ||
var BORDER_STYLE_REGEX = /^border(Top|Right|Bottom|Left)(Color|Width|Style)/; | ||
var _fontWeight = _interopRequireDefault(require("./fontWeight")); | ||
var isBorderStyle = function isBorderStyle(key, value) { | ||
return key.match(BORDER_STYLE_REGEX) && typeof value === 'string'; | ||
}; | ||
var _objectPosition = _interopRequireDefault(require("./objectPosition")); | ||
var BOX_MODEL_STYLE_REGEX = /^(margin)|(padding)/; | ||
var _transformOrigin = _interopRequireDefault(require("./transformOrigin")); | ||
var isBoxModelStyle = function isBoxModelStyle(key, value) { | ||
return key.match(BOX_MODEL_STYLE_REGEX) && typeof value === 'string'; | ||
}; | ||
var _utils = require("./utils"); | ||
var OBJECT_POSITION_STYLE_REGEX = /^objectPosition/; | ||
var isObjectPositionStyle = function isObjectPositionStyle(key, value) { | ||
return key.match(OBJECT_POSITION_STYLE_REGEX) && typeof value === 'string'; | ||
var shorthands = { | ||
flex: _flex.default, | ||
margin: _margins.default, | ||
marginHorizontal: _margins.default, | ||
marginVertical: _margins.default, | ||
padding: _paddings.default, | ||
paddingHorizontal: _paddings.default, | ||
paddingVertical: _paddings.default, | ||
border: _borders.default, | ||
borderTop: _borders.default, | ||
borderRight: _borders.default, | ||
borderBottom: _borders.default, | ||
borderLeft: _borders.default, | ||
borderColor: _borders.default, | ||
borderRadius: _borders.default, | ||
borderStyle: _borders.default, | ||
borderWidth: _borders.default, | ||
objectPosition: _objectPosition.default, | ||
transformOrigin: _transformOrigin.default, | ||
fontWeight: _fontWeight.default | ||
}; | ||
var isTransformOriginStyle = function isTransformOriginStyle(key, value) { | ||
return key.match(/^transformOrigin/) && typeof value === 'string'; | ||
}; | ||
var isFlexGrow = function isFlexGrow(key) { | ||
return key === 'flexGrow'; | ||
}; | ||
var isFlexShrink = function isFlexShrink(key) { | ||
return key === 'flexShrink'; | ||
}; | ||
var isFlexBasis = function isFlexBasis(key) { | ||
return key === 'flexBasis'; | ||
}; | ||
var processBorders = function processBorders(key, value) { | ||
var match = matchBorderShorthand(value); | ||
if (match) { | ||
if (key.match(/Color$/)) { | ||
return match[5] || value; | ||
} | ||
if (key.match(/Style$/)) { | ||
return match[4] || value; | ||
} | ||
if (key.match(/Width$/)) { | ||
return match[1] || value; | ||
} | ||
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'"); | ||
} | ||
return value; | ||
}; | ||
var processBoxModel = function processBoxModel(key, value) { | ||
if (value === 'auto') return value; | ||
var match = matchBoxModel(value); | ||
if (match) { | ||
if (key.match(/Top$/)) { | ||
return match[0]; | ||
} | ||
if (key.match(/Right$/)) { | ||
return match[1] || match[0]; | ||
} | ||
if (key.match(/Bottom$/)) { | ||
return match[2] || match[0]; | ||
} | ||
if (key.match(/Left$/)) { | ||
return match[3] || match[1] || match[0]; | ||
} | ||
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'"); | ||
} | ||
return value; | ||
}; | ||
var processFontWeight = function processFontWeight(key, value) { | ||
if (!value) return FONT_WEIGHTS.normal; | ||
if (typeof value === 'number') return value; | ||
return FONT_WEIGHTS[value.toLowerCase()]; | ||
}; | ||
exports.processFontWeight = processFontWeight; | ||
var processObjectPosition = function processObjectPosition(key, value) { | ||
var match = matchObjectPosition(value); | ||
if (match) { | ||
if (key.match(/X$/)) { | ||
return match[0] || value; | ||
} | ||
if (key.match(/Y$/)) { | ||
return match[1] || value; | ||
} | ||
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'"); | ||
} | ||
return value; | ||
}; | ||
exports.processObjectPosition = processObjectPosition; | ||
var transformOffsetKeywords = function transformOffsetKeywords(value) { | ||
switch (value) { | ||
case 'top': | ||
case 'left': | ||
return '0%'; | ||
case 'right': | ||
case 'bottom': | ||
return '100%'; | ||
case 'center': | ||
return '50%'; | ||
default: | ||
return value; | ||
} | ||
}; // Transforms shorthand transformOrigin values | ||
var processTransformOrigin = function processTransformOrigin(key, value) { | ||
var match = matchTransformOrigin(value); | ||
if (match) { | ||
var result; | ||
if (key.match(/X$/)) { | ||
result = match[0] || value; | ||
} else if (key.match(/Y$/)) { | ||
result = match[1] || match[0] || value; | ||
} else { | ||
throw new Error("StyleSheet: Invalid '" + value + "' for '" + key + "'"); | ||
} | ||
return transformOffsetKeywords(result); | ||
} | ||
return value; | ||
}; | ||
var processFlexGrow = function processFlexGrow(key, value) { | ||
if (isNumber(value)) return value; | ||
var matches = value.split(' '); | ||
return matches[0] || value; | ||
}; | ||
var processFlexShrink = function processFlexShrink(key, value) { | ||
if (isNumber(value)) return value; | ||
var matches = value.split(' '); | ||
return matches[1] || value; | ||
}; | ||
var processFlexBasis = function processFlexBasis(key, value) { | ||
if (isNumber(value)) return value; | ||
var matches = value.split(' '); | ||
return matches[2] || value; | ||
}; | ||
var keepSame = function keepSame(key, value) { | ||
return value; | ||
}; | ||
var matchNumber = R.when(R.is(String), R.test(/^-?\d*\.?\d*$/)); | ||
var castFloat = R.when(matchNumber, function (v) { | ||
return parseFloat(v, 10); | ||
}); | ||
/** | ||
@@ -230,5 +54,9 @@ * Transforms style key-value | ||
var transformStyle = R.compose(castFloat, R.cond([[isBorderStyle, processBorders], [isBoxModelStyle, processBoxModel], [isObjectPositionStyle, processObjectPosition], [isTransformOriginStyle, processTransformOrigin], [isFontWeightStyle, processFontWeight], [isFlexGrow, processFlexGrow], [isFlexShrink, processFlexShrink], [isFlexBasis, processFlexBasis], [R.T, keepSame]])); | ||
var expandStyle = function expandStyle(key, value) { | ||
var _ref; | ||
return shorthands[key] ? shorthands[key](key, value) : (_ref = {}, _ref[key] = (0, _utils.castFloat)(value), _ref); | ||
}; | ||
/** | ||
* Expand the shorthand properties to isolate every declaration from the others. | ||
* Expand the shorthand properties. | ||
* | ||
@@ -239,2 +67,3 @@ * @param { Object } style object | ||
var expand = function expand(style) { | ||
@@ -248,12 +77,9 @@ if (!style) return style; | ||
var value = style[key]; | ||
var extended = expandStyle(key, value); | ||
var keys = Object.keys(extended); | ||
if (_shorthands.default[key]) { | ||
var expandedProps = _shorthands.default[key]; | ||
for (var j = 0; j < expandedProps.length; j += 1) { | ||
var propName = expandedProps[j]; | ||
resolvedStyle[propName] = transformStyle(propName, value); | ||
} | ||
} else { | ||
resolvedStyle[key] = transformStyle(key, value); | ||
for (var j = 0; j < keys.length; j += 1) { | ||
var propName = keys[j]; | ||
var propValue = extended[propName]; | ||
resolvedStyle[propName] = propValue; | ||
} | ||
@@ -260,0 +86,0 @@ } |
{ | ||
"name": "@react-pdf/stylesheet", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "author": "Diego Muracciole <diegomuracciole@gmail.com>", | ||
"dependencies": { | ||
"@react-pdf/types": "^2.0.1", | ||
"@react-pdf/types": "^2.0.2", | ||
"color-string": "^1.5.3", | ||
@@ -25,3 +25,3 @@ "hsl-to-hex": "^1.0.0", | ||
], | ||
"gitHead": "09b1b0b45bcd7cecd2bbd340aee1b026db18815c" | ||
"gitHead": "e14aed2146d037cceae9097f8d559971e9773e2e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21538
19
521
1
Updated@react-pdf/types@^2.0.2