@react-pdf/render
Advanced tools
Comparing version 2.0.9 to 2.0.10
@@ -5,9 +5,5 @@ "use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
var R = _interopRequireWildcard(require("ramda")); | ||
var _renderNode = _interopRequireDefault(require("./primitives/renderNode")); | ||
@@ -18,3 +14,6 @@ | ||
var renderDocument = function renderDocument(ctx) { | ||
return R.compose(R.forEach((0, _renderNode.default)(ctx)), R.pathOr([], ['children'])); | ||
return function (doc) { | ||
var pages = doc.children || []; | ||
pages.forEach((0, _renderNode.default)(ctx)); | ||
}; | ||
}; | ||
@@ -21,0 +20,0 @@ |
@@ -11,82 +11,46 @@ "use strict"; | ||
// TODO: Implement using only matrices to support skew and even more operations than css. | ||
var getRotation = function getRotation(transform) { | ||
var match = /rotate\((-?\d+(.\d+)?)(.+)\)/g.exec(transform); | ||
var applySingleTransformation = function applySingleTransformation(ctx, transform, origin) { | ||
var operation = transform.operation, | ||
value = transform.value; | ||
if (match && match[1] && match[3]) { | ||
var value = match[1]; | ||
return match[3] === 'rad' ? value * 180 / Math.PI : value; | ||
} | ||
switch (operation) { | ||
case 'scale': | ||
{ | ||
var scaleX = value[0], | ||
scaleY = value[1]; | ||
ctx.scale(scaleX, scaleY, { | ||
origin: origin | ||
}); | ||
break; | ||
} | ||
return 0; | ||
}; | ||
case 'rotate': | ||
{ | ||
var angle = value[0]; | ||
ctx.rotate(angle, { | ||
origin: origin | ||
}); | ||
break; | ||
} | ||
var getTranslateX = function getTranslateX(transform) { | ||
var matchX = /translateX\((-?\d+\.?d*)\)/g.exec(transform); | ||
var matchGeneric = /translate\((-?\d+\.?d*).*(,|\s)\s*(-?\d+\.?d*).*\)/g.exec(transform); | ||
if (matchX && matchX[1]) return matchX[1]; | ||
if (matchGeneric && matchGeneric[1]) return matchGeneric[1]; | ||
return 0; | ||
}; | ||
case 'translate': | ||
{ | ||
var x = value[0], | ||
y = value[1]; | ||
ctx.translate(x, y, { | ||
origin: origin | ||
}); | ||
break; | ||
} | ||
var getTranslateY = function getTranslateY(transform) { | ||
var matchY = /translateY\((-?\d+\.?\d*)\)/g.exec(transform); | ||
var matchGeneric = /translate\((-?\d+\.?\d*).*(,|\s)\s*(-?\d+\.?\d*).*\)/g.exec(transform); | ||
if (matchY && matchY[1]) return matchY[1]; | ||
if (matchGeneric && matchGeneric[3]) return matchGeneric[3]; | ||
return 0; | ||
}; | ||
case 'matrix': | ||
{ | ||
ctx.transform.apply(ctx, value); | ||
break; | ||
} | ||
var getScaleX = function getScaleX(transform) { | ||
var matchX = /scaleX\((-?\d+\.?\d*)\)/g.exec(transform); | ||
var matchGeneric = /scale\((-?\d+\.?\d*).*,?\s*(-?\d+\.?\d*).*\)/g.exec(transform); | ||
if (matchX && matchX[1]) return matchX[1]; | ||
if (matchGeneric && matchGeneric[1]) return matchGeneric[1]; | ||
return 1; | ||
}; | ||
var getScaleY = function getScaleY(transform) { | ||
var matchY = /scaleY\((-?\d+\.?\d*)\)/g.exec(transform); | ||
var matchGeneric = /scale\((-?\d+\.?\d*).*,?\s*(-?\d+\.?\d*).*\)/g.exec(transform); | ||
if (matchY && matchY[1]) return matchY[1]; | ||
if (matchGeneric && matchGeneric[2]) return matchGeneric[2]; | ||
return 1; | ||
}; | ||
var getMatrix = function getMatrix(transform) { | ||
var match = /matrix\(([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)\)/g.exec(transform); | ||
if (match) return match.slice(1, 7); | ||
return null; | ||
}; | ||
var applySingleTransformation = function applySingleTransformation(ctx, transform, origin) { | ||
if (/rotate/g.test(transform)) { | ||
ctx.rotate(getRotation(transform), { | ||
origin: origin | ||
}); | ||
} else if (/scaleX/g.test(transform)) { | ||
ctx.scale(getScaleX(transform), 1, { | ||
origin: origin | ||
}); | ||
} else if (/scaleY/g.test(transform)) { | ||
ctx.scale(1, getScaleY(transform), { | ||
origin: origin | ||
}); | ||
} else if (/scale/g.test(transform)) { | ||
ctx.scale(getScaleX(transform), getScaleY(transform), { | ||
origin: origin | ||
}); | ||
} else if (/translateX/g.test(transform)) { | ||
ctx.translate(getTranslateX(transform), 1, { | ||
origin: origin | ||
}); | ||
} else if (/translateY/g.test(transform)) { | ||
ctx.translate(1, getTranslateY(transform), { | ||
origin: origin | ||
}); | ||
} else if (/translate/g.test(transform)) { | ||
ctx.translate(getTranslateX(transform), getTranslateY(transform), { | ||
origin: origin | ||
}); | ||
} else if (/matrix/g.test(transform)) { | ||
ctx.transform.apply(ctx, getMatrix(transform)); | ||
default: | ||
{ | ||
console.error("Transform operation: '" + operation + "' doesn't supported"); | ||
} | ||
} | ||
@@ -97,11 +61,7 @@ }; | ||
if (!node.origin) return node; | ||
var match; | ||
var re = /[a-zA-Z]+\([^)]+\)/g; | ||
var origin = [node.origin.left, node.origin.top]; | ||
var transform = node.style && node.style.transform || node.props && node.props.transform || ''; | ||
while ((match = re.exec(transform)) != null) { | ||
applySingleTransformation(ctx, match[0], origin); | ||
} | ||
var operations = node.style && node.style.transform || []; | ||
operations.forEach(function (operation) { | ||
applySingleTransformation(ctx, operation, origin); | ||
}); | ||
return node; | ||
@@ -108,0 +68,0 @@ }; |
@@ -12,4 +12,2 @@ "use strict"; | ||
var _colorString = _interopRequireDefault(require("color-string")); | ||
var _save = _interopRequireDefault(require("../operations/save")); | ||
@@ -21,14 +19,4 @@ | ||
var parseColor = function parseColor(hex) { | ||
var parsed = _colorString.default.get(hex); | ||
var _parseColor = _interopRequireDefault(require("../utils/parseColor")); | ||
var value = _colorString.default.to.hex(parsed.value.slice(0, 3)); | ||
var opacity = parsed.value[3]; | ||
return { | ||
value: value, | ||
opacity: opacity | ||
}; | ||
}; | ||
var drawBackground = function drawBackground(ctx, node) { | ||
@@ -43,3 +31,3 @@ if (node.box && node.style.backgroundColor) { | ||
height = _node$box.height; | ||
var color = parseColor(node.style.backgroundColor); | ||
var color = (0, _parseColor.default)(node.style.backgroundColor); | ||
var opacity = R.defaultTo(color.opacity, (_node$style = node.style) === null || _node$style === void 0 ? void 0 : _node$style.opacity); | ||
@@ -46,0 +34,0 @@ ctx.fillOpacity(opacity).fillColor(color.value).rect(left, top, width, height).fill(); |
@@ -22,3 +22,3 @@ "use strict"; | ||
var debugContent = function debugContent(ctx) { | ||
return R.tap(function (node) { | ||
return function (node) { | ||
var _node$box = node.box, | ||
@@ -46,7 +46,8 @@ left = _node$box.left, | ||
ctx.fillColor(CONTENT_COLOR).opacity(0.5).rect(left + paddingLeft + borderLeftWidth, top + paddingTop + borderTopWidth, width - paddingLeft - paddingRight - borderRightWidth - borderLeftWidth, height - paddingTop - paddingBottom - borderTopWidth - borderBottomWidth).fill(); | ||
}); | ||
return node; | ||
}; | ||
}; | ||
var debugPadding = function debugPadding(ctx) { | ||
return R.tap(function (node) { | ||
return function (node) { | ||
var _node$box2 = node.box, | ||
@@ -82,7 +83,8 @@ left = _node$box2.left, | ||
ctx.rect(left + paddingLeft + borderLeftWidth, top + height - paddingBottom - borderBottomWidth, width - paddingRight - paddingLeft - borderLeftWidth - borderRightWidth, paddingBottom).fill(); | ||
}); | ||
return node; | ||
}; | ||
}; | ||
var debugMargin = function debugMargin(ctx) { | ||
return R.tap(function (node) { | ||
return function (node) { | ||
var _node$box3 = node.box, | ||
@@ -110,7 +112,8 @@ left = _node$box3.left, | ||
ctx.rect(left, top + height, width, marginBottom).fill(); | ||
}); | ||
return node; | ||
}; | ||
}; | ||
var debugText = function debugText(ctx) { | ||
return R.tap(function (node) { | ||
return function (node) { | ||
var _node$box4 = node.box, | ||
@@ -131,12 +134,15 @@ left = _node$box4.left, | ||
var roundedHeight = Math.round(height + marginTop + marginBottom); | ||
ctx.fontSize(4).opacity(1).fillColor('black').text(roundedWidth + " x " + roundedHeight, left - marginLeft, Math.max(top - marginTop - 4, 1)); | ||
}); | ||
ctx.fontSize(6).opacity(1).fillColor('black').text(roundedWidth + " x " + roundedHeight, left - marginLeft, Math.max(top - marginTop - 4, 1)); | ||
return node; | ||
}; | ||
}; | ||
var debugOrigin = function debugOrigin(ctx) { | ||
return R.tap(function (node) { | ||
return function (node) { | ||
if (node.origin) { | ||
ctx.circle(node.origin.left, node.origin.top, 3).fill('red').circle(node.origin.left, node.origin.top, 5).stroke('red'); | ||
} | ||
}); | ||
return node; | ||
}; | ||
}; | ||
@@ -143,0 +149,0 @@ |
@@ -22,2 +22,4 @@ "use strict"; | ||
var _parseColor = _interopRequireDefault(require("../utils/parseColor")); | ||
/* eslint-disable no-param-reassign */ | ||
@@ -73,5 +75,5 @@ var DEST_REGEXP = /^#.+/; | ||
fontSize = _run$attributes.fontSize, | ||
color = _run$attributes.color, | ||
link = _run$attributes.link, | ||
opacity = _run$attributes.opacity; | ||
link = _run$attributes.link; | ||
var color = (0, _parseColor.default)(run.attributes.color); | ||
var opacity = R.defaultTo(color.opacity, run.attributes.opacity); | ||
var height = (0, _height.default)(run); | ||
@@ -85,3 +87,3 @@ var descent = (0, _descent.default)(run); | ||
ctx.fillColor(color); | ||
ctx.fillColor(color.value); | ||
ctx.fillOpacity(opacity); | ||
@@ -128,4 +130,8 @@ | ||
var renderBackground = function renderBackground(ctx, rect, backgroundColor) { | ||
var color = (0, _parseColor.default)(backgroundColor); | ||
ctx.save(); | ||
ctx.fillOpacity(color.opacity); | ||
ctx.rect(rect.x, rect.y, rect.width, rect.height); | ||
ctx.fill(backgroundColor); | ||
ctx.fill(color.value); | ||
ctx.restore(); | ||
}; | ||
@@ -132,0 +138,0 @@ |
{ | ||
"name": "@react-pdf/render", | ||
"version": "2.0.9", | ||
"version": "2.0.10", | ||
"license": "MIT", | ||
@@ -16,3 +16,3 @@ "author": "Diego Muracciole <diegomuracciole@gmail.com>", | ||
"@react-pdf/primitives": "^2.0.0", | ||
"@react-pdf/textkit": "^2.0.4", | ||
"@react-pdf/textkit": "^2.0.5", | ||
"@react-pdf/types": "^2.0.3", | ||
@@ -29,3 +29,3 @@ "abs-svg-path": "^0.1.1", | ||
], | ||
"gitHead": "6e546516c4406e7e61269977684f9e05c59c6d5f" | ||
"gitHead": "e15b90e39aefde8635663b58ef2e3ffa6494cecd" | ||
} |
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
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
55
101259
2168
0
Updated@react-pdf/textkit@^2.0.5