@@ -5184,15 +5184,6 @@ Worker.prototype.toContainer = function toContainer() {
51845184 this . prop . container . appendChild ( source ) ;
51855185 this . prop . overlay . appendChild ( this . prop . container ) ;
51865186 document . body . appendChild ( this . prop . overlay ) ;
5187-
5188- // Enable page-breaks.
5189- var pageBreaks = source . querySelectorAll ( '.html2pdf__page-break' ) ;
5190- var pxPageHeight = this . prop . pageSize . inner . px . height ;
5191- Array . prototype . forEach . call ( pageBreaks , function pageBreak_loop ( el ) {
5192- el . style . display = 'block' ;
5193- var clientRect = el . getBoundingClientRect ( ) ;
5194- el . style . height = pxPageHeight - clientRect . top % pxPageHeight + 'px' ;
5195- } , this ) ;
51965187 } ) ;
51975188} ;
51985189
@@ -5469,34 +5460,25 @@ Worker.prototype.updateProgress = function updateProgress(val, state, n, stack)
54695460/* ----- PROMISE MAPPING ----- */
54705461
54715462Worker . prototype . then = function then ( onFulfilled , onRejected ) {
5472- // Wrap `this` for encapsulation and bind it to the promise handlers .
5463+ // Wrap `this` for encapsulation.
54735464 var self = this ;
5474- if ( onFulfilled ) {
5475- onFulfilled = onFulfilled . bind ( self ) ;
5476- }
5477- if ( onRejected ) {
5478- onRejected = onRejected . bind ( self ) ;
5479- }
54805465
5481- // Cast self into a Promise to avoid polyfills recursively defining `then`.
5482- var selfPromise = Promise . toString ( ) . indexOf ( '[native code]' ) === - 1 ? Worker . convert ( _extends ( { } , self ) , Promise . prototype ) : self ;
5483-
5484- // Update progress while queuing, calling, and resolving `then`.
5485- self . updateProgress ( null , null , 1 , [ onFulfilled ] ) ;
5486- var returnVal = Promise . prototype . then . call ( selfPromise , function then_pre ( val ) {
5487- self . updateProgress ( null , onFulfilled ) ;
5488- return val ;
5489- } ) . then ( onFulfilled , onRejected ) . then ( function then_post ( val ) {
5490- self . updateProgress ( 1 ) ;
5491- return val ;
5466+ return this . thenCore ( onFulfilled , onRejected , function then_main ( onFulfilled , onRejected ) {
5467+ // Update progress while queuing, calling, and resolving `then`.
5468+ self . updateProgress ( null , null , 1 , [ onFulfilled ] ) ;
5469+ return Promise . prototype . then . call ( this , function then_pre ( val ) {
5470+ self . updateProgress ( null , onFulfilled ) ;
5471+ return val ;
5472+ } ) . then ( onFulfilled , onRejected ) . then ( function then_post ( val ) {
5473+ self . updateProgress ( 1 ) ;
5474+ return val ;
5475+ } ) ;
54925476 } ) ;
5493-
5494- // Return the promise, after casting it into a Worker and preserving props.
5495- return Worker . convert ( returnVal , self . __proto__ ) ;
54965477} ;
54975478
5498- Worker . prototype . thenCore = function thenCore ( onFulfilled , onRejected ) {
5499- // Core version of then, with no updates to progress.
5479+ Worker . prototype . thenCore = function thenCore ( onFulfilled , onRejected , thenBase ) {
5480+ // Handle optional thenBase parameter.
5481+ thenBase = thenBase || Promise . prototype . then ;
55005482
55015483 // Wrap `this` for encapsulation and bind it to the promise handlers.
55025484 var self = this ;
@@ -5508,32 +5490,18 @@ Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected) {
55085490 }
55095491
55105492 // Cast self into a Promise to avoid polyfills recursively defining `then`.
5511- var selfPromise = Promise . toString ( ) . indexOf ( ' [native code]' ) === - 1 ? Worker . convert ( _extends ( { } , self ) , Promise . prototype ) : self ;
5493+ var selfPromise = Promise . toString ( ) !== 'function Promise() { [native code] }' ? Worker . convert ( _extends ( { } , self ) , Promise . prototype ) : self ;
55125494
55135495 // Return the promise, after casting it into a Worker and preserving props.
5514- var returnVal = Promise . prototype . then . call ( selfPromise , onFulfilled , onRejected ) ;
5496+ var returnVal = thenBase . call ( selfPromise , onFulfilled , onRejected ) ;
55155497 return Worker . convert ( returnVal , self . __proto__ ) ;
55165498} ;
55175499
5518- Worker . prototype [ 'catch' ] = function ( onRejected ) {
5519- // Bind `this` to the promise handler, call `catch`, and return a Worker.
5520- if ( onRejected ) {
5521- onRejected = onRejected . bind ( this ) ;
5522- }
5523- var returnVal = Promise . prototype [ 'catch' ] . call ( this , onRejected ) ;
5524- return Worker . convert ( returnVal , this ) ;
5525- } ;
5526-
55275500Worker . prototype . thenExternal = function thenExternal ( onFulfilled , onRejected ) {
55285501 // Call `then` and return a standard promise (exits the Worker chain).
55295502 return Promise . prototype . then . call ( this , onFulfilled , onRejected ) ;
55305503} ;
55315504
5532- Worker . prototype . catchExternal = function catchExternal ( onRejected ) {
5533- // Call `catch` and return a standard promise (exits the Worker chain).
5534- return Promise . prototype [ 'catch' ] . call ( this , onRejected ) ;
5535- } ;
5536-
55375505Worker . prototype . thenList = function thenList ( fns ) {
55385506 // Queue a series of promise 'factories' into the promise chain.
55395507 var self = this ;
@@ -5543,6 +5511,20 @@ Worker.prototype.thenList = function thenList(fns) {
55435511 return self ;
55445512} ;
55455513
5514+ Worker . prototype [ 'catch' ] = function ( onRejected ) {
5515+ // Bind `this` to the promise handler, call `catch`, and return a Worker.
5516+ if ( onRejected ) {
5517+ onRejected = onRejected . bind ( this ) ;
5518+ }
5519+ var returnVal = Promise . prototype [ 'catch' ] . call ( this , onRejected ) ;
5520+ return Worker . convert ( returnVal , this ) ;
5521+ } ;
5522+
5523+ Worker . prototype . catchExternal = function catchExternal ( onRejected ) {
5524+ // Call `catch` and return a standard promise (exits the Worker chain).
5525+ return Promise . prototype [ 'catch' ] . call ( this , onRejected ) ;
5526+ } ;
5527+
55465528Worker . prototype . error = function error ( msg ) {
55475529 // Throw the error in the Promise chain.
55485530 return this . then ( function error_main ( ) {
@@ -5661,17 +5643,34 @@ jspdf_min.getPageSize = function (orientation, unit, format) {
56615643 return info ;
56625644} ;
56635645
5646+ var orig = {
5647+ toContainer : Worker . prototype . toContainer
5648+ } ;
5649+
5650+ Worker . prototype . toContainer = function toContainer ( ) {
5651+ return orig . toContainer . call ( this ) . then ( function toContainer_pagebreak ( ) {
5652+ // Enable page-breaks.
5653+ var pageBreaks = this . prop . container . querySelectorAll ( '.html2pdf__page-break' ) ;
5654+ var pxPageHeight = this . prop . pageSize . inner . px . height ;
5655+ Array . prototype . forEach . call ( pageBreaks , function pageBreak_loop ( el ) {
5656+ el . style . display = 'block' ;
5657+ var clientRect = el . getBoundingClientRect ( ) ;
5658+ el . style . height = pxPageHeight - clientRect . top % pxPageHeight + 'px' ;
5659+ } , this ) ;
5660+ } ) ;
5661+ } ;
5662+
56645663// Add hyperlink functionality to the PDF creation.
56655664
56665665// Main link array, and refs to original functions.
56675666var linkInfo = [ ] ;
5668- var orig = {
5667+ var orig$1 = {
56695668 toContainer : Worker . prototype . toContainer ,
56705669 toPdf : Worker . prototype . toPdf
56715670} ;
56725671
56735672Worker . prototype . toContainer = function toContainer ( ) {
5674- return orig . toContainer . call ( this ) . then ( function toContainer_hyperlink ( ) {
5673+ return orig$1 . toContainer . call ( this ) . then ( function toContainer_hyperlink ( ) {
56755674 // Retrieve hyperlink info if the option is enabled.
56765675 if ( this . opt . enableLinks ) {
56775676 // Find all anchor tags and get the container's bounds for reference.
@@ -5701,7 +5700,7 @@ Worker.prototype.toContainer = function toContainer() {
57015700} ;
57025701
57035702Worker . prototype . toPdf = function toPdf ( ) {
5704- return orig . toPdf . call ( this ) . then ( function toPdf_hyperlink ( ) {
5703+ return orig$1 . toPdf . call ( this ) . then ( function toPdf_hyperlink ( ) {
57055704 // Add hyperlinks if the option is enabled.
57065705 if ( this . opt . enableLinks ) {
57075706 // Attach each anchor tag based on info from toContainer().
0 commit comments