Skip to content

Commit 7196259

Browse files
committed
Rebuild with Angular fix and minor improvements
1 parent 74140d2 commit 7196259

File tree

6 files changed

+202
-206
lines changed

6 files changed

+202
-206
lines changed

dist/html2pdf.bundle.js

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -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

54715462
Worker.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-
55275500
Worker.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-
55375505
Worker.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+
55465528
Worker.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.
56675666
var linkInfo = [];
5668-
var orig = {
5667+
var orig$1 = {
56695668
toContainer: Worker.prototype.toContainer,
56705669
toPdf: Worker.prototype.toPdf
56715670
};
56725671

56735672
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() {
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

57035702
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() {
57055704
// Add hyperlinks if the option is enabled.
57065705
if (this.opt.enableLinks) {
57075706
// Attach each anchor tag based on info from toContainer().

dist/html2pdf.bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/html2pdf.js

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,6 @@ Worker.prototype.toContainer = function toContainer() {
243243
this.prop.container.appendChild(source);
244244
this.prop.overlay.appendChild(this.prop.container);
245245
document.body.appendChild(this.prop.overlay);
246-
247-
// Enable page-breaks.
248-
var pageBreaks = source.querySelectorAll('.html2pdf__page-break');
249-
var pxPageHeight = this.prop.pageSize.inner.px.height;
250-
Array.prototype.forEach.call(pageBreaks, function pageBreak_loop(el) {
251-
el.style.display = 'block';
252-
var clientRect = el.getBoundingClientRect();
253-
el.style.height = pxPageHeight - clientRect.top % pxPageHeight + 'px';
254-
}, this);
255246
});
256247
};
257248

@@ -528,34 +519,25 @@ Worker.prototype.updateProgress = function updateProgress(val, state, n, stack)
528519
/* ----- PROMISE MAPPING ----- */
529520

530521
Worker.prototype.then = function then(onFulfilled, onRejected) {
531-
// Wrap `this` for encapsulation and bind it to the promise handlers.
522+
// Wrap `this` for encapsulation.
532523
var self = this;
533-
if (onFulfilled) {
534-
onFulfilled = onFulfilled.bind(self);
535-
}
536-
if (onRejected) {
537-
onRejected = onRejected.bind(self);
538-
}
539524

540-
// Cast self into a Promise to avoid polyfills recursively defining `then`.
541-
var selfPromise = Promise.toString().indexOf('[native code]') === -1 ? Worker.convert(_extends({}, self), Promise.prototype) : self;
542-
543-
// Update progress while queuing, calling, and resolving `then`.
544-
self.updateProgress(null, null, 1, [onFulfilled]);
545-
var returnVal = Promise.prototype.then.call(selfPromise, function then_pre(val) {
546-
self.updateProgress(null, onFulfilled);
547-
return val;
548-
}).then(onFulfilled, onRejected).then(function then_post(val) {
549-
self.updateProgress(1);
550-
return val;
525+
return this.thenCore(onFulfilled, onRejected, function then_main(onFulfilled, onRejected) {
526+
// Update progress while queuing, calling, and resolving `then`.
527+
self.updateProgress(null, null, 1, [onFulfilled]);
528+
return Promise.prototype.then.call(this, function then_pre(val) {
529+
self.updateProgress(null, onFulfilled);
530+
return val;
531+
}).then(onFulfilled, onRejected).then(function then_post(val) {
532+
self.updateProgress(1);
533+
return val;
534+
});
551535
});
552-
553-
// Return the promise, after casting it into a Worker and preserving props.
554-
return Worker.convert(returnVal, self.__proto__);
555536
};
556537

557-
Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected) {
558-
// Core version of then, with no updates to progress.
538+
Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected, thenBase) {
539+
// Handle optional thenBase parameter.
540+
thenBase = thenBase || Promise.prototype.then;
559541

560542
// Wrap `this` for encapsulation and bind it to the promise handlers.
561543
var self = this;
@@ -567,32 +549,18 @@ Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected) {
567549
}
568550

569551
// Cast self into a Promise to avoid polyfills recursively defining `then`.
570-
var selfPromise = Promise.toString().indexOf('[native code]') === -1 ? Worker.convert(_extends({}, self), Promise.prototype) : self;
552+
var selfPromise = Promise.toString() !== 'function Promise() { [native code] }' ? Worker.convert(_extends({}, self), Promise.prototype) : self;
571553

572554
// Return the promise, after casting it into a Worker and preserving props.
573-
var returnVal = Promise.prototype.then.call(selfPromise, onFulfilled, onRejected);
555+
var returnVal = thenBase.call(selfPromise, onFulfilled, onRejected);
574556
return Worker.convert(returnVal, self.__proto__);
575557
};
576558

577-
Worker.prototype['catch'] = function (onRejected) {
578-
// Bind `this` to the promise handler, call `catch`, and return a Worker.
579-
if (onRejected) {
580-
onRejected = onRejected.bind(this);
581-
}
582-
var returnVal = Promise.prototype['catch'].call(this, onRejected);
583-
return Worker.convert(returnVal, this);
584-
};
585-
586559
Worker.prototype.thenExternal = function thenExternal(onFulfilled, onRejected) {
587560
// Call `then` and return a standard promise (exits the Worker chain).
588561
return Promise.prototype.then.call(this, onFulfilled, onRejected);
589562
};
590563

591-
Worker.prototype.catchExternal = function catchExternal(onRejected) {
592-
// Call `catch` and return a standard promise (exits the Worker chain).
593-
return Promise.prototype['catch'].call(this, onRejected);
594-
};
595-
596564
Worker.prototype.thenList = function thenList(fns) {
597565
// Queue a series of promise 'factories' into the promise chain.
598566
var self = this;
@@ -602,6 +570,20 @@ Worker.prototype.thenList = function thenList(fns) {
602570
return self;
603571
};
604572

573+
Worker.prototype['catch'] = function (onRejected) {
574+
// Bind `this` to the promise handler, call `catch`, and return a Worker.
575+
if (onRejected) {
576+
onRejected = onRejected.bind(this);
577+
}
578+
var returnVal = Promise.prototype['catch'].call(this, onRejected);
579+
return Worker.convert(returnVal, this);
580+
};
581+
582+
Worker.prototype.catchExternal = function catchExternal(onRejected) {
583+
// Call `catch` and return a standard promise (exits the Worker chain).
584+
return Promise.prototype['catch'].call(this, onRejected);
585+
};
586+
605587
Worker.prototype.error = function error(msg) {
606588
// Throw the error in the Promise chain.
607589
return this.then(function error_main() {
@@ -720,17 +702,34 @@ jsPDF.getPageSize = function (orientation, unit, format) {
720702
return info;
721703
};
722704

705+
var orig = {
706+
toContainer: Worker.prototype.toContainer
707+
};
708+
709+
Worker.prototype.toContainer = function toContainer() {
710+
return orig.toContainer.call(this).then(function toContainer_pagebreak() {
711+
// Enable page-breaks.
712+
var pageBreaks = this.prop.container.querySelectorAll('.html2pdf__page-break');
713+
var pxPageHeight = this.prop.pageSize.inner.px.height;
714+
Array.prototype.forEach.call(pageBreaks, function pageBreak_loop(el) {
715+
el.style.display = 'block';
716+
var clientRect = el.getBoundingClientRect();
717+
el.style.height = pxPageHeight - clientRect.top % pxPageHeight + 'px';
718+
}, this);
719+
});
720+
};
721+
723722
// Add hyperlink functionality to the PDF creation.
724723

725724
// Main link array, and refs to original functions.
726725
var linkInfo = [];
727-
var orig = {
726+
var orig$1 = {
728727
toContainer: Worker.prototype.toContainer,
729728
toPdf: Worker.prototype.toPdf
730729
};
731730

732731
Worker.prototype.toContainer = function toContainer() {
733-
return orig.toContainer.call(this).then(function toContainer_hyperlink() {
732+
return orig$1.toContainer.call(this).then(function toContainer_hyperlink() {
734733
// Retrieve hyperlink info if the option is enabled.
735734
if (this.opt.enableLinks) {
736735
// Find all anchor tags and get the container's bounds for reference.
@@ -760,7 +759,7 @@ Worker.prototype.toContainer = function toContainer() {
760759
};
761760

762761
Worker.prototype.toPdf = function toPdf() {
763-
return orig.toPdf.call(this).then(function toPdf_hyperlink() {
762+
return orig$1.toPdf.call(this).then(function toPdf_hyperlink() {
764763
// Add hyperlinks if the option is enabled.
765764
if (this.opt.enableLinks) {
766765
// Attach each anchor tag based on info from toContainer().

0 commit comments

Comments
 (0)