@@ -5184,15 +5184,6 @@ Worker.prototype.toContainer = function toContainer() {
5184
5184
this . prop . container . appendChild ( source ) ;
5185
5185
this . prop . overlay . appendChild ( this . prop . container ) ;
5186
5186
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 ) ;
5196
5187
} ) ;
5197
5188
} ;
5198
5189
@@ -5469,34 +5460,25 @@ Worker.prototype.updateProgress = function updateProgress(val, state, n, stack)
5469
5460
/* ----- PROMISE MAPPING ----- */
5470
5461
5471
5462
Worker . prototype . then = function then ( onFulfilled , onRejected ) {
5472
- // Wrap `this` for encapsulation and bind it to the promise handlers .
5463
+ // Wrap `this` for encapsulation.
5473
5464
var self = this ;
5474
- if ( onFulfilled ) {
5475
- onFulfilled = onFulfilled . bind ( self ) ;
5476
- }
5477
- if ( onRejected ) {
5478
- onRejected = onRejected . bind ( self ) ;
5479
- }
5480
5465
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
+ } ) ;
5492
5476
} ) ;
5493
-
5494
- // Return the promise, after casting it into a Worker and preserving props.
5495
- return Worker . convert ( returnVal , self . __proto__ ) ;
5496
5477
} ;
5497
5478
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 ;
5500
5482
5501
5483
// Wrap `this` for encapsulation and bind it to the promise handlers.
5502
5484
var self = this ;
@@ -5508,32 +5490,18 @@ Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected) {
5508
5490
}
5509
5491
5510
5492
// 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 ;
5512
5494
5513
5495
// 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 ) ;
5515
5497
return Worker . convert ( returnVal , self . __proto__ ) ;
5516
5498
} ;
5517
5499
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
-
5527
5500
Worker . prototype . thenExternal = function thenExternal ( onFulfilled , onRejected ) {
5528
5501
// Call `then` and return a standard promise (exits the Worker chain).
5529
5502
return Promise . prototype . then . call ( this , onFulfilled , onRejected ) ;
5530
5503
} ;
5531
5504
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
-
5537
5505
Worker . prototype . thenList = function thenList ( fns ) {
5538
5506
// Queue a series of promise 'factories' into the promise chain.
5539
5507
var self = this ;
@@ -5543,6 +5511,20 @@ Worker.prototype.thenList = function thenList(fns) {
5543
5511
return self ;
5544
5512
} ;
5545
5513
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
+
5546
5528
Worker . prototype . error = function error ( msg ) {
5547
5529
// Throw the error in the Promise chain.
5548
5530
return this . then ( function error_main ( ) {
@@ -5661,17 +5643,34 @@ jspdf_min.getPageSize = function (orientation, unit, format) {
5661
5643
return info ;
5662
5644
} ;
5663
5645
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
+
5664
5663
// Add hyperlink functionality to the PDF creation.
5665
5664
5666
5665
// Main link array, and refs to original functions.
5667
5666
var linkInfo = [ ] ;
5668
- var orig = {
5667
+ var orig$1 = {
5669
5668
toContainer : Worker . prototype . toContainer ,
5670
5669
toPdf : Worker . prototype . toPdf
5671
5670
} ;
5672
5671
5673
5672
Worker . 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 ( ) {
5675
5674
// Retrieve hyperlink info if the option is enabled.
5676
5675
if ( this . opt . enableLinks ) {
5677
5676
// Find all anchor tags and get the container's bounds for reference.
@@ -5701,7 +5700,7 @@ Worker.prototype.toContainer = function toContainer() {
5701
5700
} ;
5702
5701
5703
5702
Worker . 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 ( ) {
5705
5704
// Add hyperlinks if the option is enabled.
5706
5705
if ( this . opt . enableLinks ) {
5707
5706
// Attach each anchor tag based on info from toContainer().
0 commit comments