11'use strict'
22
3- import _applyPlugin from './applyPlugin'
3+ import { applyPlugin } from './applyPlugin'
44import { UserOptions } from './config'
5- import { jsPDFConstructor , jsPDFDocument } from './documentHandler'
5+ import { jsPDFDocument } from './documentHandler'
66import { CellHookData } from './HookData'
77import { parseInput } from './inputParser'
88import { Cell , Column , Row , Table } from './models'
99import { createTable as _createTable } from './tableCalculator'
1010import { drawTable as _drawTable } from './tableDrawer'
1111
1212export type autoTableInstanceType = ( options : UserOptions ) => void
13-
14- // export { applyPlugin } didn't export applyPlugin
15- // to index.d.ts for some reason
16- export function applyPlugin ( jsPDF : jsPDFConstructor ) {
17- _applyPlugin ( jsPDF )
18- }
13+ export { applyPlugin }
1914
2015export function autoTable ( d : jsPDFDocument , options : UserOptions ) {
2116 const input = parseInput ( d , options )
@@ -34,17 +29,16 @@ export function __drawTable(d: jsPDFDocument, table: Table) {
3429}
3530
3631try {
37- // eslint-disable-next-line @typescript-eslint/no-require-imports
38- let jsPDF = require ( 'jspdf' )
39- // Webpack imported jspdf instead of jsPDF for some reason
40- // while it seemed to work everywhere else.
41- if ( jsPDF . jsPDF ) jsPDF = jsPDF . jsPDF
42- applyPlugin ( jsPDF )
43- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32+ if ( typeof window !== 'undefined' && window ) {
33+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34+ const anyWindow = window as any
35+ const jsPDF = anyWindow . jsPDF || anyWindow . jspdf ?. jsPDF
36+ if ( jsPDF ) {
37+ applyPlugin ( jsPDF )
38+ }
39+ }
4440} catch ( error ) {
45- // Importing jspdf in nodejs environments does not work as of jspdf
46- // 1.5.3 so we need to silence potential errors to support using for example
47- // the nodejs jspdf dist files with the exported applyPlugin
41+ console . error ( 'Could not apply autoTable plugin' , error )
4842}
4943
5044export default autoTable
0 commit comments