|
@@ -19,14 +19,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
});
|
|
|
exports.PDFThumbnailView = undefined;
|
|
|
|
|
|
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
+
|
|
|
var _pdf = require('../pdf');
|
|
|
|
|
|
var _ui_utils = require('./ui_utils');
|
|
|
|
|
|
var _pdf_rendering_queue = require('./pdf_rendering_queue');
|
|
|
|
|
|
-var THUMBNAIL_WIDTH = 98;
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
+
|
|
|
+var MAX_NUM_SCALING_STEPS = 3;
|
|
|
var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
|
|
|
+var THUMBNAIL_WIDTH = 98;
|
|
|
var TempImageFactory = function TempImageFactoryClosure() {
|
|
|
var tempCanvasCache = null;
|
|
|
return {
|
|
@@ -56,14 +61,21 @@ var TempImageFactory = function TempImageFactoryClosure() {
|
|
|
}
|
|
|
};
|
|
|
}();
|
|
|
-var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
- function PDFThumbnailView(options) {
|
|
|
- var container = options.container;
|
|
|
- var id = options.id;
|
|
|
- var defaultViewport = options.defaultViewport;
|
|
|
- var linkService = options.linkService;
|
|
|
- var renderingQueue = options.renderingQueue;
|
|
|
- var disableCanvasToImageConversion = options.disableCanvasToImageConversion || false;
|
|
|
+
|
|
|
+var PDFThumbnailView = function () {
|
|
|
+ function PDFThumbnailView(_ref) {
|
|
|
+ var container = _ref.container,
|
|
|
+ id = _ref.id,
|
|
|
+ defaultViewport = _ref.defaultViewport,
|
|
|
+ linkService = _ref.linkService,
|
|
|
+ renderingQueue = _ref.renderingQueue,
|
|
|
+ _ref$disableCanvasToI = _ref.disableCanvasToImageConversion,
|
|
|
+ disableCanvasToImageConversion = _ref$disableCanvasToI === undefined ? false : _ref$disableCanvasToI,
|
|
|
+ _ref$l10n = _ref.l10n,
|
|
|
+ l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
|
|
|
+
|
|
|
+ _classCallCheck(this, PDFThumbnailView);
|
|
|
+
|
|
|
this.id = id;
|
|
|
this.renderingId = 'thumbnail' + id;
|
|
|
this.pageLabel = null;
|
|
@@ -83,13 +95,13 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
this.canvasWidth = THUMBNAIL_WIDTH;
|
|
|
this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
|
|
|
this.scale = this.canvasWidth / this.pageWidth;
|
|
|
- this.l10n = options.l10n || _ui_utils.NullL10n;
|
|
|
+ this.l10n = l10n;
|
|
|
var anchor = document.createElement('a');
|
|
|
anchor.href = linkService.getAnchorUrl('#page=' + id);
|
|
|
this.l10n.get('thumb_page_title', { page: id }, 'Page {{page}}').then(function (msg) {
|
|
|
anchor.title = msg;
|
|
|
});
|
|
|
- anchor.onclick = function stopNavigation() {
|
|
|
+ anchor.onclick = function () {
|
|
|
linkService.page = id;
|
|
|
return false;
|
|
|
};
|
|
@@ -111,15 +123,19 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
anchor.appendChild(div);
|
|
|
container.appendChild(anchor);
|
|
|
}
|
|
|
- PDFThumbnailView.prototype = {
|
|
|
- setPdfPage: function PDFThumbnailView_setPdfPage(pdfPage) {
|
|
|
+
|
|
|
+ _createClass(PDFThumbnailView, [{
|
|
|
+ key: 'setPdfPage',
|
|
|
+ value: function setPdfPage(pdfPage) {
|
|
|
this.pdfPage = pdfPage;
|
|
|
this.pdfPageRotate = pdfPage.rotate;
|
|
|
var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
|
this.viewport = pdfPage.getViewport(1, totalRotation);
|
|
|
this.reset();
|
|
|
- },
|
|
|
- reset: function PDFThumbnailView_reset() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'reset',
|
|
|
+ value: function reset() {
|
|
|
this.cancelRendering();
|
|
|
this.pageWidth = this.viewport.width;
|
|
|
this.pageHeight = this.viewport.height;
|
|
@@ -144,8 +160,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
this.image.removeAttribute('src');
|
|
|
delete this.image;
|
|
|
}
|
|
|
- },
|
|
|
- update: function PDFThumbnailView_update(rotation) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'update',
|
|
|
+ value: function update(rotation) {
|
|
|
if (typeof rotation !== 'undefined') {
|
|
|
this.rotation = rotation;
|
|
|
}
|
|
@@ -155,16 +173,22 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
rotation: totalRotation
|
|
|
});
|
|
|
this.reset();
|
|
|
- },
|
|
|
- cancelRendering: function PDFThumbnailView_cancelRendering() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'cancelRendering',
|
|
|
+ value: function cancelRendering() {
|
|
|
if (this.renderTask) {
|
|
|
this.renderTask.cancel();
|
|
|
this.renderTask = null;
|
|
|
}
|
|
|
this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
|
|
|
this.resume = null;
|
|
|
- },
|
|
|
- _getPageDrawContext: function PDFThumbnailView_getPageDrawContext(noCtxScale) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_getPageDrawContext',
|
|
|
+ value: function _getPageDrawContext() {
|
|
|
+ var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+
|
|
|
var canvas = document.createElement('canvas');
|
|
|
this.canvas = canvas;
|
|
|
canvas.mozOpaque = true;
|
|
@@ -178,8 +202,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
ctx.scale(outputScale.sx, outputScale.sy);
|
|
|
}
|
|
|
return ctx;
|
|
|
- },
|
|
|
- _convertCanvasToImage: function PDFThumbnailView_convertCanvasToImage() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_convertCanvasToImage',
|
|
|
+ value: function _convertCanvasToImage() {
|
|
|
var _this = this;
|
|
|
|
|
|
if (!this.canvas) {
|
|
@@ -215,8 +241,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
this.canvas.width = 0;
|
|
|
this.canvas.height = 0;
|
|
|
delete this.canvas;
|
|
|
- },
|
|
|
- draw: function draw() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'draw',
|
|
|
+ value: function draw() {
|
|
|
var _this2 = this;
|
|
|
|
|
|
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
|
@@ -266,9 +294,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
finishRenderTask(error);
|
|
|
});
|
|
|
return renderCapability.promise;
|
|
|
- },
|
|
|
-
|
|
|
- setImage: function PDFThumbnailView_setImage(pageView) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'setImage',
|
|
|
+ value: function setImage(pageView) {
|
|
|
if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
|
|
|
return;
|
|
|
}
|
|
@@ -287,7 +316,6 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
this._convertCanvasToImage();
|
|
|
return;
|
|
|
}
|
|
|
- var MAX_NUM_SCALING_STEPS = 3;
|
|
|
var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
|
var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
|
var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
@@ -304,11 +332,10 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
}
|
|
|
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
|
|
this._convertCanvasToImage();
|
|
|
- },
|
|
|
- get pageId() {
|
|
|
- return this.pageLabel !== null ? this.pageLabel : this.id;
|
|
|
- },
|
|
|
- setPageLabel: function PDFThumbnailView_setPageLabel(label) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'setPageLabel',
|
|
|
+ value: function setPageLabel(label) {
|
|
|
var _this3 = this;
|
|
|
|
|
|
this.pageLabel = typeof label === 'string' ? label : null;
|
|
@@ -326,10 +353,19 @@ var PDFThumbnailView = function PDFThumbnailViewClosure() {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- };
|
|
|
- PDFThumbnailView.cleanup = function () {
|
|
|
- TempImageFactory.destroyCanvas();
|
|
|
- };
|
|
|
+ }, {
|
|
|
+ key: 'pageId',
|
|
|
+ get: function get() {
|
|
|
+ return this.pageLabel !== null ? this.pageLabel : this.id;
|
|
|
+ }
|
|
|
+ }], [{
|
|
|
+ key: 'cleanup',
|
|
|
+ value: function cleanup() {
|
|
|
+ TempImageFactory.destroyCanvas();
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+
|
|
|
return PDFThumbnailView;
|
|
|
}();
|
|
|
+
|
|
|
exports.PDFThumbnailView = PDFThumbnailView;
|