pdfjs-dist
Version:
Generic build of Mozilla's PDF.js library.
1,595 lines (1,324 loc) • 313 kB
JavaScript
/**
* @licstart The following is the entire license notice for the
* Javascript code in this page
*
* Copyright 2021 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @licend The above is the entire license notice for the
* Javascript code in this page
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("pdfjs-dist/web/pdf_viewer", [], factory);
else if(typeof exports === 'object')
exports["pdfjs-dist/web/pdf_viewer"] = factory();
else
root["pdfjs-dist/web/pdf_viewer"] = root.pdfjsViewer = factory();
})(this, function() {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */,
/* 1 */
/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
var _pdfjsLib = __w_pdfjs_require__(2);
var _l10n_utils = __w_pdfjs_require__(3);
var _pdf_link_service = __w_pdfjs_require__(6);
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var AnnotationLayerBuilder = /*#__PURE__*/function () {
function AnnotationLayerBuilder(_ref) {
var pageDiv = _ref.pageDiv,
pdfPage = _ref.pdfPage,
linkService = _ref.linkService,
downloadManager = _ref.downloadManager,
_ref$annotationStorag = _ref.annotationStorage,
annotationStorage = _ref$annotationStorag === void 0 ? null : _ref$annotationStorag,
_ref$imageResourcesPa = _ref.imageResourcesPath,
imageResourcesPath = _ref$imageResourcesPa === void 0 ? "" : _ref$imageResourcesPa,
_ref$renderInteractiv = _ref.renderInteractiveForms,
renderInteractiveForms = _ref$renderInteractiv === void 0 ? true : _ref$renderInteractiv,
_ref$l10n = _ref.l10n,
l10n = _ref$l10n === void 0 ? _l10n_utils.NullL10n : _ref$l10n,
_ref$enableScripting = _ref.enableScripting,
enableScripting = _ref$enableScripting === void 0 ? false : _ref$enableScripting,
_ref$hasJSActionsProm = _ref.hasJSActionsPromise,
hasJSActionsPromise = _ref$hasJSActionsProm === void 0 ? null : _ref$hasJSActionsProm,
_ref$mouseState = _ref.mouseState,
mouseState = _ref$mouseState === void 0 ? null : _ref$mouseState;
_classCallCheck(this, AnnotationLayerBuilder);
this.pageDiv = pageDiv;
this.pdfPage = pdfPage;
this.linkService = linkService;
this.downloadManager = downloadManager;
this.imageResourcesPath = imageResourcesPath;
this.renderInteractiveForms = renderInteractiveForms;
this.l10n = l10n;
this.annotationStorage = annotationStorage;
this.enableScripting = enableScripting;
this._hasJSActionsPromise = hasJSActionsPromise;
this._mouseState = mouseState;
this.div = null;
this._cancelled = false;
}
_createClass(AnnotationLayerBuilder, [{
key: "render",
value: function render(viewport) {
var _this = this;
var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
return Promise.all([this.pdfPage.getAnnotations({
intent: intent
}), this._hasJSActionsPromise]).then(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
annotations = _ref3[0],
_ref3$ = _ref3[1],
hasJSActions = _ref3$ === void 0 ? false : _ref3$;
if (_this._cancelled) {
return;
}
if (annotations.length === 0) {
return;
}
var parameters = {
viewport: viewport.clone({
dontFlip: true
}),
div: _this.div,
annotations: annotations,
page: _this.pdfPage,
imageResourcesPath: _this.imageResourcesPath,
renderInteractiveForms: _this.renderInteractiveForms,
linkService: _this.linkService,
downloadManager: _this.downloadManager,
annotationStorage: _this.annotationStorage,
enableScripting: _this.enableScripting,
hasJSActions: hasJSActions,
mouseState: _this._mouseState
};
if (_this.div) {
_pdfjsLib.AnnotationLayer.update(parameters);
} else {
_this.div = document.createElement("div");
_this.div.className = "annotationLayer";
_this.pageDiv.appendChild(_this.div);
parameters.div = _this.div;
_pdfjsLib.AnnotationLayer.render(parameters);
_this.l10n.translate(_this.div);
}
});
}
}, {
key: "cancel",
value: function cancel() {
this._cancelled = true;
}
}, {
key: "hide",
value: function hide() {
if (!this.div) {
return;
}
this.div.hidden = true;
}
}]);
return AnnotationLayerBuilder;
}();
exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
var DefaultAnnotationLayerFactory = /*#__PURE__*/function () {
function DefaultAnnotationLayerFactory() {
_classCallCheck(this, DefaultAnnotationLayerFactory);
}
_createClass(DefaultAnnotationLayerFactory, [{
key: "createAnnotationLayerBuilder",
value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
var annotationStorage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var imageResourcesPath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
var renderInteractiveForms = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
var l10n = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _l10n_utils.NullL10n;
var enableScripting = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
var hasJSActionsPromise = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
var mouseState = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
return new AnnotationLayerBuilder({
pageDiv: pageDiv,
pdfPage: pdfPage,
imageResourcesPath: imageResourcesPath,
renderInteractiveForms: renderInteractiveForms,
linkService: new _pdf_link_service.SimpleLinkService(),
l10n: l10n,
annotationStorage: annotationStorage,
enableScripting: enableScripting,
hasJSActionsPromise: hasJSActionsPromise,
mouseState: mouseState
});
}
}]);
return DefaultAnnotationLayerFactory;
}();
exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
/***/ }),
/* 2 */
/***/ ((module) => {
var pdfjsLib;
if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
pdfjsLib = window["pdfjs-dist/build/pdf"];
} else {
pdfjsLib = require("../build/pdf.js");
}
module.exports = pdfjsLib;
/***/ }),
/* 3 */
/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.getL10nFallback = getL10nFallback;
exports.NullL10n = void 0;
var _regenerator = _interopRequireDefault(__w_pdfjs_require__(4));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
var DEFAULT_L10N_STRINGS = {
of_pages: "of {{pagesCount}}",
page_of_pages: "({{pageNumber}} of {{pagesCount}})",
document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
document_properties_date_string: "{{date}}, {{time}}",
document_properties_page_size_unit_inches: "in",
document_properties_page_size_unit_millimeters: "mm",
document_properties_page_size_orientation_portrait: "portrait",
document_properties_page_size_orientation_landscape: "landscape",
document_properties_page_size_name_a3: "A3",
document_properties_page_size_name_a4: "A4",
document_properties_page_size_name_letter: "Letter",
document_properties_page_size_name_legal: "Legal",
document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
document_properties_linearized_yes: "Yes",
document_properties_linearized_no: "No",
print_progress_percent: "{{progress}}%",
"toggle_sidebar.title": "Toggle Sidebar",
"toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
additional_layers: "Additional Layers",
page_landmark: "Page {{page}}",
thumb_page_title: "Page {{page}}",
thumb_page_canvas: "Thumbnail of Page {{page}}",
find_reached_top: "Reached top of document, continued from bottom",
find_reached_bottom: "Reached end of document, continued from top",
"find_match_count[one]": "{{current}} of {{total}} match",
"find_match_count[other]": "{{current}} of {{total}} matches",
"find_match_count_limit[one]": "More than {{limit}} match",
"find_match_count_limit[other]": "More than {{limit}} matches",
find_not_found: "Phrase not found",
error_version_info: "PDF.js v{{version}} (build: {{build}})",
error_message: "Message: {{message}}",
error_stack: "Stack: {{stack}}",
error_file: "File: {{file}}",
error_line: "Line: {{line}}",
rendering_error: "An error occurred while rendering the page.",
page_scale_width: "Page Width",
page_scale_fit: "Page Fit",
page_scale_auto: "Automatic Zoom",
page_scale_actual: "Actual Size",
page_scale_percent: "{{scale}}%",
loading: "Loading…",
loading_error: "An error occurred while loading the PDF.",
invalid_file_error: "Invalid or corrupted PDF file.",
missing_file_error: "Missing PDF file.",
unexpected_response_error: "Unexpected server response.",
printing_not_supported: "Warning: Printing is not fully supported by this browser.",
printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
};
function getL10nFallback(key, args) {
switch (key) {
case "find_match_count":
key = "find_match_count[".concat(args.total === 1 ? "one" : "other", "]");
break;
case "find_match_count_limit":
key = "find_match_count_limit[".concat(args.limit === 1 ? "one" : "other", "]");
break;
}
return DEFAULT_L10N_STRINGS[key] || "";
}
function formatL10nValue(text, args) {
if (!args) {
return text;
}
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
return name in args ? args[name] : "{{" + name + "}}";
});
}
var NullL10n = {
getLanguage: function getLanguage() {
return _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", "en-us");
case 1:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
},
getDirection: function getDirection() {
return _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt("return", "ltr");
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2);
}))();
},
get: function get(key) {
var _arguments = arguments;
return _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
var args, fallback;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
args = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : null;
fallback = _arguments.length > 2 && _arguments[2] !== undefined ? _arguments[2] : getL10nFallback(key, args);
return _context3.abrupt("return", formatL10nValue(fallback, args));
case 3:
case "end":
return _context3.stop();
}
}
}, _callee3);
}))();
},
translate: function translate(element) {
return _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
case "end":
return _context4.stop();
}
}
}, _callee4);
}))();
}
};
exports.NullL10n = NullL10n;
/***/ }),
/* 4 */
/***/ ((module, __unused_webpack_exports, __w_pdfjs_require__) => {
module.exports = __w_pdfjs_require__(5);
/***/ }),
/* 5 */
/***/ ((module, __unused_webpack_exports, __w_pdfjs_require__) => {
/* module decorator */ module = __w_pdfjs_require__.nmd(module);
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var runtime = function (exports) {
"use strict";
var Op = Object.prototype;
var hasOwn = Op.hasOwnProperty;
var undefined;
var $Symbol = typeof Symbol === "function" ? Symbol : {};
var iteratorSymbol = $Symbol.iterator || "@@iterator";
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
return obj[key];
}
try {
define({}, "");
} catch (err) {
define = function define(obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
var generator = Object.create(protoGenerator.prototype);
var context = new Context(tryLocsList || []);
generator._invoke = makeInvokeMethod(innerFn, self, context);
return generator;
}
exports.wrap = wrap;
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
var GenStateSuspendedStart = "suspendedStart";
var GenStateSuspendedYield = "suspendedYield";
var GenStateExecuting = "executing";
var GenStateCompleted = "completed";
var ContinueSentinel = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var IteratorPrototype = {};
IteratorPrototype[iteratorSymbol] = function () {
return this;
};
var getProto = Object.getPrototypeOf;
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
IteratorPrototype = NativeIteratorPrototype;
}
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
GeneratorFunctionPrototype.constructor = GeneratorFunction;
GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
});
}
exports.isGeneratorFunction = function (genFun) {
var ctor = typeof genFun === "function" && genFun.constructor;
return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
};
exports.mark = function (genFun) {
if (Object.setPrototypeOf) {
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
} else {
genFun.__proto__ = GeneratorFunctionPrototype;
define(genFun, toStringTagSymbol, "GeneratorFunction");
}
genFun.prototype = Object.create(Gp);
return genFun;
};
exports.awrap = function (arg) {
return {
__await: arg
};
};
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if (record.type === "throw") {
reject(record.arg);
} else {
var result = record.arg;
var value = result.value;
if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) {
return PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
});
}
return PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped;
resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
}
var previousPromise;
function enqueue(method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
this._invoke = enqueue;
}
defineIteratorMethods(AsyncIterator.prototype);
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
return this;
};
exports.AsyncIterator = AsyncIterator;
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
if (PromiseImpl === void 0) PromiseImpl = Promise;
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
};
function makeInvokeMethod(innerFn, self, context) {
var state = GenStateSuspendedStart;
return function invoke(method, arg) {
if (state === GenStateExecuting) {
throw new Error("Generator is already running");
}
if (state === GenStateCompleted) {
if (method === "throw") {
throw arg;
}
return doneResult();
}
context.method = method;
context.arg = arg;
while (true) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
if (context.method === "next") {
context.sent = context._sent = context.arg;
} else if (context.method === "throw") {
if (state === GenStateSuspendedStart) {
state = GenStateCompleted;
throw context.arg;
}
context.dispatchException(context.arg);
} else if (context.method === "return") {
context.abrupt("return", context.arg);
}
state = GenStateExecuting;
var record = tryCatch(innerFn, self, context);
if (record.type === "normal") {
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
if (record.arg === ContinueSentinel) {
continue;
}
return {
value: record.arg,
done: context.done
};
} else if (record.type === "throw") {
state = GenStateCompleted;
context.method = "throw";
context.arg = record.arg;
}
}
};
}
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (method === undefined) {
context.delegate = null;
if (context.method === "throw") {
if (delegate.iterator["return"]) {
context.method = "return";
context.arg = undefined;
maybeInvokeDelegate(delegate, context);
if (context.method === "throw") {
return ContinueSentinel;
}
}
context.method = "throw";
context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if (record.type === "throw") {
context.method = "throw";
context.arg = record.arg;
context.delegate = null;
return ContinueSentinel;
}
var info = record.arg;
if (!info) {
context.method = "throw";
context.arg = new TypeError("iterator result is not an object");
context.delegate = null;
return ContinueSentinel;
}
if (info.done) {
context[delegate.resultName] = info.value;
context.next = delegate.nextLoc;
if (context.method !== "return") {
context.method = "next";
context.arg = undefined;
}
} else {
return info;
}
context.delegate = null;
return ContinueSentinel;
}
defineIteratorMethods(Gp);
define(Gp, toStringTagSymbol, "Generator");
Gp[iteratorSymbol] = function () {
return this;
};
Gp.toString = function () {
return "[object Generator]";
};
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
if (1 in locs) {
entry.catchLoc = locs[1];
}
if (2 in locs) {
entry.finallyLoc = locs[2];
entry.afterLoc = locs[3];
}
this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal";
delete record.arg;
entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}];
tryLocsList.forEach(pushTryEntry, this);
this.reset(true);
}
exports.keys = function (object) {
var keys = [];
for (var key in object) {
keys.push(key);
}
keys.reverse();
return function next() {
while (keys.length) {
var key = keys.pop();
if (key in object) {
next.value = key;
next.done = false;
return next;
}
}
next.done = true;
return next;
};
};
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) {
return iteratorMethod.call(iterable);
}
if (typeof iterable.next === "function") {
return iterable;
}
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
while (++i < iterable.length) {
if (hasOwn.call(iterable, i)) {
next.value = iterable[i];
next.done = false;
return next;
}
}
next.value = undefined;
next.done = true;
return next;
};
return next.next = next;
}
}
return {
next: doneResult
};
}
exports.values = values;
function doneResult() {
return {
value: undefined,
done: true
};
}
Context.prototype = {
constructor: Context,
reset: function reset(skipTempReset) {
this.prev = 0;
this.next = 0;
this.sent = this._sent = undefined;
this.done = false;
this.delegate = null;
this.method = "next";
this.arg = undefined;
this.tryEntries.forEach(resetTryEntry);
if (!skipTempReset) {
for (var name in this) {
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
this[name] = undefined;
}
}
}
},
stop: function stop() {
this.done = true;
var rootEntry = this.tryEntries[0];
var rootRecord = rootEntry.completion;
if (rootRecord.type === "throw") {
throw rootRecord.arg;
}
return this.rval;
},
dispatchException: function dispatchException(exception) {
if (this.done) {
throw exception;
}
var context = this;
function handle(loc, caught) {
record.type = "throw";
record.arg = exception;
context.next = loc;
if (caught) {
context.method = "next";
context.arg = undefined;
}
return !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
var record = entry.completion;
if (entry.tryLoc === "root") {
return handle("end");
}
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc");
var hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) {
return handle(entry.catchLoc, true);
} else if (this.prev < entry.finallyLoc) {
return handle(entry.finallyLoc);
}
} else if (hasCatch) {
if (this.prev < entry.catchLoc) {
return handle(entry.catchLoc, true);
}
} else if (hasFinally) {
if (this.prev < entry.finallyLoc) {
return handle(entry.finallyLoc);
}
} else {
throw new Error("try statement without catch or finally");
}
}
}
},
abrupt: function abrupt(type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
finallyEntry = null;
}
var record = finallyEntry ? finallyEntry.completion : {};
record.type = type;
record.arg = arg;
if (finallyEntry) {
this.method = "next";
this.next = finallyEntry.finallyLoc;
return ContinueSentinel;
}
return this.complete(record);
},
complete: function complete(record, afterLoc) {
if (record.type === "throw") {
throw record.arg;
}
if (record.type === "break" || record.type === "continue") {
this.next = record.arg;
} else if (record.type === "return") {
this.rval = this.arg = record.arg;
this.method = "return";
this.next = "end";
} else if (record.type === "normal" && afterLoc) {
this.next = afterLoc;
}
return ContinueSentinel;
},
finish: function finish(finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) {
this.complete(entry.completion, entry.afterLoc);
resetTryEntry(entry);
return ContinueSentinel;
}
}
},
"catch": function _catch(tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
if (record.type === "throw") {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
};
if (this.method === "next") {
this.arg = undefined;
}
return ContinueSentinel;
}
};
return exports;
}(( false ? 0 : _typeof(module)) === "object" ? module.exports : {});
try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
Function("r", "regeneratorRuntime = r")(runtime);
}
/***/ }),
/* 6 */
/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.SimpleLinkService = exports.PDFLinkService = void 0;
var _regenerator = _interopRequireDefault(__w_pdfjs_require__(4));
var _ui_utils = __w_pdfjs_require__(7);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var PDFLinkService = /*#__PURE__*/function () {
function PDFLinkService() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
eventBus = _ref.eventBus,
_ref$externalLinkTarg = _ref.externalLinkTarget,
externalLinkTarget = _ref$externalLinkTarg === void 0 ? null : _ref$externalLinkTarg,
_ref$externalLinkRel = _ref.externalLinkRel,
externalLinkRel = _ref$externalLinkRel === void 0 ? null : _ref$externalLinkRel,
_ref$externalLinkEnab = _ref.externalLinkEnabled,
externalLinkEnabled = _ref$externalLinkEnab === void 0 ? true : _ref$externalLinkEnab,
_ref$ignoreDestinatio = _ref.ignoreDestinationZoom,
ignoreDestinationZoom = _ref$ignoreDestinatio === void 0 ? false : _ref$ignoreDestinatio;
_classCallCheck(this, PDFLinkService);
this.eventBus = eventBus;
this.externalLinkTarget = externalLinkTarget;
this.externalLinkRel = externalLinkRel;
this.externalLinkEnabled = externalLinkEnabled;
this._ignoreDestinationZoom = ignoreDestinationZoom;
this.baseUrl = null;
this.pdfDocument = null;
this.pdfViewer = null;
this.pdfHistory = null;
this._pagesRefCache = null;
}
_createClass(PDFLinkService, [{
key: "setDocument",
value: function setDocument(pdfDocument) {
var baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
this.baseUrl = baseUrl;
this.pdfDocument = pdfDocument;
this._pagesRefCache = Object.create(null);
}
}, {
key: "setViewer",
value: function setViewer(pdfViewer) {
this.pdfViewer = pdfViewer;
}
}, {
key: "setHistory",
value: function setHistory(pdfHistory) {
this.pdfHistory = pdfHistory;
}
}, {
key: "pagesCount",
get: function get() {
return this.pdfDocument ? this.pdfDocument.numPages : 0;
}
}, {
key: "page",
get: function get() {
return this.pdfViewer.currentPageNumber;
},
set: function set(value) {
this.pdfViewer.currentPageNumber = value;
}
}, {
key: "rotation",
get: function get() {
return this.pdfViewer.pagesRotation;
},
set: function set(value) {
this.pdfViewer.pagesRotation = value;
}
}, {
key: "navigateTo",
value: function navigateTo(dest) {
console.error("Deprecated method: `navigateTo`, use `goToDestination` instead.");
this.goToDestination(dest);
}
}, {
key: "_goToDestinationHelper",
value: function _goToDestinationHelper(rawDest) {
var _this = this;
var namedDest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var explicitDest = arguments.length > 2 ? arguments[2] : undefined;
var destRef = explicitDest[0];
var pageNumber;
if (destRef instanceof Object) {
pageNumber = this._cachedPageNumber(destRef);
if (pageNumber === null) {
this.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
_this.cachePageRef(pageIndex + 1, destRef);
_this._goToDestinationHelper(rawDest, namedDest, explicitDest);
})["catch"](function () {
console.error("PDFLinkService._goToDestinationHelper: \"".concat(destRef, "\" is not ") + "a valid page reference, for dest=\"".concat(rawDest, "\"."));
});
return;
}
} else if (Number.isInteger(destRef)) {
pageNumber = destRef + 1;
} else {
console.error("PDFLinkService._goToDestinationHelper: \"".concat(destRef, "\" is not ") + "a valid destination reference, for dest=\"".concat(rawDest, "\"."));
return;
}
if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
console.error("PDFLinkService._goToDestinationHelper: \"".concat(pageNumber, "\" is not ") + "a valid page number, for dest=\"".concat(rawDest, "\"."));
return;
}
if (this.pdfHistory) {
this.pdfHistory.pushCurrentPosition();
this.pdfHistory.push({
namedDest: namedDest,
explicitDest: explicitDest,
pageNumber: pageNumber
});
}
this.pdfViewer.scrollPageIntoView({
pageNumber: pageNumber,
destArray: explicitDest,
ignoreDestinationZoom: this._ignoreDestinationZoom
});
}
}, {
key: "goToDestination",
value: function () {
var _goToDestination = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee(dest) {
var namedDest, explicitDest;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (this.pdfDocument) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
if (!(typeof dest === "string")) {
_context.next = 9;
break;
}
namedDest = dest;
_context.next = 6;
return this.pdfDocument.getDestination(dest);
case 6:
explicitDest = _context.sent;
_context.next = 13;
break;
case 9:
namedDest = null;
_context.next = 12;
return dest;
case 12:
explicitDest = _context.sent;
case 13:
if (Array.isArray(explicitDest)) {
_context.next = 16;
break;
}
console.error("PDFLinkService.goToDestination: \"".concat(explicitDest, "\" is not ") + "a valid destination array, for dest=\"".concat(dest, "\"."));
return _context.abrupt("return");
case 16:
this._goToDestinationHelper(dest, namedDest, explicitDest);
case 17:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function goToDestination(_x) {
return _goToDestination.apply(this, arguments);
}
return goToDestination;
}()
}, {
key: "goToPage",
value: function goToPage(val) {
if (!this.pdfDocument) {
return;
}
var pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
console.error("PDFLinkService.goToPage: \"".concat(val, "\" is not a valid page."));
return;
}
if (this.pdfHistory) {
this.pdfHistory.pushCurrentPosition();
this.pdfHistory.pushPage(pageNumber);
}
this.pdfViewer.scrollPageIntoView({
pageNumber: pageNumber
});
}
}, {
key: "getDestinationHash",
value: function getDestinationHash(dest) {
if (typeof dest === "string") {
if (dest.length > 0) {
return this.getAnchorUrl("#" + escape(dest));
}
} else if (Array.isArray(dest)) {
var str = JSON.stringify(dest);
if (str.length > 0) {
return this.getAnchorUrl("#" + escape(str));
}
}
return this.getAnchorUrl("");
}
}, {
key: "getAnchorUrl",
value: function getAnchorUrl(anchor) {
return (this.baseUrl || "") + anchor;
}
}, {
key: "setHash",
value: function setHash(hash) {
if (!this.pdfDocument) {
return;
}
var pageNumber, dest;
if (hash.includes("=")) {
var params = (0, _ui_utils.parseQueryString)(hash);
if ("search" in params) {
this.eventBus.dispatch("findfromurlhash", {
source: this,
query: params.search.replace(/"/g, ""),
phraseSearch: params.phrase === "true"
});
}
if ("page" in params) {
pageNumber = params.page | 0 || 1;
}
if ("zoom" in params) {
var zoomArgs = params.zoom.split(",");
var zoomArg = zoomArgs[0];
var zoomArgNumber = parseFloat(zoomArg);
if (!zoomArg.includes("Fit")) {
dest = [null, {
name: "XYZ"
}, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
} else {
if (zoomArg === "Fit" || zoomArg === "FitB") {
dest = [null, {
name: zoomArg
}];
} else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
dest = [null, {
name: zoomArg
}, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
} else if (zoomArg === "FitR") {
if (zoomArgs.length !== 5) {
console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
} else {
dest = [null, {
name: zoomArg
}, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
}
} else {
console.error("PDFLinkService.setHash: \"".concat(zoomArg, "\" is not ") + "a valid zoom value.");
}
}
}
if (dest) {
this.pdfViewer.scrollPageIntoView({
pageNumber: pageNumber || this.page,
destArray: dest,
allowNegativeOffset: true
});
} else if (pageNumber) {
this.page = pageNumber;
}
if ("pagemode" in params) {
this.eventBus.dispatch("pagemode", {
source: this,
mode: params.pagemode
});
}
if ("nameddest" in params) {
this.goToDestination(params.nameddest);
}
} else {
dest = unescape(hash);
try {
dest = JSON.parse(dest);
if (!Array.isArray(dest)) {
dest = dest.toString();
}
} catch (ex) {}
if (typeof dest === "string" || isValidExplicitDestination(dest)) {
this.goToDestination(dest);
return;
}
console.error("PDFLinkService.setHash: \"".concat(unescape(hash), "\" is not ") + "a valid destination.");
}
}
}, {
key: "executeNamedAction",
value: function executeNamedAction(action) {
switch (action) {
case "GoBack":
if (this.pdfHistory) {
this.pdfHistory.back();
}
break;
case "GoForward":
if (this.pdfHistory) {
this.pdfHistory.forward();
}
break;
case "NextPage":
this.pdfViewer.nextPage();
break;
case "PrevPage":
this.pdfViewer.previousPage();
break;
case "LastPage":
this.page = this.pagesCount;
break;
case "FirstPage":
this.page = 1;
break;
default:
break;
}
this.eventBus.dispatch("namedaction", {
source: this,
action: action
});
}
}, {
key: "cachePageRef",
value: function cachePageRef(pageNum, pageRef) {
if (!pageRef) {
return;
}
var refStr = pageRef.gen === 0 ? "".concat(pageRef.num, "R") : "".concat(pageRef.num, "R").concat(pageRef.gen);
this._pagesRefCache[refStr] = pageNum;
}
}, {
key: "_cachedPageNumber",
value: function _cachedPageNumber(pageRef) {
var _this$_pagesRefCache;
var refStr = pageRef.gen === 0 ? "".concat(pageRef.num, "R") : "".concat(pageRef.num, "R").concat(pageRef.gen);
return ((_this$_pagesRefCache = this._pagesRefCache) === null || _this$_pagesRefCache === void 0 ? void 0 : _this$_pagesRefCache[refStr]) || null;
}
}, {
key: "isPageVisible",
value: function isPageVisible(pageNumber) {
return this.pdfViewer.isPageVisible(pageNumber);
}
}, {
key: "isPageCached",
value: function isPageCached(pageNumber) {
return this.pdfViewer.isPageCached(pageNumber);
}
}]);
return PDFLinkService;
}();
exports.PDFLinkService = PDFLinkService;
function isValidExplicitDestination(dest) {
if (!Array.isArray(dest)) {
return false;
}
var destLength = dest.length;
if (destLength < 2) {
return false;
}
var page = dest[0];
if (!(_typeof(page) === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
return false;
}
var zoom = dest[1];
if (!(_typeof(zoom) === "object" && typeof zoom.name === "string")) {
return false;
}
var allowNull = true;
switch (zoom.name) {
case "XYZ":
if (destLength !== 5) {
return false;
}
break;
case "Fit":
case "FitB":
return destLength === 2;
case "FitH":
case "FitBH":
case "FitV":
case "FitBV":
if (destLength !== 3) {
return false;
}
break;
case "FitR":
if (destLength !== 6) {
return false;
}
allowNull = false;
break;
default:
return false;
}
for (var i = 2; i < destLength; i++) {
var param = dest[i];
if (!(typeof param === "number" || allowNull && param === null)) {
return false;
}
}
return true;
}
var SimpleLinkService = /*#__PURE__*/function () {
function SimpleLinkService() {
_classCallCheck(this, SimpleLinkService);
this.externalLinkTarget = null;
this.externalLinkRel = null;
this.externalLinkEnabled = true;
this._ignoreDestinationZoom = false;
}
_createClass(SimpleLinkService, [{
key: "pagesCount",
get: function get() {
return 0;
}
}, {
key: "page",
get: function get() {
return 0;
},
set: function set(value) {}
}, {
key: "rotation",
get: function get() {
return 0;
},
set: function set(value) {}
}, {
key: "goToDestination",
value: function () {
var _goToDestination2 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee2(dest) {
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function goToDestination(_x2) {
return _goToDestination2.apply(this, arguments);
}
return goToDestination;
}()
}, {
key: "goToPage",
value: function goToPage(val) {}
}, {
key: "getDestinationHash",
value: function getDestinationHash(dest) {
return "#";
}
}, {
key: "getAnchorUrl",
value: function getAnchorUrl(hash) {
return "#";
}
}, {
key: "setHash",
value: function setHash(hash) {}
}, {
key: "executeNamedAction",
value: function executeNamedAction(action) {}
}, {
key: "cachePageRef",
value: function cachePageRef(pageNum, pageRef) {}
}, {
key: "isPageVisible",
value: function isPageVisible(pageNumber) {
return true;
}
}, {
key: "isPageCached",
value: function isPageCached(pageNumber) {
return true;
}
}]);
return SimpleLinkService;
}();
exports.