Skip to content

Commit

Permalink
3.5.29
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbengtsson committed May 20, 2023
1 parent 5d9f793 commit d13bcca
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 84 deletions.
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dts-bundle-generator v7.1.0
// Generated by dts-bundle-generator v8.0.1

export type jsPDFConstructor = any;
export type jsPDFDocument = any;
Expand All @@ -13,7 +13,7 @@ declare class DocHandler {
private static unifyColor;
applyStyles(styles: Partial<Styles>, fontOnly?: boolean): void;
splitTextToSize(text: string | string[], size: number, opts: Opts): string[];
rect(x: number, y: number, width: number, height: number, fillStyle: string): any;
rect(x: number, y: number, width: number, height: number, fillStyle: string | null): any;
getLastAutoTable(): Table | null;
getTextWidth(text: string | string[]): number;
getDocument(): any;
Expand Down
131 changes: 92 additions & 39 deletions dist/jspdf.plugin.autotable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
*
* jsPDF AutoTable plugin v3.5.28
* jsPDF AutoTable plugin v3.5.29
*
* Copyright (c) 2022 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
* Copyright (c) 2023 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*
Expand Down Expand Up @@ -1550,6 +1550,15 @@ function cellStyles(sectionName, column, rowIndex, themeName, styles, scaleFacto
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addPage = exports.drawTable = void 0;
var config_1 = __webpack_require__(913);
Expand Down Expand Up @@ -1802,53 +1811,96 @@ function drawCellBorders(doc, cell, cursor) {
var cellStyles = cell.styles;
doc.getDocument().setFillColor(doc.getDocument().getFillColor());
if (typeof cellStyles.lineWidth === 'number') {
// prints normal cell border
// prints normal cell border using rect's stroke
var fillStyle = (0, common_1.getFillStyle)(cellStyles.lineWidth, cellStyles.fillColor);
if (fillStyle) {
doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle);
}
}
else if (typeof cellStyles.lineWidth === 'object') {
doc.rect(cell.x, cursor.y, cell.width, cell.height, 'F');
var sides = Object.keys(cellStyles.lineWidth);
var lineWidth_1 = cellStyles.lineWidth;
sides.map(function (side) {
var fillStyle = (0, common_1.getFillStyle)(lineWidth_1[side], cellStyles.fillColor);
drawBorderForSide(doc, cell, cursor, side, fillStyle || 'S', lineWidth_1[side]);
});
drawCellBackground(doc, cell, cursor, cellStyles.fillColor);
drawBorders(doc, cell, cursor, cellStyles.fillColor, cellStyles.lineWidth);
}
}
function drawBorderForSide(doc, cell, cursor, side, fillStyle, lineWidth) {
/**
* Prints cell background without borders and allows transparent color.
* @param doc
* @param cell
* @param cursor
* @param fillColor - `false` for transparent, `string` for color, other types will use "F" from jsPDF.rect
*/
function drawCellBackground(doc, cell, cursor, fillColor) {
var cellFillColor = fillColor === false ? null : typeof fillColor !== 'string' ? 'F' : fillColor;
doc.rect(cell.x, cursor.y, cell.width, cell.height, cellFillColor);
}
/**
* Draw all specified borders. Borders are centered on cell's edge and lengthened
* to overlap with neighbours to create sharp corners.
* @param doc
* @param cell
* @param cursor
* @param fillColor
* @param lineWidth
*/
function drawBorders(doc, cell, cursor, fillColor, lineWidth) {
var x1, y1, x2, y2;
switch (side) {
case 'top':
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y;
break;
case 'left':
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x;
y2 = cursor.y + cell.height;
break;
case 'right':
x1 = cursor.x + cell.width;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height;
break;
default:
// default it will print bottom
x1 = cursor.x;
y1 = cursor.y + cell.height - lineWidth;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height - lineWidth;
break;
if (lineWidth.top) {
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y;
if (lineWidth.right) {
x2 += 0.5 * lineWidth.right;
}
if (lineWidth.left) {
x1 -= 0.5 * lineWidth.left;
}
drawLine([x1, y1, x2, y2], lineWidth.top, fillColor);
}
if (lineWidth.bottom) {
x1 = cursor.x;
y1 = cursor.y + cell.height;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height;
if (lineWidth.right) {
x2 += 0.5 * lineWidth.right;
}
if (lineWidth.left) {
x1 -= 0.5 * lineWidth.left;
}
drawLine([x1, y1, x2, y2], lineWidth.bottom, fillColor);
}
if (lineWidth.left) {
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x;
y2 = cursor.y + cell.height;
if (lineWidth.top) {
y1 -= 0.5 * lineWidth.top;
}
if (lineWidth.bottom) {
y2 += 0.5 * lineWidth.bottom;
}
drawLine([x1, y1, x2, y2], lineWidth.left, fillColor);
}
if (lineWidth.right) {
x1 = cursor.x + cell.width;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height;
if (lineWidth.top) {
y1 -= 0.5 * lineWidth.top;
}
if (lineWidth.bottom) {
y2 += 0.5 * lineWidth.bottom;
}
drawLine([x1, y1, x2, y2], lineWidth.right, fillColor);
}
function drawLine(coords, width, color) {
var _a;
doc.getDocument().setLineWidth(width);
(_a = doc.getDocument()).line.apply(_a, __spreadArray(__spreadArray([], coords, false), [(0, common_1.getFillStyle)(width, color)], false));
}
doc.getDocument().setLineWidth(lineWidth);
doc.getDocument().line(x1, y1, x2, y2, fillStyle);
}
function getRemainingPageSpace(doc, table, isLastRow, cursor) {
var bottomContentHeight = table.settings.margin.bottom;
Expand Down Expand Up @@ -1877,6 +1929,7 @@ function addPage(doc, table, startPos, cursor, columns) {
startPos.y = margin.top;
if (table.settings.showHead === 'everyPage') {
table.head.forEach(function (row) { return printRow(doc, table, row, cursor, columns); });
doc.applyStyles(doc.userStyles);
}
}
exports.addPage = addPage;
Expand Down
6 changes: 3 additions & 3 deletions dist/jspdf.plugin.autotable.min.js

Large diffs are not rendered by default.

130 changes: 93 additions & 37 deletions dist/jspdf.plugin.autotable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function parseSpacing(value, defaultValue) {
}

// Limitations
// - No support for border spacing
// - No support for transparency
function parseCss(supportedFonts, element, scaleFactor, style, window) {
var result = {};
var pxScaleFactor = 96 / 72;
Expand Down Expand Up @@ -232,6 +234,16 @@ function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}

function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}

/**
Expand Down Expand Up @@ -1459,53 +1471,96 @@ function drawCellBorders(doc, cell, cursor) {
var cellStyles = cell.styles;
doc.getDocument().setFillColor(doc.getDocument().getFillColor());
if (typeof cellStyles.lineWidth === 'number') {
// prints normal cell border
// prints normal cell border using rect's stroke
var fillStyle = getFillStyle(cellStyles.lineWidth, cellStyles.fillColor);
if (fillStyle) {
doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle);
}
}
else if (typeof cellStyles.lineWidth === 'object') {
doc.rect(cell.x, cursor.y, cell.width, cell.height, 'F');
var sides = Object.keys(cellStyles.lineWidth);
var lineWidth_1 = cellStyles.lineWidth;
sides.map(function (side) {
var fillStyle = getFillStyle(lineWidth_1[side], cellStyles.fillColor);
drawBorderForSide(doc, cell, cursor, side, fillStyle || 'S', lineWidth_1[side]);
});
drawCellBackground(doc, cell, cursor, cellStyles.fillColor);
drawBorders(doc, cell, cursor, cellStyles.fillColor, cellStyles.lineWidth);
}
}
function drawBorderForSide(doc, cell, cursor, side, fillStyle, lineWidth) {
/**
* Prints cell background without borders and allows transparent color.
* @param doc
* @param cell
* @param cursor
* @param fillColor - `false` for transparent, `string` for color, other types will use "F" from jsPDF.rect
*/
function drawCellBackground(doc, cell, cursor, fillColor) {
var cellFillColor = fillColor === false ? null : typeof fillColor !== 'string' ? 'F' : fillColor;
doc.rect(cell.x, cursor.y, cell.width, cell.height, cellFillColor);
}
/**
* Draw all specified borders. Borders are centered on cell's edge and lengthened
* to overlap with neighbours to create sharp corners.
* @param doc
* @param cell
* @param cursor
* @param fillColor
* @param lineWidth
*/
function drawBorders(doc, cell, cursor, fillColor, lineWidth) {
var x1, y1, x2, y2;
switch (side) {
case 'top':
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y;
break;
case 'left':
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x;
y2 = cursor.y + cell.height;
break;
case 'right':
x1 = cursor.x + cell.width;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height;
break;
default:
// default it will print bottom
x1 = cursor.x;
y1 = cursor.y + cell.height - lineWidth;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height - lineWidth;
break;
if (lineWidth.top) {
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y;
if (lineWidth.right) {
x2 += 0.5 * lineWidth.right;
}
if (lineWidth.left) {
x1 -= 0.5 * lineWidth.left;
}
drawLine([x1, y1, x2, y2], lineWidth.top, fillColor);
}
if (lineWidth.bottom) {
x1 = cursor.x;
y1 = cursor.y + cell.height;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height;
if (lineWidth.right) {
x2 += 0.5 * lineWidth.right;
}
if (lineWidth.left) {
x1 -= 0.5 * lineWidth.left;
}
drawLine([x1, y1, x2, y2], lineWidth.bottom, fillColor);
}
if (lineWidth.left) {
x1 = cursor.x;
y1 = cursor.y;
x2 = cursor.x;
y2 = cursor.y + cell.height;
if (lineWidth.top) {
y1 -= 0.5 * lineWidth.top;
}
if (lineWidth.bottom) {
y2 += 0.5 * lineWidth.bottom;
}
drawLine([x1, y1, x2, y2], lineWidth.left, fillColor);
}
if (lineWidth.right) {
x1 = cursor.x + cell.width;
y1 = cursor.y;
x2 = cursor.x + cell.width;
y2 = cursor.y + cell.height;
if (lineWidth.top) {
y1 -= 0.5 * lineWidth.top;
}
if (lineWidth.bottom) {
y2 += 0.5 * lineWidth.bottom;
}
drawLine([x1, y1, x2, y2], lineWidth.right, fillColor);
}
function drawLine(coords, width, color) {
var _a;
doc.getDocument().setLineWidth(width);
(_a = doc.getDocument()).line.apply(_a, __spreadArray(__spreadArray([], coords, false), [getFillStyle(width, color)], false));
}
doc.getDocument().setLineWidth(lineWidth);
doc.getDocument().line(x1, y1, x2, y2, fillStyle);
}
function getRemainingPageSpace(doc, table, isLastRow, cursor) {
var bottomContentHeight = table.settings.margin.bottom;
Expand Down Expand Up @@ -1534,6 +1589,7 @@ function addPage(doc, table, startPos, cursor, columns) {
startPos.y = margin.top;
if (table.settings.showHead === 'everyPage') {
table.head.forEach(function (row) { return printRow(doc, table, row, cursor, columns); });
doc.applyStyles(doc.userStyles);
}
}
function nextPage(doc) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jspdf-autotable",
"version": "3.5.28",
"version": "3.5.29",
"description": "Generate pdf tables with javascript (jsPDF plugin)",
"main": "dist/jspdf.plugin.autotable.js",
"exports": {
Expand Down

0 comments on commit d13bcca

Please sign in to comment.